【问题标题】:How to exclude all files under a directory in lint using angular CLI?如何使用角度 CLI 排除 lint 目录下的所有文件?
【发布时间】:2018-07-30 18:53:52
【问题描述】:

我们可以通过这种方式排除 node_modules。

  "lint": [
        {
          "project": "src/main/webapp/app/file.json",
          "exclude": "**/node_modules/**"
        }
    ]

但是如何排除一个目录下的所有文件呢?

我尝试了以下方式。它不工作

"exclude": [
 "**/*whatever.pipe.ts", 
 "**/*whatever_else.component.ts"
]

所以这是我当前目录"src/main/assets/js/ngx-typeahead"的路径

我必须从 linting 中排除此目录下的所有文件。

我怎样才能做到这一点?

任何建议将不胜感激。

【问题讨论】:

    标签: angular angular-cli lint


    【解决方案1】:

    您可以通过修改 lint 内的 tsconfig.json 行来做到这一点:

    "lint": [
        {
            "exclude": [
                "src/main/assets/js/ngx-typeahead/**/*.ts", 
            ]
        }
    ]
    

    这个PATH/**/*.ts是指这个路径下的所有文件以及里面的任何扩展名为.ts的子目录

    而且我相信"src/main/assets/js/ngx-typeahead/* 会排除此路径下的所有文件

    编辑: 另一种选择是使用tslint.json

    {
        "extends": "tslint:recommended",
        ......
        "linterOptions": { 
            "exclude": [
                "src/main/assets/js/ngx-typeahead/**/*.ts", 
            ]
        }
    }
    

    更多:https://palantir.github.io/tslint/usage/configuration/

    编辑 2: 我发现 this issue link 用于 angular-cli 特定的 linting,通过提供您想要 lint 的内容,而不是使用排除项 linting 项目!

    .angular-cli.json 内提供lint 选项:

    "lint": [{
          "files": "src/**/*.ts",
          "project": "src/tsconfig.app.json"
        },
        {
          "files": "src/**/*.ts",
          "project": "src/tsconfig.spec.json"
        },
        {
          "files": "src/**/*.ts",
          "project": "e2e/tsconfig.e2e.json"
        }
    ]
    

    【讨论】:

    • 您好,感谢您的回答。我不知道为什么上述解决方案对我不起作用
    • @al-mothafar 是“排除”用于从项目中完全排除文件吗? OP 要求仅将它们从 lint 中排除。
    • @MarcoAltieri 我在哪里提到我从项目中排除了文件? exclude 行逻辑上是在 tsconfig.json 文件内 "lint": [ ..... ] 所以它将配置 tslint,而不是项目。
    • @al-mothafar 我认为您的回答需要完整。如果您建议在 lint 部分添加排除项,您至少应该提及它。
    • @MarcoAltieri 我已经编辑了我的答案,希望对您有所帮助
    【解决方案2】:

    最后这对我有用

    "lint": [
        {
          "project": "src/main/webapp/app/tsconfig.app.json",
          "exclude": ["**/node_modules/**", "**/src/main/assets/js/ngx-typeahead**"]
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-12
      • 1970-01-01
      相关资源
      最近更新 更多