wbuchwalter / tslint-loader

tslint loader for webpack
193 stars 65 forks source link

display better error messages #108

Open dagda1 opened 5 years ago

dagda1 commented 5 years ago

I have my tslint-loader configured like this:

        {
          test: /\.tsx$/,
          enforce: 'pre',
          use: [
            {
              loader: 'tslint-loader',
              options: {
                configFile: paths.tsLintConfig,
                tsConfig: paths.tsConfig,
                emitError: true,
                failOnHint: true,
                fix: false
              }
            }
          ]
        },

Is there a way to improve the error messages from this:

tslint

almondtools commented 5 years ago

Problems occur with webpack 4 together with gulp/webpack-stream. In this case the fileName is omitted completely leaving:

[3, 17]: Type boolean trivially inferred from a boolean literal, remove type annotation

while e.g ts-loader displays:

 [tsl] ERROR in path/to.ts(35,5)
      TS2531: Object is possibly 'null'.
crenshaw-dev commented 5 years ago

@almondtools any workaround? I'm experiencing the same issue. Super frustrating when enabling tslint on an existing codebase. Could take a long time to hunt down these errors.

almondtools commented 5 years ago

I tried to fix this issue in a fork, yet this lets every unit test fail. So this would have meant a complete API change and I think it should be confirmed by the project owner.

However I found out that a custom formatter has access to more information. Look at the file customFormatter.js and prepend failure.fileName to positionTuple. To include a custom formatter you have to configure the formatter directory and the name of the new formatter.

crenshaw-dev commented 5 years ago

Took some trial-and-error to get it right.

Options:

{
    formatter: 'michael',
    formattersDirectory: 'tslint-formatters'
}

I created the file tslint-formatters/michaelFormatter.js and copied/pasted the contents of customFormatter.js linked above. I made the one tweak @almondtools mentioned. No need to change the Formatter name in the file.

Thanks for the help!