Comparing version 1.4.1 to 1.4.2
@@ -62,4 +62,14 @@ /** | ||
matchClass, | ||
currentRules = lodash.assign({}, rules), | ||
messages = []; | ||
if ( options.excludeRules ) { | ||
for (var i in rules) { | ||
if ( options.excludeRules.indexOf(i) >= 0 ) { | ||
delete currentRules[i]; | ||
} | ||
} | ||
} | ||
/** | ||
@@ -74,20 +84,14 @@ * Generates messages for given classname in source | ||
*/ | ||
function validate (input, source, line, column, rulesToExclude) { | ||
var currentRules = lodash.assign({}, rules); | ||
function validate (input, source, line, column) { | ||
rulesToExclude = lodash.assign([], options.excludeRules, rulesToExclude); | ||
if ( rulesToExclude ) { | ||
for (var i in rules) { | ||
if ( rulesToExclude.indexOf(i) >= 0 ) { | ||
delete currentRules[i]; | ||
} | ||
} | ||
} | ||
for (var rule_id in currentRules) { | ||
var messageOptions = lodash.assign({}, { | ||
input: input, | ||
source: source, | ||
elem: options.elem, | ||
mod: options.mod, | ||
wordPattern: options.wordPattern | ||
}), | ||
message = new Message(currentRules[rule_id], messageOptions); | ||
var message = new Message(currentRules[rule_id], { input: input, source: source }); | ||
if ( message.text ) { | ||
@@ -149,11 +153,8 @@ messages.push({ | ||
if ( arrayClasses.length > 1 ) { | ||
if ( sliced.length > 1 ) { | ||
sliced = arrayClasses.islice(arrayClasses, className); | ||
validate(className, sliced, line, columnCounted); | ||
} else { | ||
validate(className, sliced, line, columnCounted, ['dublicate']); | ||
} | ||
validate(className, sliced, line, columnCounted); | ||
} | ||
@@ -160,0 +161,0 @@ |
@@ -22,5 +22,5 @@ /** | ||
this.options = lodash.assign({ elem: '__', mod: '_' }, options); | ||
this.options = options; | ||
bemNaming(this.options); | ||
this.bemNaming = bemNaming(this.options); | ||
@@ -47,7 +47,8 @@ /** | ||
this.isRuleOptionsValid = function () { | ||
if ( rule.isBlock && bemNaming.isBlock(input) || | ||
rule.isElem && bemNaming.isElem(input) || | ||
rule.isBlockMod && bemNaming.isBlockMod(input) || | ||
rule.isElemMod && bemNaming.isElemMod(input) ) { | ||
if ( rule.isBlock && this.bemNaming.isBlock(input) || | ||
rule.isElem && this.bemNaming.isElem(input) || | ||
rule.isBlockMod && this.bemNaming.isBlockMod(input) || | ||
rule.isElemMod && this.bemNaming.isElemMod(input) ) { | ||
return true; | ||
@@ -59,3 +60,3 @@ } | ||
if ( this.isRuleOptionsValid(rule) && !rule.valid(input, this.options.source) ) { | ||
if ( this.isRuleOptionsValid(rule) && !rule.valid(this.bemNaming, input, this.options.source) ) { | ||
if ( typeof rule.message == 'function' ) { | ||
@@ -62,0 +63,0 @@ return rule.message(this.options); |
@@ -8,5 +8,3 @@ /** | ||
var bemNaming = require("bem-naming"); | ||
var allRules = { | ||
@@ -29,3 +27,11 @@ /** | ||
message: (options) => 'Dublicate classes found', | ||
valid: (input, source) => source.indexOf(input) < 0 | ||
valid: (bemNaming, input, source) => { | ||
// compare input with itself in source | ||
if ( source && source[0] == input ) { | ||
return true; | ||
} | ||
return source.indexOf(input) < 0; | ||
} | ||
}, | ||
@@ -42,3 +48,3 @@ | ||
valid: function(input, source) { | ||
valid: function(bemNaming, input, source) { | ||
let valid = true, | ||
@@ -73,3 +79,3 @@ bemObj = bemNaming.parse(input); | ||
valid: function(input, source) { | ||
valid: function(bemNaming, input, source) { | ||
let valid = true, | ||
@@ -103,3 +109,3 @@ bemObj = bemNaming.parse(input); | ||
message: (options) => 'An element' + options.elem + 'mod' + options.mod + 'val specified, but element not found', | ||
valid: function(input, source) { | ||
valid: function(bemNaming, input, source) { | ||
let valid = true, | ||
@@ -106,0 +112,0 @@ bemObj = bemNaming.parse(input); |
{ | ||
"name": "bemlint", | ||
"version": "1.4.1", | ||
"version": "1.4.2", | ||
"description": "Linting module checks BEM-naming conventions in `class` attribute of the html files", | ||
@@ -5,0 +5,0 @@ "main": "./lib/bemlint.js", |
# bemlint | ||
[![Build Status](https://travis-ci.org/DesTincT/bemlint.svg?branch=master)](https://travis-ci.org/DesTincT/bemlint) | ||
[![NPM version][npm-image]][npm-url] | ||
[![build status][travis-image]][travis-url] | ||
[![Downloads][downloads-image]][downloads-url] | ||
This linter checks attribute `class` in final `html` files for [BEM naming](https://github.com/bem/bem-naming) conventions. | ||
@@ -59,3 +60,3 @@ | ||
``` | ||
bemlint test.html --er='['isBlockElementInBlock']' | ||
bemlint test.html --no-ignore | ||
``` | ||
@@ -71,6 +72,7 @@ | ||
## Versions | ||
- __v1.4.0__ - ignore-path update, regex match better and minor | ||
- __v1.3.0__ - minor fixes, some tests added | ||
- __v1.2.0__ - minor fixes, readme update | ||
- __v1.1.0__ - added formatters, message generator and few cli updates | ||
[npm-image]: https://img.shields.io/npm/v/bemlint.svg?style=flat-square | ||
[npm-url]: https://www.npmjs.com/package/bemlint | ||
[travis-image]: https://img.shields.io/travis/DesTincT/bemlint/master.svg?style=flat-square | ||
[travis-url]: https://travis-ci.org/DesTincT/bemlint | ||
[downloads-image]: https://img.shields.io/npm/dm/bemlint.svg?style=flat-square | ||
[downloads-url]: https://www.npmjs.com/package/bemlint |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
83029
2096
77