【问题标题】:Stop Typescript compiler putting semicolons in src停止 Typescript 编译器将分号放入 src
【发布时间】:2021-05-18 11:27:54
【问题描述】:

我正在使用 Microsoft 的 Typescript Node Starter Project 创建 Node/Express API - https://github.com/microsoft/TypeScript-Node-Starter

当我构建项目时,它会在我的所有代码中插入分号。不是 /dist 中的编译代码,而是 /src 中我不想要分号的源代码。

package.json 有以下脚本(略)

"scripts": {
    ...
    "build": "npm run build-ts && npm run lint && npm run copy-static-assets",
    "build-ts": "tsc",
    "copy-static-assets": "ts-node copyStaticAssets.ts",
    "lint": "tsc --noEmit && eslint \"**/*.{js,ts}\" --quiet --fix",
    ...
},

这是我的 tsconfig.json 的内容

{
    "compilerOptions": {
        "module": "commonjs",
        "esModuleInterop": true,
        "allowSyntheticDefaultImports": true,
        "target": "es6",
        "lib": ["es2019", "dom"],
        "noImplicitAny": true,
        "moduleResolution": "node",
        "sourceMap": true,
        "outDir": "dist",
        "baseUrl": ".",
        "paths": {
            "*": [
                "node_modules/*",
                "src/types/*"
            ]
        }
    },
    "include": [
        "src/**/*"
    ]
}

我可以使用一个标志来关闭此行为吗?

【问题讨论】:

    标签: node.js typescript tsc


    【解决方案1】:

    这不是 TypeScript 编译器,它可能是 eslint 的 --fix 标志(在 lint 脚本中)。请参阅文件.eslintrc 中的semi 规则。你可以把它改成["error", "never"]

    【讨论】:

      【解决方案2】:

      .eslintrc 文件中将规则 semi 更改为

      "rules" : {
        ...,
        "semi": ["error", "never"],
      }
      
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-09-04
        • 1970-01-01
        • 2015-01-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-08-18
        • 2016-07-06
        相关资源
        最近更新 更多