gulp-bootlint
Advanced tools
Comparing version 0.11.0 to 1.0.0
231
index.js
/* | ||
* gulp-bootlint | ||
* https://github.com/tschortsch/gulp-bootlint | ||
* | ||
* Copyright (c) 2015 Juerg Hunziker | ||
* Licensed under the MIT license. | ||
*/ | ||
@@ -13,5 +10,6 @@ | ||
var through = require('through2'); | ||
var Log = require('log'); | ||
var merge = require('merge'); | ||
var bootlint = require('bootlint'); | ||
var log = require('log'); | ||
require('log-node')(); // initialize log writer | ||
@@ -21,133 +19,130 @@ // consts | ||
function gulpBootlint(options) { | ||
var hasError = false, | ||
hasWarning = false, | ||
log, stream; | ||
function gulpBootlint (options) { | ||
var hasError = false; | ||
var hasWarning = false; | ||
var stream; | ||
/** | ||
* Reporter function for linting errors and warnings. | ||
* | ||
* @param file Current file object. | ||
* @param lint Current linting error. | ||
* @param isError True if this is an error. | ||
* @param isWarning True if this is a warning. | ||
* @param errorLocation Error location object. | ||
*/ | ||
var defaultReportFn = function(file, lint, isError, isWarning, errorLocation) { | ||
var lintId = (isError) ? colors.bgRed(colors.white(lint.id)) : colors.bgYellow(colors.white(lint.id)); | ||
var message = ''; | ||
if (errorLocation) { | ||
message = file.path + ':' + (errorLocation.line + 1) + ':' + (errorLocation.column + 1) + ' ' + lintId + ' ' + lint.message; | ||
} else { | ||
message = file.path + ': ' + lintId + ' ' + lint.message; | ||
} | ||
/** | ||
* Reporter function for linting errors and warnings. | ||
* | ||
* @param file Current file object. | ||
* @param lint Current linting error. | ||
* @param isError True if this is an error. | ||
* @param isWarning True if this is a warning. | ||
* @param errorLocation Error location object. | ||
*/ | ||
var defaultReportFn = function (file, lint, isError, isWarning, errorLocation) { | ||
var lintId = (isError) ? colors.bgRed(colors.white(lint.id)) : colors.bgYellow(colors.white(lint.id)); | ||
var message = ''; | ||
if (errorLocation) { | ||
message = file.path + ':' + (errorLocation.line + 1) + ':' + (errorLocation.column + 1) + ' ' + lintId + ' ' + lint.message; | ||
} else { | ||
message = file.path + ': ' + lintId + ' ' + lint.message; | ||
} | ||
if (isError) { | ||
log.error(message); | ||
} else { | ||
log.warning(message); | ||
} | ||
}; | ||
if (isError) { | ||
log.error(message); | ||
} else { | ||
log.warning(message); | ||
} | ||
}; | ||
/** | ||
* Reporter function for linting summary. | ||
* | ||
* @param file File which was linted. | ||
* @param errorCount Total count of errors in file. | ||
* @param warningCount Total count of warnings in file. | ||
*/ | ||
var defaultSummaryReportFn = function(file, errorCount, warningCount) { | ||
if (errorCount > 0 || warningCount > 0) { | ||
var message = ''; | ||
if (errorCount > 0) { | ||
message += colors.red(errorCount + ' lint ' + (errorCount === 1 ? 'error' : 'errors')); | ||
} | ||
/** | ||
* Reporter function for linting summary. | ||
* | ||
* @param file File which was linted. | ||
* @param errorCount Total count of errors in file. | ||
* @param warningCount Total count of warnings in file. | ||
*/ | ||
var defaultSummaryReportFn = function (file, errorCount, warningCount) { | ||
if (errorCount > 0 || warningCount > 0) { | ||
var message = ''; | ||
if (errorCount > 0) { | ||
message += colors.red(errorCount + ' lint ' + (errorCount === 1 ? 'error' : 'errors')); | ||
} | ||
if (warningCount > 0) { | ||
if (errorCount > 0) { | ||
message += ' and '; | ||
} | ||
message += colors.yellow(warningCount + ' lint ' + (warningCount === 1 ? 'warning' : 'warnings')); | ||
} | ||
message += ' found in file ' + file.path; | ||
log.notice(message); | ||
} else { | ||
log.info(colors.green(file.path + ' is lint free!')); | ||
if (warningCount > 0) { | ||
if (errorCount > 0) { | ||
message += ' and '; | ||
} | ||
}; | ||
message += colors.yellow(warningCount + ' lint ' + (warningCount === 1 ? 'warning' : 'warnings')); | ||
} | ||
message += ' found in file ' + file.path; | ||
log.notice(message); | ||
} else { | ||
log.info(colors.green(file.path + ' is lint free!')); | ||
} | ||
}; | ||
options = merge({ | ||
stoponerror: false, | ||
stoponwarning: false, | ||
loglevel: 'error', | ||
disabledIds: [], | ||
issues: [], | ||
reportFn: defaultReportFn, | ||
summaryReportFn: defaultSummaryReportFn | ||
}, options); | ||
options = merge({ | ||
stoponerror: false, | ||
stoponwarning: false, | ||
disabledIds: [], | ||
issues: [], | ||
reportFn: defaultReportFn, | ||
summaryReportFn: defaultSummaryReportFn, | ||
}, options); | ||
log = new Log(options.loglevel); | ||
// creating a stream through which each file will pass | ||
stream = through.obj(function (file, enc, cb) { | ||
var errorCount = 0; | ||
var warningCount = 0; | ||
// creating a stream through which each file will pass | ||
stream = through.obj(function (file, enc, cb) { | ||
var errorCount = 0, | ||
warningCount = 0; | ||
if (file.isNull()) { | ||
return cb(null, file); | ||
} | ||
if (file.isNull()) { | ||
return cb(null, file); | ||
} | ||
if (file.isStream()) { | ||
this.emit('error', new PluginError(PLUGIN_NAME, 'Streams are not supported!')); | ||
return cb(); | ||
} | ||
if (file.isStream()) { | ||
this.emit('error', new PluginError(PLUGIN_NAME, 'Streams are not supported!')); | ||
return cb(); | ||
} | ||
var reporter = function (lint) { | ||
var isError = (lint.id[0] === 'E'); | ||
var isWarning = (lint.id[0] === 'W'); | ||
var errorElementsAvailable = false; | ||
var reporter = function (lint) { | ||
var isError = (lint.id[0] === 'E'), | ||
isWarning = (lint.id[0] === 'W'), | ||
errorElementsAvailable = false; | ||
if (lint.elements) { | ||
lint.elements.each(function (_, element) { | ||
if (options.reportFn) { | ||
options.reportFn(file, lint, isError, isWarning, element.startLocation); | ||
} | ||
errorElementsAvailable = true; | ||
}); | ||
} | ||
if (!errorElementsAvailable && options.reportFn) { | ||
options.reportFn(file, lint, isError, isWarning, null); | ||
} | ||
if (lint.elements) { | ||
lint.elements.each(function (_, element) { | ||
if(options.reportFn){ | ||
options.reportFn(file, lint, isError, isWarning, element.startLocation); | ||
} | ||
errorElementsAvailable = true; | ||
}); | ||
} | ||
if (!errorElementsAvailable && options.reportFn) { | ||
options.reportFn(file, lint, isError, isWarning, null); | ||
} | ||
if (isError) { | ||
++errorCount; | ||
hasError = true; | ||
} | ||
if (isWarning) { | ||
++warningCount; | ||
hasWarning = true; | ||
} | ||
options.issues.push(lint); | ||
}; | ||
if (isError) { | ||
++errorCount; | ||
hasError = true; | ||
} | ||
if (isWarning) { | ||
++warningCount; | ||
hasWarning = true; | ||
} | ||
options.issues.push(lint); | ||
}; | ||
log.info(colors.gray('Linting file ' + file.path)); | ||
bootlint.lintHtml(file.contents.toString(), reporter, options.disabledIds); | ||
log.info(colors.gray('Linting file ' + file.path)); | ||
bootlint.lintHtml(file.contents.toString(), reporter, options.disabledIds); | ||
if (options.summaryReportFn) { | ||
options.summaryReportFn(file, errorCount, warningCount); | ||
} | ||
if(options.summaryReportFn){ | ||
options.summaryReportFn(file, errorCount, warningCount); | ||
} | ||
return cb(null, file); | ||
}, function (cb) { | ||
if (hasError && options.stoponerror) { | ||
this.emit('error', new PluginError(PLUGIN_NAME, 'Lint errors found!')); | ||
} | ||
if (hasWarning && options.stoponwarning) { | ||
this.emit('warning', new PluginError(PLUGIN_NAME, 'Lint warnings found!')); | ||
} | ||
return cb(null, file); | ||
}, function (cb) { | ||
if (hasError && options.stoponerror ) { | ||
this.emit('error', new PluginError(PLUGIN_NAME, 'Lint errors found!')); | ||
} | ||
if (hasWarning && options.stoponwarning) { | ||
this.emit('warning', new PluginError(PLUGIN_NAME, 'Lint warnings found!')); | ||
} | ||
return cb(); | ||
}); | ||
return cb(); | ||
}); | ||
return stream; | ||
return stream; | ||
} | ||
@@ -154,0 +149,0 @@ |
{ | ||
"name": "gulp-bootlint", | ||
"version": "0.11.0", | ||
"version": "1.0.0", | ||
"description": "A gulp wrapper for Bootlint, the HTML linter for Bootstrap projects", | ||
@@ -13,3 +13,3 @@ "license": "MIT", | ||
"email": "juerg.hunziker@gmail.com", | ||
"url": "http://juerghunziker.ch" | ||
"url": "https://juerghunziker.ch" | ||
}, | ||
@@ -23,3 +23,4 @@ "engines": { | ||
"scripts": { | ||
"pretest": "./node_modules/.bin/eslint *.js test/*.js", | ||
"pretest": "npm run lint", | ||
"lint": "eslint *.js test/*.js", | ||
"test": "mocha" | ||
@@ -41,5 +42,6 @@ }, | ||
"dependencies": { | ||
"ansi-colors": "^3.2.4", | ||
"bootlint": "^0.16.6", | ||
"log": "^1.4.0", | ||
"ansi-colors": "^4.1.1", | ||
"bootlint": "^1.0.0", | ||
"log": "^6.0.0", | ||
"log-node": "^7.0.0", | ||
"merge": "^1.2.1", | ||
@@ -50,4 +52,5 @@ "plugin-error": "^1.0.1", | ||
"devDependencies": { | ||
"eslint": "^6.0.0", | ||
"mocha": "^6.1.4", | ||
"eslint": "^6.7.2", | ||
"eslint-config-gulp": "^3.0.1", | ||
"mocha": "^6.2.2", | ||
"should": "^13.2.3", | ||
@@ -54,0 +57,0 @@ "vinyl": "^2.2.0" |
@@ -29,7 +29,7 @@ # gulp-bootlint | ||
var gulp = require('gulp'); | ||
var bootlint = require('gulp-bootlint'); | ||
var bootlint = require('gulp-bootlint'); | ||
gulp.task('bootlint', function() { | ||
return gulp.src('./index.html') | ||
.pipe(bootlint()); | ||
return gulp.src('./index.html') | ||
.pipe(bootlint()); | ||
}); | ||
@@ -56,10 +56,2 @@ ``` | ||
### 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 | ||
@@ -110,35 +102,50 @@ | ||
var gulp = require('gulp'); | ||
var bootlint = require('gulp-bootlint'); | ||
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); | ||
} | ||
} | ||
})); | ||
gulp.task('bootlint', function () { | ||
var fileIssues = []; | ||
return gulp.src('./index.html') | ||
.pipe(bootlint({ | ||
stoponerror: true, | ||
stoponwarning: true, | ||
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 | ||
## Log level | ||
To set the log level please use the `LOG_LEVEL` environment variable before starting your gulp task: | ||
``` | ||
$ LOG_LEVEL=error npm run gulp | ||
``` | ||
Available log levels are listed here: https://github.com/medikoo/log#available-log-levels | ||
## Changelog | ||
* 2019-12-12 - v1.0.0 | ||
* Updated `bootlint` to v1.0.0 | ||
* Updated `log` package to v6.0.0 | ||
* Dropped `loglevel` option since it's not supported anymore by the new `log` package. | ||
To set the log level please use the `LOG_LEVEL` environment variable before running your gulp task (see: https://github.com/tschortsch/gulp-bootlint#log-level). | ||
* Bumped other dependency versions | ||
* 2019-06-26 - v0.11.0 | ||
@@ -145,0 +152,0 @@ * **Dropped support for Node.js versions <= 7** |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
0
172
13054
7
5
129
+ Addedlog-node@^7.0.0
+ Addedansi-colors@4.1.3(transitive)
+ Addedansi-regex@2.1.13.0.1(transitive)
+ Addedbootlint@1.1.0(transitive)
+ Addedcli-color@1.4.02.0.4(transitive)
+ Addedcli-sprintf-format@1.1.1(transitive)
+ Addedd@1.0.2(transitive)
+ Addedduration@0.2.2(transitive)
+ Addedes5-ext@0.10.64(transitive)
+ Addedes6-iterator@2.0.3(transitive)
+ Addedes6-symbol@3.1.4(transitive)
+ Addedes6-weak-map@2.0.3(transitive)
+ Addedesniff@2.0.1(transitive)
+ Addedevent-emitter@0.3.5(transitive)
+ Addedext@1.7.0(transitive)
+ Addedhas-ansi@3.0.0(transitive)
+ Addedis-promise@2.2.2(transitive)
+ Addedlog@6.3.1(transitive)
+ Addedlog-node@7.0.0(transitive)
+ Addedlru-queue@0.1.0(transitive)
+ Addedmemoizee@0.4.15(transitive)
+ Addednext-tick@1.1.0(transitive)
+ Addedsprintf-kit@2.0.1(transitive)
+ Addedsupports-color@6.1.0(transitive)
+ Addedtimers-ext@0.1.7(transitive)
+ Addedtype@2.7.2(transitive)
+ Addeduni-global@1.0.0(transitive)
- Removedaccepts@1.3.8(transitive)
- Removedansi-colors@3.2.4(transitive)
- Removedarray-flatten@1.1.1(transitive)
- Removedbasic-auth@2.0.1(transitive)
- Removedbody-parser@1.20.2(transitive)
- Removedbootlint@0.16.8(transitive)
- Removedbytes@3.1.2(transitive)
- Removedcall-bind@1.0.7(transitive)
- Removedcontent-disposition@0.5.4(transitive)
- Removedcontent-type@1.0.5(transitive)
- Removedcookie@0.6.0(transitive)
- Removedcookie-signature@1.0.6(transitive)
- Removeddebug@2.6.94.3.4(transitive)
- Removeddefine-data-property@1.1.4(transitive)
- Removeddepd@2.0.0(transitive)
- Removeddestroy@1.2.0(transitive)
- Removedee-first@1.1.1(transitive)
- Removedencodeurl@1.0.2(transitive)
- Removedes-define-property@1.0.0(transitive)
- Removedes-errors@1.3.0(transitive)
- Removedescape-html@1.0.3(transitive)
- Removedetag@1.8.1(transitive)
- Removedexpress@4.19.2(transitive)
- Removedfinalhandler@1.2.0(transitive)
- Removedforwarded@0.2.0(transitive)
- Removedfresh@0.5.2(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedget-intrinsic@1.2.4(transitive)
- Removedgopd@1.0.1(transitive)
- Removedhas-property-descriptors@1.0.2(transitive)
- Removedhas-proto@1.0.3(transitive)
- Removedhas-symbols@1.0.3(transitive)
- Removedhasown@2.0.2(transitive)
- Removedhttp-errors@2.0.0(transitive)
- Removediconv-lite@0.4.24(transitive)
- Removedipaddr.js@1.9.1(transitive)
- Removedlog@1.4.0(transitive)
- Removedmedia-typer@0.3.0(transitive)
- Removedmerge-descriptors@1.0.1(transitive)
- Removedmethods@1.1.2(transitive)
- Removedmime@1.6.0(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removedmorgan@1.10.0(transitive)
- Removedms@2.0.02.1.22.1.3(transitive)
- Removednegotiator@0.6.3(transitive)
- Removedobject-inspect@1.13.1(transitive)
- Removedon-finished@2.3.02.4.1(transitive)
- Removedon-headers@1.0.2(transitive)
- Removedparseurl@1.3.3(transitive)
- Removedpath-to-regexp@0.1.7(transitive)
- Removedproxy-addr@2.0.7(transitive)
- Removedqs@6.11.0(transitive)
- Removedrange-parser@1.2.1(transitive)
- Removedraw-body@2.5.2(transitive)
- Removedsafe-buffer@5.1.2(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedsend@0.18.0(transitive)
- Removedserve-static@1.15.0(transitive)
- Removedset-function-length@1.2.2(transitive)
- Removedsetprototypeof@1.2.0(transitive)
- Removedside-channel@1.0.6(transitive)
- Removedstatuses@2.0.1(transitive)
- Removedtoidentifier@1.0.1(transitive)
- Removedtype-is@1.6.18(transitive)
- Removedunpipe@1.0.0(transitive)
- Removedutils-merge@1.0.1(transitive)
- Removedvary@1.1.2(transitive)
Updatedansi-colors@^4.1.1
Updatedbootlint@^1.0.0
Updatedlog@^6.0.0