How to exclude all files under a directory in lint using angular CLI?

喜夏-厌秋 提交于 2020-12-13 04:11:36

问题


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

So this is my current path for the directory "src/main/assets/js/ngx-typeahead"

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

How can i achieve that?

Any suggestions would be appreciated.


回答1:


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

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

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

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

Edit: Another option is to use tslint.json:

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

For more: https://palantir.github.io/tslint/usage/configuration/

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!

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



回答2:


Finally this works for me

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


来源:https://stackoverflow.com/questions/48884789/how-to-exclude-all-files-under-a-directory-in-lint-using-angular-cli

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!