diff --git a/CHANGELOG.md b/CHANGELOG.md index cc1c19c9..0d6100c4 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# 6.0.0 - 2015-06-17 + +- Changed: warnings messages are now using postcss message api (4.1.x) +- Added: warning when a import statement has not been closed correctly +([#42](https://github.com/postcss/postcss-import/issues/42)) + # 5.2.2 - 2015-04-19 - Fixed: globbed imports work for module directories ([#37](https://github.com/postcss/postcss-import/pull/37)) diff --git a/index.js b/index.js index 44a429bf..69da8901 100755 --- a/index.js +++ b/index.js @@ -20,6 +20,10 @@ var moduleDirectories = [ "node_modules", ] +var warnNodesMessage = + "It looks like you didn't end correctly your @import statement. " + + "Some children nodes are attached to it" + /** * Inline `@import`ed files * @@ -35,7 +39,7 @@ function AtImport(options) { (options.path || []) // fallback to empty array ) - return function(styles) { + return function(styles, result) { // auto add from option if possible if ( !options.from && @@ -68,6 +72,7 @@ function AtImport(options) { var hashFiles = {} parseStyles( + result, styles, options, insertRules, @@ -90,7 +95,9 @@ function AtImport(options) { * @param {Object} styles * @param {Object} options */ -function parseStyles(styles, +function parseStyles( + result, + styles, options, cb, importedFiles, @@ -100,6 +107,9 @@ function parseStyles(styles, ) { var imports = [] styles.eachAtRule("import", function checkAtRule(atRule) { + if (atRule.nodes) { + result.warn(warnNodesMessage, {node: atRule}) + } if (options.glob && glob.hasMagic(atRule.params)) { imports = parseGlob(atRule, options, imports) } @@ -110,6 +120,7 @@ function parseStyles(styles, imports.forEach(function(atRule) { helpers.try(function transformAtImport() { readAtImport( + result, atRule, options, cb, @@ -205,6 +216,7 @@ function addIgnoredAtRulesOnTop(styles, ignoredAtRules) { * @param {Object} options */ function readAtImport( + result, atRule, options, cb, @@ -261,6 +273,7 @@ function readAtImport( importedFiles[resolvedFilename][media] = true readImportedContent( + result, atRule, parsedAtImport, clone(options), @@ -282,7 +295,9 @@ function readAtImport( * @param {String} resolvedFilename * @param {Function} cb */ -function readImportedContent(atRule, +function readImportedContent( + result, + atRule, parsedAtImport, options, resolvedFilename, @@ -310,7 +325,7 @@ function readImportedContent(atRule, ) if (fileContent.trim() === "") { - console.log(helpers.message(resolvedFilename + " is empty", atRule.source)) + result.warn(resolvedFilename + " is empty", {node: atRule}) detach(atRule) return } @@ -337,6 +352,7 @@ function readImportedContent(atRule, // recursion: import @import from imported file parseStyles( + result, newStyles, options, cb, @@ -506,3 +522,4 @@ module.exports = postcss.plugin( "postcss-import", AtImport ) +module.exports.warnNodesMessage = warnNodesMessage diff --git a/package.json b/package.json index 9bf1b7e1..81aebe4b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "postcss-import", - "version": "5.2.2", + "version": "6.0.0", "description": "PostCSS plugin to import CSS files", "keywords": [ "css", @@ -24,8 +24,8 @@ "dependencies": { "clone": "^0.1.17", "glob": "^5.0.1", - "postcss": "^4.0.2", "object-assign": "^3.0.0", + "postcss": "^4.1.4", "postcss-message-helpers": "^2.0.0", "resolve": "^1.0.0", "string-hash": "^1.1.0" diff --git a/test/index.js b/test/index.js index 7b530e1e..f59ec60c 100755 --- a/test/index.js +++ b/test/index.js @@ -230,3 +230,25 @@ test("@import custom resolve", function(t) { t.end() }) + +test("warn when a import doesn't have ;", function(t) { + t.equal( + postcss() + .use(atImport()) + .process("@import url('http://') :root{}") + .warnings()[0].text, + atImport.warnNodesMessage, + "should warn when a user didn't close an import with ;" + ) + + t.equal( + postcss() + .use(atImport()) + .process("@import url('http://');") + .warnings().length, + 0, + "should not warn when a user closed an import with ;" + ) + + t.end() +})