Programming style should be unified

The programming style thing, to be honest, is very difficult for a new member of the team to fully adapt to. Because everyone’s programming style is different, it’s totally different

After entering the new company, everyone in the team has their own programming habits. They can’t stop the code even if they lift it up. Don’t ask anything

On the other hand, in team development, it’s extremely important that all code look the same, so we also need some code checking tools, from JSLint,JSHint, to today’s leading player, ESLint

So let’s cut to the chase and dive right into ESLint!!

ESLint is great

Looking ahead, in the front end, whenever there is a project, no matter how big or small, it will be seen. It’s not to improve the biggs or get people to praise them, but it actually helps us detect subtle errors and avoid more than a dozen online bugs

Also through its rules, so that the entire team has a neat and uniform code output style, but also has the industry’s best practice writing, in-depth, benefit….. Advantages and advantages are not much to say, with all say

Since all say good, that return nonsense so much, small two hasten to serve food

Install ESLint

Webpack is one of the most popular build tools used in front-end projects (if you are not familiar with Webpack, you can use it here), so let’s take a look at how to use it in projects

  1. So let’s install it
// Install eslint // install eslint-Loader to parse in WebPack // Install babel-esLint to wrap the Babel parser compatible with ESLint // -d install in devDependencies environment Original --save-dev NPM I eslint eslint-loader babel-eslint-dCopy the code

Note: ESLint is based on Node (as is Webpack of course), so make sure Node is installed before using it

  1. Create.eslintrc.js configuration file (default is.eslintrc file)
//.eslintrc.js module.exports = {// specify the parser'parse': ' ', // Specify parser options'parserOptions': {}, // specify the environment in which the script will run'env': {}, // Others can use your ESLint configuration directly'root': true, // Additional global variables that the script accesses during execution'globals': {}, // Enabled rules and their respective error levels'rules': {}};Copy the code
  1. Add the configured rules to webPack to check js files
// webpack.config.js

module.exports = {
    entry: ' ',
    output: {},
    module: {
        rules: [
            {
                test: /\.js$/,
                use: ['babel-loader'.'eslint-loader']
            }
        ]
    },
    plugins: [],
    devServer: {}
};
Copy the code

In accordance with the above three steps after writing, should give their own flowers, haha

But it doesn’t work. Too early to be happy

Rules used at work

Is the so-called people in the river’s lake floating ah, which have not the truth of the knife. Who can say that writing code in ESLint will not report errors at all? Errors are perfectly normal and there’s no need to panic

Now for some of the more common norms to simple comb, so many rules, in fact, I also eat a whale

Now let’s look at the rules for error reporting during compilation

Non-friendly warning: 0, 1, and 2 corresponding to each rule indicate three error levels: OFF, Warning, and Error

  • no-unused-vars
    • Variables are defined but not used in the code to prevent unnecessary variables from being created
  • semi
    • The semicolon is missing and must be used at the end of the line in case of an unexpected situation when compressing the code
  • no-console
    • Disable console and remind developers to remove it when online, as warning does not cause problems with compiled JS
  • consistent-this
    • This rule allows only self and that, which prevents some people from writing _this or me, etc
  • curly
    • If must be followed by {, except for a single if line, also for easy code reading
    // Error writingfunction fn (key) {
       if (key === 'a') 
           return 1;
    }
    fn('a'); // Write correctlyfunction fn (key) {
       if (key === 'a') {
           return 1;
       }
       if (key === 'b') return 2;
    }
    fn('a');
    Copy the code
  • default-case
    • The switch statement must contain default
    // Error writingfunction fn (key) {
        let str = ' ';
    
        switch (key) {
            case 'a':
                str = 'a';
                break;
            case 'b':
                str = 'b';
                break;
        }
        returnstr; } // Write correctlyfunction fn (key) {
        let str = ' ';
    
        switch(key) {
            case 'a':
                str = 'a';
                break;
            case 'b':
                str = 'b';
                break;
            default:
                str = 'c';
                break;
        }
        return str;
    }
    Copy the code
  • eqeqeq
    • You must use congruent === for comparisons to prevent unexpected problems with implicit conversions
  • guard-for-in
    • For in checks hasOwnProperty to avoid traversing inherited property methods
  • max-depth
    • The maximum size of nesting cannot exceed 5 layers
    // Write correctlyif () {
        if () {
            if () {
                if () {
                    if() {}}}}}Copy the code
  • max-params
    • A function must have no more than 8 parameters. If there are too many, we can now use the extension operator… To replace the unnecessary parameters
  • new-cap
    • The class name should be capitalized after the new keyword, and the category and function should be specified
  • no-array-constructor
    • Disallow the use of Array constructors; define arrays directly in the quickest way [1, 2, 3]
  • no-await-in-loop
    • It is forbidden to write await inside a loop. Loops are synchronous operations and should not write await asynchronously inside
  • no-caller
    • Disables arguments.caller and arguments.callee, deprecated in ES6
  • no-const-assign
    • Disallow reassignment to const definitions
  • no-delete-var
    • Do not use the delete keyword on variables. Delete applies only to the properties of objects
  • no-dupe-args
    • Function arguments do not have the same name
  • no-empty-function
    • Disallow empty functions and make sure every function you write is useful
  • no-eval
    • Eval is forbidden. Eval is the devil, so avoid it during development
  • no-extra-semi
    • Prohibit extra semicolons. Some places where semicolons are unnecessary, such as if () {}; That would be wrong
  • no-global-assign
    • Disallow assigning to global variables

Well and some will require everyone in use and experience, I will use our work below ESLint rules posted, facilitate everybody to do code review

//.eslintrc.js module.exports = {// exports'parser': 'babel-eslint'.'parserOptions': {// Enable ES8 syntax support'ecmaVersion': 2017, // module indicates the ECMAScript module'sourceType': 'module', // Use additional language features'ecmaFeatures': {
            'experimentalObjectRestSpread': true.'jsx': true.'modules': true}}, // These environments are not mutually exclusive, so you can define more than one at a time'env': {
        'browser': true.'jquery': true.'node': true.'commonjs': true.'es6': true,},'root': true, // The no-undef rule warns when accessing undefined variables in the current source file // so these additional global variables need to be defined'globals': {
        'OnlySVG': true.'monitor': true.'CanvasRender': true.'Vue': true.'VueRouter': true
    },
    'rules': {// Setters must be set accordingly, and getters must not be set otherwise'accessor-pairs': 2, // Array square brackets before and after the use of newlines rule // @off does not care'array-bracket-newline': 0, // Array square brackets before and after the space rule // @off does not care'array-bracket-spacing': 0, // array map, filter, sort, etc. Callback function must have a return value'array-callback-return': 2, // each array item gets an exclusive row // @off does not care'array-element-newline': 0, // Arrow function writing rules // @off is not limited'arrow-body-style': 0, // The use of parentheses for arrow functions // @off is not restricted'arrow-parens': 0, // Arrow function space use rule // @off is not limited'arrow-spacing': 0, // Variables defined in block-scoped var cannot be used outside a block'block-scoped-var': 2, // code block before and after curly braces space rule // @off does not care'block-spacing': / / 0if else// @off doesn't care'brace-style': 0, // Callback must immediately followreturn// @off No need'callback-return': 0, // the variable name must use the hump // @off is not limited'camelcase': 0, // The first letter of the comment should be capitalized // @off is not necessary'capitalized-comments': 0, // non-static methods of class must contain the this keyword'class-methods-use-this': 2, // whether to write a comma after the last item of the object // @off this project does not care // @fixable for PC projects to consider compatibility needs to set'comma-dangle': 0, // whether there is space before and after the comma // @off does not care'comma-spacing': 0, // comma at the beginning or end of the line // @off doesn't care'comma-style': 0, // Disable the functionif.else if.elseThe complexity of is over 20'complexity': 2, // @off does not care about the spacing rule before and after square brackets when accessing object properties'computed-property-spacing': 0, // disallow functions to return different types of values under different conditions // @off sometimes wants to get different types of return values from arguments'consistent-return': 0, // this alias rule, allowing only self or that'consistent-this'A: [2,'self'.'that'], // the constructor must call super // @off is not necessary'constructor-super': / / 0ifMust contain {, single lineifWith the exception of'curly'A: [2,'multi-line'.'consistent'], // The switch statement must contain default'default-case': 2, // @off does not care whether the dot is at the end of the previous line or at the beginning of the next line'dot-location': 0, // file must end with blank line // @off is not restricted'eol-last': 0, // must use === and! ==, except when comparing with NULL'eqeqeq'A: [2,'always', { 'null': 'ignore'}]. / /forThe loop shall not cause an infinite loop due to the wrong direction'for-direction': 2, // Executes function parentheses before and after the space rule // @off does not care'func-call-spacing': 0, // When assigning a function to a variable or object property, the name of the function must be the same as the name of the variable or object property // @off is not restricted'func-name-matching': 0, // Anonymous functions are not allowed // @off is not restricted'func-names': 0, // Only function declarations or only function expressions must be used // @off is not restricted'func-style': 0, // Generator * before and after the space rule // @off is not limited'generator-star-spacing': 0, // The getter must have a return value, allowing the return of undefined'getter-return': [2, { allowImplicit: true}], // require must be in global scope // @off Conditional loading is common'global-require': / / 0for inCheck hasOwnProperty'guard-for-in': 2, // The err, error parameters and variables in the callback must be handled'handle-callback-err': 2, // id blacklist // @off'id-blacklist': 0, // limit the length of variable names // @off is not important, legibility is the key'id-length': 0, // The variable name must match the specified regular expression // @off There is no need to restrict the variable name'id-match': 0, // indent using TAB or space // @off doesn't care'indent': 0, // The variable must be assigned when it is defined // @off is defined first and then assigned'init-declarations': 0, // In JSX syntax, attribute values must be in double quotes'jsx-quotes'A: [2,'prefer-double'], // The rule for using Spaces before and after colons on object literals // @off does not care'key-spacing': 0, // There must be Spaces before and after the keyword'keyword-spacing': 2, // newline use rule // @off does not care'linebreak-style': 0, // Single-line comments must be written at the beginning or end of the line // @off is unlimited'line-comment-position': 0, // whether to leave a blank line before and after the comment // @off is not limited'lines-around-comment': 0, // Maximum block nesting depth is 5 layers'max-depth': [2, 5], // limit the length of a single line of code // @off is not limited'max-len': 0, // limit the maximum number of lines in a single file // @off is not limited'max-lines': 0, // The maximum callback depth is 3 layers'max-nested-callbacks': [2, 3], // The function cannot have more than 8 parameters'max-params': [2, 8], // limit the number of statements in a row // @off No restriction is necessary'max-statements-per-line': 0, // limit the number of statements in a function block // @off is not necessary'max-statements': 0, // Ternary expression newline rule // @off is not limited'multiline-ternary': 0, // new Capitalize the class name after the keyword'new-cap': [2, {
            'capIsNew': false}]; // The class should contain parentheses after the new keyword'new-parens': 2, // whether chained calls should be newlines // @off is not restricted'newline-per-chained-call': 0, // Disable the alert'no-alert': 1, // Disallow the use of Array constructors. Use Array(num) to create an Array of length num'no-array-constructor': 2, // Disallow writing await inside loops'no-await-in-loop': 2, // disable bit operation // @off is not restricted'no-bitwise': 0, // Disallow direct calls to the Buffer constructor in Node.js'no-buffer-constructor': 2, // Disable arguments.caller and arguments.callee'no-caller': 2, // switch condition with var,let, const,function, class, etc. The content must be enclosed in curly braces'no-case-declarations': 2, // Catch must not use defined variable names'no-catch-shadow': 2, // class defines a class whose name must not be the same as any other variable'no-class-assign': 2, // Forbid comparisons with -0'no-compare-neg-zero': 2, // prohibit inif,for,whileUnless enclosed in parentheses'no-cond-assign'A: [2,'except-parens'], // disallow incomprehensible arrow functions unless enclosed in parentheses'no-confusing-arrow': [2, { 'allowParens': true}, // Disable the use of console, remind developers to remove it when online'no-console': 1, // Disable the use of constants as criteria'no-constant-condition': [2, { 'checkLoops': false}, // Disallow reassigning const definitions'no-const-assign': 2, // Forbiddencontinue// @off is very common'no-continue': 0, // disallows the ASCII representation of Ctrl in regular expressions, that is, /\x1f/'no-control-regex': 2, // disable debugger statements and remind developers to remove them when online'no-debugger': 1, // Disallow the use of the delete keyword on variables. There is no restriction on the deletion of object properties'no-delete-var': 2, // Disallow the beginning of the similar division operator in regular expressions, for exampleletA = /=foo/ // @off With code highlighting, there is no ambiguity or difficulty in understanding when reading this code'no-div-regex': 0, // Function arguments are not allowed to have the same name'no-dupe-args': 2, // disallow objects with the same key'no-dupe-keys': 2, // Class methods disallow duplicate names'no-dupe-class-members': 2, // disable the same in switchcase
        'no-duplicate-case': 2, // prohibit repeating import'no-duplicate-imports': 2, // forbiddenif (cond) { return a } else { returnB}, should be written asif (cond) { return a } returnB // @off Sometimes the former is clearer'no-else-return': 0, // Forbade empty character sets in regular expressions []'no-empty-character-class': 2, // Prohibit emptyfunction// This is allowed if comments are included'no-empty-function': 2, // Disallow empty {} or [] in deconstruction'no-empty-pattern': 2, // disallow empty code blocks'no-empty': [2, { 'allowEmptyCatch': true}, // Prohibit == and! = to compare with null, you must use === or! == // @off = null and undefined'no-eq-null': 0, // Forbiddeneval
        'no-eval': 2, // Arguments defined by catch disallow assignment'no-ex-assign': 2, // Disable extension of native objects'no-extend-native': [2, { 'exceptions': ['Array'.'Object']}], // Prohibit additionalbind
        'no-extra-bind': 2, // disallow additional Boolean conversions'no-extra-boolean-cast': 2, // Disable additional labels'no-extra-label': 2, // Disallow additional parentheses only for the function body'no-extra-parens'A: [2,'functions'], // Prohibit additional semicolons'no-extra-semi': 2, // for each switchcaseNeed to havebreak.returnOr throw // containing comments'no-fallthrough': [2, { 'commentPattern': '. '}}, // You are not allowed to use 2. Or.5 to represent the number, you need to use 2, 2.0, 0.5 format'no-floating-decimal': 2, // Disallow reassignment of function declarations'no-func-assign': 2, // Disallow assigning to global variables'no-global-assign': 2, // Disable implicit conversions'no-implicit-coercion': [2, {
            'allow': ['+'.'!!!!! '] // Allow + conversion value' '+ turn string and!! }], // disable insetThe Timeout andsetInterval, because implicit is triggeredeval
        'no-implied-eval': 2, // Disallow implicitly defining global variables'no-implicit-globals': 2, // Prohibit inline comments // @off is very common'no-inline-comments': 0, // Disallow var or function declarations in block scope'no-inner-declarations'A: [2,'both'], // Disallow illegal regular expressions'no-invalid-regexp': 2, // Disallow the use of this outside of the class // @off this is very flexible. The current element can be represented in the event callback, and the function can use this first and then call it later'no-invalid-this': 0, // Prohibit the use of irregular Spaces'no-irregular-whitespace': [2, {
            'skipStrings': true, // Allow it to be used in strings'skipComments': true, // Allowed in comments'skipRegExps': true, // Allow use in regular expressions'skipTemplates': true}] is allowed in template strings, and __iterator__ is disallowed'no-iterator': 2, // label must not have the same name as a defined variable'no-label-var': 2, // disable the use of label // @off will be difficult to disablebreakMultiple loops and multiple switches'no-labels': 0, // Disallow invalid block scope'no-lone-blocks': 2, // ForbiddenelseThere is only one singleif// @off AloneifYou can express the logic more clearly'no-lonely-if': 0, // Disablefor (var i) { function() {use I}}letThen you can'no-loop-func': 2, // Forbid magic numbers'no-magic-numbers': 0, // Disallow the use of mixed logic judgment, the different logic must be enclosed in parentheses'no-mixed-operators': [2, {
            "groups": [["&"."| |"[]}], // require of the same type must be put together // @off is not restricted'no-mixed-requires': 0, // Do not use space and TAB to indent, must be uniform'no-mixed-spaces-and-tabs': 2, // Disallow constant assignment'no-multi-assign': 2, // Disallow consecutive Spaces'no-multi-spaces': 2, // Do not use \ to define multi-line strings. Use template strings to do so'no-multi-str': 2, // limit on the number of consecutive blank lines'no-multiple-empty-lines': [2, {Max: 3, // A maximum of three consecutive maxEOF: 1 in the file, // a maximum of one consecutive maxBOF: 1 at the end of the file}], // ForbiddenifNegative expression appears in! == // @off The negative expression can express the logic more clearly'no-negated-condition': 0, // Disallow nested ternary expressions // @off is not necessarily restricted'no-nested-ternary': 0, // disallow new Function // @off Is sometimes used to parse JSON data in non-standard formats'no-new-func': 0, // Disable the use of new Object'no-new-object': 2, // Prohibit using new require'no-new-require': 2, // Prohibit using new Symbol'no-new-symbol': 2, // Disallow new Boolean, Number, or String'no-new-wrappers': 2, // Disallow a new class without storing the instance'no-new': 2, // Disallow using native objects like Math, JSON, and Reflect as functions'no-obj-calls': 2, // Disallow octal escape characters'no-octal-escape': 2, // Disallow the use of digits beginning with 0 to indicate octal'no-octal': 2, // Disable __dirname +'file'Join or path.resolve should be used instead'no-path-concat': 2, // Disallow reassignment of function arguments'no-param-reassign': 2, // prohibit ++ and -- // @off'no-plusplus': 0, // Disable process.env.node_env // @off is common'no-process-env': 0, // Disables process.exit(0) // @off is common'no-process-exit': 0, // Disallow hasOwnProperty, isPrototypeOf, or propertyIsEnumerable // @off conflicts with the Guardfor-in rule and is not necessary'no-prototype-builtins': 0, // Disallow __proto__'no-proto': 2, // Do not repeat statements'no-redeclare': 2, // Disallow consecutive Spaces in regular expressions'no-regex-spaces': 2, // disable specific global variables // @off is not available'no-restricted-globals': 0, // disable import of specific modules // @off is not available'no-restricted-imports': 0, // disable the use of specific modules // @off is not currently available'no-restricted-modules': 'off', // disallow specific object properties // @off is temporarily unavailable'no-restricted-properties': 0, // prohibit the use of specific syntax // @off is not currently available'no-restricted-syntax': 0, // Prohibit inreturnIn the assignment'no-return-assign': 2, // prohibit inreturnThe use of await'no-return-await': 2, // disable location.href ='javascript:void'
        'no-script-url': 2, // Disallow assigning to yourself'no-self-assign': 2, // Forbid comparing yourself to yourself'no-self-compare': 2, // Disallow the comma operator'no-sequences': 2, // Do not use reserved words as variable names'no-shadow-restricted-names': 2, // Disallow the definition of the same name in nested scopes, such aslet a; function b() { let a }
        'no-shadow': 2, // Disallow sequential commas in arrays'no-sparse-arrays': 2, // Disable node synchronization methods such as fs.readFileSync // @off'no-sync': 0, // Disable using tabs // @off is not restricted'no-tabs': 0, // Disallow template string syntax in normal strings'no-template-curly-in-string': 2, // disallow ternary expressions // @off is commonly used'no-ternary': 0, // Disallow the use of this before the super constructor'no-this-before-super': 2, // Disallow throw literals, must throw an Error object'no-throw-literal': 2, // Disallow Spaces at the end of lines'no-trailing-spaces': [2, {
            "skipBlankLines": true, // Do not check for blank lines"ignoreComments": true// Do not check comments}], // disallow assignment of undefined to variables'no-undef-init': 2, // Disallow access to undefined variables or methods'no-undef': 2, // Prohibit using undefined. To determine whether a variable is undefined, use typeof a ==='undefined'
        'no-undefined': 2, // disallow the use of underscores in variable names // @off is not restricted for now'no-underscore-dangle': 0, // disallow incomprehensible multiline code'no-unexpected-multiline': 2, // Circulation conditions must be modified in the circulatory body'no-unmodified-loop-condition': 2, // Disallow unnecessary ternary expressions'no-unneeded-ternary': [2, { 'defaultAssignment': false}], // disallow unreachable code, such as inreturn, throw'no-unreachable': 2, // Disallow in finally blocksreturn, throw,break,continue
        'no-unsafe-finally': 2, // Prohibit the occurrence of unsafe negative, e.gfor(! keyinObj} {}for(! (keyin obj)} {}
        'no-unsafe-negation': 2, // Disallow useless expressions'no-unused-expressions': [2,
            {
                'allowShortCircuit': true, / / allow the use of (a) | | b and a & b ()'allowTernary': true, // Allow ternary operators in expressions'allowTaggedTemplates': true}]; // Disallow defining unused labels'no-unused-labels': 2, // Disallow defining unused variables'no-unused-vars': [2,
            {
                'vars': 'all', // Variable definitions must be used'args': 'none', // Do not check for function parameters'ignoreRestSiblings': true// Ignore the remaining subterms fn(... Args), {a, b... coords}'caughtErrors': 'none', // ignore catch arguments using}], // disallow use of variables before they are defined'no-use-before-define': [2,
            {
                'functions': false, // allows functions to be called before they are defined'classes': false, // allow classes to be referenced before they are defined}], // prohibit unnecessary calls and apply'no-useless-call'Var a = {[var a = {[var a = {[var a = {['0']: 0 }
        'no-useless-computed-key': 2, // Disallow unnecessary string concatenation'no-useless-concat': 2, // disallow useless constructors'no-useless-constructor': 2, // Prohibit useless escapes'no-useless-escape': 2, // Disallow invalid renames, such as import {a as a} from XXX'no-useless-rename': 2, // Prohibition is unnecessaryreturn// @off No restriction is necessary'no-useless-return': 0, // Var is forbidden and must be usedletOr const'no-var': 2, // Disallow void'no-void': 2, // Disable TODO or FIXME in comments. Use this to remind developers to write TODO and finish it'no-warning-comments': 1, // disallow Spaces before properties, such as foo.bar ()'no-whitespace-before-property': 2, // prohibit with'no-with': 2, // ForbiddenifThe statement wraps lines without curly braces'nonblock-statement-body-position': 2, // define whether to add blank lines before and after curly braces // @off does not care'object-curly-newline': 0, // define whether the object's curly braces should be followed by Spaces // @off does not care'object-curly-spacing': 0, // the object must have an exclusive row for each property // @off is not limited'object-property-newline': 0, // obj = {a: a} must be converted to obj = {a} // @off'object-shorthand': 0, // each variable declaration must have an exclusive line // @off does not need this rule if there is one-var'one-var-declaration-per-line': 0, // Whether to allow multiple variables to be declared at once using commas'one-var': [2, {
            'const': 'never'// All const declarations must be exclusive to one line, no comma is allowed to define multiple}], // must use x = x + y instead of x += y // @off no restriction is necessary'operator-assignment': 0, // the operator is at the beginning or end of the line // @off doesn't care'operator-linebreak': 0, // Code block must start and end blank line // @off no need to limit'padded-blocks': 0, // limit blank lines between statements. For example, the variable must be blank after definition. // @off is not necessary'padding-line-between-statements': 0, // must use the arrow function as the callback // @off is not necessary'prefer-arrow-callback': 0, // Variables that are not modified after declaration must be const // @off is not necessary'prefer-const': 0, // Must use deconstruction // @off is not necessary'prefer-destructuring': 0, // must use 0b11111011 instead of parseInt('111110111', 2) // @off no need'prefer-numeric-literals': 0, // Reject a promise must pass Error objects instead of literals'prefer-promise-reject-errors': 2, // Must use deconstruction... Args instead of arguments'prefer-rest-params': 2, // Must use func(... Args) instead of func.apply(args) // @off is not necessary'prefer-spread': 0, // Must use template strings instead of string concatenation // @off is not limited'prefer-template': 0, // Strings must use single quotes'quotes'A: [2,'single', {
            'avoidEscape': true, // Allow a string containing single quotes to use double quotes'allowTemplateLiterals': true, // Template string}] is allowed, // key names of object literals are not allowed to be enclosed in quotation marks // @off is unnecessary'quote-props': 0, // parseInt must be passed in base parameters'radix': 2, // Async function must have await statement // @off asyncfunctionIt is common to write without await in, as in the KOA example'require-await': 0, // Must use jsdoc style comments // @off is not considered open for now'require-jsdoc': 0, // Generator functions must have yield'require-yield': 2, / /... No space is allowed after it'rest-spread-spacing'A: [2,'never'], // the space rule before and after the semicolon // @off is not restricted'semi-spacing': 0, // Disallow the semicolon at the beginning of a line'semi-style'A: [2,'last'], // Lines must end with a semicolon'semi': 2, // imports must be sorted // @off is not necessary'sort-imports': 0, // The key names of object literals must be sorted // @off is unnecessary'sort-keys': 0, // Variable declarations must be sorted // @off no restriction necessary'sort-vars': / / 0functionDoes not care whether the space // @off is used before the curly braces'space-before-blocks': / / 0functionDoes not care whether the parentheses are preceded by Spaces // @off'space-before-function-paren': 0, // Rules for using Spaces inside parentheses // @off doesn't care'space-in-parens': 0, the // operator must be preceded by Spaces'space-infix-ops': 2, // new, delete, typeof, void, yield, etc. ,!!!!! No space before or after the expression'space-unary-ops': [2, {
            'words': true.'nonwords': false,}], // Comments should be followed by Spaces after the slash and asterisk'spaced-comment'A: [2,'always', {
            'block': {
                exceptions: [The '*'],
                balanced: true}}], // Disable strict mode, forbidden anywhere'use strict'
        'strict'A: [2,'never'], // the space rule before and after the colon in the switch // @off does not care'switch-colon-spacing': 0, // When creating a Symbol, you must pass in a description'symbol-description': 2, // Template stringThe ${}// @off is not limited'template-curly-spacing': 0, // Template string before and after the space rule // @off is not limited'template-tag-spacing': 0, // BOM is forbidden in all file headers'unicode-bom': 2, // Do not judge NaN directly. IsNaN must be used'use-isnan': 2, // Comments must comply with the jsdoc specification // @off is not considered open for now'valid-jsdoc': 0, // Typeof can only be"undefined"."object"."boolean"."number"."string"."function""symbol"
        'valid-typeof': 2, // var must be at the beginning of the scope // @off var is not at the beginning of the scope'vars-on-top': 0, // Self-executing functions must be enclosed in parentheses, such as (function() {dosomething... }) ()'wrap-iife'A: [2,'inside'], // The regular expression must be enclosed in parentheses // @off is not limited'wrap-regex': 0, // yield (*); // @off is not restricted'yield-star-spacing': 0, // Disable the Yoda judgment condition, such asif (true=== a) should be usedif (a === true)
        'yoda': 2,}};Copy the code

Say something more

These are the ESLint rules THAT I use for my corporate projects, so you can apply them to your own projects. These rules are configurable, but if you don’t find them useful, just set them to 0

We want to do a very standardized Coder, let others see the code we write to read accessibility, on the hand fast, this is efficient development

Ha ha, that’s it, thank you all!