Codelyzer: Exclude node_modules using tsconfig.json

Created on 15 Mar 2017  路  4Comments  路  Source: mgechev/codelyzer

Hi,

I'm trying to configure codelyzer so that I can run tslint over all the source files in my project, but obviously excluding node_modules.

I configured my script in package.json like this

"lint": "tslint --type-check --project tsconfig.json"

So if I understand tslint should use tsconfig.json to check which files should lint.
When I run npm run lint I get an error in my app.component.ts, which is fine, but I also get a few errors from files within node_modules, something like this

Error: Error encountered resolving symbol values statically. Calling function '傻makeDecorator', function calls are not supported. Consider replacing the function or lambda with a reference to an exported function
    at simplify (/Users/david/Documents/work/my-angular-seed/node_modules/@angular/compiler/bundles/compiler.umd.js:21818:58)
    at simplifyCall (/Users/david/Documents/work/my-angular-seed/node_modules/@angular/compiler/bundles/compiler.umd.js:21624:28)
    at simplify (/Users/david/Documents/work/my-angular-seed/node_modules/@angular/compiler/bundles/compiler.umd.js:21806:52)
    at simplifyInContext (/Users/david/Documents/work/my-angular-seed/node_modules/@angular/compiler/bundles/compiler.umd.js:21831:28)
    at simplify (/Users/david/Documents/work/my-angular-seed/node_modules/@angular/compiler/bundles/compiler.umd.js:21667:40)
    at simplifyInContext (/Users/david/Documents/work/my-angular-seed/node_modules/@angular/compiler/bundles/compiler.umd.js:21831:28)
    at simplify (/Users/david/Documents/work/my-angular-seed/node_modules/@angular/compiler/bundles/compiler.umd.js:21789:52)
    at simplify (/Users/david/Documents/work/my-angular-seed/node_modules/@angular/compiler/bundles/compiler.umd.js:21649:60)
    at simplifyInContext (/Users/david/Documents/work/my-angular-seed/node_modules/@angular/compiler/bundles/compiler.umd.js:21831:28)
    at recordedSimplifyInContext (/Users/david/Documents/work/my-angular-seed/node_modules/@angular/compiler/bundles/compiler.umd.js:21844:28) 'node_modules/@angular/core/typings/core.d.ts'

My tsconfig.json looks like this

{
  "compilerOptions": {
    "target": "es5",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "noEmitHelpers": false,
    "pretty": true,
    "sourceMap": true,
    "lib": ["es5", "dom"],
    "strictNullChecks": false
  },
  "include": [
    "src/**/*"
  ],
  "exclude": [
    "node_modules"
  ],
  "awesomeTypescriptLoaderOptions": {
    "useWebpackText": true,
    "forkChecker": true,
    "useCache": true
  },
  "compileOnSave": false,
  "buildOnSave": false
}

and my tslint.json is the standard version as in the npm site

Does anyone know what I'm doing wrong?
Thanks

Most helpful comment

The only working solution for me was to add files against all linting files

.angular-cli.json

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

All 4 comments

Hey @davidanaya! You must be using [email protected]? If so, the problem comes from the deep metadata collection which is performed by ngast. This is required in order to be able to parse component templates in the appropriate context.

Usually the problem occurs when the basePath and genDir properties are not presented in tsconfig.json. Once [email protected] is released, most such issues should have be already fixed. By then, you can use [email protected].

I'll close this issue since it's related to ngast, not codelyzer.

I have had the same problem. I could solve it with removing the.

"exclude": [
    "node_modules"
  ],

from the config. But no idea why this helps...

Just to clarify. I was having the same issue and the exclude should be on your angular-cli.json

Eq:

{
    lint: [
        {
            "exclude": "**/node_modules/**/*"
        }
    ]
}

Via: https://github.com/angular/angular-cli/issues/4350#issuecomment-277501678

The only working solution for me was to add files against all linting files

.angular-cli.json

"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"
    }
  ]
Was this page helpful?
0 / 5 - 0 ratings

Related issues

artaommahe picture artaommahe  路  3Comments

mattlewis92 picture mattlewis92  路  5Comments

fabioemoutinho picture fabioemoutinho  路  5Comments

marbug picture marbug  路  3Comments

snebjorn picture snebjorn  路  5Comments