我使用create-react-app制作一个反应应用程序。
linter在create-react-app中工作,但现在我想让它在我的sublimetext中工作。
yarn global add eslint
(eslint v4.1.1但也试过v3.19.0,因为反应应用程序使用了那个)eslint --init
并配置它.eslintrc
的文件{ "extends": "react-app" }
eslint src/App.js
中运行我添加了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
所以我发现你需要在全局安装'全部'的eslint包。因为它不会让你处理全局的eslint和本地包
所以我做的是yarn global add eslint@^3.19.0 eslint-plugin-jsx-a11y@^5.0.
,现在它的工作原理:|
您的package-lock.json
文件中可能存在配置错误,其中删除了ESLint。我遇到了完全相同的问题并通过以下方式解决了这个问题:
cd <your-project-directory>
rm package-lock.json
rm -rf node_modules
npm install
您可以运行npm ls eslint --depth=99
来验证是否已安装eslint
软件包。我在GitHub上通过comment from feross偶然发现了这个。
首先安装此软件包,ESLint和必要的插件。
npm install --save-dev eslint-config-react-app [email protected] [email protected] [email protected] [email protected] [email protected] [email protected]
然后在项目的根文件夹中创建一个名为.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
}
}