-
-
Notifications
You must be signed in to change notification settings - Fork 158
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
Add a TypeScript config for mixed TS/JS projects #1101
Comments
I like the idea, but I might note that the job has already been made considerably easier by letting the typescript configs--including a new one for typescript-flavor which works on plain JavaScript and does not exclude types--exclude I'm in favor of a config which handles the But I do think it is useful to have one config to handle it for people. |
We had problems with our JavaScript only code base flagging up warnings like so...
Using the TypeScript recommended fix solved the warning, but JSDoc itself treats it as a syntax error. The solution ultimately was to change the setting settings: {
jsdoc: {
mode: 'jsdoc'
}
} It took a while to delve through the documentation to figure this out, and I was left thinking:
The recommendation from jaydenseric to apply rules appropriately based on file extension sounds ideal from my perspective. |
It's not treating the file as TypeScript; it's treating the JSDoc as being of the TypeScript flavor of JSDoc. It can still work in JavaScript.
You should get rid of the
The recommendation is a good one, but it won't apply to your situation. Also, as an update, given that flat config has dropped |
This can easily be done in both legacy config and new flag config by restricting the "extends" to only certain file types. // flat config:
export default [
{
...jsdoc.configs['flat/recommended'],
files: ['**/*.js', '**/*.jsx', '**/*.cts', '**/*.mts'],
},
{
...jsdoc.configs['flat/recommended-typescript'],
files: ['**/*.ts', '**/*.tsx', '**/*.cts', '**/*.mts'],
},
// other configuration objects...
]; // legacy config:
module.exports = {
overrides: [
{
files: ['**/*.js', '**/*.jsx', '**/*.cts', '**/*.mts'],
extends: ['plugin:jsdoc/recommended'],
},
{
files: ['**/*.ts', '**/*.tsx', '**/*.cts', '**/*.mts'],
extends: ['plugin:jsdoc/recommended-typescript'],
},
],
// other configuration objects...
}; EDIT: Ah, I realize this doesn't explicitly special-case |
Motivation
At the moment, there isn’t a config for a TypeScript project that has type checking in the TypeScript modules (
.ts
,.tsx
,.mts
,.cts
) as well as the JavaScript modules (.js
,.mjs
,.cjs
). Quite often you will have asrc/
dir that contains all the.mts
files for TypeScript to compile todist/
, but you also have files like.eslintrc.js
that don't contain TypeScript syntax but still are type checked by TypeScript via the// @ts-check
comment and TypeScript flavour of JSDoc comments.It would be good to add a
eslint-plugin-jsdoc
recommended config for TypeScript mixed TS/JS projects, deprecating the current recommended TypeScript configs that assume a TypeScript type checked project is only TS, or only JS, but not mixed.Current behavior
To try to get things working with v44, here was my approach in
.eslintrc.js
(with all noneslint-plugin-jsdoc
config removed for brevity):This approach of picking a config and then trying to overwrite it with overrides is frustrating to figure out and maintain, and most people don't understand how all this fits together well enough to get it right.
Desired behavior
There would be a recommended config that targets the specific types of JavaScript and TypeScript modules that can exist in a project by file extension, applying only the relevant JSDoc rules to each kind of module.
Alternatives considered
jsdoc/no-undefined-types
become no-ops if they individually detect if the current module is TypeScript (.ts
,.tsx
,.mts
,.cts
), or if the current JavaScript module falls under TS config for checking all JavaScript modules, or if the JavaScript module contains a// @ts-check
comment. You could actually have just oneeslint-plugin-jsdoc
recommended config then, that would universally work for all projects regardless if they are type-checked with TypeScript.The text was updated successfully, but these errors were encountered: