Vue項目中ESlint規(guī)范示例代碼
更新時間:2019年07月04日 09:37:53 作者:靜水流深醬
這篇文章主要給大家介紹了關(guān)于Vue項目中ESlint規(guī)范的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家學習或者使用Vue具有一定的參考學習價值,需要的朋友們下面來一起學習學習吧
前言
eslint是一種代碼風格管理的工具,可以制定一些代碼編寫規(guī)范,在vue項目中經(jīng)常用到,本文就給大家分享了開發(fā)項目中使用的eslint校驗規(guī)范,供參考:
示例代碼
module.exports = {
root: true,
parserOptions: {
parser: 'babel-eslint',
sourceType: 'module'
},
env: {
browser: true,
node: true,
es6: true,
},
extends: ['plugin:vue/essential', 'eslint:recommended'],
rules: {
// 等級分為三級: 0-不顯示;1-顯示警告warning; 2-顯示錯誤error
////////////////////
///// vue.規(guī)范 /////
///////////////////
"vue/max-attributes-per-line": [1, { //多個特性的元素應該分多行撰寫,每個特性一行
"singleline": 10,
"multiline": {
"max": 1,
"allowFirstLine": false
}
}],
"vue/singleline-html-element-content-newline": 0, // 在單行元素的內(nèi)容前后需要換行符
"vue/multiline-html-element-content-newline": 0, // 在多行元素的內(nèi)容之前和之后需要換行符
"vue/name-property-casing": [1, "PascalCase"], // JS/JSX中的組件名應該始終是帕斯卡命名法
"vue/no-v-html": 0,
"vue/prop-name-casing": [1, "camelCase"], // 在聲明prop的時候,其命名應該始終使用駝峰命名
"vue/require-v-for-key": 1, // 給v-for設(shè)置鍵值,與key結(jié)合使用,可以高效的更新虛擬DOM
"vue/no-use-v-if-with-v-for": [2, {
"allowUsingIterationVar": false
}], // 不要把 v-if 和 v-for 用在同一個元素上——因為v-for 比 v-if 具有更高的優(yōu)先級
"vue/order-in-components": [0, { // 組件/實例的選項的順序
"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.規(guī)范 /////
///////////////////
'accessor-pairs': 2, // 在對象中強制使用getter/setter
'arrow-spacing': [2, { // 在箭頭函數(shù)之前/之后需要空格
'before': true,
'after': true
}],
'block-spacing': [2, 'always'], // 在打開塊之后和關(guān)閉塊之前,禁止或強制執(zhí)行塊內(nèi)部的空格
'brace-style': [1, '1tbs', { // 需要大括號樣式
'allowSingleLine': true
}],
'camelcase': [0, { // 需要駝峰命名
'properties': 'always'
}],
'comma-dangle': [2, 'never'], // 要求或禁止使用尾隨逗號;最后一個屬性是不需要逗號
'comma-spacing': [2, { // 強制逗號旁邊的間距: 左右一個空格
'before': false,
'after': true
}],
'comma-style': [2, 'last'], // 逗號風格
'constructor-super': 2, // 構(gòu)建方法中使用super方法
'curly': [2, 'multi-line'],
'dot-location': [1, 'property'], // 在dot之前和之后強制換行
'eol-last': 2, // 在文件末尾要求或禁止換行
'eqeqeq': [0, "always", { "null": "ignore" }], // 是否使用全等
'generator-star-spacing': [2, { // 在生成器函數(shù)中強制執(zhí)行*周圍的間距
'before': true,
'after': true
}],
'handle-callback-err': [1, '^(err|error)$'], // 強制執(zhí)行回調(diào)錯誤處理
'indent': [2, 2, { // 強制執(zhí)行一致的縮進
'SwitchCase': 1
}],
'jsx-quotes': [2, 'prefer-single'], // 強制在JSX文件中一致使用單引號
'key-spacing': [2, { // 在對象屬性中強制鍵和值之間的一致間距
'beforeColon': false,
'afterColon': true
}],
'keyword-spacing': [2, { // 關(guān)鍵字前后強制執(zhí)行一致的間距
'before': true,
'after': true
}],
'new-cap': [2, { // 要求構(gòu)造函數(shù)名稱以大寫字母開頭
'newIsCap': true,
'capIsNew': false
}],
'new-parens': 2, // 調(diào)用不帶參數(shù)的函數(shù)時需要括號
'no-array-constructor': 2, // 禁止陣列構(gòu)建器
'no-caller': 2, // 禁止使用來電者/被叫者
'no-console': 'off', // 不允許使用控制臺
'no-class-assign': 2, // 禁止修改類聲明的變量
'no-cond-assign': 2, // 在條件語句中禁止賦值運算符
'no-const-assign': 2, // 禁止修改使用const聲明的變量
'no-control-regex': 0, // 禁止正則表達式中的控制字符
'no-delete-var': 2, // 禁止刪除變量
'no-dupe-args': 2, // 在函數(shù)定義中禁止重復參數(shù)
'no-dupe-class-members': 2, // 禁止在類成員中重復名稱
'no-dupe-keys': 2, // 禁止對象重復聲明屬性
'no-duplicate-case': 2, // 規(guī)則禁止重復案例標簽
'no-empty-character-class': 2, // 禁止在正則表達式中使用空字符類
'no-empty-pattern': 2, // 不允許空的解構(gòu)模式
'no-eval': 2, // 禁止使用eval()
'no-ex-assign': 2, // 禁止在catch子句中重新分配異常
'no-extend-native': 2, // 禁止擴展原生對象
'no-extra-bind': 2, // 禁止不必要的功能綁定
'no-extra-boolean-cast': 2, // 禁止不必要的布爾類型轉(zhuǎn)換
'no-extra-parens': [2, 'functions'], // 禁止不必要的括號
'no-fallthrough': 2, // 禁止太多陳述描述
'no-floating-decimal': 2, // 禁止浮動小數(shù)
'no-func-assign': 2, // 禁止重新分配函數(shù)聲明
'no-implied-eval': 2,
'no-inner-declarations': [2, 'functions'], // 禁止嵌套塊中的變量或函數(shù)聲明
'no-invalid-regexp': 2, // 禁止在RegExp中使用無效的正則表達式字符串
'no-irregular-whitespace': 2, // 不允許不規(guī)則的空白
'no-iterator': 2, // 禁止迭代器
'no-label-var': 2, // 禁止變量名稱的標簽
'no-labels': [2, {
'allowLoop': false,
'allowSwitch': false
}],
'no-lone-blocks': 2, // 禁止不必要的嵌套塊
'no-mixed-spaces-and-tabs': 2, // 禁止使用混合空格和制表符進行縮進
'no-multi-spaces': 2, // 禁止多個空格
'no-multi-str': 2, // 禁止多行字符串
'no-multiple-empty-lines': [2, { // 禁止多個空行
'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, // 禁止未修改的循環(huán)條件
'no-unneeded-ternary': [2, { // 當存在更簡單的替代方案時,不允許三元運算符
'defaultAssignment': false
}],
'no-unreachable': 2, // 返回,拋出,繼續(xù)和中斷語句后禁止無法訪問的代碼
'no-unsafe-finally': 2, // 禁止finally塊中的控制流語句
'no-unused-vars': [1, { // 禁止使用未聲明的變量
'vars': 'all',
'args': 'none'
}],
'no-useless-call': 2, // 禁止不必要的call()和apply()方法
'no-useless-computed-key': 2, // 禁止在對象上使用不必要的計算屬性鍵
'no-useless-constructor': 2, // 禁止不必要的構(gòu)造方法
'no-useless-escape': 0, // 禁止不必要的轉(zhuǎn)義用法
'no-whitespace-before-property': 2, // 在屬性之前禁止空格
'no-with': 2,
'one-var': [2, {
'initialized': 'never'
}],
'operator-linebreak': [2, 'after', { // 為維護強制執(zhí)行一致的換行方式
'overrides': {
'?': 'before',
':': 'before'
}
}],
'padded-blocks': [2, 'never'], // 在塊內(nèi)要求或禁止填充
'quotes': [2, 'single', {
'avoidEscape': true,
'allowTemplateLiterals': true
}],
'semi': [2, 'never'],
'semi-spacing': [2, {
'before': false,
'after': true
}],
'space-before-blocks': [2, 'always'], // 不要存在多余的塊空間
'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': process.env.NODE_ENV === 'production' ? 2 : 0,
'object-curly-spacing': [2, 'always', {
objectsInObjects: false
}],
'array-bracket-spacing': [2, 'never']
}
}
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學習或者工作具有一定的參考學習價值,謝謝大家對腳本之家的支持。
相關(guān)文章
vue中父組件通過props向子組件傳遞數(shù)據(jù)但子組件接收不到解決辦法
大家都知道可以使用props將父組件的數(shù)據(jù)傳給子組件,下面這篇文章主要給大家介紹了關(guān)于vue中父組件通過props向子組件傳遞數(shù)據(jù)但子組件接收不到的解決辦法,文中通過代碼介紹的非常詳細,需要的朋友可以參考下2024-01-01
vue3?使用provide?inject父子組件傳值失敗且子組件不響應
這篇文章主要介紹了vue3使用provide?inject父子組件傳值傳不過去且傳遞后子組件不具備響應性問題解決方法,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-08-08
tdesign和vue的子組件關(guān)閉是父組件執(zhí)行方法
這篇文章主要介紹了tdesign和vue的子組件關(guān)閉是父組件執(zhí)行方法,需要的朋友可以參考下2006-06-06
Vue3+TS項目中eslint、prettier安裝配置詳細指南
為了更好的統(tǒng)一項目的代碼風格,因此在編寫時就可以使用eslint+prettier,它們不僅能方便代碼編寫,還能避免不必要的錯誤,讓代碼變得更加嚴謹,這篇文章主要給大家介紹了關(guān)于Vue3+TS項目中eslint、prettier安裝配置的相關(guān)資料,需要的朋友可以參考下2024-07-07

