From bb339468ff77544149ff0e0515fcb607daddcae5 Mon Sep 17 00:00:00 2001 From: Xianming Zhong Date: Fri, 28 Sep 2018 11:14:26 +0800 Subject: [PATCH] keep the original line number if no source map --- src/index.js | 2 +- test/emptycode.test.js | 46 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 test/emptycode.test.js diff --git a/src/index.js b/src/index.js index 7e575bc..70962f8 100644 --- a/src/index.js +++ b/src/index.js @@ -102,7 +102,7 @@ module.exports = options => ({ // Replace "brace" with "backtick" in warnings, e.g. // "Unexpected empty line before closing backtick" (instead of "brace") text: warning.text.replace(/brace/, 'backtick'), - line: lineCorrection[warning.line] + line: lineCorrection[warning.line] || warning.line }) ) diff --git a/test/emptycode.test.js b/test/emptycode.test.js new file mode 100644 index 0000000..01a1b80 --- /dev/null +++ b/test/emptycode.test.js @@ -0,0 +1,46 @@ +const stylelint = require('stylelint') +const path = require('path') + +const processor = path.join(__dirname, '../lib/index.js') +const rules = { + 'no-empty-source': true +} + +describe('empty source', () => { + let data + + beforeAll(done => { + stylelint + .lint({ + code: '', + config: { + processors: [processor], + rules + } + }) + .then(result => { + data = result + done() + }) + .catch(err => { + data = err + done() + }) + }) + + it('should have one result', () => { + expect(data.results.length).toEqual(1) + }) + + it('should have errored', () => { + expect(data.errored).toEqual(true) + }) + + it('should have one warning', () => { + expect(data.results[0].warnings.length).toEqual(1) + }) + + it('should have the right line number', () => { + expect(data.results[0].warnings[0].line).toEqual(1) + }) +})