欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue3+ts項(xiàng)目之安裝eslint、prettier和sass的詳細(xì)過程

 更新時(shí)間:2023年10月12日 17:11:53   作者:假裝我不帥  
這篇文章主要介紹了vue3+ts項(xiàng)目02-安裝eslint、prettier和sass的詳細(xì)過程,在本文講解中需要注意執(zhí)行yarn format會(huì)自動(dòng)格式化css、js、html、json還有markdown代碼,需要的朋友可以參考下

創(chuàng)建項(xiàng)目

項(xiàng)目創(chuàng)建

安裝eslint

yarn add eslint -D

生成配置文件

npx eslint --init

安裝其他插件

yarn add  -D eslint-plugin-import eslint-plugin-vue eslint-plugin-node eslint-plugin-prettier eslint-config-prettier eslint-plugin-node @babel/eslint-parser vue-eslint-parser

修改.eslintrc.cjs

module.exports = {
  env: {
    browser: true,
    es2021: true,
    node: true,
    jest: true,
  },
  /* 指定如何解析語法 */
  parser: "vue-eslint-parser",
  parserOptions: {
    ecmaVersion: "latest",
    parser: "@typescript-eslint/parser",
    sourceType: "module",
  },
  extends: [
    "eslint:recommended",
    "plugin:@typescript-eslint/recommended",
    "plugin:vue/vue3-essential",
  ],
  overrides: [
    {
      env: {
        node: true,
      },
      files: [".eslintrc.{js,cjs}"],
      parserOptions: {
        sourceType: "script",
      },
    },
  ],
  plugins: ["@typescript-eslint", "vue"],
  rules: {
    // 參考 https://typescript-eslint.io/
    // 禁止// @ts-ignore
    "@typescript-eslint/ban-ts-ignore": "off",
    //要求函數(shù)和類方法有顯式返回類型。
    "@typescript-eslint/explicit-function-return-type": "off",
    //禁用any類型
    "@typescript-eslint/no-explicit-any": "off",
    //除 import 語句外,不允許使用 require 語句。
    "@typescript-eslint/no-var-requires": "off",
    //禁止空函數(shù)
    "@typescript-eslint/no-empty-function": "off",
    //在定義變量之前禁止使用變量。
    "@typescript-eslint/no-use-before-define": "off",
    //禁止 @ts-<directive> 注釋或要求指令后有描述。
    "@typescript-eslint/ban-ts-comment": "off",
    //禁止某些類型。
    "@typescript-eslint/ban-types": "off",
    //禁止使用 ! 進(jìn)行非空斷言后綴運(yùn)算符。
    "@typescript-eslint/no-non-null-assertion": "off",
    //要求導(dǎo)出函數(shù)和類的公共類方法顯式返回和參數(shù)類型。
    "@typescript-eslint/explicit-module-boundary-types": "off",
    // 參考 https://eslint.vuejs.org/rules/
    //強(qiáng)制執(zhí)行自定義事件名稱的特定大小寫
    "vue/custom-event-name-casing": "off",
    //強(qiáng)制執(zhí)行屬性順序
    "vue/attributes-order": "off",
    //強(qiáng)制每個(gè)組件都應(yīng)位于自己的文件中
    "vue/one-component-per-file": "off",
    //不允許在標(biāo)簽的右括號(hào)之前換行
    "vue/html-closing-bracket-newline": "off",
    //強(qiáng)制每行的最大屬性數(shù)
    "vue/max-attributes-per-line": "off",
    //需要在多行元素的內(nèi)容之前和之后換行
    "vue/multiline-html-element-content-newline": "off",
    //需要在單行元素的內(nèi)容之前和之后換行
    "vue/singleline-html-element-content-newline": "off",
    //對(duì)模板中的自定義組件強(qiáng)制執(zhí)行屬性命名樣式
    "vue/attribute-hyphenation": "off",
    //強(qiáng)制執(zhí)行自關(guān)閉風(fēng)格
    "vue/html-self-closing": "off",
    //禁止向模板添加多個(gè)根節(jié)點(diǎn)
    "vue/no-multiple-template-root": "off",
    "vue/require-default-prop": "off",
    //禁止向自定義組件中使用的 v-model 添加參數(shù)
    "vue/no-v-model-argument": "off",
    //禁止使用箭頭函數(shù)來定義觀察者
    "vue/no-arrow-functions-in-watch": "off",
    //禁止 <template> 上的key屬性
    "vue/no-template-key": "off",
    //禁止使用v-html以防止XSS攻擊
    "vue/no-v-html": "off",
    //支持 <template> 中的注釋指令
    "vue/comment-directive": "off",
    //禁止 <template> 中出現(xiàn)解析錯(cuò)誤
    "vue/no-parsing-error": "off",
    //禁止使用已棄用的 .native 修飾符(在 Vue.js 3.0.0+ 中)
    "vue/no-deprecated-v-on-native-modifier": "off",
    //要求組件名稱始終為多個(gè)單詞
    "vue/multi-word-component-names": "off",
    // 參考 http://eslint.cn/docs/rules/
    //禁止添加論據(jù)v-model 用于定制組件
    "no-v-model-argument": "off",
    //禁止使用不必要的轉(zhuǎn)義字符
    "no-useless-escape": "off",
    //禁止稀疏數(shù)組
    "no-sparse-arrays": "off",
    //禁止直接在對(duì)象上調(diào)用某些 Object.prototype 方法
    "no-prototype-builtins": "off",
    //禁止條件中的常量表達(dá)式
    "no-constant-condition": "off",
    //在定義變量之前禁止使用變量
    "no-use-before-define": "off",
    //禁止指定的全局變量
    "no-restricted-globals": "off",
    //不允許指定的語法
    "no-restricted-syntax": "off",
    //在生成器函數(shù)中圍繞*運(yùn)算符強(qiáng)制執(zhí)行一致的間距
    "generator-star-spacing": "off",
    //不允許在return、throw、continue和break語句之后出現(xiàn)無法訪問的代碼
    "no-unreachable": "off",
    //vue2只有一個(gè)節(jié)點(diǎn)但是vue3支持多個(gè)
    "no-multiple-template-root": "off",
    //該規(guī)則旨在消除未使用的變量,函數(shù)和函數(shù)的參數(shù)。
    "no-unused-vars": "error",
    //禁止case聲明
    "no-case-declarations": "off",
    //禁止console
    "no-console": "error",
  },
};

添加.eslintignore

*.sh
node_modules
lib
*.md
*.scss
*.woff
*.ttf
.vscode
.idea
dist
mock
public
bin
build
config
index.html
src/assets

安裝prettier

https://prettier.io/

yarn add -D eslint-plugin-prettier prettier eslint-config-prettier

添加.prettierrc.cjs

module.exports = {
	// 一行最多多少個(gè)字符
	printWidth: 150,
	// 指定每個(gè)縮進(jìn)級(jí)別的空格數(shù)
	tabWidth: 2,
	// 使用制表符而不是空格縮進(jìn)行
	useTabs: true,
	// 在語句末尾打印分號(hào)
	semi: true,
	// 使用單引號(hào)而不是雙引號(hào)
	singleQuote: true,
	// 更改引用對(duì)象屬性的時(shí)間 可選值"<as-needed|consistent|preserve>"
	quoteProps: 'as-needed',
	// 在JSX中使用單引號(hào)而不是雙引號(hào)
	jsxSingleQuote: false,
	// 多行時(shí)盡可能打印尾隨逗號(hào)。(例如,單行數(shù)組永遠(yuǎn)不會(huì)出現(xiàn)逗號(hào)結(jié)尾。) 可選值"<none|es5|all>",默認(rèn)none
	trailingComma: 'es5',
	// 在對(duì)象文字中的括號(hào)之間打印空格
	bracketSpacing: true,
	// jsx 標(biāo)簽的反尖括號(hào)需要換行
	jsxBracketSameLine: false,
	// 在單獨(dú)的箭頭函數(shù)參數(shù)周圍包括括號(hào) always:(x) => x \ avoid:x => x
	arrowParens: 'always',
	// 這兩個(gè)選項(xiàng)可用于格式化以給定字符偏移量(分別包括和不包括)開始和結(jié)束的代碼
	rangeStart: 0,
	rangeEnd: Infinity,
	// 指定要使用的解析器,不需要寫文件開頭的 @prettier
	requirePragma: false,
	// 不需要自動(dòng)在文件開頭插入 @prettier
	insertPragma: false,
	// 使用默認(rèn)的折行標(biāo)準(zhǔn) always\never\preserve
	proseWrap: 'preserve',
	// 指定HTML文件的全局空格敏感度 css\strict\ignore
	htmlWhitespaceSensitivity: 'css',
	// Vue文件腳本和樣式標(biāo)簽縮進(jìn)
	vueIndentScriptAndStyle: false,
	// 換行符使用 lf 結(jié)尾是 可選值"<auto|lf|crlf|cr>"
	endOfLine: 'lf',
};

添加.prettierignore

/dist/*
/html/*
.local
/node_modules/**
**/*.svg
**/*.sh
/public/*

安裝sass

yarn add sass sass-loader stylelint postcss postcss-scss postcss-html stylelint-config-prettier stylelint-config-recess-order stylelint-config-recommended-scss stylelint-config-standard stylelint-config-standard-vue stylelint-scss stylelint-order stylelint-config-standard-scss -D

https://stylelint.io/

配置.stylelintrc.cjs

// @see https://stylelint.bootcss.com/
module.exports = {
  extends: [
    'stylelint-config-standard', // 配置stylelint拓展插件
    'stylelint-config-html/vue', // 配置 vue 中 template 樣式格式化
    'stylelint-config-standard-scss', // 配置stylelint scss插件
    'stylelint-config-recommended-vue/scss', // 配置 vue 中 scss 樣式格式化
    'stylelint-config-recess-order', // 配置stylelint css屬性書寫順序插件,
    'stylelint-config-prettier', // 配置stylelint和prettier兼容
  ],
  overrides: [
    {
      files: ['**/*.(scss|css|vue|html)'],
      customSyntax: 'postcss-scss',
    },
    {
      files: ['**/*.(html|vue)'],
      customSyntax: 'postcss-html',
    },
  ],
  ignoreFiles: [
    '**/*.js',
    '**/*.jsx',
    '**/*.tsx',
    '**/*.ts',
    '**/*.json',
    '**/*.md',
    '**/*.yaml',
  ],
  /**
   * null  => 關(guān)閉該規(guī)則
   * always => 必須
   */
  rules: {
    'value-keyword-case': null, // 在 css 中使用 v-bind,不報(bào)錯(cuò)
    'no-descending-specificity': null, // 禁止在具有較高優(yōu)先級(jí)的選擇器后出現(xiàn)被其覆蓋的較低優(yōu)先級(jí)的選擇器
    'function-url-quotes': 'always', // 要求或禁止 URL 的引號(hào) "always(必須加上引號(hào))"|"never(沒有引號(hào))"
    'no-empty-source': null, // 關(guān)閉禁止空源碼
    'selector-class-pattern': null, // 關(guān)閉強(qiáng)制選擇器類名的格式
    'property-no-unknown': null, // 禁止未知的屬性(true 為不允許)
    'block-opening-brace-space-before': 'always', //大括號(hào)之前必須有一個(gè)空格或不能有空白符
    'value-no-vendor-prefix': null, // 關(guān)閉 屬性值前綴 --webkit-box
    'property-no-vendor-prefix': null, // 關(guān)閉 屬性前綴 -webkit-mask
    'selector-pseudo-class-no-unknown': [
      // 不允許未知的選擇器
      true,
      {
        ignorePseudoClasses: ['global', 'v-deep', 'deep'], // 忽略屬性,修改element默認(rèn)樣式的時(shí)候能使用到
      },
    ],
  },
}

配置忽略文件.stylelintignore

/node_modules/*
/dist/*
/html/*
/public/*

package.json增加配置

"format": "prettier --write \"./**/*.{html,vue,ts,js,json,md}\"",
"lint:eslint": "eslint src/**/*.{ts,vue} --cache --fix",
"lint:style": "stylelint src/**/*.{css,scss,vue} --cache --fix",

執(zhí)行yarn format會(huì)自動(dòng)格式化css、js、html、json還有markdown代碼

到此這篇關(guān)于vue3+ts項(xiàng)目02-安裝eslint、prettier和sass的文章就介紹到這了,更多相關(guān)vue3 ts安裝eslint、prettier和sass內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • vue el-date-picker 開始日期不能大于結(jié)束日期的實(shí)現(xiàn)代碼

    vue el-date-picker 開始日期不能大于結(jié)束日期的實(shí)現(xiàn)代碼

    這篇文章主要介紹了vue el-date-picker 開始日期不能大于結(jié)束日期的實(shí)現(xiàn)代碼,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧
    2024-01-01
  • Vue使用NProgress進(jìn)度條的方法

    Vue使用NProgress進(jìn)度條的方法

    這篇文章主要為大家詳細(xì)介紹了Vue使用NProgress進(jìn)度條的方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-09-09
  • vue監(jiān)聽鍵盤事件的快捷方法【推薦】

    vue監(jiān)聽鍵盤事件的快捷方法【推薦】

    這篇文章主要介紹了vue監(jiān)聽鍵盤事件的快捷方法,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2018-07-07
  • vue.js指令和組件詳細(xì)介紹及實(shí)例

    vue.js指令和組件詳細(xì)介紹及實(shí)例

    這篇文章主要介紹了vue.js功能介紹 - 指令,組件詳細(xì)介紹及實(shí)例,詳細(xì)的介紹了指令和組件的用法,有興趣的可以了解一下。
    2017-04-04
  • vue項(xiàng)目中Eslint校驗(yàn)代碼報(bào)錯(cuò)的解決方案

    vue項(xiàng)目中Eslint校驗(yàn)代碼報(bào)錯(cuò)的解決方案

    這篇文章主要介紹了vue項(xiàng)目中Eslint校驗(yàn)代碼報(bào)錯(cuò)的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-04-04
  • Vue+SSM實(shí)現(xiàn)圖片上傳預(yù)覽效果

    Vue+SSM實(shí)現(xiàn)圖片上傳預(yù)覽效果

    這篇文章主要為大家詳細(xì)介紹了Vue+SSM實(shí)現(xiàn)圖片上傳預(yù)覽效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-11-11
  • Vue3文件下載方法實(shí)現(xiàn)的簡(jiǎn)單代碼

    Vue3文件下載方法實(shí)現(xiàn)的簡(jiǎn)單代碼

    在Web開發(fā)中,文件下載可通過多種方式實(shí)現(xiàn),下面這篇文章主要介紹了Vue3文件下載方法實(shí)現(xiàn)的相關(guān)資料,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2024-10-10
  • Vue組件中常見的props默認(rèn)值陷阱問題

    Vue組件中常見的props默認(rèn)值陷阱問題

    這篇文章主要介紹了避免Vue組件中常見的props默認(rèn)值陷阱,本文通過問題展示及解決方案給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-09-09
  • 在Vue中創(chuàng)建可重用的 Transition的方法

    在Vue中創(chuàng)建可重用的 Transition的方法

    這篇文章主要介紹了在Vue中創(chuàng)建可重用的 Transition,本文通過示例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-06-06
  • Vue通過路由實(shí)現(xiàn)頁面間參數(shù)的傳遞

    Vue通過路由實(shí)現(xiàn)頁面間參數(shù)的傳遞

    這篇文章主要介紹了Vue通過路由實(shí)現(xiàn)頁面間參數(shù)的傳遞,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-04-04

最新評(píng)論