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

Scope typescript settings to *.ts files #82

Open
rchl opened this issue Feb 19, 2020 · 4 comments
Open

Scope typescript settings to *.ts files #82

rchl opened this issue Feb 19, 2020 · 4 comments
Labels
enhancement New feature or request nuxt2-legacy Issues related to the legacy Nuxt 2 eslint config

Comments

@rchl
Copy link

rchl commented Feb 19, 2020

In:
https://github.com/nuxt/eslint-config/blob/dc55bbf218c8627d3c4ef73656a32730dd2a9d3c/packages/eslint-config-typescript/index.js#L1-L12

all typescript-specific settings should be in an override block and scoped to *.ts extension:

    overrides: [
        {
            files: ['*.ts'],
            plugins: ['@typescript-eslint'],
            parserOptions: {
              parser: '@typescript-eslint/parser'
            },
            rules: {
              '@typescript-eslint/no-unused-vars': ['error', { args: 'all', argsIgnorePattern: '^_' }]
            }
    ],

One of the many reasons why it should be so is that when enabling some typescript rules, like @typescript-eslint/no-unused-vars, you are supposed to disable eslint's own no-unused-vars rule (see https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-unused-vars.md#options) and you don't want to do that in general, only for *.ts.

Also, current way overrides parserOptions.parser which it would ideally not do for all file types since other might want to use babel-parser rather (although I haven't found specific issues with current solution).

@rchl
Copy link
Author

rchl commented Feb 19, 2020

Note that I'm not sure how and if that will affect typescript script blocks in Vue components...

@manniL manniL added the enhancement New feature or request label Apr 2, 2020
@rchl
Copy link
Author

rchl commented Jun 3, 2020

Also, the current use of typescript plugin is rather minimal.

Only the typescript parser from typescript plugin is enabled but otherwise, no rules are utilized (besides one). It would make sense to at least extend the base config from that plugin. That would also take care of setting the parserOptions so that it wouldn't have to be done in this package itself.

EDIT: Actually extending base configuration from typescript plugin wouldn't work as that would override the parser and break vue plugin. So rules would need to be copied over and scoped to .ts/.tsx extensions instead.

@rchl
Copy link
Author

rchl commented Jun 3, 2020

And typescript config doesn't even follow base Nuxt rules like no semi and single quotes (amongst others). Is that on purpose to diverge from JS/Vue style used in base config?

@antfu antfu added the nuxt2-legacy Issues related to the legacy Nuxt 2 eslint config label Mar 19, 2024
@rmannjbs
Copy link

rmannjbs commented Oct 7, 2024

Ran into this recently myself. Ended up having to set checkJs to true in my tsconfig and then turn off strict and allow implicit any. And then add types to global.d.ts to make it not complain about some things.

Ultimately our JS code is a lot better now and intellisense is better, but it's not currently possible to isolated js and ts in the linter using the auto generated nuxt eslint config.

It seems to favor only using js, or only using ts and doesn't favor mixed mode for nuxt 2 migrations from js on nuxt 2 to typescript and js on nuxt 3.

But the way I did it works, if you can go that route.

Fortunately this is a really easy module to fork and then refer to by git url :).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request nuxt2-legacy Issues related to the legacy Nuxt 2 eslint config
Projects
None yet
Development

No branches or pull requests

4 participants