Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Field docs are ignored #910

Closed
danfuzz opened this issue Aug 29, 2022 · 2 comments
Closed

Field docs are ignored #910

danfuzz opened this issue Aug 29, 2022 · 2 comments

Comments

@danfuzz
Copy link

danfuzz commented Aug 29, 2022

Expected behavior

Documentation comments on field declarations — e.g. foo; or #foo = ...; etc. at the top level scope of a class — are scrutinized for valid doc comments, including feeding types into the "unused variable" calculations.

Actual behavior

Field declarations seem to be entirely ignored, for all combos of {public, private} x {static, instance}.

ESLint Config

module.exports = {
  extends: [
    "eslint:recommended",
    "plugin:jsdoc/recommended"
  ],
  plugins: ["jsdoc"],
  parserOptions: {
    "sourceType": "module",
    "ecmaVersion": "2022"
  }
};

ESLint sample

import * as net from 'node:net';

/** Likes are now florps. */
export class Florp {
  /** {net.Server} A server. */
  #privateField = null;

  /** {net.Server} A server. */
  publicField = null;

  /** {net.Server} A server. */
  static #privateStatic = null;

  /** {net.Server} A server. */
  static publicStatic = null;
}

Error:

$ ./node_modules/.bin/eslint Test.js 

/Users/danfuzz/tmp/linty/Test.js
  1:13  error  'net' is defined but never used  no-unused-vars

✖ 1 problem (1 error, 0 warnings)

Environment

  • Node version: 18.7.0
  • ESLint version 8.22.0
  • eslint-plugin-jsdoc version: 39.3.6
@brettz9
Copy link
Collaborator

brettz9 commented Aug 30, 2022

I am not aware of JSDoc types being used as you have done without an initial tag name. (I believe doing so would be ambiguous with curly brackets used as part of a block's main description text.)

If you add a tag, e.g.:

/** @type {net.Server} A server. */

...and then use it with plugin:jsdoc/recommended as you were doing (or with just the jsdoc/no-undefined-types rule which is currently responsible for marking JSDoc variables as used), no error should be reported.

FWIW, you may also wish to subscribe to #858 because we really should be moving to our own separate jsdoc/no-unused-vars rule rather than marking variables as used when our jsdoc/no-undefined-types is enabled. But for now, adding a tag name should resolve.

Closing as that should resolve, but feel free to comment further.

@brettz9 brettz9 closed this as completed Aug 30, 2022
@danfuzz
Copy link
Author

danfuzz commented Aug 31, 2022

The last time I used JSDoc annotations was before class fields were settled syntax, and I just went with what seemed to me to be sensible (like, what else would I be documenting directly above a field declaration?). But that's on me and my faulty headcanon.

Thanks for the explanation! And sorry for the trouble.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants