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

如果我的项目混用 js 和 ts,如何正确设置配置? #67

Closed
bigbigbo opened this issue May 17, 2019 · 6 comments
Closed

如果我的项目混用 js 和 ts,如何正确设置配置? #67

bigbigbo opened this issue May 17, 2019 · 6 comments

Comments

@bigbigbo
Copy link

因为当前项目是混用了 javascript 和 typescript 开发,如果同时设置

extends: [
'eslint-config-alloy/react',
'eslint-config-alloy/typescript',
]

因为 typescript 使用的 parser 不是 babel-eslint,会出现我在 js 文件中使用新的 babel-plugin-proposal-optional-chaining 等插件提供的语法出现报错的问题。我现在是使用 tslint 来检测 typescript,但是tslint的规则实在是少,想用 eslint 统一做检测,但是又没法区分不同的文件后缀应用不同的配置,请问如何解决这个问题呢?

@xcatliu
Copy link
Member

xcatliu commented May 17, 2019

eslint 没办法在一个项目中针对不同后缀的文件使用不同的 eslintrc
js 文件和 ts 文件必须使用同一个 parser

@xcatliu
Copy link
Member

xcatliu commented May 17, 2019

你也可以在运行脚本的时候,指定不同的后缀使用不同的 eslintrc
但是只有运行脚本时有效,在 vscode 中还是只能识别一个 eslintrc

@bigbigbo
Copy link
Author

你也可以在运行脚本的时候,指定不同的后缀使用不同的 eslintrc
但是只有运行脚本时有效,在 vscode 中还是只能识别一个 eslintrc

那好像针对这种情况没有特别完美的方案了,只能同时使用 Eslint 和 TsLint 了,或者项目统一切换至 TypeScript 了。

@ethanleeX
Copy link

现在应该可以根据不同的后缀使用不同的规则

"overrides": [
    {
      "files": ['*.js'],
      "parser": 'babel-eslint',
    },
    {
      "files": ['*.ts', '*.tsx'],
      "extends": ["plugin:@typescript-eslint/recommended"],
      "parser": '@typescript-eslint/parser',
      "plugins": ['@typescript-eslint/eslint-plugin'],
    },
  ]

typescript-eslint/typescript-eslint#109

@cccttt10
Copy link

cccttt10 commented Sep 8, 2019

现在应该可以根据不同的后缀使用不同的规则

"overrides": [
    {
      "files": ['*.js'],
      "parser": 'babel-eslint',
    },
    {
      "files": ['*.ts', '*.tsx'],
      "extends": ["plugin:@typescript-eslint/recommended"],
      "parser": '@typescript-eslint/parser',
      "plugins": ['@typescript-eslint/eslint-plugin'],
    },
  ]

typescript-eslint/typescript-eslint#109

overrides 里面 不允许有extends

@ethanleeX
Copy link

eslint 6.0之后可以有

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

4 participants