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

readme 中 react 部分的一些疑惑 #78

Open
GitHubJian opened this issue Aug 15, 2022 · 6 comments
Open

readme 中 react 部分的一些疑惑 #78

GitHubJian opened this issue Aug 15, 2022 · 6 comments

Comments

@GitHubJian
Copy link

对于 react + ts 项目,按照 readme 中的配置,添加 @ecomfe/eslint-config/react 后,会对 tsx 中的 interface 报一些未定义的错误,经过源码阅读与个人尝试,对于这类项目 @ecomfe/eslint-config/typescript 更加合适,所以是否需要升级一下 readme 呢?

@Justineo
Copy link
Member

应该是两个一起使用的。

@otakustay
Copy link
Member

2个都用的情况下也会报这些错吗?

@GitHubJian
Copy link
Author

GitHubJian commented Aug 15, 2022

extends: ['@ecomfe/eslint-config', '@ecomfe/eslint-config/typescript', '@ecomfe/eslint-config/react']
typescript & react 的顺序前后都试过了
两个一起用不会报错,这个 rule [react/jsx-indent] 就会导致格式上出现了问题,会出现超长的缩进
有 @ecomfe/eslint-config/react 配置 lint 的结果
image
无 @ecomfe/eslint-config/react 配置lint的结果
image
可以很明显的看出来两种格式的结果不同,但是前者的缩进匹配好像有点问题,我看了一下 react/index.js 的源码,里边并没有 tsx 的配置,只是 jsx 的,所以我不太理解这块为什么导致了这个现象,是否符合预期?

@otakustay
Copy link
Member

格式化的话,我感觉是indent规则和TS的问题:typescript-eslint/typescript-eslint#1824

indent规则关掉试试?

@GitHubJian
Copy link
Author

@GitHubJian
Copy link
Author

'react/jsx-indent': [
2,
4,
{
checkAttributes: false,
indentLogicalExpressions: true,
},
],
'react/jsx-no-bind': [
'warn',
{
ignoreDOMComponents: true,
ignoreRefs: false,
allowArrowFunctions: true,
allowFunctions: true,
allowBind: false,
},
],
'react/jsx-indent-props': [
2,
{
indentMode: 4,
ignoreTernaryOperator: true,
},
],
'react/jsx-wrap-multilines': [
2,
{
declaration: 'parens-new-line',
assignment: 'parens-new-line',
return: 'parens-new-line',
arrow: 'parens-new-line',
condition: 'parens-new-line',
logical: 'parens-new-line',
prop: 'parens-new-line',
},
],

修改一下这三个规则就可以了

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

3 participants