Socket
Socket
Sign inDemoInstall

gulp-bootlint

Package Overview
Dependencies
86
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

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**

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc