wbuchwalter / tslint-loader

tslint loader for webpack
192 stars 65 forks source link

Lint.Configuration.parseConfigFile Does Not Resolve "extends" #79

Open taicho opened 7 years ago

taicho commented 7 years ago

All,

After struggling to understand to understand why tslint-loader would not honor the "extends" directive in my tslint.config it appears that I've been able to isolate the cause.

index.js

function parseConfigFile(webpackInstance, configFile, options) {
  if (!options.configuration) {
    return Lint.Linter.findConfiguration(configFile, webpackInstance.resourcePath).results;
  }

  if (semver.satisfies(Lint.Linter.VERSION, '>=5.0.0')) {      
    Lint.Configuration.parseConfigFile(options.configuration);
  }

  return options.configuration;
}

My version of tslint is 5.4.0 and I am using a tslint.json located at my root which looks like this:

{
  "extends": [
    "tslint:recommended"
  ],
  "rules": {    
  }
}

Therefore the code will use Lint.Configuration.parseConfigFile to parse the config file. The problem is that in tslint (at least in 5.4.0) parseConfigFile does not traverse and resolve any of the rules provided via the "extends" option. I was able to fix this by using Lint.Configuration.loadConfigurationFromPath; the changed code looks like this:

function parseConfigFile(webpackInstance, configFile, options) {
  if (!options.configuration) {
    return Lint.Linter.findConfiguration(configFile, webpackInstance.resourcePath).results;
  }

  if (semver.satisfies(Lint.Linter.VERSION, '>=5.0.0')) {      
    return Lint.Configuration.loadConfigurationFromPath(configFile,configFile);
  }

  return options.configuration;
}

Using the above fix everything appears to work properly. Also worth mentioning is that in the tslint codebase parseConfigFile is only use internally by loadConfigurationFromPath...

Three questions:

  1. Has nobody else run into this issue??
  2. Am I completely doing something wrong or crazy...?
  3. If not, should I do a pull request...?
moneydance commented 7 years ago

From what I can gather by looking through the repo, don't provide a configuration property in the options for the loader. If you're using a tslint.json I don't think you need that property as you can specify new rules in the tslint.json. If you ommit the configuration property Lint.Linter.findConfiguration will be called which in turn calls loadConfigurationFromPath.

https://github.com/palantir/tslint/blob/master/src/configuration.ts#L93

moneydance commented 7 years ago

I'll try it when i get home. I was having a similar issue, but was trying to call extends from webpack options configuration property. Which from the look of things is unsupported.

RehanSaeed commented 6 years ago

I had TS-Lint working a few weeks ago. At some point my project lost the ability to produce TS-Lint warnings, possibly due to a package upgrade. Is there a specific version of tslint that I can use to get linting working again. It looks like the PR to fix this issue has been around for some time.