亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為 TSLint (NestJs) 和 ESLint (VueJs)

為 TSLint (NestJs) 和 ESLint (VueJs)

手掌心 2022-01-13 17:24:01
我正在使用帶有 Typescript / TSLint 的 NestJs 和帶有 Javascript / ESLint 的 VueJs。我的 VSCode 擴展是 ESLint、TSLint、Prettier 和 Vetur。開發后端時一切都很好,代碼的格式也很好。使用 Vue 開發時,我使用了 airbnb linter 配置,但我遇到了問題。假設我有這個 vue 實例<script>export default {  components: {},  data() {    return {      foo: '',    };  },};</script>然后我保存文件,格式化程序將代碼更新為<script>export default {  components: {},  data() {    return {      foo: ""    };  }};</script>我無法運行代碼,因為 linter 基于 airbnb linter 配置拋出錯誤。雖然它不應該修復代碼,因為我已經使用了 airbnb 樣式指南。我使用設置同步,因此我可以共享我的整個 VSCode 設置以進行復制。這些是我的設置{    "vetur.validation.template": true,    "eslint.autoFixOnSave": true,    // ...    "javascript.updateImportsOnFileMove.enabled": "always",    // ...    "typescript.updateImportsOnFileMove.enabled": "always",    "prettier.singleQuote": true,    "prettier.trailingComma": "es5",    "prettier.useTabs": true,    "editor.formatOnSave": true,    // ...    "vetur.format.defaultFormatter.html": "prettier"}你可以在這里看到整個要點https://gist.github.com/matthiashermsen/9620a315960fa7b9e31bf6cda8583e84那么 Prettier 是否在為 TSLint 和 ESLint 苦苦掙扎?我想為 Typescript 和 Javascript 項目設置一個標準設置。我還嘗試使用 prettier 作為 linter 創建一個新的 Vue 項目,并且一切正常。因此,它似乎只是在與 airbnb linter 配置作斗爭。有任何想法嗎?感謝幫助!
查看完整描述

1 回答

?
開心每一天1111

TA貢獻1836條經驗 獲得超13個贊

根據這篇文章TSLint 已于 2019 年棄用。您必須使用 ESLint 進行打字稿。我分享我的配置,您可以使用它或編輯它的某些部分。


tsconfig.json:


{

  "compilerOptions": {

      // Target latest version of ECMAScript.

      "target": "esnext",

      // path to output directory

      "outDir": "./dist",

      // enable strict null checks as a best practice

      "strictNullChecks": true,

      // Search under node_modules for non-relative imports.

      "moduleResolution": "node",

      // Process & infer types from .js files.

      "allowJs": true,

      // Don't emit; allow Babel to transform files.

      "noEmit": true,

      // Enable strictest settings like strictNullChecks & noImplicitAny.

      "strict": true,

      // Import non-ES modules as default imports.

      "esModuleInterop": true,

      // use typescript to transpile jsx to js

      "baseUrl": "./src",

      "module": "esnext",

      "removeComments": true,

      "alwaysStrict": true,

      "allowUnreachableCode": false,

      "noImplicitAny": true,

      "noImplicitThis": true,

      "noUnusedLocals": true,

      "noUnusedParameters": true,

      "noImplicitReturns": true,

      "noFallthroughCasesInSwitch": true,

      "forceConsistentCasingInFileNames": true,

      "importHelpers": true,

      "typeRoots": [

        "src/@types",

        "node_modules/@types"

      ]

  }

}

.eslintrc.js


module.exports = {

    parser: '@typescript-eslint/parser',

    plugins: ['@typescript-eslint'],

    extends: [

        "eslint:recommended",

        "plugin:@typescript-eslint/eslint-recommended",

        "plugin:@typescript-eslint/recommended",

        "plugin:react/recommended",

        "plugin:prettier/recommended",

        "prettier/@typescript-eslint",

    ],

    env: {

        "browser": true,

        "es6": true,

        "node": true

    },

    overrides: [

        {

            "files": ["*.tsx"],

            "rules": {

                "react/prop-types": "off"

            }

        },

        {

            "files": ["*.js"],

            "rules": {

                "@typescript-eslint/no-var-requires": "off"

            }

        }

    ]

}

.prettierrc.js


module.exports =  {

  semi:  true,

  trailingComma:  'all',

  singleQuote:  true,

  printWidth:  120,

  tabWidth:  2,

};


查看完整回答
反對 回復 2022-01-13
  • 1 回答
  • 0 關注
  • 327 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號