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

flat/recommended-typescript should default "no-types" to "off" in JS files #1253

Closed
runarberg opened this issue Jul 1, 2024 · 3 comments
Closed

Comments

@runarberg
Copy link

runarberg commented Jul 1, 2024

Motivation

I’m writing typescript in JS using JSDoc. When I finished my initial setup and was ready to push I got a syntax error in my jsdoc/valid-types because I was using template literal types. So I switched my mode from jsdoc to typescript like I though I was supposed to and reran the linter. However, I accidentally (out of habit) reran it with --fix which automatically stripped all my type definitions because of the no-types rule.

Current behavior

The jsdoc/no-types rule automatically marks all types as non-passing regardless of whether they are in a .ts or a .js file. This is a dangerous behavior when they are auto-included in the latter case since the @type is the only way to annotate types in .js files

Desired behavior

The flat config for flat/recommended-typescript should have something like a:

{
  files: [**/*.js],
  rules: {
    "jsdoc/no-types": "off",
  },
},

To prevent this rule from destroying all your type definitions.

Alternatives considered

You should at least warn users heavily in the docs what switching modes can do to your code.

@runarberg runarberg changed the title flat/recommended-typescript should default no-types to off" flat/recommended-typescript should default "no-types" to "off" in JS files Jul 1, 2024
@runarberg
Copy link
Author

Sorry, I didn’t mean to close this.

@runarberg runarberg reopened this Jul 1, 2024
@brettz9
Copy link
Collaborator

brettz9 commented Jul 1, 2024

The behavior recommended by the docs for JavaScript files is to use one of the recommended-typescript-flavor configs (e.g., flat/recommended-typescript-flavor).

There is already a request for a config to combine the file formats and handle them automatically (#1101 ), so I think we can close this issue. Feel free to comment further if not.

@brettz9 brettz9 closed this as completed Jul 1, 2024
@runarberg
Copy link
Author

Turns out my problem wasn’t in the mode actually. Template literal types were simply unimplemented: jsdoc-type-pratt-parser/jsdoc-type-pratt-parser#166

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