1.0.1 • Published 5 years ago

@hankliu/eslint-react v1.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
5 years ago

HankLiu React Eslint

提供React项目中基础的eslint规则和插件

安装

npm install @hankliu/eslint-react -D

or

yarn add @hankliu/eslint-react -D

使用

  • in .eslintrc.js
const eslint = require('@hankliu/eslint-react');

// 修改规则

// eslint.plugins.push('react');
// eslint.rules = Object.assign(eslint.rules, {
//   'func-names': 'off',
//   'import/no-extraneous-dependencies': 'off',
//   'jsx-a11y/anchor-is-valid': 'off',
//   'jsx-a11y/click-events-have-key-events': 'off',
//   'jsx-a11y/media-has-caption': 'off',
//   'jsx-a11y/no-noninteractive-element-interactions': 'off',
//   'jsx-a11y/no-static-element-interactions': 'off',
// });
// eslint.globals = Object.assign(eslint.globals, {
//   'app.less': true,
//   '$': true
// });

module.exports = eslint;
  • in webpack with eslint-loader
{
   rules: [{
      test: /\.(js|jsx)$/,
      enforce: 'pre',
      loader: 'eslint-loader',
      options: {
         eslintPath: require.resolve('eslint'),
         baseConfig: {
            extends: [require.resolve('@hankliu/eslint-react')]
         },
         ignore: false,
         useEslintrc: false,
         formatter: require('eslint-friendly-formatter')
      }
   }]
}

注意

我们使用的是 peerDependencies 管理依赖,如果是在npm2中使用该插件,不许需要在自己项目中额外安装下列依赖,npm2会自行强制安装peerDependencies所要求指定的依赖包;如果是在npm3+中使用该插件,npm3中不会再要求peerDependencies所指定的依赖包被强制安装,相反npm3会在安装结束后检查本次安装是否正确,如果不正确会给用户打印警告提示。

"peerDependencies": {
  "babel-eslint": "^10.x",
  "eslint": "^5.x",
  "eslint-config-airbnb": "^17.x",
  "eslint-config-standard": "^12.x",
  "eslint-plugin-babel": "^5.x",
  "eslint-plugin-flowtype": "^3.x",
  "eslint-plugin-import": "^2.x",
  "eslint-plugin-jsx-a11y": "^6.x",
  "eslint-plugin-react": "^7.x"
}