From f3bd2c688fc03f5543f9943aeb50735b8570aa5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Knezi=C4=87?= Date: Tue, 1 Nov 2016 15:30:10 +0100 Subject: [PATCH 1/7] Fix annotation parsing in nested comment blocks --- index.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index b99b1fa..b2d4bf1 100644 --- a/index.js +++ b/index.js @@ -168,20 +168,21 @@ var scssContextParser = (function () { var filterAndGroup = function (lines) { var nLines = []; var group = false; - lines.forEach(function (line){ - var isAnnotation = line.indexOf('@') === 0; - if (line.trim().indexOf('---') !== 0) { // Ignore lines that start with "---" - if (group){ - if ( isAnnotation ) { - nLines.push(line); + lines.forEach(function (line) { + var trimmedLine = line.trim(); + var isAnnotation = trimmedLine.indexOf('@') === 0; + if (trimmedLine.trim().indexOf('---') !== 0) { // Ignore lines that start with "---" + if (group) { + if (isAnnotation) { + nLines.push(trimmedLine); } else { - nLines[nLines.length - 1] += '\n' + line ; + nLines[nLines.length - 1] += '\n' + line; } } else if (isAnnotation) { group = true; - nLines.push(line); + nLines.push(trimmedLine); } else { - nLines.push(line); + nLines.push(trimmedLine); } } }); From d08dc1d0e79f057c8a6b4a95f7018aac295e2464 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Knezi=C4=87?= Date: Tue, 1 Nov 2016 15:55:33 +0100 Subject: [PATCH 2/7] Don't trim line twice in filterAndGroup function --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index b2d4bf1..0cadb5e 100644 --- a/index.js +++ b/index.js @@ -171,7 +171,7 @@ var filterAndGroup = function (lines) { lines.forEach(function (line) { var trimmedLine = line.trim(); var isAnnotation = trimmedLine.indexOf('@') === 0; - if (trimmedLine.trim().indexOf('---') !== 0) { // Ignore lines that start with "---" + if (trimmedLine.indexOf('---') !== 0) { // Ignore lines that start with "---" if (group) { if (isAnnotation) { nLines.push(trimmedLine); From ec7e7b28595e61a975b9bfa1768f7b90494aaf88 Mon Sep 17 00:00:00 2001 From: emortlock Date: Mon, 6 May 2019 08:44:53 +0100 Subject: [PATCH 3/7] Added tests for parsing annotations --- test/fixtures/annotation.test.scss | 5 +++++ test/fixtures/indentedAnnotation.test.scss | 9 +++++++++ test/test.js | 21 +++++++++++++++++++-- 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 test/fixtures/annotation.test.scss create mode 100644 test/fixtures/indentedAnnotation.test.scss 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..02e00e8 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: content => 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 () { From ebcc8bfb1ed1dcb7689285d80e784d397e82548c Mon Sep 17 00:00:00 2001 From: emortlock Date: Mon, 6 May 2019 08:51:12 +0100 Subject: [PATCH 4/7] Removed semicolons for consitent formatting --- index.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index aad3025..2ca02b3 100644 --- a/index.js +++ b/index.js @@ -170,25 +170,25 @@ var scssContextParser = (function () { })() var filterAndGroup = function (lines) { - var nLines = []; - var group = false; + var nLines = [] + var group = false lines.forEach(function (line) { - var trimmedLine = line.trim(); - var isAnnotation = trimmedLine.indexOf('@') === 0; + var trimmedLine = line.trim() + var isAnnotation = trimmedLine.indexOf('@') === 0 if (trimmedLine.indexOf('---') !== 0) { // Ignore lines that start with "---" if (group) { if (isAnnotation) { - nLines.push(trimmedLine); + nLines.push(trimmedLine) } else { - nLines[nLines.length - 1] += '\n' + line; + nLines[nLines.length - 1] += '\n' + line } } else if (isAnnotation) { - group = true; - nLines.push(trimmedLine); + group = true + nLines.push(trimmedLine) } else { - nLines.push(trimmedLine); + nLines.push(trimmedLine) } } }) From 8b7c39d41ed9085eed36f663ade06b91fc83853b Mon Sep 17 00:00:00 2001 From: emortlock Date: Mon, 6 May 2019 08:58:37 +0100 Subject: [PATCH 5/7] Removed arrow function to support older versions of node --- test/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test.js b/test/test.js index 02e00e8..f92ed0c 100644 --- a/test/test.js +++ b/test/test.js @@ -186,7 +186,7 @@ describe('scss-comment-parser', function () { parser = new ScssCommentParser({ _: { alias: {} }, test: { - parse: content => content.toString() + parse: function(content) { return content.toString() } } }) }) From 89207acc3574481de109a9035b4cccd9df28c011 Mon Sep 17 00:00:00 2001 From: emortlock Date: Mon, 6 May 2019 10:43:56 +0100 Subject: [PATCH 6/7] Updated travis config to match SassDoc/sassdoc --- .travis.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index d7cdecc..8b4db2b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,10 @@ language: node_js node_js: - - '0.10' - - '0.12' - - '4.2' - - 'stable' + - 6 + - 8 + - lts/* + - stable sudo: false From 43e1e2d7910e4b528f44f3e469d59293b929f35c Mon Sep 17 00:00:00 2001 From: emortlock Date: Mon, 6 May 2019 18:44:32 +0100 Subject: [PATCH 7/7] Reverted removal of node versions --- .travis.yml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8b4db2b..62374bd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,13 @@ language: node_js node_js: - - 6 - - 8 - - lts/* - - stable + - '0.10' + - '0.12' + - '4.2' + - '6' + - '8' + - 'lts/*' + - 'stable' sudo: false