国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

eslint+stylelint+prettier全流程配置

這篇具有很好參考價值的文章主要介紹了eslint+stylelint+prettier全流程配置。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

一.npm引入

//eslint
"eslint": "^8.35.0",
"eslint-config-prettier": "^8.6.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-vue": "^9.9.0",
"@typescript-eslint/eslint-plugin": "^5.54.0",
"@typescript-eslint/parser": "^5.54.0",
"@typescript-eslint/typescript-estree": "^6.9.0",
"vite-plugin-eslint": "^1.8.1",
"vue-eslint-parser": "^9.1.0",

//stylelint
"stylelint": "^14.14.0",
"stylelint-config-prettier": "^9.0.5",
"stylelint-config-recommended": "^9.0.0",
"stylelint-config-recommended-scss": "^8.0.0",
"stylelint-config-recommended-vue": "^1.4.0",
"stylelint-config-standard": "^29.0.0",
"stylelint-order": "^6.0.2",
"stylelint-scss": "^4.4.0",
"vite-plugin-stylelint": "^4.2.0",

//prettier
"eslint-config-prettier": "^8.6.0",
"eslint-plugin-prettier": "^4.2.1",
"prettier": "^2.8.4",
"stylelint-config-prettier": "^9.0.5",

//ts
"typescript": "^4.9.4",

二.創(chuàng)建以下5個文件放在項目頂層

.eslintignore;.eslintrc.cjs;.prettierignore;.prettierrc.cjs;.stylelintrc.cjs,具體文件內(nèi)容如下

.eslintrc.cjs

module.exports = {
	env: {
		browser: true,
		es2021: true,
		node: true
	},
	globals: {
		wx: "readonly",
		uni: "readonly"
	},
	extends: ["eslint:recommended", "plugin:vue/vue3-essential", "plugin:@typescript-eslint/recommended", "plugin:prettier/recommended"],
	overrides: [],
	parser: "vue-eslint-parser",
	parserOptions: {
		ecmaVersion: "latest",
		sourceType: "module",
		parser: "@typescript-eslint/parser"
	},
	plugins: ["vue", "@typescript-eslint", "prettier"],
	rules: {
		indent: ["warn", "tab", { ignoredNodes: ["ConditionalExpression"] }],
		"no-var": "error",
		"no-eval": "error",
		"no-alert": "error",
		"no-console": process.env.NODE_ENV === "production" ? "error" : "off",
		"no-debugger": "warn",
		"default-case": "error", // 要求 switch 語句中有 default 分支
		quotes: ["warn", "double", { allowTemplateLiterals: true }], // 使用單/雙引號
		"no-extra-parens": "error", // 禁止不必要的括號
		"consistent-return": ["error", { treatUndefinedAsUnspecified: false }], // 要求使用一致的 return 語句
		"default-case": "warn", // 要求 Switch 語句中有 Default 分支
		curly: ["error", "multi-line"], // 多行語句使用大括號
		"no-empty-function": "error", // 禁止空函數(shù)
		"no-eq-null": "error", // 禁止與 null 進行比較, 必須使用 !== 和 ===
		"no-floating-decimal": "warn", // 禁止不必要的浮點小數(shù)
		"no-implied-eval": "error", // 禁用隱式的eval()
		"no-labels": "error", // 禁止標(biāo)簽語法
		"no-lone-blocks": "error", // 禁用不必要的嵌套塊
		"no-multi-spaces": "error", // 禁止不必要的空格
		"no-shadow": "off", // 禁止未使用變量
		"no-undef": "off", // 允許未知全局變量-防止ts聲明報錯
		"no-undef-init": "warn", // 禁止將變量初始化為 undefined
		"block-spacing": "error", // 括號前后加空格
		"brace-style": "error", // 強制在代碼塊中使用一致的大括號風(fēng)格
		camelcase: "error", // 強制使用駝峰命名
		"comma-dangle": ["error", "never"], // 禁止末尾逗號
		"comma-spacing": "error", // 逗號后強制空格
		"computed-property-spacing": ["warn", "never"], // 強制在計算的屬性的方括號中使用一致的空格
		"func-style": ["error", "expression"], // declaration 或 expression 強制一致地使用 function 聲明或表達式
		indent: ["off", "tab"], // 使用tab縮進
		"key-spacing": "warn", // 對象key之后使用一致的空格
		"keyword-spacing": "warn", // 強制在關(guān)鍵字前后使用一致的空格
		"new-parens": "warn", // new對象需要有括號
		"no-lonely-if": "error", // 禁止 if 作為唯一的語句出現(xiàn)在 else 語句中
		"no-mixed-operators": "warn", // 禁止混合使用不同的操作符
		"no-nested-ternary": "warn", // 禁用嵌套的三元表達式
		"no-trailing-spaces": "error", // 禁用行尾空格
		"no-whitespace-before-property": "warn", // 禁止屬性前有空白
		"one-var": ["error", "never"], // 前置變量分開聲明
		semi: ["error", "never"], // 不使用分號
		"space-in-parens": ["error", "never"], // 小括號前后不加空格
		"prefer-rest-params": "off",
		// ts
		"@typescript-eslint/array-type": ["warn", { default: "array" }], // 數(shù)組聲明使用Array<any> 而不是 any[]
		"@typescript-eslint/ban-ts-comment": "off", // 可以使用@ts-ignore注釋
		"@typescript-eslint/no-explicit-any": "warn", // any警告
		"@typescript-eslint/triple-slash-reference": "off", // 啟用三斜杠引用
		"@typescript-eslint/no-non-null-assertion": "off", // 允許非空聲明賦值,防止onLoad報錯
		// vue
		"vue/multi-word-component-names": "off", // 允許單詞文件命名
		"vue/script-indent": "off", // 允許script縮進一行 原配置["warn", "tab", { "baseIndent": 1 }]
		// prettier
		"prettier/prettier": "error",
		"arrow-body-style": "off",
		"prefer-arrow-callback": "off"
	}
}

.eslintignore

.vscode
node_modules
*.md
*.woff
*.ttf
.idea
dist
.husky

.stylelintrc.cjs

module.exports = {
	extends: ["stylelint-config-standard", "stylelint-config-recommended-scss", "stylelint-config-recommended-vue", "stylelint-config-prettier"],
	plugins: ["stylelint-order"],
	ignoreFiles: ["**/*.js", "**/*.jsx", "**/*.tsx", "**/*.ts", "**/*.json", "**/*.md"],
	rules: {
		"at-rule-no-unknown": [
			true,
			{
				// 禁止未知規(guī)則
				ignoreAtRules: ["function", "if", "else", "else-if", "each", "include", "mixin", "use"]
			}
		],
		"at-rule-empty-line-before": [
			"always",
			{
				// 規(guī)則之前要求空行
				except: ["blockless-after-same-name-blockless", "first-nested"],
				ignore: ["after-comment"],
				ignoreAtRules: ["else", "else-if"]
			}
		],
		"color-hex-case": null, // 顏色hex大小寫無要求
		"color-hex-length": null, // 不要求顏色單位長短
		"declaration-block-trailing-semicolon": null, // css語句末尾加分號 棄用風(fēng)險
		"function-no-unknown": [true, { ignoreFunctions: ["map.get"] }], // 禁止未知函數(shù)
		"import-notation": "string", // 使用string模式引入
		"no-empty-source": null, // 允許空格
		"no-descending-specificity": null,
		"no-duplicate-selectors": true, // 禁止重復(fù)標(biāo)簽
		"number-leading-zero": "always", // 禁止小數(shù)點前無0 棄用風(fēng)險
		"property-no-unknown": true, // 禁止出現(xiàn)未知屬性
		"rule-empty-line-before": "always", // 每個樣式聲明之間需要換行
		"selector-pseudo-class-no-unknown": true, // 禁止未知偽類選擇器
		"selector-pseudo-element-no-unknown": true, // 禁止未知未知偽元素選擇器
		"selector-type-no-unknown": null, // 允許未知選擇器(微信標(biāo)簽)
		"string-quotes": "double", // 使用雙引號 棄用風(fēng)險
		"unit-case": "lower", // 單位使用小寫 棄用風(fēng)險
		"unit-no-unknown": [true, { ignoreUnits: ["rpx"] }], // 允許使用rpx單位
		"scss/at-import-partial-extension": "always", // import使用擴展名
		// "scss/no-global-function-names": null,

		"order/properties-order": [
			// 順序
			"position",
			"top",
			"right",
			"bottom",
			"left",
			"z-index",
			"display",
			"justify-content",
			"align-items",
			"flex-shrink",
			"float",
			"clear",
			"overflow",
			"overflow-x",
			"overflow-y",
			"width",
			"min-width",
			"max-width",
			"height",
			"min-height",
			"max-height",
			"padding",
			"padding-top",
			"padding-right",
			"padding-bottom",
			"padding-left",
			"margin",
			"margin-top",
			"margin-right",
			"margin-bottom",
			"margin-left",
			"font-size",
			"font-family",
			"text-align",
			"text-justify",
			"text-indent",
			"text-overflow",
			"text-decoration",
			"white-space",
			"color",
			"background",
			"background-position",
			"background-repeat",
			"background-size",
			"background-color",
			"background-clip",
			"border",
			"border-style",
			"border-width",
			"border-color",
			"border-top-style",
			"border-top-width",
			"border-top-color",
			"border-right-style",
			"border-right-width",
			"border-right-color",
			"border-bottom-style",
			"border-bottom-width",
			"border-bottom-color",
			"border-left-style",
			"border-left-width",
			"border-left-color",
			"border-radius",
			"opacity",
			"filter",
			"list-style",
			"outline",
			"visibility",
			"box-shadow",
			"text-shadow",
			"resize",
			"transition",
			"content"
		]
	}
}

.prettierrc.cjs

module.exports = {
	arrowParens: "avoid", // 單一箭頭函數(shù)不加括號
	bracketSameLine: true, // 尖括號不換行
	bracketSpacing: true, // 大括號前后加空格
	endOfLine: "auto", // 句尾換行不報錯
	htmlWhitespaceSensitivity: "css", // html敏感
	jsxSingleQuote: false, // jsx使用雙引號
	jsxBracketSameLine: true, // jsx尖括號不換行
	printWidth: 160,
	quoteProps: "as-needed", // 必要時對象key值加分號
	requirePragma: false, // 不需要寫文件開頭的 @prettier
	semi: false, // 句尾無分號
	singleQuote: false, // 使用雙引號
	singleAttributePerLine: false, // vue文件允許一行多個屬性
	tabWidth: 4,
	trailingComma: "none", // 末尾無逗號
	useTabs: true, // tab縮進
	vueIndentScriptAndStyle: true // style和script標(biāo)簽?zāi)J縮進
}

.prettierignore

/dist/*
/.vscode/*
/.husky/*
/node_modules/**
/src/static/**

三.vite.config.ts引入

import viteEslint from "vite-plugin-eslint"
import viteStylelint from "vite-plugin-stylelint"

plugins: [vue(), viteEslint({ failOnError: false, failOnWarning: true }), viteStylelint({ fix: true })],

四.最后

執(zhí)行一次npx prettier . --write,格式化一次code,如果是使用的Vscode編輯器,格式化代碼的時候選取prettier相關(guān)的格式方法文章來源地址http://www.zghlxwxcb.cn/news/detail-766088.html

到了這里,關(guān)于eslint+stylelint+prettier全流程配置的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • vite 創(chuàng)建vue3項目,使用 Prettier 統(tǒng)一格式化代碼,集成 ESLint、Stylelint 代碼校驗規(guī)范

    vite 創(chuàng)建vue3項目,使用 Prettier 統(tǒng)一格式化代碼,集成 ESLint、Stylelint 代碼校驗規(guī)范

    在團隊開發(fā)中,保持代碼風(fēng)格的一致性和代碼質(zhì)量的高度,對于項目的可維護性和可讀性非常重要。為了實現(xiàn)這一目標(biāo),我們可以使用工具來自動格式化代碼并進行代碼校驗,在開發(fā)過程中捕獲潛在的問題,并提供修復(fù)建議。 本示例中,我們將使用 Vite 來創(chuàng)建一個新的 Vue

    2024年04月28日
    瀏覽(24)
  • 【vue3-element-admin】ESLint+Prettier+Stylelint+EditorConfig 約束和統(tǒng)一前端代碼

    【vue3-element-admin】ESLint+Prettier+Stylelint+EditorConfig 約束和統(tǒng)一前端代碼

    本文介紹?vue3-element-admin?如何通過ESLint 檢測 JS/TS 代碼、Prettier 格式化代碼、Stylelint 檢測 CSS/SCSS 代碼和配置 EditorConfig 來全方位約束和統(tǒng)一前端代碼規(guī)范。 ESLint?可組裝的JavaScript和JSX檢查工具,目標(biāo)是保證代碼的一致性和避免錯誤。 ESLint 安裝 安裝 ESLint 插件 VSCode 插件市場

    2024年02月13日
    瀏覽(53)
  • 【vue3-element-admin】ESLint+Prettier+Stylelint+EditorConfig 約束和統(tǒng)一前端代碼規(guī)范

    本文介紹 vue3-element-admin 如何通過ESLint 檢測 JS/TS 代碼、Prettier 格式化代碼、Stylelint 檢測 CSS/SCSS 代碼和配置 EditorConfig 來全方位約束和統(tǒng)一前端代碼規(guī)范。 ESLint 可組裝的JavaScript和JSX檢查工具,目標(biāo)是保證代碼的一致性和避免錯誤。 安裝 ESLint 插件 VSCode 插件市場搜索 ESLint 插

    2023年04月17日
    瀏覽(16)
  • 基于Vue3+Vite+TS+ESLint+Prettier+Husky+lint-staged+commitlint+stylelint的項目構(gòu)建

    基于Vue3+Vite+TS+ESLint+Prettier+Husky+lint-staged+commitlint+stylelint的項目構(gòu)建

    博客后臺管理系統(tǒng)使用后的是基于Vue3+Vite+TS+ESLint+Prettier的開發(fā),具體項目構(gòu)建如下 ESLint: 控制代碼質(zhì)量 Prettier: 控制代碼風(fēng)格 2.1、安裝ESLint、Prettier相關(guān)相關(guān)包 eslint: ESLint的核心代碼庫 prettier: Prettier的格式化代碼的核心代碼庫 eslint-config-airbnb-base: airbnb的代碼規(guī)范(依賴pl

    2024年02月07日
    瀏覽(28)
  • 前端工程化 | vue3+ts+jsx+sass+eslint+prettier 配置化全流程

    前端工程化 | vue3+ts+jsx+sass+eslint+prettier 配置化全流程

    前端開發(fā)是一個工程化的流程。 包括持續(xù)集成、持續(xù)部署。 我認為集成 的第一方面就是開發(fā),在前端項目開發(fā)中,需要保證代碼格式規(guī)范的統(tǒng)一、代碼質(zhì)量、提交的規(guī)劃。而這些要求需要通過各種插件來保證規(guī)范化和流程化開發(fā)。 如何配置這些插件,這些插件各自的功能是

    2024年02月12日
    瀏覽(29)
  • eslint prettier 配置

    1.創(chuàng)建: pnpm create vite 2. 自啟瀏覽器;技巧01 : package.json - \\\"dev\\\": \\\"vite\\\" -- \\\"dev\\\": \\\"vite\\\" -- \\\"dev\\\": \\\"vite --open \\\" 一個項目要有統(tǒng)一的規(guī)范,需要使用 eslint + stylelint + prettier 來對我們的代碼質(zhì)量做檢測和修復(fù) eslint用于代碼語法檢測 stylelint用于對css代碼進行語法檢測 prettier用于代碼格式規(guī)范

    2024年03月22日
    瀏覽(15)
  • Vue typescript項目配置eslint+prettier

    Vue typescript項目配置eslint+prettier

    前言 本文基于 “vite”: “^5.0.0” 1.安裝依賴 安裝 eslint 安裝 eslint-plugin-vue 主要用于檢查 Vue 文件語法 安裝 prettier 及相關(guān)插件 安裝 typescript 解析器、規(guī)則補充 2.根目錄創(chuàng)建 .eslintrc.cjs 3.根目錄創(chuàng)建 .prettierrc.cjs 4.配置 package.json 的 scripts 字段 5.測試配置 如果本篇文章對你有幫

    2024年01月16日
    瀏覽(35)
  • vue項目中配置eslint和prettier

    eslint檢查語法錯誤,格式問題并不重要 prettier是格式化工具,保證代碼美觀 vscode插件Eslint(務(wù)必安裝),錯誤標(biāo)紅,保存的時候自動修正eslint錯誤 如果項目中一開始就沒有配置,用下面的方法從零配置 若項目中已經(jīng)有別人配好的,可根據(jù)需要修改規(guī)則 eslint插件,初始化,生

    2024年02月07日
    瀏覽(20)
  • vscode中使用eslint+prettier的配置

    eslint+prettier+vscode自動保存用起來感覺非常爽快。 一般來說,安裝eslint+prettier插件,然后使用相關(guān)腳手架配套的eslint+prettier,無法自動格式代碼,每次都需要執(zhí)行格式化命令。這里貼出保存自動格式化代碼的setting.json。 如果不使用腳手架自帶的eslint+prettier配置,可以參考我之

    2024年02月10日
    瀏覽(39)
  • 在IDEA中配置eslint和prettier

    在IDEA中配置eslint和prettier

    一開始用的是ESlint8以上的版本,后來一直報莫名其妙的錯,就回退到7.5.0的版本。? .eslintrc.js(主要用來在rules中自定義規(guī)則) ? prettierrc.js (自動修復(fù)代碼中的規(guī)范) ? .eslintignore (規(guī)則忽略的文件夾) ?.editorconfig(這個文件夾會去查看.md文件夾中的規(guī)范,可配置可不配)

    2024年02月06日
    瀏覽(11)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包