Fork-ts-checker-webpack-plugin: It tries to lint json files as ts files

Created on 20 Jan 2019  路  9Comments  路  Source: TypeStrong/fork-ts-checker-webpack-plugin

import * as pJSON from './package.json'
ERROR in package.json
ERROR in package.json(1,1):
no-unused-expression: unused expression, expected an assignment or function call

and of course many more errors

bug

Most helpful comment

Can confirm that the problem is specific to tslint being run through fork-ts-checker-webpack-plugin.

tslint has implemented a check to avoid this here, therefore it no longer happens by directly calling tslint, even without any special configuration.

fork-ts-checker-webpack-plugin also seems to either ignore or override linterOptions.exclude array from the specified tslint config, which was a config based fix for this issue for manually ran lints until that fix was released.

All 9 comments

I think you may want to raise a bug with tslint?

I suppose then this plugin is simply using tslint, alright

But what a moment...I just linted the file with tslint manually, this error is only present when using this plugin

Can confirm that the problem is specific to tslint being run through fork-ts-checker-webpack-plugin.

tslint has implemented a check to avoid this here, therefore it no longer happens by directly calling tslint, even without any special configuration.

fork-ts-checker-webpack-plugin also seems to either ignore or override linterOptions.exclude array from the specified tslint config, which was a config based fix for this issue for manually ran lints until that fix was released.

I muted this error by adding "**/*.json" to my linterOptions.exclude array in tslint.json

Running into this issue too. Adding "linterOptions": { "exclude": ["**/*.json"]} to the relevant tslint.json did not do anything for me. Running tslint manually on the project results in no errors.

It's worth considering starting to move to ESLint now that TSLint is deprecated. We're not planning further work on TSLint support for that reason

By judicious sprinkling of console.log statements, I think I may have figured this out!

In ApiIncrementalChecker.initLinterConfig, if I print the value of linterOptions.exclude, they have all been resolved as absolute paths. Ie, say my project is located in /wherever/project/packages/subproject, then at the time the linter is initialized, the "**/*.json" exclude is transformed to /wherever/project/packages/subproject/**/*.json. The issue with this is that the root project is host to many packages/sub-projects, and the .jsons I'm importing belong to _another_ sub-project, something like: /wherever/project/packages/anotherproject/foo/bar.json. So the exclude filter does not match it.

My workaround was to set the following tslint.json in "subproject":

{
  "extends": "@myorg/our-tslint-rules",
  "linterOptions": {
    "//": "Workaround for https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/issues/207",
    "exclude": ["../../../**/*.json"]
  }
}

console.log answers many questions 馃榿

Was this page helpful?
0 / 5 - 0 ratings