gulp-bootlint
A gulp wrapper for Bootlint, the HTML linter for Bootstrap projects.
Requirements
- Node.js >= 8.x
First steps
If you are familiar with gulp just install the plugin from npm with the following command:
npm install gulp-bootlint --save-dev
Otherwise check out the Getting Started guide of gulp first.
Create a new gulp task
After installing the plugin you can create a new gulp task in your gulpfile.js
like this:
var gulp = require('gulp');
var bootlint = require('gulp-bootlint');
gulp.task('bootlint', function() {
return gulp.src('./index.html')
.pipe(bootlint());
});
Options
You can pass the following options as a single object when calling the bootlint plugin.
options.stoponerror
- Type:
Boolean
- Default:
false
Stops the gulp task if there are errors in the linted file.
options.stoponwarning
- Type:
Boolean
- Default:
false
Stops the gulp task if there are warnings in the linted file.
options.loglevel
- Type:
String
- Default:
'error'
- Options:
'emergency'
,'alert'
,'critical'
,'error'
,'warning'
,'notice'
,'info'
,'debug'
Defines which log messages should be printed to stdout
.
options.disabledIds
- Type:
String[]
- Default:
[]
Array of bootlint problem ID codes (as Strings
) to explicitly ignore.
options.issues
- Type:
Array
ofLintWarning
andLintError
objects - Default:
[]
All found issues (Objects of type LintWarning
and LintError
) are stored in this array.
You can access and use them after executing this module.
The classes LintWarning
and LintError
are described here https://github.com/twbs/bootlint#api-documentation.
options.reportFn
- Type:
Function
- Parameter:
Object
file - File with linting error.Object
lint - Linting error.Boolean
isError - True if current linting problem is an error.Boolean
isWarning - True if current linting problem is a warning.Object
errorLocation - Error location in file.
A function that will log out the lint errors to the console. Only use this if you want to customize how the lint errors are reported.
If desired, this can be turned off entirely by setting reportFn: false
.
options.summaryReportFn
- Type:
Function
- Parameter:
Object
file - File which was linted.Integer
errorCount - Total count of errors in the file.Integer
warningCount - Total count of warnings in the file.
A function that will log out the final lint error/warning summary to the console. Only use this if you want to customize how this is reported.
If desired, this can be turned off entirely by setting summaryReportFn: false
.
Example of options usage:
var gulp = require('gulp');
var bootlint = require('gulp-bootlint');
gulp.task('bootlint', function() {
var fileIssues = [];
return gulp.src('./index.html')
.pipe(bootlint({
stoponerror: true,
stoponwarning: true,
loglevel: 'debug',
disabledIds: ['W009', 'E007'],
issues: fileIssues,
reportFn: function(file, lint, isError, isWarning, errorLocation) {
var message = (isError) ? "ERROR! - " : "WARN! - ";
if (errorLocation) {
message += file.path + ' (line:' + (errorLocation.line + 1) + ', col:' + (errorLocation.column + 1) + ') [' + lint.id + '] ' + lint.message;
} else {
message += file.path + ': ' + lint.id + ' ' + lint.message;
}
console.log(message);
},
summaryReportFn: function(file, errorCount, warningCount) {
if (errorCount > 0 || warningCount > 0) {
console.log("please fix the " + errorCount + " errors and "+ warningCount + " warnings in " + file.path);
} else {
console.log("No problems found in "+ file.path);
}
}
}));
});
Release History
- 2019-XX-XX - v0.11.1: Bumped dependency versions
- 2019-06-26 - v0.11.0
- Dropped support for Node.js versions <= 7
- Updated Bootlint to v0.16.6
- Bumped dependency versions
- 2018-12-15 - v0.10.2: Bumped dependency versions
- 2018-10-02 - v0.10.1: Updated bootlint to v0.15.1 / Bumped dependency versions
- 2018-04-24 - v0.9.0: Replaced deprecated gulp-util (thanks to TheDancingCode)
- 2017-02-01 - v0.8.1: Bumped dependency versions
- 2016-05-24 - v0.8.0: Possibility to provide array where found issues are stored
- 2016-04-12 - v0.7.2: Bumped dependency versions
- 2015-11-25 - v0.7.1: Updated Bootlint to v0.14.2
- 2015-11-16 - v0.7.0: Updated Bootlint to v0.14.1 / Added options to define reporters (thx @chrismbarr) / Bumped dependency versions
- 2015-07-28 - v0.6.4: Bumped dependency versions
- 2015-06-21 - v0.6.0: Added option to define log level
- 2015-06-18 - v0.5.1: Bumped dependency versions
- 2015-04-28 - v0.5.0: Added parameters to stop task on error or warning
- 2015-04-25 - v0.4.0: Updated Bootlint to v0.12.0 / Bumped other dependency versions
- 2015-02-24 - v0.3.0: Updated Bootlint to v0.11.0 / Bumped other dependency versions
- 2015-01-26 - v0.2.3: Updated Bootlint to v0.10.0
- 2015-01-07 - v0.2.2: Updated dependencies
- 2015-01-01 - v0.2.1: Code cleanup
- 2015-01-01 - v0.2.0: Updated Bootlint to v0.9.1
- 2015-01-01 - v0.1.1: Fail on linting errors
- 2014-11-23 - v0.1.0: First public release