@linthtml/gulp-linthtml
Advanced tools
Comparing version 0.6.0 to 0.7.0
# Changelog | ||
## 0.7.0 | ||
* [FEAT] Upgrade to @linthtml/linthtml@0.7.x | ||
## 0.6.0 | ||
@@ -4,0 +8,0 @@ |
97
index.js
@@ -1,13 +0,13 @@ | ||
const { Transform } = require('stream'); | ||
const { Transform } = require("stream"); | ||
// const relative = require('path').relative; | ||
const linthtml = require('@linthtml/linthtml'); | ||
const PluginError = require('plugin-error'); | ||
const fancy = require('fancy-log'); | ||
const chalk = require('chalk'); | ||
const Table = require('table-layout'); | ||
const path = require('path'); | ||
const PLUGIN_NAME = 'gulp-linthtml'; | ||
const linthtml = require("@linthtml/linthtml"); | ||
const PluginError = require("plugin-error"); | ||
const fancy = require("fancy-log"); | ||
const chalk = require("chalk"); | ||
const Table = require("table-layout"); | ||
const path = require("path"); | ||
const PLUGIN_NAME = "gulp-linthtml"; | ||
/** | ||
* @typedef {Object} Issue | ||
* @typedef {Object} Issue | ||
* @property {Number} line | ||
@@ -20,3 +20,3 @@ * @property {Number} column | ||
* @typedef {Object} Report | ||
* @property {String} fileName - File path of the analysed file | ||
* @property {String} fileName - File path of the analysed file | ||
* @property {Issue[]} issues - The issues found during fil analysis | ||
@@ -28,3 +28,3 @@ */ | ||
const column = start.column.toString(); | ||
return `${line.padStart(maxLine, ' ')}:${column.padEnd(maxColumn, ' ')}`; | ||
return `${line.padStart(maxLine, " ")}:${column.padEnd(maxColumn, " ")}`; | ||
} | ||
@@ -34,4 +34,4 @@ | ||
return `${{ | ||
warning: 'yellow warning', | ||
error: 'red error' | ||
warning: "yellow warning", | ||
error: "red error" | ||
}[issue.severity]}`; | ||
@@ -42,4 +42,4 @@ } | ||
if (error.code) { | ||
const ctx = new chalk.Instance({level: 0}); | ||
const [type, code] = error.code.split('-'); | ||
const ctx = new chalk.Instance({ level: 0 }); | ||
const [type, code] = error.code.split("-"); | ||
const error_message = linthtml.messages[`${type}_ERRORS`][code]; | ||
@@ -51,7 +51,6 @@ return error_message(ctx, error.meta); | ||
/** | ||
* Output a report | ||
* | ||
* @param {Report} report | ||
* | ||
* @param {Report} report | ||
*/ | ||
@@ -89,4 +88,4 @@ function lintHTMLreporter(report) { | ||
*/ | ||
function transform (transform, flush) { | ||
if (typeof flush === 'function') { | ||
function transform(transform, flush) { | ||
if (typeof flush === "function") { | ||
return new Transform({ | ||
@@ -113,6 +112,6 @@ objectMode: true, | ||
* @param {(String|GulpLintHTMLOptions)} [options] - Rules to convert | ||
* @returns {Object} converted options | ||
* @returns {Object} converted options | ||
*/ | ||
function convertOptions(options = {}) { | ||
if (typeof options === 'string') { | ||
if (typeof options === "string") { | ||
// basic config path overload: gulpLintHTML('path/to/config.json') | ||
@@ -127,6 +126,6 @@ options = { | ||
/** | ||
* | ||
* @param {(Strint|GulpLintHTMLOptions)} [options] - Configure rules for running LintHTML | ||
* | ||
* @param {(Strint|GulpLintHTMLOptions)} [options] - Configure rules for running LintHTML | ||
* @param {Function} [reporter] - A custom reporter to format LintHTML errors | ||
* | ||
* | ||
* @returns {stream} gulp file stream | ||
@@ -142,3 +141,3 @@ */ | ||
if (file.isStream()) { | ||
return cb(new PluginError(PLUGIN_NAME, 'gulp-linthtml doesn\'t support vinyl files with Stream contents.')); | ||
return cb(new PluginError(PLUGIN_NAME, "gulp-linthtml doesn't support vinyl files with Stream contents.")); | ||
} | ||
@@ -158,3 +157,3 @@ let linter = null; | ||
} | ||
return getLintReport(file, linter, /*options */ cb); | ||
return getLintReport(file, linter, /* options */ cb); | ||
}); | ||
@@ -164,12 +163,13 @@ } | ||
/** | ||
* | ||
* @param {*} file | ||
* @param {*} cb | ||
* | ||
* @param {*} file | ||
* @param {*} cb | ||
*/ | ||
function getLintReport(file, linter, /*options,*/ cb) { | ||
function getLintReport(file, linter, /* options, */ cb) { | ||
try { | ||
let p = linter.lint(file.contents.toString()); | ||
const p = linter.lint(file.contents.toString()); | ||
p.catch(e => cb(new PluginError(PLUGIN_NAME, e))); | ||
p.then(reports => file.linthtml = reports) | ||
.then(() => cb(null, file)); | ||
p.then(reports => { | ||
file.linthtml = reports; | ||
}).then(() => cb(null, file)); | ||
} catch (error) { | ||
@@ -186,4 +186,3 @@ return cb(new PluginError(PLUGIN_NAME, error.message)); | ||
*/ | ||
gulpLintHTML.format = (/*formatter*/) => { | ||
gulpLintHTML.format = (/* formatter */) => { | ||
const results = []; | ||
@@ -202,4 +201,4 @@ results.errorsCount = 0; | ||
const errorsCount = file.linthtml.reduce((count, issue) => issue.severity === 'error' ? count + 1 : count, 0); | ||
const warningsCount = file.linthtml.reduce((count, issue) => issue.severity === 'warning' ? count + 1 : count, 0); | ||
const errorsCount = file.linthtml.reduce((count, issue) => issue.severity === "error" ? count + 1 : count, 0); | ||
const warningsCount = file.linthtml.reduce((count, issue) => issue.severity === "warning" ? count + 1 : count, 0); | ||
results.errorsCount += errorsCount; | ||
@@ -209,19 +208,18 @@ results.warningsCount += warningsCount; | ||
done(null, file); | ||
}, done => { | ||
const { errorsCount, warningsCount } = results; | ||
const problemsCount = errorsCount + warningsCount; | ||
let output = '\n'; | ||
let output = "\n"; | ||
output = results.reduce((out, result) => { | ||
return out += lintHTMLreporter(result); | ||
return out + lintHTMLreporter(result); | ||
}, output); | ||
output += '\n'; | ||
output += "\n"; | ||
if (results.errorCount !== 0) { | ||
output += chalk` {red ✖ ${problemsCount} ${problemsCount > 1 ? 'problems' : 'problem'} (${errorsCount} ${errorsCount > 1 ? 'errors' : 'error'}, ${warningsCount} ${warningsCount > 1 ? 'warnings' : 'warning'})}`; | ||
output += '\n'; | ||
output += chalk` {red ✖ ${problemsCount} ${problemsCount > 1 ? "problems" : "problem"} (${errorsCount} ${errorsCount > 1 ? "errors" : "error"}, ${warningsCount} ${warningsCount > 1 ? "warnings" : "warning"})}`; | ||
output += "\n"; | ||
fancy(output); | ||
} else if (results.warningCount !== 0) { | ||
output += chalk` {yellow ✖ ${problemsCount} ${problemsCount > 1 ? 'problems' : 'problem'} (0 error, ${warningsCount} ${warningsCount > 1 ? 'warnings' : 'warning'})}`; | ||
output += '\n'; | ||
output += chalk` {yellow ✖ ${problemsCount} ${problemsCount > 1 ? "problems" : "problem"} (0 error, ${warningsCount} ${warningsCount > 1 ? "warnings" : "warning"})}`; | ||
output += "\n"; | ||
fancy(output); | ||
@@ -240,7 +238,7 @@ } | ||
return transform((file, enc, done) => { | ||
const errors = file.linthtml.filter(_ => _.severity === 'error'); | ||
const errors = file.linthtml.filter(_ => _.severity === "error"); | ||
if (errors.length > 0) { | ||
const error = errors[0]; | ||
return done(new PluginError(PLUGIN_NAME, { | ||
name: 'LintHTMLError', | ||
name: "LintHTMLError", | ||
fileName: file.path, | ||
@@ -255,3 +253,2 @@ message: linthtml.messages.renderIssue(error), | ||
module.exports = gulpLintHTML; | ||
module.exports = gulpLintHTML; |
{ | ||
"name": "@linthtml/gulp-linthtml", | ||
"version": "0.6.0", | ||
"version": "0.7.0", | ||
"description": "A gulp plugin for processing files with LintHTML", | ||
@@ -27,15 +27,19 @@ "main": "index.js", | ||
"dependencies": { | ||
"@linthtml/linthtml": "0.6.x", | ||
"chalk": "4.1.0", | ||
"fancy-log": "1.3.3", | ||
"plugin-error": "1.0.1", | ||
"table-layout": "1.0.1" | ||
"@linthtml/linthtml": "0.7.x", | ||
"chalk": "^4.1.0", | ||
"fancy-log": "^1.3.3", | ||
"plugin-error": "^1.0.1", | ||
"table-layout": "^1.0.1" | ||
}, | ||
"devDependencies": { | ||
"chai": "4.2.0", | ||
"eslint": "7.17.0", | ||
"from2-string": "1.1.0", | ||
"mocha": "8.2.1", | ||
"vinyl": "2.2.1" | ||
"chai": "^4.3.4", | ||
"eslint": "^7.23.0", | ||
"eslint-config-standard": "^16.0.2", | ||
"eslint-plugin-import": "^2.19.1", | ||
"eslint-plugin-node": "^11.0.0", | ||
"eslint-plugin-promise": "^4.2.1", | ||
"from2-string": "^1.1.0", | ||
"mocha": "^8.3.2", | ||
"vinyl": "^2.2.1" | ||
} | ||
} |
@@ -1,22 +0,23 @@ | ||
/* global describe, it*/ | ||
'use strict'; | ||
/* global describe, it */ | ||
/* eslint-disable no-unused-expressions */ | ||
"use strict"; | ||
const linthtml = require('..'); | ||
const File = require('vinyl'); | ||
const expect = require('chai').expect; | ||
const linthtml = require(".."); | ||
const File = require("vinyl"); | ||
const expect = require("chai").expect; | ||
describe('gulp-linthtml failOnError', () => { | ||
it('should fail a file immediately if an error is found', done => { | ||
const lintStream = linthtml('./test/fixtures/config.json'); | ||
describe("gulp-linthtml failOnError", () => { | ||
it("should fail a file immediately if an error is found", done => { | ||
const lintStream = linthtml("./test/fixtures/config.json"); | ||
function endWithoutError() { | ||
done(new Error('An error was not thrown before ending')); | ||
done(new Error("An error was not thrown before ending")); | ||
} | ||
lintStream.pipe(linthtml.failOnError()) | ||
.on('error', function(err) { | ||
this.removeListener('finish', endWithoutError); | ||
expect(err).to.have.property('message'); | ||
expect(err.message).to.equal('HTML element should specify the language of the page'); | ||
expect(err).to.have.property('lineNumber'); | ||
.on("error", function(err) { | ||
this.removeListener("finish", endWithoutError); | ||
expect(err).to.have.property("message"); | ||
expect(err.message).to.equal("<HTML> tag should specify the language of the page using the \"lang\" attribute"); | ||
expect(err).to.have.property("lineNumber"); | ||
expect(err.lineNumber).to.equal(1); | ||
@@ -26,7 +27,7 @@ | ||
}) | ||
.on('finish', endWithoutError); | ||
.on("finish", endWithoutError); | ||
lintStream.write(new File({ | ||
path: 'test/fixtures/test.html', | ||
contents: Buffer.from('<html></html>') | ||
path: "test/fixtures/test.html", | ||
contents: Buffer.from("<html></html>") | ||
})); | ||
@@ -37,10 +38,10 @@ | ||
it('should not fail a immediately if an issue with level warning is found', done => { | ||
const lintStream = linthtml('./test/fixtures/new_config_format.json'); | ||
it("should not fail a immediately if an issue with level warning is found", done => { | ||
const lintStream = linthtml("./test/fixtures/new_config_format.json"); | ||
lintStream.pipe(linthtml.failOnError()) | ||
.on('error', function() { | ||
done(new Error('Should not fail immediately for warning report')); | ||
.on("error", function() { | ||
done(new Error("Should not fail immediately for warning report")); | ||
}) | ||
.on('data', file => { | ||
.on("data", file => { | ||
expect(file).to.exist; | ||
@@ -52,10 +53,10 @@ expect(file.contents).to.exist; | ||
.and.have.lengthOf(1); | ||
// expect(file.linthtml).to.have.property('filePath', path.resolve('test/fixtures/test.html')); | ||
// expect(file.linthtml[0]).to.have.property('filePath', path.resolve('test/fixtures/test.html')); | ||
const report = file.linthtml[0]; | ||
expect(report).to.have.property('rule'); | ||
expect(report).to.have.property('position'); | ||
expect(report).to.have.property("rule"); | ||
expect(report).to.have.property("position"); | ||
// .and.have.property('ruleId', 'strict'); | ||
@@ -67,4 +68,4 @@ | ||
lintStream.write(new File({ | ||
path: 'test/fixtures/test.html', | ||
contents: Buffer.from('<html></html>') | ||
path: "test/fixtures/test.html", | ||
contents: Buffer.from("<html></html>") | ||
})); | ||
@@ -74,2 +75,2 @@ | ||
}); | ||
}); | ||
}); |
@@ -1,11 +0,12 @@ | ||
/* global describe, it*/ | ||
'use strict'; | ||
/* global describe, it */ | ||
/* eslint-disable no-unused-expressions */ | ||
"use strict"; | ||
const path = require('path'); | ||
const linthtml = require('..'); | ||
const File = require('vinyl'); | ||
const stringToStream = require('from2-string'); | ||
const expect = require('chai').expect; | ||
const path = require("path"); | ||
const linthtml = require(".."); | ||
const File = require("vinyl"); | ||
const stringToStream = require("from2-string"); | ||
const expect = require("chai").expect; | ||
require('mocha'); | ||
require("mocha"); | ||
@@ -40,8 +41,7 @@ const content = ` | ||
describe('gulp-linthtml plugin', () => { | ||
it('should support sharable config', done => { | ||
linthtml('./test/fixtures/config.json') | ||
.on('error', done) | ||
.on('data', file => { | ||
describe("gulp-linthtml plugin", () => { | ||
it("should support sharable config", done => { | ||
linthtml("./test/fixtures/config.json") | ||
.on("error", done) | ||
.on("data", file => { | ||
expect(file).to.exist; | ||
@@ -53,10 +53,10 @@ expect(file.contents).to.exist; | ||
.and.have.lengthOf(1); | ||
// expect(file.linthtml).to.have.property('filePath', path.resolve('test/fixtures/test.html')); | ||
// expect(file.linthtml[0]).to.have.property('filePath', path.resolve('test/fixtures/test.html')); | ||
const report = file.linthtml[0]; | ||
expect(report).to.have.property('rule'); | ||
expect(report).to.have.property('position'); | ||
expect(report).to.have.property("rule"); | ||
expect(report).to.have.property("position"); | ||
// .and.have.property('ruleId', 'strict'); | ||
@@ -67,3 +67,3 @@ | ||
.end(new File({ | ||
path: 'test/fixtures/test.html', | ||
path: "test/fixtures/test.html", | ||
contents: Buffer.from(content) | ||
@@ -73,6 +73,6 @@ })); | ||
it('should support sharable config', done => { | ||
linthtml('./test/fixtures/config.json') | ||
.on('error', done) | ||
.on('data', file => { | ||
it("should support sharable config", done => { | ||
linthtml("./test/fixtures/config.json") | ||
.on("error", done) | ||
.on("data", file => { | ||
expect(file).to.exist; | ||
@@ -84,10 +84,10 @@ expect(file.contents).to.exist; | ||
.and.have.lengthOf(1); | ||
// expect(file.linthtml).to.have.property('filePath', path.resolve('test/fixtures/test.html')); | ||
// expect(file.linthtml[0]).to.have.property('filePath', path.resolve('test/fixtures/test.html')); | ||
const report = file.linthtml[0]; | ||
expect(report).to.have.property('rule'); | ||
expect(report).to.have.property('position'); | ||
expect(report).to.have.property("rule"); | ||
expect(report).to.have.property("position"); | ||
// .and.have.property('ruleId', 'strict'); | ||
@@ -98,3 +98,3 @@ | ||
.end(new File({ | ||
path: 'test/fixtures/test.html', | ||
path: "test/fixtures/test.html", | ||
contents: Buffer.from(content) | ||
@@ -104,6 +104,6 @@ })); | ||
it('should support new config format', done => { | ||
linthtml('./test/fixtures/new_config_format.json') | ||
.on('error', done) | ||
.on('data', file => { | ||
it("should support new config format", done => { | ||
linthtml("./test/fixtures/new_config_format.json") | ||
.on("error", done) | ||
.on("data", file => { | ||
expect(file).to.exist; | ||
@@ -115,10 +115,10 @@ expect(file.contents).to.exist; | ||
.and.have.lengthOf(1); | ||
// expect(file.linthtml).to.have.property('filePath', path.resolve('test/fixtures/test.html')); | ||
// expect(file.linthtml[0]).to.have.property('filePath', path.resolve('test/fixtures/test.html')); | ||
const report = file.linthtml[0]; | ||
expect(report).to.have.property('rule'); | ||
expect(report).to.have.property('position'); | ||
expect(report).to.have.property("rule"); | ||
expect(report).to.have.property("position"); | ||
// .and.have.property('ruleId', 'strict'); | ||
@@ -129,3 +129,3 @@ | ||
.end(new File({ | ||
path: 'test/fixtures/test.html', | ||
path: "test/fixtures/test.html", | ||
contents: Buffer.from(content) | ||
@@ -135,7 +135,6 @@ })); | ||
it('should produce expected message via buffer', done => { | ||
linthtml({rules: { 'html-req-lang': true }}) | ||
.on('error', done) | ||
.on('data', file => { | ||
it("should produce expected message via buffer", done => { | ||
linthtml({ rules: { "html-req-lang": true } }) | ||
.on("error", done) | ||
.on("data", file => { | ||
expect(file).to.exist; | ||
@@ -148,10 +147,10 @@ expect(file.contents).to.exist; | ||
.and.have.lengthOf(1); | ||
// expect(file.linthtml).to.have.property('filePath', path.resolve('test/fixtures/test.html')); | ||
// expect(file.linthtml[0]).to.have.property('filePath', path.resolve('test/fixtures/test.html')); | ||
const report = file.linthtml[0]; | ||
expect(report).to.have.property('rule'); | ||
expect(report).to.have.property('position'); | ||
expect(report).to.have.property("rule"); | ||
expect(report).to.have.property("position"); | ||
// .and.have.property('ruleId', 'strict'); | ||
@@ -162,3 +161,3 @@ | ||
.end(new File({ | ||
path: 'test/fixtures/test.html', | ||
path: "test/fixtures/test.html", | ||
contents: Buffer.from(content) | ||
@@ -168,6 +167,6 @@ })); | ||
it('should ignore files with null content', done => { | ||
linthtml({rules: { 'html-req-lang': true }}) | ||
.on('error', done) | ||
.on('data', file => { | ||
it("should ignore files with null content", done => { | ||
linthtml({ rules: { "html-req-lang": true } }) | ||
.on("error", done) | ||
.on("data", file => { | ||
expect(file).to.exist; | ||
@@ -179,3 +178,3 @@ expect(file.contents).to.not.exist; | ||
.end(new File({ | ||
path: 'test/fixtures', | ||
path: "test/fixtures", | ||
isDirectory: true | ||
@@ -185,24 +184,24 @@ })); | ||
it('should emit an error when it takes a steam content', done => { | ||
it("should emit an error when it takes a steam content", done => { | ||
linthtml() | ||
.on('error', err => { | ||
expect(err.plugin).to.equal('gulp-linthtml'); | ||
expect(err.message).to.equal('gulp-linthtml doesn\'t support vinyl files with Stream contents.'); | ||
.on("error", err => { | ||
expect(err.plugin).to.equal("gulp-linthtml"); | ||
expect(err.message).to.equal("gulp-linthtml doesn't support vinyl files with Stream contents."); | ||
done(); | ||
}) | ||
.end(new File({ | ||
path: 'test/fixtures/text.html', | ||
contents: stringToStream('') | ||
path: "test/fixtures/text.html", | ||
contents: stringToStream("") | ||
})); | ||
}); | ||
it('should emit an error when the config file specified does not exist', (done) => { | ||
linthtml('./test/fixtures/config.js') | ||
.on('error', err => { | ||
expect(err.plugin).to.equal('gulp-linthtml'); | ||
expect(err.message).to.equal(`gulp-linthtml - Error: Cannot find the config file ${path.resolve(__dirname, 'fixtures/config.js')}`); | ||
it("should emit an error when the config file specified does not exist", (done) => { | ||
linthtml("./test/fixtures/config.js") | ||
.on("error", err => { | ||
expect(err.plugin).to.equal("gulp-linthtml"); | ||
expect(err.message).to.equal(`gulp-linthtml - Error: Cannot find the config file ${path.resolve(__dirname, "fixtures/config.js")}`); | ||
done(); | ||
}) | ||
.end(new File({ | ||
path: 'test/fixtures/text.html', | ||
path: "test/fixtures/text.html", | ||
contents: Buffer.from(content) | ||
@@ -212,11 +211,11 @@ })); | ||
it('should emit an error when the config file specified is not valid', (done) => { | ||
linthtml('./test/fixtures/invalid_config.json') | ||
.on('error', err => { | ||
expect(err.plugin).to.equal('gulp-linthtml'); | ||
expect(err.message).to.equal('Configuration for rule "html-req-lang" is invalid: Expected boolean got string.'); | ||
it("should emit an error when the config file specified is not valid", (done) => { | ||
linthtml("./test/fixtures/invalid_config.json") | ||
.on("error", err => { | ||
expect(err.plugin).to.equal("gulp-linthtml"); | ||
expect(err.message).to.equal("Configuration for rule \"html-req-lang\" is invalid: Expected boolean got string."); | ||
done(); | ||
}) | ||
.end(new File({ | ||
path: 'test/fixtures/text.html', | ||
path: "test/fixtures/text.html", | ||
contents: Buffer.from(content) | ||
@@ -226,11 +225,11 @@ })); | ||
it('should report linter errors', (done) => { | ||
linthtml('./test/fixtures/config.json') | ||
.on('error', err => { | ||
expect(err.plugin).to.equal('gulp-linthtml'); | ||
expect(err.message).to.equal('Cannot parse inline configuration.'); | ||
it("should report linter errors", (done) => { | ||
linthtml("./test/fixtures/config.json") | ||
.on("error", err => { | ||
expect(err.plugin).to.equal("gulp-linthtml"); | ||
expect(err.message).to.equal("Cannot parse inline configuration."); | ||
done(); | ||
}) | ||
.end(new File({ | ||
path: 'test/fixtures/text.html', | ||
path: "test/fixtures/text.html", | ||
contents: Buffer.from(invalid_content) | ||
@@ -256,2 +255,2 @@ })); | ||
// }); | ||
}); | ||
}); |
22401
9
489
+ Added@linthtml/linthtml@0.7.2(transitive)
+ Addedchalk@4.1.2(transitive)
+ Addedhtmlparser2@6.1.0(transitive)
+ Addedtable-layout@1.0.2(transitive)
- Removed@linthtml/linthtml@0.6.4(transitive)
- Removeddomhandler@3.3.0(transitive)
- Removedhtmlparser2@5.0.1(transitive)
Updated@linthtml/linthtml@0.7.x
Updatedchalk@^4.1.0
Updatedfancy-log@^1.3.3
Updatedplugin-error@^1.0.1
Updatedtable-layout@^1.0.1