How to ignore/exclude some files/directory from linting in angular cli
Asked Answered
C

4

44

Similar to this question

I am running the following command to linting my angular2 typeScript code.

ng lint

It is proving all the linting error nicely.

But I want my vendor folder (let say "src/app/quote/services/generated/**/*") should not get included at the time of lining.

I know this can be done with tslint command as follows (Reference Here)

tslint \"src/**/*.ts\" -e \"**/__test__/**\"

But in angular cli what will be the parameter? How to exclude some files from tslint?

Note: My Angular Cli version is : @angular/cli: 1.0.0-rc.0

Cupriferous answered 28/2, 2017 at 11:40 Comment(0)
F
64

From Angular6+, .angular-cli.json has been replaced by angular.json, but you can still add the exclude path in its lint part.

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

According to the angular-cli issue#5063, you can add the exclude path in .angular-cli.json like this:

"lint": [
{
  "project": "src/tsconfig.app.json",
  "exclude": "**/node_modules/**/*"   // the node_modules for example
}]
Ferromanganese answered 28/2, 2017 at 11:59 Comment(1)
Actually, I found that the solution for me was to edit the exclude property under ./src/tsconfig.app.json, instead of .angular-cli.json.Essequibo
D
13

Figured out it HAS to be a blob pattern..

If you want multiple files/directories just use an array in your .angular-cli.json

"exclude": [
 "**/*whatever.pipe.ts", 
 "**/*whatever_else.component.ts"
]
Donato answered 2/5, 2017 at 18:25 Comment(1)
Actually, I found that the solution for me was to edit the exclude property under ./src/app/tsconfig.app.json, instead of .angular-cli.json.Essequibo
S
1

Recent answer (10/2022 - eslint v8) :

Quote from eslint official documentation :

You can tell ESLint to ignore specific files and directories using ignorePatterns in your config files. ignorePatterns patterns follow the same rules as .eslintignore. Please see the .eslintignore file documentation to learn more.

If you have an .eslintrc.json config file, you can set ignorePatterns option as following :

{
    "ignorePatterns": ["your_file.js", "/your_dir/*.js"],
    "rules": {
        //...
    }
}

If you don't have the .eslintrc.json file, check the link below to find a suitable solution for your setup.

Ressources & useful links you might want to check for more information https://eslint.org/docs/latest/user-guide/configuring/ignoring-code

Strom answered 19/10, 2022 at 10:25 Comment(0)
C
-1

Your angular-cli.json file would be like this-

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

You need to remove the lint path for "src/tsconfig.spec.json". So either remove the second object or comment it. Your updated lint array should be like this-

"lint": [
    {
      "project": "src/tsconfig.app.json",
      "exclude": "**/node_modules/**"
    },
    {
      "project": "e2e/tsconfig.e2e.json",
      "exclude": "**/node_modules/**"
    }
  ]
Charlsiecharlton answered 15/1, 2018 at 11:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.