【问题标题】:lint is linting files that are marked as excluded in the exclude section in angular.json of angular 6 applicationlint 是在 angular 6 应用程序的 angular.json 的 exclude 部分中标记为排除的 lint 文件
【发布时间】:2019-03-17 02:13:57
【问题描述】:

我已经通过在 angular.json 中添加 Lint 部分提到了需要在 lint 过程中排除的文件,但它似乎仍然会对这些文件进行 lint。因此,当我运行 npm run lint 命令时,我最初收到 All files passed linting 消息并突然收到以下消息,但如果我在 tsconfig 文件中注释 include 语句,则 linting 通过。让我知道这样是否可以

C:/Development/xxx/src/app/api/generated/testData.ts:2:1

ERROR: 2:1    no-trailing-whitespace       trailing whitespace
ERROR: 3:1    indent                       space indentation expected
ERROR: 4:1    indent                       space indentation expected
ERROR: 5:1    indent                       space indentation expected
ERROR: 8:1    no-trailing-whitespace       trailing whitespace
ERROR: 9:1    no-consecutive-blank-lines   Exceeds the 2 allowed consecutive blank lines
ERROR: 11:1   no-trailing-whitespace       trailing whitespace

如果您在下面看到,我提到了“/src/app/api//*”,尽管它仍会尝试对 /src/app/api/ 文件夹下的文件进行 lint。

angular.json 中的 lint 部分

"lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "src/tsconfig.app.json",
              "src/tsconfig.spec.json"
            ],
            "exclude": [
              "**/node_modules/**/*",
              "**/src/app/api/**/*",
              "**/src/polyfills.ts"

            ]
          }

完整的 angular.json 文件

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "app": {
      "root": "",
      "sourceRoot": "src",
      "projectType": "application",
      "prefix": "irm",
      "schematics": {},
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "../wwwroot",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.app.json",
            "assets": [
              "src/assets",
              "src/favicon.ico",
              "src/favicon.png",
              "src/web.config",
              {
                "glob": "**/*",
                "input": "./node_modules/@wtw/platform/assets",
                "output": "./assets"
              },
              {
                "glob": "**/*",
                "input": "./assets",
                "output": "./assets"
              }
            ],
            "styles": [
              "../IRM.ClientSide/node_modules/@wtw/platform/styling/platform.scss"
            ],
            "scripts": [
              "../IRM.ClientSide/node_modules/jsoneditor/dist/jsoneditor.js"
            ]
          },
          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "environments/environment.ts",
                  "with": "environments/environment.prod.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": false,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "app:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "app:build:production"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "app:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.spec.json",
            "karmaConfig": "./karma.config.js",
            "styles": [],
            "scripts": [],
            "assets": []
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "src/tsconfig.app.json",
              "src/tsconfig.spec.json"
            ],
            "exclude": [
              "**/node_modules/**/*",
              "**/src/app/api/**/*",
              "**/src/polyfills.ts"

            ]
          }
        }
      }
    },
    "pdf": {
      "root": "src",
      "sourceRoot": "src",
      "projectType": "application",
      "prefix": "irm",
      "schematics": {},
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "../pdf",
            "index": "pdf.html",
            "main": "pdf.ts",
            "polyfills": "polyfills.ts",
            "tsConfig": "tsconfig.app.json",
            "assets": [
              "assets",
              "favicon.ico",
              {
                "glob": "**/*",
                "input": "../node_modules/@wtw/platform/assets",
                "output": "./assets"
              }
            ],
            "styles": [
              "./styles.scss"
            ],
            "scripts": []
          },
          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "environments/environment.ts",
                  "with": "environments/environment.prod.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": false,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "app:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "app:build:production"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "app:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.spec.json",
            "karmaConfig": "./karma.config.js",
            "styles": [],
            "scripts": [],
            "assets": []
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "src/tsconfig.app.json",
              "src/tsconfig.spec.json"
            ],
            "exclude": [
              "**/node_modules/**/*",
              "**/src/app/api/**/*",
              "**/src/polyfills.ts"

            ]
          }
        }
      }
    },
    "app-e2e": {
      "root": "e2e/",
      "projectType": "application",
      "architect": {
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "e2e/protractor.conf.js",
            "devServerTarget": "app:serve"
          },
          "configurations": {
            "production": {
              "devServerTarget": "app:serve:production"
            }
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": "e2e/tsconfig.e2e.json",
            "exclude": [
              "**/node_modules/**"
            ]
          }
        }
      }
    }
  },
  "defaultProject": "app"
}

tsconfig.app.json

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/app",
    "baseUrl": "./",
    "module": "es2015",
    "types": []
  },
  "exclude": [
    "**/*.spec.ts",
    "**/*.stub.ts",
    "test/**/*.ts"

  ]

}

tsconfig.spec.json

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/spec",
    "baseUrl": "./",
    "module": "commonjs",
    "target": "es5",
    "types": [
      "jasmine",
      "node"
    ]
  },
  "files": [
    "test.ts"
  ]

}

tsconfig

{
  "compileOnSave": false,

  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "baseUrl": "src",
    "sourceMap": true,
    "declaration": false,
     "module": "es2015",
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2017",
      "dom"
    ]
  }
//  ,
//   "include": [
//     "./src/**/*",
//     "./node_modules/@wtw/**/*",
//      "./node_modules/@types/**/*"
//   ]
}

【问题讨论】:

    标签: angular


    【解决方案1】:

    从 tslint v5.8.0 开始,您现在可以忽略 tslint.json 文件中的文件。只需将其添加到您的顶级 tslint.json 文件中:

    "linterOptions": {
        "exclude": ["src/app/api/**/*"]
    }
    

    更多信息请参考原PR

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-20
      • 1970-01-01
      • 2019-03-13
      • 2019-05-26
      • 1970-01-01
      • 2019-08-22
      • 2020-09-20
      • 2020-01-13
      相关资源
      最近更新 更多