panuhorsmalahti / gulp-tslint

TypeScript linter plugin for Gulp
MIT License
118 stars 44 forks source link

Check the return value from the formatter and avoid writing to console if it's undefined. #75

Closed jp7677 closed 8 years ago

jp7677 commented 8 years ago

gulp-tslint version: 6.1.1 tslint version: 3.15.1 Operating system: Fedora Linux 24

Example gulp configuration (if applicable):

  var consoleFormatter = function () {
      consoleFormatter.prototype.format = function (results) {
        results.forEach(function (element) {
          var message = '[' + util.colors.cyan('lint') + '] ' +
            util.colors.red('error') + ' ' + element.fileName +
            '[' + (element.startPosition.lineAndCharacter.line + 1) + ', ' + (element.startPosition.lineAndCharacter.character + 1) + ']: ' +
            element.failure
          util.log(message)
        })
      }
    }

   var tslint = require('gulp-tslint')
    return gulp.src([paths.src + '**/*.ts', paths.test + '**/*.ts', '!' + paths.jspmPackages])
      .pipe(tslint({formatter: consoleFormatter}))
      .pipe(tslint.report({emitError: false}))
  }

Error console output:

[18:11:40] Starting 'lint:ts'...
[18:11:40] [lint] error app.ts[15, 43]: expected call-signature to have a typedef
undefined
[18:11:41] Finished 'lint:ts' after 835 ms

Hi there,

As you can see in my gulp code, I'm doing the writing to console in the formatter itself. Due to that I do not return any value from the formatter back to gulp-tslint. Unfortunately the "undefined" result is still written to console within gulp-tslint. Could you please check the return from the formatter and avoid writing to console if it's undefined, empty of the like?

Thanks for your hard work!

panuhorsmalahti commented 8 years ago

I think this should be done in tslint, not gulp-tslint.

jp7677 commented 8 years ago

Thank you for your response. Unfortunately I'm not close to a workstation right now to test several things, but looking at the gulp-tslint source I would say that just a small check is needed within index.ts at line 207. I suspect that in my case, when the custom formatter return nothing, file.tslint.output is undefined and thus undefined is written to console at that line. Though my thought are just based on looking at the source.

Would you be interested in a PR if my case is resolved with just a check for undefined at that line when testing confirms my thoughts?

Best regards.

On 23 sep. 2016, at 19:12, Panu Horsmalahti notifications@github.com wrote:

I think this should be done in typescript, not gulp-typescript.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

panuhorsmalahti commented 8 years ago

Ah, you're right, that could work. Yeah, a PR would be fine.

jp7677 commented 8 years ago

Will do that ;) Where do I need to do the change? Just index.ts or also within index.js?

On 24 sep. 2016, at 21:49, Panu Horsmalahti notifications@github.com wrote:

Ah, you're right, that could work. Yeah, a PR would be fine.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

panuhorsmalahti commented 8 years ago

Modify index.ts and them compile with gulp.

jp7677 commented 8 years ago

Check. Thanks!

On 25 sep. 2016, at 15:52, Panu Horsmalahti notifications@github.com wrote:

Modify index.ts and them compile with gulp.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

jp7677 commented 8 years ago

See https://github.com/panuhorsmalahti/gulp-tslint/pull/79