Preface
eslint is a code style management tool that can formulate some code writing specifications, which are often used in vue projects. This article will share with you the eslint verification specifications used in development projects for reference:
Sample code
= { root: true, parserOptions: { parser: 'babel-eslint', sourceType: 'module' }, env: { browser: true, node: true, es6: true, }, extends: ['plugin:vue/essential', 'eslint:recommended'], rules: { // The levels are divided into three levels: 0-not displayed; 1-show warning; 2-show error error //////////////////// ////// vue. Specification //////// /////////////////// "vue/max-attributes-per-line": [1, { //Elements of multiple characteristics should be written in multiple lines, one line for each characteristic "singleline": 10, "multiline": { "max": 1, "allowFirstLine": false } }], "vue/singleline-html-element-content-newline": 0, // Line breaks are required before and after the content of a single line element "vue/multiline-html-element-content-newline": 0, // Need a newline before and after the content of a multi-line element "vue/name-property-casing": [1, "PascalCase"], // The component name in JS/JSX should always be Pascal nomenclature "vue/no-v-html": 0, "vue/prop-name-casing": [1, "camelCase"], // When declaring a prop, its naming should always be named using camel "vue/require-v-for-key": 1, // Set key values for v-for, and use them in combination with keys to efficiently update the virtual DOM "vue/no-use-v-if-with-v-for": [2, { "allowUsingIterationVar": false }], // Don't use v-if and v-for on the same element - because v-for has a higher priority than v-if "vue/order-in-components": [0, { // Order of options for components/instances "order": [ "el", "name", "parent", "functional", ["delimiters", "comments"], ["components", "directives", "filters"], "extends", "mixins", "inheritAttrs", "model", ["props", "propsData"], "data", "computed", "watch", "LIFECYCLE_HOOKS", "methods", ["template", "render"], "renderError" ] }], //////////////////// ////// js. Specification ////// /////////////////// 'accessor-pairs': 2, // Force getter/setter in object 'arrow-spacing': [2, { // Require space before/after arrow function 'before': true, 'after': true }], 'block-spacing': [2, 'always'], // Disable or enforce spaces inside the block after opening and before closing the block 'brace-style': [1, '1tbs', { // Brace style is required 'allowSingleLine': true }], 'camelcase': [0, { // Need to be named 'properties': 'always' }], 'comma-dangle': [2, 'never'], // Require or prohibit the use of trailing commas; the last attribute is that no commas are required 'comma-spacing': [2, { // Force the spacing next to the comma: a space on the left and right 'before': false, 'after': true }], 'comma-style': [2, 'last'], // Comma style 'constructor-super': 2, // Use super method in the build method 'curly': [2, 'multi-line'], 'dot-location': [1, 'property'], // Force wrap before and after dot 'eol-last': 2, // Require or prohibit line breaks at the end of the file 'eqeqeq': [0, "always", { "null": "ignore" }], // Whether to use the same 'generator-star-spacing': [2, { // Force spacing around * in generator function 'before': true, 'after': true }], 'handle-callback-err': [1, '^(err|error)$'], // Force callback error handling 'indent': [2, 2, { // Enforce consistent indentation 'SwitchCase': 1 }], 'jsx-quotes': [2, 'prefer-single'], // Force single quotes to be used consistently in JSX files 'key-spacing': [2, { // Force a consistent spacing between keys and values in object properties 'beforeColon': false, 'afterColon': true }], 'keyword-spacing': [2, { // Enforce consistent spacing before and after keywords 'before': true, 'after': true }], 'new-cap': [2, { // Require the constructor name to start with capital letters 'newIsCap': true, 'capIsNew': false }], 'new-parens': 2, // Parentheses are required when calling a function without parameters 'no-array-constructor': 2, // Disable array builder 'no-caller': 2, //Unable to use callers/callees 'no-console': 'off', //Console is not allowed 'no-class-assign': 2, // Disable modification of variables declared in class 'no-cond-assign': 2, // Disable assignment operators in conditional statements 'no-const-assign': 2, // Disable modification of variables declared using const 'no-control-regex': 0, // Disable control characters in regular expressions 'no-delete-var': 2, // Disable variable deletion 'no-dupe-args': 2, // Disable duplicate parameters in function definition 'no-dupe-class-members': 2, //Don't repeat names in class members 'no-dupe-keys': 2, // Objects are prohibited from repeatedly declaring properties 'no-duplicate-case': 2, // Rules prohibit duplicate case tags 'no-empty-character-class': 2, // Use empty character classes in regular expressions are prohibited 'no-empty-pattern': 2, // No empty deconstruction mode is allowed 'no-eval': 2, // Use of eval() is prohibited 'no-ex-assign': 2, // Reassign exceptions in catch clauses 'no-extend-native': 2, // Disable expansion of native objects 'no-extra-bind': 2, // Unnecessary function binding is prohibited 'no-extra-boolean-cast': 2, // Disable unnecessary boolean type conversion 'no-extra-parens': [2, 'functions'], // Unnecessary brackets are prohibited 'no-fallthrough': 2, // Too many statements and descriptions are prohibited 'no-floating-decimal': 2, // Floating decimals is prohibited 'no-func-assign': 2, // Reassign function declarations are prohibited 'no-implied-eval': 2, 'no-inner-declarations': [2, 'functions'], // Disable variables or function declarations in nested blocks 'no-invalid-regexp': 2, // Disable the use of invalid regular expression strings in RegExp 'no-irregular-whitespace': 2, // Irregular blanks are not allowed 'no-iterator': 2, // Iterator is prohibited 'no-label-var': 2, // Disable tags of variable names 'no-labels': [2, { 'allowLoop': false, 'allowSwitch': false }], 'no-lone-blocks': 2, // ban unnecessary nested blocks 'no-mixed-spaces-and-tabs': 2, // Use of mixed spaces and tabs for indentation is prohibited 'no-multi-spaces': 2, // Multiple spaces are prohibited 'no-multi-str': 2, // Multi-line strings are prohibited 'no-multiple-empty-lines': [2, { // Forbid multiple empty lines 'max': 1 }], 'no-native-reassign': 2, 'no-negated-in-lhs': 2, 'no-new-object': 2, 'no-new-require': 2, 'no-new-symbol': 2, 'no-new-wrappers': 2, 'no-obj-calls': 2, 'no-octal': 2, 'no-octal-escape': 2, 'no-path-concat': 2, 'no-proto': 2, 'no-redeclare': 2, 'no-regex-spaces': 2, 'no-return-assign': [2, 'except-parens'], 'no-self-assign': 2, 'no-self-compare': 2, 'no-sequences': 2, 'no-shadow-restricted-names': 2, 'no-spaced-func': 2, 'no-sparse-arrays': 2, 'no-this-before-super': 2, 'no-throw-literal': 2, 'no-trailing-spaces': 2, 'no-undef': 0, 'no-undef-init': 2, 'no-unexpected-multiline': 2, 'no-unmodified-loop-condition': 2, // Unmodified loop conditions are prohibited 'no-unneeded-ternary': [2, { // ternary operators are not allowed when simpler alternatives exist 'defaultAssignment': false }], 'no-unreachable': 2, // ban inaccessible code after returning, throwing, continuing and interrupt statements 'no-unsafe-finally': 2, // Disable control flow statements in finally blocks 'no-unused-vars': [1, { //Undeclared variables are prohibited 'vars': 'all', 'args': 'none' }], 'no-useless-call': 2, // Disable unnecessary call() and apply() methods 'no-useless-computed-key': 2, // Use unnecessary computed attribute keys on objects are prohibited 'no-useless-constructor': 2, // Unnecessary construction methods are prohibited 'no-useless-escape': 0, // Unnecessary escaping usage is prohibited 'no-whitespace-before-property': 2, // Disable spaces before attribute 'no-with': 2, 'one-var': [2, { 'initialized': 'never' }], 'operator-linebreak': [2, 'after', { // Enforce consistent line breaking methods to maintain 'overrides': { '?': 'before', ':': 'before' } }], 'padded-blocks': [2, 'never'], // Require or prohibit filling in blocks 'quotes': [2, 'single', { 'avoidEscape': true, 'allowTemplateLiterals': true }], 'semi': [2, 'never'], 'semi-spacing': [2, { 'before': false, 'after': true }], 'space-before-blocks': [2, 'always'], // Don't have extra block space 'space-before-function-paren': [2, 'never'], 'space-in-parens': [2, 'never'], 'space-infix-ops': 2, 'space-unary-ops': [2, { 'words': true, 'nonwords': false }], 'spaced-comment': [2, 'always', { 'markers': ['global', 'globals', 'eslint', 'eslint-disable', '*package', '!', ','] }], 'template-curly-spacing': [2, 'never'], 'use-isnan': 2, 'valid-typeof': 2, 'wrap-iife': [2, 'any'], 'yield-star-spacing': [2, 'both'], 'yoda': [2, 'never'], 'prefer-const': 1, 'no-debugger': .NODE_ENV === 'production' ? 2 : 0, 'object-curly-spacing': [2, 'always', { objectsInObjects: false }], 'array-bracket-spacing': [2, 'never'] } }
Summarize
The above is the entire content of this article. I hope that the content of this article has certain reference value for your study or work. Thank you for your support.