From 488dc277b95850bd0f3dd3b32a8caab770e00a86 Mon Sep 17 00:00:00 2001 From: Bogdan Chadkin Date: Wed, 27 Jan 2016 19:35:29 +0300 Subject: [PATCH] Skip comments between imports --- lib/parse-statements.js | 3 +++ test/lint.js | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/lib/parse-statements.js b/lib/parse-statements.js index 90bd86a2..727ad29f 100644 --- a/lib/parse-statements.js +++ b/lib/parse-statements.js @@ -70,6 +70,9 @@ function parseMedia(result, atRule) { function parseImport(result, atRule) { var prev = atRule.prev() + while (prev && prev.type === "comment") { + prev = prev.prev() + } if (prev) { if ( prev.type !== "atrule" || diff --git a/test/lint.js b/test/lint.js index c3152b21..c4e4bb53 100644 --- a/test/lint.js +++ b/test/lint.js @@ -21,6 +21,22 @@ test("should warn when not @charset and not @import statement before", t => { }) }) +test("should not warn if comments before @import", t => { + return processor.process(`/* skipped comment */ @import "";`) + .then(function(result) { + const warnings = result.warnings() + t.is(warnings.length, 1) + t.is(warnings[0].text, `Unable to find uri in '@import ""'`) + }) +}) + +test("should warn if something before comments", t => { + return processor.process(`a{} /* skipped comment */ @import "";`) + .then(function(result) { + t.is(result.warnings().length, 1) + }) +}) + test("should not warn when @charset or @import statement before", t => { return Promise.all([ processor.process(`@import "bar.css"; @import "bar.css";`, {