Coder Social home page Coder Social logo

alloyteam / eslint-config-alloy Goto Github PK

View Code? Open in Web Editor NEW
2.6K 44.0 320.0 12 MB

Progressive ESLint config for your React/Vue/TypeScript projects

Home Page: https://alloyteam.github.io/eslint-config-alloy/

JavaScript 73.11% Vue 10.03% TypeScript 15.93% CSS 0.72% HTML 0.17% Shell 0.05%
eslint-config alloyteam eslint react vue typescript

eslint-config-alloy's Introduction

Build Status Build Status npm package npm downloads

English / 简体中文

NEWS: eslint-config-alloy now support TypeScript 5.0
If you are using TypeScript 4.0, please npm install --save-dev eslint-config-alloy@4

NEWS: eslint-config-alloy now support Vue 3.0
If you are using Vue 2.0, please npm install --save-dev eslint-config-alloy@3


The AlloyTeam ESLint config is not only a progressive ESLint config for your React/Vue/TypeScript projects but also the best reference for configuring your personalized ESLint rules.

Quick start

Please choose the following configuration based on the technology stack used by your project:

Philosophy

  • Let Prettier handle style-related rules
  • Inherit ESLint's philosophy and help everyone build their own rules
  • High degree of automation: advanced rules management, test as a document, as a website
  • Keep up with the times, follow up the latest rules as soon as possible
Details

Let Prettier handle style-related rules

Prettier is a code formatting tool that offers fewer options but is more professional than the style-related rules in ESLint.

Now that Prettier has become a necessary tool in front-end projects, eslint-config-alloy does not need to maintain the style-related rules in ESLint anymore, so we completely removed all Prettier related rules in the v3 version, and use ESLint to check logical errors which it's good at.

As for whether two spaces or four spaces are used for indentation and whether there is a semicolon at the end, you can configure it in the project's .prettierrc.js. Of course, we also provide a recommended Prettier configuration for your reference.

Inherit ESLint's philosophy and help everyone build their own rules

Don't you remember how ESLint defeated JSHint and became the most popular JS code inspection tool? It is because of the plugin and configuration that ESLint advocates, which meets the individual needs of different technology stacks of different teams.

Therefore, eslint-config-alloy also inherits the philosophy of ESLint. It will not emphasize the need to use our config. Instead, we help you to make your config by reference our completed documents, examples, tests, websites, etc.

High degree of automation: advanced rules management, test as a document, as a website

Relentless push automation

eslint-config-alloy uses a high degree of automation to hand over all processes that can be managed automatically, including:

  • Through GitHub Actions, automatically weekly check whether ESLint and related plugins have new versions and if there are new rules in the new version which we need to add
  • Automatically check if our rules include Prettier rules
  • Automatically check if our rules include deprecated rules

Also, through automated scripts, we can even divide and conquer thousands of ESLint configuration files, and each rule is managed in a separate directory:

  • Integrate single configurations into a final configuration through a script
  • The description and reason in single configurations are built into a website by a script for everyone to view
  • The bad.js and good.js in a single configuration are output to website by script, and you can even see the error message (which are run in a real ESLint script) in the bad.js of website

The benefits of this are very obvious — test as a document, as a website. We can maintain the rules and tests in one place. Other tasks are handed over to an automated script, which greatly reduces the maintenance cost. In short, when we have a new rule to add, we only need to write three files test/index/another-rule/.eslintrc.js, test/index/another-rule/bad.js, test/index/another-rule/good.js.

Keep up with the times, follow up the latest rules as soon as possible

ESLint is updated very quickly, there is a new version almost every week, sometimes there are new rules, sometimes existing rules are deprecated, and related plug-ins (React/Vue/TypeScript) will be updated from time to time. Without automation tools, it is difficult to follow up.

And eslint-config-alloy, through the above-mentioned automated tools, can receive notifications from GitHub Actions at the first time, telling us which rules need to be added:

In this way, we can follow the latest rules in a time when the front-end community is changing rapidly, and always keep the vitality and advanced of eslint-config-alloy.

Usage

Built-in

npm install --save-dev eslint @babel/core @babel/eslint-parser eslint-config-alloy

Create an .eslintrc.js in the root directory of your project, then copy the following content into it:

module.exports = {
  extends: [
    'alloy',
  ],
  env: {
    // Your environments (which contains several predefined global variables)
    //
    // browser: true,
    // node: true,
    // mocha: true,
    // jest: true,
    // jquery: true
  },
  globals: {
    // Your global variables (setting to false means it's not allowed to be reassigned)
    //
    // myGlobal: false
  },
  rules: {
    // Customize your rules
  },
};

React

npm install --save-dev eslint @babel/core @babel/eslint-parser @babel/preset-react@latest eslint-plugin-react eslint-config-alloy

Create an .eslintrc.js in the root directory of your project, then copy the following content into it:

module.exports = {
  extends: [
    'alloy',
    'alloy/react',
  ],
  env: {
    // Your environments (which contains several predefined global variables)
    //
    // browser: true,
    // node: true,
    // mocha: true,
    // jest: true,
    // jquery: true
  },
  globals: {
    // Your global variables (setting to false means it's not allowed to be reassigned)
    //
    // myGlobal: false
  },
  rules: {
    // Customize your rules
  },
};

Vue

npm install --save-dev eslint @babel/core @babel/eslint-parser vue-eslint-parser eslint-plugin-vue eslint-config-alloy

Create an .eslintrc.js in the root directory of your project, then copy the following content into it:

module.exports = {
  extends: [
    'alloy',
    'alloy/vue',
  ],
  env: {
    // Your environments (which contains several predefined global variables)
    //
    // browser: true,
    // node: true,
    // mocha: true,
    // jest: true,
    // jquery: true
  },
  globals: {
    // Your global variables (setting to false means it's not allowed to be reassigned)
    //
    // myGlobal: false
  },
  rules: {
    // Customize your rules
  },
};

TypeScript

npm install --save-dev eslint typescript @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint-config-alloy

Create an .eslintrc.js in the root directory of your project, then copy the following content into it:

module.exports = {
  extends: [
    'alloy',
    'alloy/typescript',
  ],
  env: {
    // Your environments (which contains several predefined global variables)
    //
    // browser: true,
    // node: true,
    // mocha: true,
    // jest: true,
    // jquery: true
  },
  globals: {
    // Your global variables (setting to false means it's not allowed to be reassigned)
    //
    // myGlobal: false
  },
  rules: {
    // Customize your rules
  },
};

TypeScript React

npm install --save-dev eslint typescript @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint-plugin-react eslint-config-alloy

Create an .eslintrc.js in the root directory of your project, then copy the following content into it:

module.exports = {
  extends: [
    'alloy',
    'alloy/react',
    'alloy/typescript',
  ],
  env: {
    // Your environments (which contains several predefined global variables)
    //
    // browser: true,
    // node: true,
    // mocha: true,
    // jest: true,
    // jquery: true
  },
  globals: {
    // Your global variables (setting to false means it's not allowed to be reassigned)
    //
    // myGlobal: false
  },
  rules: {
    // Customize your rules
  },
};

TypeScript Vue

It is recommended to use npm init vue@3 to create a project with Vue, TypeScript and ESLint integrated, and then refer to this example to adjust its ESLint configuration.

The conventional way is as follows:

npm install --save-dev @babel/core @babel/eslint-parser @typescript-eslint/eslint-plugin @typescript-eslint/parser @vue/eslint-config-typescript eslint eslint-config-alloy eslint-plugin-vue vue-eslint-parser

Create an .eslintrc.js in the root directory of your project, then copy the following content into it:

module.exports = {
  extends: ['alloy', 'alloy/vue', 'alloy/typescript'],
  parser: 'vue-eslint-parser',
  parserOptions: {
    parser: {
      js: '@babel/eslint-parser',
      jsx: '@babel/eslint-parser',

      ts: '@typescript-eslint/parser',
      tsx: '@typescript-eslint/parser',

      // Leave the template parser unspecified, so that it could be determined by `<script lang="...">`
    },
  },
  env: {
    // Your environments (which contains several predefined global variables)
    //
    // browser: true,
    // node: true,
    // mocha: true,
    // jest: true,
    // jquery: true
  },
  globals: {
    // Your global variables (setting to false means it's not allowed to be reassigned)
    //
    // myGlobal: false
  },
  rules: {
    // Customize your rules
  },
};

Troubleshooting

With VSCode

Just install the ESLint extension in VSCode.

Refer to here to configure the extension.

Autofix ESLint errors on save

If you want to enable auto-fix-on-save, you need to set your .vscode/settings.json like this:

{
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true
  },
}

With Prettier

eslint-config-alloy does not include any style-related rules in v3, so there is no need to install eslint-config-prettier. Just install prettier and related VSCode plugins.

AlloyTeam provides a set of Prettier configuration, you can create a .prettierrc to reuse it:

"eslint-config-alloy/.prettierrc.js"

A best practice for VSCode is to auto format code with Prettier and autofix errors with ESLint by setting .vscode/settings.json to this:

{
  "files.eol": "\n",
  "editor.tabSize": 2,
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  "[jsonc]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true
  }
}

Scripts

# install dependencies
pnpm i
# build eslintrc like index.js, react.js, etc.
pnpm build
# run tests
pnpm test
# autofix prettier errors
pnpm prettier:fix
# check if all rules are covered
pnpm rulesCoverage
# publish new version
npm version <major|minor|patch>
git push --follow-tags
npm publish

Q & A

Why another ESLint config

Our team initially used Airbnb rules, but because it was too strict, some rules still needed to be personalized, which led to more and more changes in the future and finally decided to maintain a new set. After more than four years of maintaining, eslint-config-alloy is now very mature and progressive and has been welcomed by many teams inside and outside the company.

Why not standard

The standard specification believes that everyone should not waste time in personalized specifications, but the entire community should unify a specification. This statement makes some sense, but it runs against the ESLint's design philosophy. Don't you remember how ESLint defeated JSHint and became the most popular JS code inspection tool? It is because of the plugin and configuration that ESLint advocates, which meets the individual needs of different technology stacks of different teams.

Therefore, eslint-config-alloy also inherits the philosophy of ESLint. It will not force you to use our config. Instead, we help you to make your config by referencing our examples, tests, websites and so on.

Why not airbnb

  1. eslint-config-alloy has officially maintained vue, typescript and react+typescript rules. In contrast, airbnb's vue and typescript are maintained by third parties.
  2. Progressive to ensure that we can keep up with the times, as mentioned earlier
  3. Convenient personalization, including explanations and website examples

Looks good, but I still choose airbnb

It's okay, eslint-config-alloy believes that different teams and projects can have different configurations from the design concept. Although you choose to use airbnb, you can still come to our website when you have personalized configuration needs.

Reference

eslint-config-alloy's People

Contributors

999946 avatar dc3671 avatar dependabot[bot] avatar diamondyuan avatar greenkeeper[bot] avatar jiangjiu avatar kenve avatar lcxfs1991 avatar meteorlxy avatar revelt avatar sfesh2012 avatar xcatliu avatar xuing avatar zoubingwu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

eslint-config-alloy's Issues

[规则问题]no-unused-vars

'no-unused-vars': [

对于rest写法,解构赋值时前面的参数可能没有用到,但却是必须要填写的,如:

var [ type, ...coords ] = data;

此时无论type是否用到,都需要填写该值。

建议配置为:
'no-unused-vars': ['error', { vars: 'all', args: 'none', ignoreRestSiblings: true }]

TypeScript 规则不支持 cast

发现如 (x as sometype) 这样的 casting 不支持,ESLint 会报错:Parsing error: Unexpected token

这是我现在的 .eslintrc.js 配置:

module.exports = {
  extends: [
    'eslint-config-alloy/typescript-react',
  ],
  globals: {
  },
  rules: {
    'react/jsx-indent-props': 'off',
    'typescript/member-ordering': 'off',
  },
  "parser": "babel-eslint",
  "plugins": ["typescript"]
};

[规则问题]no-script-url

'no-script-url': 'off',

不懂为什么会off掉这个规则,javascript:伪协议肯定是不使用为好啊,既影响性能,又不安全,和eval是一个性质。
为了一个javascript:void(0)而关闭整个规则?其实javascript:void(0)也不应该存在,这不是在做无用功吗,只有重构在写a标签时有可能用到,但完全可以preventDefault啊

[规则问题]array-callback-return

// @off 太严格了

'array-callback-return': 'off',

如果
Array.from
Array.prototype.every
Array.prototype.filter
Array.prototype.find
Array.prototype.findIndex
Array.prototype.map
Array.prototype.reduce
Array.prototype.reduceRight
Array.prototype.some
Array.prototype.sort

这些方法中没有return,那和forEach有什么区别呢?我认为这条规则应该限制,这些函数都是有return才生效。

为啥用Typescript还要依赖babel-eslint

[!] (eslint plugin) Error: Cannot find module 'babel-eslint'
Referenced from: /Users/xxx/Desktop/xx/node_modules/eslint-config-alloy/index.js
Referenced from: /Users/xxx/Desktop/xx/node_modules/eslint-config-alloy/typescript.js
Referenced from: /Users/xxx/Desktop/xx/.eslintrc
src/index.ts
Error: Cannot find module 'babel-eslint'
Referenced from: /Users/xxx/Desktop/xx/node_modules/eslint-config-alloy/index.js
Referenced from: /Users/xxx/Desktop/xx/node_modules/eslint-config-alloy/typescript.js
Referenced from: /Users/xxx/Desktop/xx/.eslintrc
at ModuleResolver.resolve (/Users/xxx/Desktop/xx/node_modules/eslint/lib/util/module-resolver.js:72:19)
at loadFromDisk (/Users/xxx/Desktop/xx/node_modules/eslint/lib/config/config-file.js:537:42)
at load (/Users/xxx/Desktop/xx/node_modules/eslint/lib/config/config-file.js:587:20)
at configExtends.reduceRight (/Users/xxx/Desktop/xx/node_modules/eslint/lib/config/config-file.js:453:36)
at Array.reduceRight ()
at applyExtends (/Users/xxx/Desktop/xx/node_modules/eslint/lib/config/config-file.js:431:26)
at loadFromDisk (/Users/xxx/Desktop/xx/node_modules/eslint/lib/config/config-file.js:551:22)
at load (/Users/xxx/Desktop/xx/node_modules/eslint/lib/config/config-file.js:587:20)
at configExtends.reduceRight (/Users/xxx/Desktop/xx/node_modules/eslint/lib/config/config-file.js:453:36)
at Array.reduceRight ()

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] build: rollup -c config/rollup.config.js
npm ERR! Exit status 1

Vue 版本文档更新

使用Vue版本时,文档中没有提到安装babel-eslint,可以加下,别人使用时一起安装更方便
npm install --save-dev eslint babel-eslint [email protected] eslint-plugin-vue@3 eslint-config-alloy

typescript/adjacent-overload-signatures

默认的typescript配置开启了规则:

    // 函数有重载时,必须将重载成员分组在一起
    'typescript/adjacent-overload-signatures': 'error',

然后校验我的代码报错,我不确定是否是eslint-plugin-typescript的问题,定位问题刚好看到你也在这个issue内:bradzacher/eslint-plugin-typescript#49

建议暂时将这个规则关闭掉,第一可能是typescript插件问题,第二当依赖第三方的库,然后根据需要在此基础上做扩展时,需要重载方法,这导致这条规则一定会报错。

[规则问题]no-else-return

// @off else 中使用 return 可以使代码结构更清晰

目前前端比较受大家推崇的是扁平化的编码风格,减少不必要的else及else if会让整个代码结构更加扁平化,层级不那么深,当习惯了这种风格再看else及else if会非常难受,逻辑层次其实相对来说也不会差,建议开启规则:

'no-else-return': ['error', { allowElseIf: false }]

[no-undef] interface 错误

interface Foo{
    bar: string;
}

export default Foo;

以上代码会报错

  5:16  error  'Foo' is not defined  no-undef

关于空catch块的看法

allowEmptyCatch: true

空的catch绝大多数的情况下是一个bad practice,尤其是对于新手来说,只有在极少数的情况下,当对发生的错误无能为力的时候才会用到,因此我认为最佳实践是直接禁止空catch块,在极少数有必要的情况下注释说明,这样可以有效防止新人将错误掩盖的行为。

off require-await

async function 中没有 await 的写法很常见,比如 koa 的示例中就有这种用法,故关闭此规则

code ELIFECYCLE

hello, there is a error, but I am not sure where it from.

 yu$ npm run lint

> projectName
> eslint --ext .js --ext .jsx fileloader

eslint-config-alloy/react:
        Configuration for rule "react/jsx-curly-spacing" is invalid:
        Value "[object Object]" must be an enum value.

Referenced from: path/.eslintrc.js
Error: eslint-config-alloy/react:
        Configuration for rule "react/jsx-curly-spacing" is invalid:
        Value "[object Object]" must be an enum value.

Referenced from: path/.eslintrc.js
    at validateRuleOptions (path/node_modules/eslint/lib/config/config-validator.js:109:15)
    at Object.keys.forEach.id (path/node_modules/eslint/lib/config/config-validator.js:156:13)
    at Array.forEach (<anonymous>)
    at Object.validate (path/node_modules/eslint/lib/config/config-validator.js:155:35)
    at load (path/node_modules/eslint/lib/config/config-file.js:559:19)
    at configExtends.reduceRight (path/node_modules/eslint/lib/config/config-file.js:424:36)
    at Array.reduceRight (<anonymous>)
    at applyExtends (path/node_modules/eslint/lib/config/config-file.js:408:28)
    at Object.load (path/node_modules/eslint/lib/config/config-file.js:566:22)
    at loadConfig (path/node_modules/eslint/lib/config.js:63:33)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! projectName@ lint: `eslint --ext .js --ext .jsx folderName
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the projectName lint script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/yu/.npm/_logs/2018-08-16T01_21_35_977Z-debug.log

when I do steps:

npm cache clean --force
delete node_modules
npm i

or comment 'react/jsx-curly-spacing' rule like this(eslint-config-alloy/react.js)

        // @fixable 大括号内前后禁止有空格
        // 'react/jsx-curly-spacing': [
        //     'error',
        //     {
        //         when: 'never',
        //         attributes: {
        //             allowMultiline: true
        //         },
        //         children: true,
        //         spacing: {
        //             objectLiterals: 'never'
        //         }
        //     }
        // ],

the problem is still exist.

.eslintrc.js

module.exports = {
  extends: [
    "eslint-config-alloy/react"
  ],
  "parserOptions": {
    "ecmaFeatures": {
      "arrowFunctions": true,
      "binaryLiterals": true,
      "blockBindings": true,
      "classes": true,
      "defaultParams": true,
      "destructuring": true,
      "forOf": true,
      "generators": true,
      "modules": true,
      "objectLiteralComputedProperties": true,
      "objectLiteralDuplicateProperties": true,
      "objectLiteralShorthandMethods": true,
      "objectLiteralShorthandProperties": true,
      "octalLiterals": true,
      "regexUFlag": true,
      "regexYFlag": true,
      "spread": true,
      "superInFunctions": true,
      "templateStrings": true,
      "unicodeCodePointEscapes": true,
      "globalReturn": true,
      "jsx": true
    }
  },

  "env": {
    "browser": true,
    "node": true,
    "es6": true,
    "jquery": true
  },

  "parser": "babel-eslint",

  "plugins": ["react"],

  "rules": {
    // some rules
  },
  
  "globals": {
    
  }
}

and the version:

node: 8.11.3
npm: 5.6.0
eslint: 3.19.0
babel-eslint: 7.0.0
eslint-loader: 2.0.0
babel-plugin-react: 6.10.3
eslint-config-alloy: 1.4.2

Ignore null in eqeqeq

foo == null 用于判断 foo 不是 undefined 并且不是 null,比较常用,故允许此写法

[规则问题]no-implicit-coercion

'no-implicit-coercion': 'off',

业界大多数声音对这类奇技淫巧持反对态度,确实在一定程度上会破坏可读性。
至于性能,现代浏览器架构下也不一定不用位运算符性能就会差,且这种性能差距在一般业务中不会体现,只有在高性能计算场景才有明显的区别,以下是对单条语句做的测试:

image
image

建议开启该规则,不要让这类奇技淫巧充斥在我们的代码里

[规则问题]vars-on-top

'vars-on-top': 'off',

var引起变量提升,应该放在作用域顶端来定义,实际上应该推荐no-var,如果一定要使用var,不应该让它进行作用域的提升,这是一个好的实践。

建议打开该规则。

在 vue-cli 默认的webpack 模板工程中使用出错

首先感谢这么详尽友好的配置,然后想要反馈下问题:

这套配置,直接在 vue init webpack 的模板工程里会报错

复现过程如下:

  1. vue init webpack vue-webpack-tpl,eslint 默认 风格 standard
  2. 以上可正常运行,之后,安装eslint-config-alloy vue 配置相关
npm install --save-dev eslint babel-eslint [email protected] eslint-plugin-vue@3 eslint-config-alloy
  1. 替换.eslintrc.js 中 extends:'eslint-config-alloy/vue'
  2. npm start 之后出错:
 ERROR  Failed to compile with 1 errors                                                                                       14:12:49

 error  in ./src/main.js

Module build failed: Error: /Users/liuml/Workspace/personal/Vue/vue-webpack-tpl/node_modules/eslint-config-alloy/index.js:
        Configuration for rule "no-multi-spaces" is invalid:
        Value "data["0"].ignoreEOLComments" has additional properties.

Referenced from: eslint-config-alloy/vue
Referenced from: /Users/liuml/Workspace/personal/Vue/vue-webpack-tpl/.eslintrc.js
    at validateRuleOptions (/Users/liuml/Workspace/personal/Vue/vue-webpack-tpl/node_modules/eslint/lib/config/config-validator.js:109
:15)
    at Object.keys.forEach.id (/Users/liuml/Workspace/personal/Vue/vue-webpack-tpl/node_modules/eslint/lib/config/config-validator.js:
156:13)
    at Array.forEach (<anonymous>)
    at Object.validate (/Users/liuml/Workspace/personal/Vue/vue-webpack-tpl/node_modules/eslint/lib/config/config-validator.js:155:35)
    at load (/Users/liuml/Workspace/personal/Vue/vue-webpack-tpl/node_modules/eslint/lib/config/config-file.js:559:19)
    at configExtends.reduceRight (/Users/liuml/Workspace/personal/Vue/vue-webpack-tpl/node_modules/eslint/lib/config/config-file.js:42
4:36)
    at Array.reduceRight (<anonymous>)
    at applyExtends (/Users/liuml/Workspace/personal/Vue/vue-webpack-tpl/node_modules/eslint/lib/config/config-file.js:408:28)
    at load (/Users/liuml/Workspace/personal/Vue/vue-webpack-tpl/node_modules/eslint/lib/config/config-file.js:566:22)
    at configExtends.reduceRight (/Users/liuml/Workspace/personal/Vue/vue-webpack-tpl/node_modules/eslint/lib/config/config-file.js:424:36)
    at Array.reduceRight (<anonymous>)
    at applyExtends (/Users/liuml/Workspace/personal/Vue/vue-webpack-tpl/node_modules/eslint/lib/config/config-file.js:408:28)
    at Object.load (/Users/liuml/Workspace/personal/Vue/vue-webpack-tpl/node_modules/eslint/lib/config/config-file.js:566:22)
    at loadConfig (/Users/liuml/Workspace/personal/Vue/vue-webpack-tpl/node_modules/eslint/lib/config.js:63:33)
    at getLocalConfig (/Users/liuml/Workspace/personal/Vue/vue-webpack-tpl/node_modules/eslint/lib/config.js:130:29)
    at Config.getConfig (/Users/liuml/Workspace/personal/Vue/vue-webpack-tpl/node_modules/eslint/lib/config.js:260:26)

 @ multi (webpack)-dev-server/client?http://localhost:8081 webpack/hot/dev-server ./src/main.js

[规则问题]no-confusing-arrow

'no-confusing-arrow': 'error',

var x = a => (1 ? 2 : 3);
这种写法应该是可以被接受的,尤其是逻辑仅仅是一个三元表达式,不用多写括号和return。
建议配置为:

'no-confusing-arrow': ['error', { allowParens: true }]

[规则问题]no-invalid-this

// @off this 的使用很灵活,事件回调中可以表示当前元素,函数也可以先用 this,等以后被调用的时候再 call
'no-invalid-this': 'off',

之前维护过代码中有各种this的奇技淫巧,对于这种滥用this的行为比较抵制,会造成很难理解。

对于事件回调,如果用箭头函数,其实根本就没有那个this,依赖于浏览器的context我认为不是一个最佳实践,理应使用target或currentTarget获取DOM。

建议开启该规则

[no-extra-semi] [semi] export default interface 分号问题

export default interface Foo {
    bar: string;
}

末尾加分号的话,就会报错:

  3:2  error  Missing semicolon      semi
  3:2  error  Unnecessary semicolon  no-extra-semi

末尾不加分号的话,就会报错:

  3:2  error  Missing semicolon  semi

no-constant-condition这个规则注释有误

“禁止将常量作为 if, for, while 里的测试条件,比如 if (true), for (;;),除非循环内部有 break 语句”这是你们给出的注释

  1. for (;;)这种形式并没有将常量作为条件,这应该不是这规则所警告的

  2. checkLoops为 false是指 允许在循环中使用常量表达式。而不是指“循环内部有 break 语句”就可以的

[规则问题]no-extra-parens

// @fixable 禁止出现多余的括号,比如 (a * b) + c

https://eslint.org/docs/rules/no-extra-parens
规则原文是禁止多余的括号,嵌套的二元表达式只是all中的一个选项而已,函数表达式中的括号理应被禁止,而条件语句、return语句、嵌套二元表达式、箭头函数等可以允许多余的括号。

如:

/* eslint no-extra-parens: ["error", "functions"] */

((function foo() {}))();

var y = (function () {return 1;});

这类多余的括号就是一种非常不好的实现

建议配置为:
'no-extra-parens': ['error', 'functions']

space-before-function-paren 规则描述有问题

image

函数表达式应该是设置成禁止在括号前面有空格
所以,我觉得翻译成:命名函数表达式括号前禁止有空格,箭头函数表达式括号前面要有一个空格

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.