如何安装eslint-airbnb?

Liu*_*uil 3 npm eslint

当我( export PKG=eslint-config-airbnb; npm info "$PKG@latest" peerDependencies --json | command sed 's/[\{\},]//g ; s/: /@/g' | xargs npm install --save-dev "$PKG@latest" )成功运行时 。eslint --init并在中运行脚本package.json

信息:我的节点 node v7.5.0 npm 4.1.2

下面有问题。

npm ERR! Darwin 15.6.0
npm ERR! argv "/Users/next/.nvm/versions/node/v7.5.0/bin/node"
/Users/next/.nvm/versions/node/v7.5.0/bin/npm" "run" "lint"
npm ERR! node v7.5.0
npm ERR! npm  v4.1.2
npm ERR! code ELIFECYCLE
npm ERR! beslint@1.0.0 lint: `eslint app.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the beslint@1.0.0 lint script 'eslint app.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the beslint package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     eslint app.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs beslint
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls beslint
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/next/es6/jsmodules/beslint/npm-debug.log
Run Code Online (Sandbox Code Playgroud)

adr*_*520 5

您确定跑步eslint --init有效吗?

就像您没有.eslintrc文件一样(ESLint解析器选项和规则的配置文件)。.eslintrc在项目的根目录下检查/创建名为“ beslint ”的文件。

然后,您需要将其添加到.eslintrc文件中,以便ESLint考虑到您要扩展Airbnb团队的规则:

{ "extends": "airbnb" }

请注意,您可以从Airbnb团队安装不同的规则:

  • airbnb ”:Airbnb ESLint规则,包括ECMAScript 6+和React
  • airbnb-base ”:Airbnb ESLint规则,包括ECMAScript 6+
  • airbnb-base / legacy ”:Airbnb ESLint规则,包括ECMAScript 5和更低版本

extends.eslintrc文件中的值应与您的安装相匹配,并且应为前三个值之一。

我制作了一个命令行工具,可以使用这三种不同的Airbnb配置之一安装ESLint。.eslintrc如果尚未完成,它将自动创建和配置文件。它对我的个人项目和工作都有很大帮助!叫做esbnb。希望它能对您有所帮助。