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