- 前端开发过程中由于要规范我们的代码,需要用到eslint+ stylelint对 js和css进行规范约束, 而按照规范配置我们开发者工具(vscode)显得尤为方便
// vscode setting配置, 可以实现ctrl+s保存根据eslint+style实现自动修复
...
"eslint.validate": [
"javascript",
"vue",
"html"
],
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true,
"source.fixAll.stylelint": true,
},
"stylelint.validate": [
"vue",
"html"
],
"stylelint.enable": true,
"css.validate": true,
"scss.validate": true,
"less.validate": true,
...
module.exports = {
root: true,
parserOptions: {
sourceType: 'module',
parser: 'babel-eslint',
},
env: {
browser: true
},
extends: [
'standard',
'plugin:vue/recommended',
],
plugins: ['html', 'vue'],
rules: {
'vue/max-attributes-per-line': [2, {
singleline: 10,
multiline: {
max: 1,
allowFirstLine: false
}
}],
'vue/singleline-html-element-content-newline': 'off',
'vue/multiline-html-element-content-newline': 'off',
'vue/name-property-casing': ['error', 'PascalCase'],
'vue/no-v-html': 'off',
'vue/require-v-for-key': 'error',
'vue/no-use-v-if-with-v-for': ['error', {
allowUsingIterationVar: false
}],
'vue/component-name-in-template-casing': ['error', 'kebab-case', {
registeredComponentsOnly: false,
ignores: []
}],
'arrow-parens': 0,
'generator-star-spacing': 0,
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0,
'semi': [1, 'always', { omitLastInOneLineBlock: true }],
'space-before-function-paren': [1, 'never'],
'padded-blocks': [0, { blocks: 'always' }],
'comma-dangle': [0, 'always-multiline'],
'indent': [1, 2, { SwitchCase: 1, CallExpression: { arguments: 2 } }],
'no-mixed-spaces-and-tabs': 2,
'operator-linebreak': [2, 'after'],
'quotes': [2, 'single'],
'no-control-regex': 0,
'max-statements-per-line': ['error', { max: 1 }],
'comma-style': [2, 'last', { exceptions: { CallExpression: false } }],
'no-extra-semi': 2,
'no-var': 2,
'no-use-before-define': [2, { functions: true, classes: true, variables: true }
],
'radix': 2,
'quote-props': [2, 'consistent-as-needed'],
'no-extend-native': 2,
'max-lines-per-function': [1, { max: 50 }],
'max-params': [1, 6],
'guard-for-in': 1,
}
};
module.exports = {
extends: ['stylelint-config-standard', 'css-properties-sorting'],
plugins: ['stylelint-order'],
rules: {
'function-url-quotes': 'always',
'number-leading-zero': 'never',
'number-no-trailing-zeros': true,
'string-quotes': 'double',
'value-keyword-case': 'lower',
'length-zero-no-unit': true,
'shorthand-property-no-redundant-values': true,
'keyframe-declaration-no-important': true,
'selector-class-pattern': '^[a-z]+([a-z0-9]?|[a-z0-9\\-]*[a-z0-9])$',
'max-nesting-depth': 5,
'no-duplicate-selectors': true,
'order/order': [
['custom-properties', 'declarations'], {
disableFix: true
}
],
'order/properties-order': [
'position',
'display',
'float',
'top',
'right',
'bottom',
'left',
'z-index',
'overflow',
'clear',
'width',
'height',
'max-width',
'max-height',
'min-width',
'min-height',
'padding',
'padding-top',
'padding-right',
'padding-bottom',
'padding-left',
'margin',
'margin-top',
'margin-right',
'margin-bottom',
'margin-left',
'margin-collapse',
'margin-top-collapse',
'margin-right-collapse',
'margin-bottom-collapse',
'margin-left-collapse',
'font',
'font-family',
'font-size',
'font-smoothing',
'osx-font-smoothing',
'font-style',
'font-weight',
'hyphens',
'src',
'line-height',
'letter-spacing',
'word-spacing',
'color',
'text-align',
'text-decoration',
'text-indent',
'text-overflow',
'text-rendering',
'text-size-adjust',
'text-shadow',
'text-transform',
'word-break',
'word-wrap',
'white-space',
'vertical-align',
'list-style',
'content',
'box-shadow',
'border-radius',
'transform'
]
}
};
- 这样在实际的开发过程中 我们很方便的可以对我们代码进行按照我们自定的规范对我们写的代码规范处理。