diff --git a/index.js b/index.js index d9fb6b8..1b7d2e8 100644 --- a/index.js +++ b/index.js @@ -14,6 +14,6 @@ postcss(plugins) .process(sourceCss, processOpts) .then(function (result) { result.messages.forEach(function(i) { - console.log('i', i); + console.log('-- RULE', i); }); }); diff --git a/src/plugins.js b/src/plugins.js index 1f08654..7e301fc 100644 --- a/src/plugins.js +++ b/src/plugins.js @@ -1,7 +1,8 @@ var postcss = require('postcss'); -function LintError (msg, source, obj) { +function LintError(msg, id, source, obj) { this.msg = msg; + this.id = id; this.opts = { line: source.start.line, column: source.start.column @@ -82,8 +83,28 @@ var ensureSpaceInProperty = postcss.plugin('space-in-property', function (opts) }; }); -module.exports = [ensureNoIndentSelectors, - ensureSpaceInRuleName]; +var SPC04_SpaceBeforeBracket = postcss.plugin('SPC04_SpaceBeforeBracket', + function(opts) { + opts = opts || {}; + + return function(css, result) { + var desired = ' '; + css.walkDecls(function(decl) { + var actual = decl.parent.raws.between; + + if (actual === desired) return; + var e = new LintError('Put spaces before { in rule declarations.', + 'SPC04', decl.source, decl); + result.warn(e.msg, e.opts); + }); + }; +}); + +module.exports = [ + //ensureNoIndentSelectors, + //ensureSpaceInRuleName, + SPC04_SpaceBeforeBracket +]; // ensureEachPropertyOwnLine, // ensureSpaceInProperty, // ensureNewLineBeforeRuleClosing, diff --git a/test/ugly.scss b/test/ugly.scss index 2feba40..65e4bd1 100644 --- a/test/ugly.scss +++ b/test/ugly.scss @@ -1,13 +1,13 @@ body { color: green; } -.div { +.div{ color:blue; } +/* .span { color: yellow; } -/* @mixin fakeMixin { color: coral; }