让前端飞Web前端之路

npm script工作流 (一) eslint

2020-08-04  本文已影响0人  ZoranLee

创建项目

{
  "name": "hello-npm-script",
  "version": "0.1.0",
  "description": "hello npm script",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [
    "npm",
    "script"
  ],
  "author": "wangshijun <wangshijun2010@gmail.com> (https://github.com/wangshijun)",
  "license": "MIT"
}

修改基本信息信息

$ npm config set init.author.email "zoranlee@gmail.com"
$ npm config set init.author.name "zoranlee"
$ npm config set init.author.url "https://github.com/zoranli"
$ npm config set init.license "MIT"
$ npm config set init.version "0.1.0"

执行任意命令

自定义 npm script

步骤

$ npm install eslint -D
$  ./node_modules/.bin/eslint --init

如下图:


image.png
module.exports = {
  env: {
    es6: true,
    node: true,
  },
  extends: 'eslint:recommended',
  rules: {
    indent: ['error', 4],
    'linebreak-style': ['error', 'unix'],
    quotes: ['error', 'single'],
    semi: ['error', 'always'],
  },
};
{
  "scripts": {
    "eslint": "eslint *.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
}

React检查

eslint-plugin-react

react-native检查

react-plugin-react-native

eslint-config-airbnb
(内置eslint-plugin-react)

peerDependencies 安装失败

(
  export PKG=eslint-config-airbnb;
  npm info "$PKG@latest" peerDependencies --json | command sed 's/[\{\},]//g ; s/: /@/g' | xargs npm install --save-dev "$PKG@latest"
)

vue检查

eslint-plugin-vue

.eslintrc* 里面的 rules 中配置

module.exports = {
  env: {
    es6: true,
    node: true,
  },
  extends: 'eslint:recommended',
  rules: {
    indent: ['error', 2],
    'linebreak-style': ['error', 'unix'],
    quotes: ['error', 'single'],
    semi: ['error', 'always'],
  },
};
上一篇 下一篇

猜你喜欢

热点阅读