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

Should Ignore js files for type awared rules #375

Closed
5 tasks done
mutoe opened this issue Dec 24, 2023 · 3 comments
Closed
5 tasks done

Should Ignore js files for type awared rules #375

mutoe opened this issue Dec 24, 2023 · 3 comments

Comments

@mutoe
Copy link
Contributor

mutoe commented Dec 24, 2023

Describe the bug

When I assign a tsconfig path to typescript option. It told me I should include the js file to tsconfig.json
image

However, after I include the js files in tsconfig. It told me there has some types is unsafe, like this
image

Actually I don't really want to check the js files' type. I'm not sure if this is expected behavior or a bug.

Happy to contribute if it is a bug :)

Reproduction

https://github.com/mutoe-archive/antfu-eslint-config-type-aware-in-js-issue

System Info

N/A

Used Package Manager

pnpm

Validations

  • Follow our Code of Conduct
  • Read the Contributing Guide.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
  • The provided reproduction is a minimal reproducible of the bug.
@Dimava
Copy link
Contributor

Dimava commented Dec 24, 2023

I guess it's mostly trying to say you are missing @types/node devDependency

I do agree config should not chech ts rules on js files by default unless you have allowJs on, so you don't have to make eslint.tsconfig.json just to make it not crash on eslint.config.js

@mutoe
Copy link
Contributor Author

mutoe commented Dec 24, 2023

I guess it's mostly trying to say you are missing @types/node devDependency

I don't think this is @types/node issue. Still having this error after I installed it.

so you don't have to make eslint.tsconfig.json just to make it not crash on eslint.config.js

What's you mean? Whether I include that js file or not, it gives an error, like I said in the post.

@Dimava
Copy link
Contributor

Dimava commented Dec 25, 2023

The problem is there is no easy way to not typecheck JS files

@mutoe

import antfu from '@antfu/eslint-config'

export default antfu({
  typescript: {
    tsconfigPath: './tsconfig.json',
  },
  // overrides: {
  //   javascript: {
  //     'ts/no-unsafe-argument': 'off', // won't work
  //   },
  // },
}, {
  files: ['**/*.js'],
  rules: {
    'ts/no-unsafe-argument': 'off',
    'ts/no-unsafe-assignment': 'off',
    'ts/no-unsafe-call': 'off',
    'ts/no-unsafe-member-access': 'off',
    'ts/no-unsafe-return': 'off',
  },
})

will error less but will still require JS in your tsconfig

@antfu please consider adding some easy way to exclude out-of-tsconfig files from type-aware rules

 export async function typescript(
   options: OptionsFiles & OptionsComponentExts & OptionsOverrides & OptionsTypeScriptWithTypes & OptionsTypeScriptParserOptions = {},
 ): Promise<FlatConfigItem[]> {
   const {
     componentExts = [],
     overrides = {},
     parserOptions = {},
+    excludes = [], // e.g. `['**/*.js']` or `['./*.js']` or `['./scripts/**/*']` to exclude files that are not in tsconfig
   } = options
 
   const files = options.files ?? [
-    GLOB_SRC,
+    options.typecheckJs ? GLOB_SRC : GLOB_TS, // some way to disable type-aware-rules for JS
+                                              // as they are often configs/scrips outside of the project. 
+                                              // Currently you *have* to add eslint.config.js into tsconfig or it gonna bark
     ...componentExts.map(ext => `**/*.${ext}`),
   ]

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

No branches or pull requests

2 participants