standard / standard-engine

:fire_engine: The guts of `standard` modularized for reuse
MIT License
145 stars 39 forks source link

.lintText() strange behaviour #20

Closed ricardofbarros closed 9 years ago

ricardofbarros commented 9 years ago

The node API has a different outcome from the CLI.

For instance, take this piece of code as proof of this strange behaviour:

function test () {
  try{
  } catch(e) {
    return 1;
  }
}

If I run the semistandard's CLI I get the following errors:

semistandard: Use Semicolons For All! (https://github.com/Flet/semistandard)
  /Users/rbarros/Desktop/github/linter-js-standard/test.js:1:10: "test" is defined but never used (no-unused-vars)
  /Users/rbarros/Desktop/github/linter-js-standard/test.js:2:3: Keyword "try" must be followed by whitespace. (space-after-keywords)
  /Users/rbarros/Desktop/github/linter-js-standard/test.js:2:6: Missing space before opening brace. (space-before-blocks)
  /Users/rbarros/Desktop/github/linter-js-standard/test.js:3:5: Keyword "catch" must be followed by whitespace. (space-after-keywords)

But If I run the .lintText() I get this:

[ { filePath: '<text>',
    messages:
     [ { ruleId: 'no-unused-vars',
         severity: 2,
         message: '"test" is defined but never used',
         line: 1,
         column: 10,
         nodeType: 'Identifier',
         source: 'function test () {' },
       { ruleId: 'space-after-keywords',
         severity: 2,
         message: 'Keyword "try" must be followed by whitespace.',
         line: 2,
         column: 3,
         nodeType: 'TryStatement',
         source: '  try{' },
       { ruleId: 'space-before-blocks',
         severity: 2,
         message: 'Missing space before opening brace.',
         line: 2,
         column: 6,
         nodeType: 'BlockStatement',
         source: '  try{' } ],
    errorCount: 3,
    warningCount: 0 } ]

Only 3 errors instead of the expected 4 errors. This issue was found out by @JGAntunes

node.js API - lintText() code:

var semistandard = require('semistandard')
var fs = require('fs')
var util = require('util')

semistandard.lintText(fs.readFileSync('./test.js', 'utf-8'), function (err, res) {
  console.log(util.inspect(res.results, {showHidden: false, depth: null}))
})
ricardofbarros commented 9 years ago

Btw the version of standard-engine inside semistandard is 2.0.7. Maybe this issue is already solved on the latest releases.

Flet commented 9 years ago

Probably worth updating and checking!

ricardofbarros commented 9 years ago

Yup, updating manually to 2.2.0 fixed this issue. Hmm okay, I'm going to close this issue and will do some mechanism to check new updates and update linter-js-standard dependencies (standard, semistandard, etc.) dependencies (standard-engine, etc.)