我使用create-react-app制作一个react应用程序。
linter在创建反应应用中起作用,但现在我想让它在我的sublimetext中起作用。
- 安装了ESLINT
yarn global add eslint
(ESLINT v4.1.1,但也尝试了v3.19.0,因为React App使用了该应用程序( - 运行
eslint --init
并配置它 - 转到项目目录,并制作了一个名为
.eslintrc
的文件 - 内部文件:
{ "extends": "react-app" }
- 在项目目录中运行
eslint src/App.js
-
在终端中获取错误:
从:/mnt/storage/dev/newapp/.eslintrc引用 错误:找不到模块'eslint-config-react-app'
从:/mnt/storage/dev/newapp/.eslintrc引用 在moduleReSolver.resolve(/home/user/.config/yarn/global/node_modules/eslint/lib/modil/module-resolver.js:74:19( 在resolve(/home/user/.config/yarn/global/node_modules/eslint/lib/config/config/config-file.js:515:25( 在load(/home/user/.config/yarn/global/node_modules/eslint/lib/config/config/config-file.js:584:26( 在configextends.reduceright(/home/user/.config/yarn/global/node_modules/eslint/lib/config/config/config-file.js:421:36(( 在array.reduceright(本机( 在applyextends(/home/user/.config/yarn/global/node_modules/eslint/lib/config/config/config-file.js:405:28( 在loadfromdisk(/home/user/.config/yarn/global/node_modules/eslint/lib/config/config/config/config-file.js:556:22( 在object.load(/home/user/.config/yarn/global/node_modules/eslint/lib/config/config/config-file.js:592:20( 在config.getlocalconfighierarchy(/home/user/.config/yarn/global/node_modules/eslint/lib/config.js:228:44(( 在config.getConfighierarchy(/home/user/.config/yarn/global/node_modules/eslint/lib/config.js:182:43(
>
我确实添加了yarn global add babel-eslint eslint-plugin-react eslint-plugin-import eslint-plugin-jsx-a11y eslint-plugin-flowtype
。但是我认为这不再需要!
我想,如果您添加错误消息(eslint-config-react-app
(中提到的模块,它应该有效吗?例如。yarn add --dev eslint-config-react-app
在您的package-lock.json
文件中可能存在错误的配置,其中删除了ESLINT。我遇到了完全相同的问题,并通过:
-
cd <your-project-directory>
-
rm package-lock.json
-
rm -rf node_modules
-
npm install
您可以运行npm ls eslint --depth=99
来验证已安装eslint
软件包。我通过Feross在Github上的评论偶然发现了这一点。
,所以我发现您必须安装'所有'Eslint软件包全局。因为它不会让您处理全局ESLINT和本地软件包
所以我做的是 yarn global add eslint@^3.19.0 eslint-plugin-jsx-a11y@^5.0.
现在有效:|
首先安装此软件包,ESLINT和必要的插件。
npm install --save-dev eslint-config-react-app babel-eslint@9.x eslint@5.x eslint-plugin-flowtype@2.x eslint-plugin-import@2.x eslint-plugin-jsx-a11y@6.x eslint-plugin-react@7.x
然后创建一个名为.eslintrc.json的文件,在您的项目的根文件夹中使用以下内容:
{
"root": true,
"ecmaFeatures": {
"jsx": true
},
"env": {
"browser": true,
"node": true,
"jquery": true
},
"rules": {
"quotes": 0,
"no-trailing-spaces": 0,
"eol-last": 0,
"no-unused-vars": 0,
"no-underscore-dangle": 0,
"no-alert": 0,
"no-lone-blocks": 0
},
"globals": {
"jQuery": true,
"$": true
}
}
请参阅参考
在组织黑客马拉松时,我遇到了这个问题。以上与配置相关的解决方案对我不起作用。
这对我来说是一个错误。
首先,Sublimetext目前(2021年11月12日(与Eslint V8.0不兼容,该V8.0于2021年9月或10月在某个地方发布。我通过执行以下操作解决了这一点:
# HEADS UP: If your project currently relies on eslint v8.0, then further Sublime Text configuration might be required.
# Global install
npm uninstall -g eslint
npm install -g eslint@7
# Local install
npm uninstall -D eslint
npm install -D eslint@7
但这还不够。现在,这东西想要打字稿,因为当我在本地项目上初始化文件时,我选择使用Typescript。(您也可以通过运行eslint --init
来做到这一点(
所以我必须执行以下操作:
# Local install
npm install -D typescript
现在工作正常。
我的解决方案:
- 只是从.eslinttc.js' 删除"扩展" param
- 然后从.eslinttc.js' 删除"浏览器"以外的" env"属性
- 然后在控制台上击中"纱线棉绒",它将告诉您什么是缺少
update @typescript-eslint/* packages,以避免使用ts版本错误
在我的情况下,这两个做了技巧
npm install eslint-plugin-react-native@latest --save-dev npm install eslint-plugin-unused-imports@latest --save-dev