grunt-lint-pattern
Advanced tools
Comparing version 0.1.3 to 0.1.4
@@ -46,3 +46,3 @@ /* | ||
}, | ||
does_not_match: { | ||
does_not_match_simple: { | ||
options: { | ||
@@ -66,2 +66,20 @@ rules: [ | ||
}, | ||
does_not_match_filter: { | ||
options: { | ||
rules: [ | ||
{ | ||
pattern: /Debug/i, | ||
message: "Debug isn't allowed. Remove all references to Debug.", | ||
filter: function(src) { | ||
return !/testingDebug/.test(src); | ||
}, | ||
}, | ||
], | ||
}, | ||
files: { | ||
src: [ | ||
'test/fixtures/testing*' | ||
], | ||
}, | ||
}, | ||
no_pattern_option: { | ||
@@ -68,0 +86,0 @@ options: {}, |
{ | ||
"name": "grunt-lint-pattern", | ||
"description": "Search for patterns in files. Error if any match.", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"homepage": "https://github.com/chrisdanford/grunt-lint-pattern", | ||
@@ -6,0 +6,0 @@ "author": { |
@@ -28,8 +28,8 @@ # grunt-lint-pattern | ||
lint_pattern: { | ||
your_target: { | ||
your_first_target: { | ||
options: { | ||
rules: [ | ||
{ | ||
pattern: /console\./; | ||
message: 'Calling "console." is not allowed.' | ||
pattern: /console\./, | ||
message: 'Do not call "console".' | ||
}, | ||
@@ -42,13 +42,20 @@ ], | ||
}, | ||
your_target: { | ||
your_second_target: { | ||
options: { | ||
rules: [ | ||
{ | ||
pattern: /moz-border-radius/; | ||
message: 'Don't use vendor prefixes for the border-radius property.' | ||
pattern: /moz-border-radius/, | ||
message: 'Do not use vendor prefixes for the border-radius property.' | ||
}, | ||
{ | ||
pattern: /!important/; | ||
pattern: /!important/, | ||
message: 'Do not use "!important".' | ||
}, | ||
{ | ||
pattern: /@import\s+/, | ||
message: 'Do not use import statements', | ||
filter: function(src) { | ||
} | ||
}, | ||
], | ||
@@ -84,4 +91,11 @@ }, | ||
### Usage Examples | ||
##### filter | ||
Type: `function` | ||
Optional | ||
If present, this function will be called once for each matching file to decide whether to test this rule. Return `true` to allow checking this file. Return `false` to skip checking this file. | ||
This is particularly useful if you are checking a large list of rules over a large list of files and a small number of files that should be excluded by certain rules. The advantage of filtering out the few exclusions compared to creating multiple targets is that the files need only be read from disk once if there's a single target. | ||
## Contributing | ||
@@ -91,2 +105,3 @@ In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/). | ||
## Release History | ||
* 0.1 Initial release | ||
* 0.1.0 Initial release | ||
* 0.1.4 add `filter` option |
@@ -49,7 +49,13 @@ /* | ||
// Read file source. | ||
var src = grunt.file.read(filepath); | ||
var contents = null; | ||
for (i = 0; i < options.rules.length; i++) { | ||
rule = options.rules[i]; | ||
if ('filter' in rule && !rule.filter(filepath)) { | ||
continue; | ||
} | ||
if (contents === null) { | ||
contents = grunt.file.read(filepath); | ||
} | ||
var matchingFilesForRule = matchingFiles[i]; | ||
if (src.match(rule.pattern)) { | ||
if (rule.pattern.test(contents)) { | ||
matchingFilesForRule.push(filepath); | ||
@@ -56,0 +62,0 @@ } |
11269
206
104