gajus / eslint-plugin-jsdoc

JSDoc specific linting rules for ESLint.
Other
1.09k stars 157 forks source link

@type is not always redundant when using a type system #1142

Closed Lalem001 closed 1 year ago

Lalem001 commented 1 year ago

Expected behavior

Some types are generics and the default value for the generic variables, if they exist, may not be correct for the usage. An example would be setting the ExecutionContext in AVA's test function:

/**
 * @typedef Context
 * @property {number} foo
 */
const test = /** @type {import('ava').TestFn<Context>} */ (require('ava').default);

test.before((t) => {
  t.context.foo = 42;
});

Typescript marks the above code as valid, and code suggestions work as expected.

Actual behavior

ESLint as configured below, shows a warning for the line t.context.foo = 42;. The warning is: '@type' is redundant when using a type system jsdoc/check-tag-names

If you remove the @type declaration, then:

ESLint Config

{
  "extends": [
    "plugin:jsdoc/recommended-typescript"
  ]
}

ESLint sample

See the example in Expected behavior above

Environment

brettz9 commented 1 year ago

I think the idea is to use as type-assertions instead of a @type tag: https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#type-assertions

Lalem001 commented 1 year ago

I think the idea is to use as type-assertions instead of a @type tag: https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#type-assertions

I am not writing in Typescript though. I am writing in JavaScript with JSDoc, and type checking with TS. This way there is no compile step for running in node.

Lalem001 commented 1 year ago

Am I using the wrong configuration?

brettz9 commented 1 year ago

You should be using plugin:jsdoc/recommended-typescript-flavor instead.

Lalem001 commented 1 year ago

Indeed. Thanks for the help.