Skip to content
This repository has been archived by the owner on Nov 1, 2020. It is now read-only.

Commit

Permalink
Merge pull request #3 from Wolfium/fix-undefined-when-screen
Browse files Browse the repository at this point in the history
Don't emit undefined when no file name provided
  • Loading branch information
SimenB committed Nov 14, 2015
2 parents 35cca45 + f5514a2 commit 3d98ca8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
5 changes: 4 additions & 1 deletion stylish.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ export default {
})
}

return `\n${underlinedFilename}\n${table(output)}`
if (underlinedFilename) {
return `\n${underlinedFilename}\n${table(output)}`
}
return `\n${table(output)}`
}
}
27 changes: 27 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,31 @@ describe('csslint-stylish', () => {

assert(CSSLint.hasFormat('stylish'), 'csslint should be stylish')
})

it('should not report undefined output lines when no filename provided', () => {
const res = CSSLint.verify('.class {\n color: red !important\n}\n')

let report = reporter.startFormat() + reporter.formatResults(res) + reporter.endFormat()

report = chalk.stripColor(report)

let matches = report.match(/^undefined$/gm)

assert(matches === null, 'report should not contains undefined text output')
})

it('should report filename provided', () => {
const res = CSSLint.verify('.class {\n color: red !important\n}\n')
const filename = path.resolve('filenamestyle.css')
let report = reporter.startFormat() + reporter.formatResults(res, filename,
{ absoluteFilePathsForFormatters: true }) + reporter.endFormat()

report = chalk.stripColor(report)

const matches = report.match(/^undefined$/gm)
const outfilename = report.split('\n')[1]

assert(matches === null, 'report should not contains undefined text output')
assert(outfilename === filename, 'filename should be in output lines')
})
})

0 comments on commit 3d98ca8

Please sign in to comment.