зеркало из https://github.com/twbs/grunt-bootlint.git
Relaxerror can be defined as object of error IDs and filepath masks
This commit is contained in:
Родитель
e9e57f8606
Коммит
bec72c2d4d
|
@ -41,12 +41,18 @@ module.exports = function(grunt) {
|
|||
},
|
||||
relaxerror: {
|
||||
options: {
|
||||
relaxerror: ['E001'],
|
||||
relaxerror: {
|
||||
'E001': [],
|
||||
'W005': [
|
||||
'test/fixtures/missing-jquery.html'
|
||||
]
|
||||
},
|
||||
},
|
||||
files: {
|
||||
'tmp/relaxerror': [
|
||||
'test/fixtures/missing-doctype.html',
|
||||
'test/fixtures/missing-charset.html',
|
||||
'test/fixtures/missing-jquery.html',
|
||||
]
|
||||
}
|
||||
},
|
||||
|
|
19
README.md
19
README.md
|
@ -87,10 +87,24 @@ Shows all errors and warnings before stopping the task. (Overrides `stoponerror`
|
|||
|
||||
#### options.relaxerror
|
||||
|
||||
* Type: `Array`
|
||||
* Type: `Array|Object`
|
||||
* Default: `[]`
|
||||
|
||||
Array of [bootlint problem ID codes](https://github.com/twbs/bootlint/wiki) (`String`s) to explicitly ignore.
|
||||
Array of [bootlint problem ID codes][] (`String`s) to explicitly ignore.
|
||||
|
||||
Object of [bootlint problem ID codes][] as **keys** and filepath masks as array **value**.
|
||||
|
||||
##### Example
|
||||
|
||||
```
|
||||
relaxerror: {
|
||||
'E001': [],
|
||||
'W005': [
|
||||
'path/to/file.html',
|
||||
'file/path/*.mask'
|
||||
]
|
||||
},
|
||||
```
|
||||
|
||||
## Contributing
|
||||
|
||||
|
@ -117,3 +131,4 @@ In lieu of a formal styleguide, take care to maintain the existing coding style.
|
|||
|
||||
Code released under [the MIT license](https://github.com/twbs/grunt-bootlint/blob/master/LICENSE-MIT).
|
||||
|
||||
[bootlint problem ID codes]: https://github.com/twbs/bootlint/wiki
|
||||
|
|
|
@ -29,7 +29,8 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"bootlint": "^0.12.0",
|
||||
"chalk": "^1.0.0"
|
||||
"chalk": "^1.0.0",
|
||||
"micromatch": "^2.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"grunt": "~0.4.5",
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
module.exports = function(grunt) {
|
||||
var bootlint = require('bootlint');
|
||||
var chalk = require('chalk');
|
||||
var micromatch = require('micromatch');
|
||||
|
||||
|
||||
grunt.registerMultiTask('bootlint', 'An HTML linter for Bootstrap projects', function() {
|
||||
|
@ -68,7 +69,8 @@ module.exports = function(grunt) {
|
|||
|
||||
};
|
||||
|
||||
bootlint.lintHtml(src, reporter, options.relaxerror);
|
||||
var disabledIds = getDisabledIdsForFilepath(filepath);
|
||||
bootlint.lintHtml(src, reporter, disabledIds);
|
||||
totalFileCount++;
|
||||
});
|
||||
|
||||
|
@ -81,6 +83,35 @@ module.exports = function(grunt) {
|
|||
grunt.log.ok(totalFileCount + ' file(s) lint free.');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function getDisabledIdsForFilepath(filepath) {
|
||||
// Relaxerror defined as array without filepaths
|
||||
if (options.relaxerror instanceof Array) {
|
||||
return options.relaxerror;
|
||||
}
|
||||
|
||||
// Relaxerror as object with error IDs as keys and filepaths as values
|
||||
var disabledIds = Object.keys(options.relaxerror);
|
||||
|
||||
// Lookup disabled IDs filepaths
|
||||
var returnIds = disabledIds.filter(function(key) {
|
||||
var paths = options.relaxerror[key];
|
||||
|
||||
// handle 'E001': true, 'E001': []
|
||||
if (!(paths instanceof Array) || paths.length === 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// handle 'E001': ['*']
|
||||
if (paths.indexOf('*') !== -1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// test filepath pattern
|
||||
return micromatch.any(filepath, paths);
|
||||
});
|
||||
|
||||
return returnIds;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
|
@ -37,13 +37,13 @@ exports.bootlint = {
|
|||
'Should print file path');
|
||||
test.ok(result.stdout.indexOf("Document is missing a DOCTYPE declaration") >= 0,
|
||||
'Should warn about missing a DOCTYPE');
|
||||
test.ok(result.stdout.indexOf("8 lint error(s) found across 4 file(s)") >= 0,
|
||||
test.ok(result.stdout.indexOf("9 lint error(s) found across 5 file(s)") >= 0,
|
||||
'Should print number of lint errors and files');
|
||||
test.done();
|
||||
});
|
||||
},
|
||||
relaxerror: function(test) {
|
||||
test.expect(3);
|
||||
test.expect(4);
|
||||
grunt.util.spawn({
|
||||
grunt: true,
|
||||
args: ['bootlint:relaxerror', '--no-color'],
|
||||
|
@ -52,7 +52,9 @@ exports.bootlint = {
|
|||
'Should not warn about missing a DOCTYPE');
|
||||
test.ok(result.stdout.indexOf("W001") >= 0,
|
||||
'Should warn about missing charset');
|
||||
test.ok(result.stdout.indexOf("1 lint error(s) found across 2 file(s)") >= 0,
|
||||
test.ok(result.stdout.indexOf("W005") === -1,
|
||||
'Should not warn about missing jQuery');
|
||||
test.ok(result.stdout.indexOf("1 lint error(s) found across 3 file(s)") >= 0,
|
||||
'Should print correct number of lint errors and files');
|
||||
test.done();
|
||||
});
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>Test</title>
|
||||
<!--[if lt IE 9]>
|
||||
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
|
||||
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
|
||||
<![endif]-->
|
||||
|
||||
<link rel="stylesheet" href="../../lib/qunit-1.14.0.css">
|
||||
<script src="../../lib/qunit-1.14.0.js"></script>
|
||||
<script src="../../../dist/browser/bootlint.js"></script>
|
||||
<script src="../generic-qunit.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="qunit"></div>
|
||||
<ol id="bootlint">
|
||||
<li data-lint="Document is missing a jQuery"></li>
|
||||
</ol>
|
||||
</body>
|
||||
</html>
|
Загрузка…
Ссылка в новой задаче