diff --git a/.travis.yml b/.travis.yml index d7cdecc..62374bd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,9 @@ node_js: - '0.10' - '0.12' - '4.2' + - '6' + - '8' + - 'lts/*' - 'stable' sudo: false diff --git a/index.js b/index.js index 50bc711..2ca02b3 100644 --- a/index.js +++ b/index.js @@ -174,20 +174,21 @@ var filterAndGroup = function (lines) { var group = false lines.forEach(function (line) { - var isAnnotation = line.indexOf('@') === 0 + var trimmedLine = line.trim() + var isAnnotation = trimmedLine.indexOf('@') === 0 - if (line.trim().indexOf('---') !== 0) { // Ignore lines that start with "---" + if (trimmedLine.indexOf('---') !== 0) { // Ignore lines that start with "---" if (group) { if (isAnnotation) { - nLines.push(line) + nLines.push(trimmedLine) } else { nLines[nLines.length - 1] += '\n' + line } } else if (isAnnotation) { group = true - nLines.push(line) + nLines.push(trimmedLine) } else { - nLines.push(line) + nLines.push(trimmedLine) } } }) diff --git a/test/fixtures/annotation.test.scss b/test/fixtures/annotation.test.scss new file mode 100644 index 0000000..5f4dd8a --- /dev/null +++ b/test/fixtures/annotation.test.scss @@ -0,0 +1,5 @@ +/// Description +/// @test Test +.foo { + font-weight: bold; +} diff --git a/test/fixtures/indentedAnnotation.test.scss b/test/fixtures/indentedAnnotation.test.scss new file mode 100644 index 0000000..5ce7e82 --- /dev/null +++ b/test/fixtures/indentedAnnotation.test.scss @@ -0,0 +1,9 @@ +$foo: true; + +@if ($foo) { + /// Description + /// @test Test + .foo { + font-weight: bold; + } +} diff --git a/test/test.js b/test/test.js index b78edf2..f92ed0c 100644 --- a/test/test.js +++ b/test/test.js @@ -170,7 +170,7 @@ describe('scss-comment-parser', function () { }) describe('unknown', function () { - it('should assing unknown', function () { + it('should assign unknown', function () { var context = parser.contextParser(getContent('unknown.test.scss')) assert.deepEqual(context, { type: 'unknown' @@ -183,7 +183,12 @@ describe('scss-comment-parser', function () { var parser beforeEach(function () { - parser = new ScssCommentParser({}) + parser = new ScssCommentParser({ + _: { alias: {} }, + test: { + parse: function(content) { return content.toString() } + } + }) }) describe('group by type', function () { @@ -221,6 +226,18 @@ describe('scss-comment-parser', function () { } }) }) + + it('should parse annotations', function () { + var result = parser.parse(getContent('annotation.test.scss')) + assert.equal(result[0].description, 'Description\n') + assert.equal(result[0].test, 'Test') + }) + + it('should parse indented annotations', function () { + var result = parser.parse(getContent('indentedAnnotation.test.scss')) + assert.equal(result[0].description, 'Description\n') + assert.equal(result[0].test, 'Test') + }) }) describe('#extractCode', function () {