postcss-bem-linter
Advanced tools
Comparing version 2.2.0 to 2.3.0
@@ -0,1 +1,5 @@ | ||
=== 2.3.0 (November 24, 2015) | ||
* Add ability to ignore custom properties via `postcss-bem-linter: ignore` comments and the `ignoreCustomProperties` pattern. | ||
=== 2.2.0 (November 15, 2015) | ||
@@ -2,0 +6,0 @@ |
20
index.js
@@ -32,2 +32,3 @@ var postcss = require('postcss'); | ||
var config = generateConfig(primaryOptions, secondaryOptions); | ||
var patterns = config.patterns; | ||
@@ -48,3 +49,3 @@ return function(root, result) { | ||
if (range.defined === UTILITIES_IDENT) { | ||
if (!config.patterns.utilitySelectors) { | ||
if (!patterns.utilitySelectors) { | ||
throw new Error( | ||
@@ -57,4 +58,4 @@ 'You tried to `@define utilities` but have not provided ' + | ||
rule: rule, | ||
utilityPattern: toRegexp(config.patterns.utilitySelectors), | ||
ignorePattern: toRegexp(config.patterns.ignoreSelectors), | ||
utilityPattern: toRegexp(patterns.utilitySelectors), | ||
ignorePattern: toRegexp(patterns.ignoreSelectors), | ||
result: result, | ||
@@ -65,3 +66,3 @@ }); | ||
if (!config.patterns.componentSelectors) { | ||
if (!patterns.componentSelectors) { | ||
throw new Error( | ||
@@ -72,3 +73,8 @@ 'You tried to `@define` a component but have not provided ' + | ||
} | ||
validateCustomProperties(rule, range.defined, result); | ||
validateCustomProperties({ | ||
rule: rule, | ||
componentName: range.defined, | ||
result: result, | ||
ignorePattern: toRegexp(patterns.ignoreCustomProperties), | ||
}); | ||
validateSelectors({ | ||
@@ -78,5 +84,5 @@ rule: rule, | ||
weakMode: range.weakMode, | ||
selectorPattern: config.patterns.componentSelectors, | ||
selectorPattern: patterns.componentSelectors, | ||
selectorPatternOptions: config.presetOptions, | ||
ignorePattern: toRegexp(config.patterns.ignoreSelectors), | ||
ignorePattern: toRegexp(patterns.ignoreSelectors), | ||
result: result, | ||
@@ -83,0 +89,0 @@ }); |
@@ -12,2 +12,3 @@ var presetPatterns = require('./preset-patterns'); | ||
* @param {RegExp} [primaryOptions.ignoreSelectors] | ||
* @param {RegExp} [primaryOptions.ignoreCustomProperties] | ||
* @param {String} [primaryOptions.preset] - The same as passing a string for `primaryOptions` | ||
@@ -39,2 +40,5 @@ * @param {Object} [primaryOptions.presetOptions] - Options that are can be used by | ||
} | ||
if (primaryOptions.ignoreCustomProperties) { | ||
patterns.ignoreCustomProperties = primaryOptions.ignoreCustomProperties; | ||
} | ||
} | ||
@@ -41,0 +45,0 @@ |
@@ -1,10 +0,10 @@ | ||
var IGNORE_COMMENT = 'postcss-bem-linter: ignore'; | ||
var constants = require('./constants'); | ||
module.exports = function(rule) { | ||
var prev = rule.prev(); | ||
var previousNode = rule.prev(); | ||
return ( | ||
prev | ||
&& prev.type === 'comment' | ||
&& prev.text === IGNORE_COMMENT | ||
previousNode | ||
&& previousNode.type === 'comment' | ||
&& previousNode.text === constants.IGNORE_COMMENT | ||
); | ||
} |
// patterns can be a single regexp or an array of regexps | ||
module.exports = function(selector, patterns) { | ||
if (!patterns) return; | ||
return [].concat(patterns).some(function(p) { | ||
@@ -4,0 +5,0 @@ return p.test(selector); |
@@ -0,13 +1,21 @@ | ||
var shouldIgnoreCustomProperty = require('./should-ignore-custom-property'); | ||
/** | ||
* @param {Rule} rule - PostCSS rule | ||
* @param {String} componentName | ||
* @param {Result} result - PostCSS Result, for registering warnings | ||
* @param {Object} config | ||
* @param {Rule} config.rule | ||
* @param {String} config.componentName | ||
* @param {Result} config.result - PostCSS Result, for registering warnings | ||
* @param {RegExp} config.ignorePattern | ||
*/ | ||
module.exports = function(rule, componentName, result) { | ||
rule.walkDecls(function(declaration, i) { | ||
module.exports = function(config) { | ||
config.rule.walkDecls(function(declaration) { | ||
var property = declaration.prop; | ||
if (property.indexOf('--') !== 0) return; | ||
if (property.indexOf(componentName + '-') === 2) return; | ||
result.warn( | ||
if (shouldIgnoreCustomProperty(property, declaration, config.ignorePattern)) return; | ||
if (property.indexOf(config.componentName + '-') === 2) return; | ||
config.result.warn( | ||
'Invalid custom property name "' + property + '": ' + | ||
@@ -14,0 +22,0 @@ 'a component\'s custom properties must start with the ' + |
{ | ||
"name": "postcss-bem-linter", | ||
"version": "2.2.0", | ||
"version": "2.3.0", | ||
"description": "A BEM linter for postcss", | ||
@@ -19,3 +19,3 @@ "files": [ | ||
"start": "mocha --reporter spec --watch", | ||
"test": "npm run lint && mocha --no-colors" | ||
"test": "npm run lint && mocha --no-colors test/index.js" | ||
}, | ||
@@ -22,0 +22,0 @@ "license": "MIT", |
@@ -145,2 +145,6 @@ # postcss-bem-linter | ||
##### `ignoreCustomProperties` | ||
Describes custom properties to ignore. Works the same as `ignoreSelectors`, above, so please read about that. | ||
### Overriding Presets | ||
@@ -147,0 +151,0 @@ |
31408
17
391
424