如何使用angular CLI排除lint目录下的所有文件? [英] How to exclude all files under a directory in lint using angular CLI?

查看:45
本文介绍了如何使用angular CLI排除lint目录下的所有文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

We can exclude node_modules in this way.

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

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

But how to exclude all files under a directory?

我尝试了以下方式.它不起作用

I tried below way. It is not working

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

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

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

I have to exclude all the files under this directory from linting.

我怎样才能做到这一点?

How can i achieve that?

如有任何建议,我们将不胜感激.

Any suggestions would be appreciated.

推荐答案

您可以通过修改 tsconfig.json 中的 lint 行来实现:

You can do that by modifying your lint line inside tsconfig.json:

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

PATH/**/*.ts 表示此路径下的所有文件以及其中扩展名为.ts 的任何子目录

This PATH/**/*.ts means all files under this path and any subdirectory inside with the extension .ts

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

And I believe "src/main/assets/js/ngx-typeahead/* will exclude all files under this path

另一种选择是使用 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 而不是使用 excludes 对项目进行 lint!

Edit 2: I found this issue link for angular-cli specific linting, by providing what exactly you want to lint instead of linting the project with excludes!

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

inside .angular-cli.json provide lint option:

"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"
    }
]

这篇关于如何使用angular CLI排除lint目录下的所有文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆