@linthtml/gulp-linthtml
Advanced tools
Comparing version 0.4.0 to 0.5.0
module.exports = { | ||
"env": { | ||
"es6": true, | ||
"node": true | ||
'env': { | ||
'es6': true, | ||
'node': true | ||
}, | ||
"extends": "eslint:recommended", | ||
"globals": { | ||
"Atomics": "readonly", | ||
"SharedArrayBuffer": "readonly" | ||
'extends': 'eslint:recommended', | ||
'globals': { | ||
'Atomics': 'readonly', | ||
'SharedArrayBuffer': 'readonly' | ||
}, | ||
"parserOptions": { | ||
"ecmaVersion": 2018 | ||
'parserOptions': { | ||
'ecmaVersion': 2018 | ||
}, | ||
"rules": { | ||
"indent": [ | ||
"error", | ||
'rules': { | ||
'indent': [ | ||
'error', | ||
2 | ||
], | ||
"linebreak-style": [ | ||
"error", | ||
"unix" | ||
'linebreak-style': [ | ||
'error', | ||
'unix' | ||
], | ||
"quotes": [ | ||
"error", | ||
"single" | ||
'quotes': [ | ||
'error', | ||
'single' | ||
], | ||
"semi": [ | ||
"error", | ||
"always" | ||
'semi': [ | ||
'error', | ||
'always' | ||
] | ||
} | ||
}; |
# Changelog | ||
## 0.5.0 | ||
* [FEAT] Upgrade to @linthtml/linthtml@0.5.x | ||
## 0.4.0 | ||
@@ -4,0 +8,0 @@ |
82
index.js
@@ -7,7 +7,4 @@ const { Transform } = require('stream'); | ||
const chalk = require('chalk'); | ||
const { cosmiconfigSync } = require('cosmiconfig'); | ||
const Table = require('table-layout'); | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const Table = require('table-layout'); | ||
const PLUGIN_NAME = 'gulp-linthtml'; | ||
@@ -28,5 +25,5 @@ | ||
function printPosition(issue, maxLine, maxColumn) { | ||
const line = issue.line.toString(); | ||
const column = issue.column.toString(); | ||
function print_position({ position: { start } }, maxLine, maxColumn) { | ||
const line = start.line.toString(); | ||
const column = start.column.toString(); | ||
return `${line.padStart(maxLine, ' ')}:${column.padEnd(maxColumn, ' ')}`; | ||
@@ -42,2 +39,13 @@ } | ||
function print_error(error) { | ||
if (error.code) { | ||
const ctx = new chalk.Instance({level: 0}); | ||
const [type, code] = error.code.split('-'); | ||
const error_message = linthtml.messages[`${type}_ERRORS`][code]; | ||
return error_message(ctx, error.meta); | ||
} | ||
return error.message; | ||
} | ||
/** | ||
@@ -57,3 +65,3 @@ * Output a report | ||
const msg = linthtml.messages.renderIssue(issue); | ||
const positionTxt = printPosition(issue, maxLine, maxColumn); | ||
const positionTxt = print_position(issue, maxLine, maxColumn); | ||
const level = printLevel(issue); | ||
@@ -102,3 +110,3 @@ issues.push({ | ||
/** | ||
* @param {(Strint|GulpLintHTMLOptions)} [options] - Rules to convert | ||
* @param {(String|GulpLintHTMLOptions)} [options] - Rules to convert | ||
* @returns {Object} converted options | ||
@@ -124,38 +132,4 @@ */ | ||
function gulpLintHTML(options) { | ||
const explorer = cosmiconfigSync('linthtml', { stopDir: process.cwd(), packageProp: 'linthtmlConfig'}); | ||
options = convertOptions(options); | ||
return transform((file, enc, cb) => { | ||
let config = null; | ||
if (options.configFile) { | ||
const configPath = path.join(process.cwd(), options.configFile); | ||
let isConfigDirectory = false; | ||
try { | ||
isConfigDirectory = fs.lstatSync(configPath).isDirectory(); | ||
if (isConfigDirectory) { | ||
config = cosmiconfigSync('linthtml', { stopDir: configPath, packageProp: 'linthtmlConfig' }).search(configPath); | ||
} else { | ||
config = explorer.load(configPath); | ||
} | ||
if (config === null) { | ||
throw new Error(); | ||
} | ||
} catch (error) { | ||
if (isConfigDirectory) { | ||
return cb(new PluginError(PLUGIN_NAME, `gulp-linthtml cannot read config file in directory '${configPath}'`)); | ||
} else { | ||
return cb(new PluginError(PLUGIN_NAME, `gulp-linthtml cannot read config file '${configPath}'`)); | ||
} | ||
} | ||
} | ||
if (config === undefined || config === null) { | ||
config = explorer.search(); | ||
} | ||
if (config) { | ||
options.rules = config.config? config.config : config; | ||
} | ||
if (file.isNull()) { | ||
@@ -168,3 +142,16 @@ return cb(null, file); | ||
} | ||
getLintReport(file, options, cb); | ||
let linter = null; | ||
try { | ||
if (options.configFile) { | ||
linter = linthtml.from_config_path(options.configFile); | ||
} else if (options.rules) { | ||
linter = linthtml.fromConfig(options); | ||
} else { | ||
linter = linthtml.create_linters_for_files([path.relative(process.cwd(), file.path)]); | ||
linter = linter[0] ? linter[0].linter : null; | ||
} | ||
} catch (error) { | ||
return cb(new PluginError(PLUGIN_NAME, `gulp-linthtml - ${print_error(error)}`)); | ||
} | ||
return getLintReport(file, linter, /*options */ cb); | ||
}); | ||
@@ -178,7 +165,6 @@ } | ||
*/ | ||
function getLintReport(file, options, cb) { | ||
function getLintReport(file, linter, /*options,*/ cb) { | ||
try { | ||
let p = linthtml(file.contents.toString(), options.rules); | ||
let p = linter.lint(file.contents.toString()); | ||
p.catch(e => cb(new PluginError(PLUGIN_NAME, e))); | ||
p.then(reports => file.linthtml = reports) | ||
@@ -255,3 +241,3 @@ .then(() => cb(null, file)); | ||
message: linthtml.messages.renderIssue(error), | ||
lineNumber: error.line | ||
lineNumber: error.position.start.line | ||
})); | ||
@@ -258,0 +244,0 @@ } |
{ | ||
"name": "@linthtml/gulp-linthtml", | ||
"version": "0.4.0", | ||
"version": "0.5.0", | ||
"description": "A gulp plugin for processing files with LintHTML", | ||
@@ -27,5 +27,4 @@ "main": "index.js", | ||
"dependencies": { | ||
"@linthtml/linthtml": "0.4.x", | ||
"chalk": "3.0.0", | ||
"cosmiconfig": "^6.0.0", | ||
"@linthtml/linthtml": "0.5.x", | ||
"chalk": "4.1.0", | ||
"fancy-log": "1.3.3", | ||
@@ -37,7 +36,7 @@ "plugin-error": "1.0.1", | ||
"chai": "4.2.0", | ||
"eslint": "6.8.0", | ||
"eslint": "7.9.0", | ||
"from2-string": "1.1.0", | ||
"mocha": "8.0.1", | ||
"mocha": "8.1.3", | ||
"vinyl": "2.2.0" | ||
} | ||
} |
@@ -57,4 +57,3 @@ /* global describe, it*/ | ||
expect(report).to.have.property('rule'); | ||
expect(report).to.have.property('line'); | ||
expect(report).to.have.property('column'); | ||
expect(report).to.have.property('position'); | ||
// .and.have.property('ruleId', 'strict'); | ||
@@ -61,0 +60,0 @@ |
@@ -59,4 +59,3 @@ /* global describe, it*/ | ||
expect(report).to.have.property('rule'); | ||
expect(report).to.have.property('line'); | ||
expect(report).to.have.property('column'); | ||
expect(report).to.have.property('position'); | ||
// .and.have.property('ruleId', 'strict'); | ||
@@ -89,4 +88,3 @@ | ||
expect(report).to.have.property('rule'); | ||
expect(report).to.have.property('line'); | ||
expect(report).to.have.property('column'); | ||
expect(report).to.have.property('position'); | ||
// .and.have.property('ruleId', 'strict'); | ||
@@ -119,4 +117,3 @@ | ||
expect(report).to.have.property('rule'); | ||
expect(report).to.have.property('line'); | ||
expect(report).to.have.property('column'); | ||
expect(report).to.have.property('position'); | ||
// .and.have.property('ruleId', 'strict'); | ||
@@ -151,4 +148,3 @@ | ||
expect(report).to.have.property('rule'); | ||
expect(report).to.have.property('line'); | ||
expect(report).to.have.property('column'); | ||
expect(report).to.have.property('position'); | ||
// .and.have.property('ruleId', 'strict'); | ||
@@ -196,3 +192,3 @@ | ||
expect(err.plugin).to.equal('gulp-linthtml'); | ||
expect(err.message).to.equal(`gulp-linthtml cannot read config file '${path.resolve(__dirname, 'fixtures/config.js')}'`); | ||
expect(err.message).to.equal(`gulp-linthtml - Error: Cannot find the config file ${path.resolve(__dirname, 'fixtures/config.js')}`); | ||
done(); | ||
@@ -210,3 +206,3 @@ }) | ||
expect(err.plugin).to.equal('gulp-linthtml'); | ||
expect(err.message).to.equal('Configuration for rule "html-req-lang" is invalid: Expected boolean got string'); | ||
expect(err.message).to.equal('Configuration for rule "html-req-lang" is invalid: Expected boolean got string.'); | ||
done(); | ||
@@ -213,0 +209,0 @@ }) |
Sorry, the diff of this file is not supported yet
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
5
1
21949
514
+ Added@linthtml/linthtml@0.5.2(transitive)
+ Addedchalk@4.1.0(transitive)
+ Addeddom-serializer@1.4.1(transitive)
+ Addeddomhandler@3.3.04.3.1(transitive)
+ Addeddomutils@2.8.0(transitive)
+ Addedglobby@11.0.1(transitive)
+ Addedhtmlparser2@4.1.0(transitive)
+ Addedis-unicode-supported@0.1.0(transitive)
+ Addedlog-symbols@4.1.0(transitive)
+ Addedmeow@7.1.1(transitive)
+ Addedora@5.1.0(transitive)
+ Addedtype-fest@0.13.1(transitive)
- Removedcosmiconfig@^6.0.0
- Removed@linthtml/linthtml@0.4.2(transitive)
- Removed@types/glob@7.2.0(transitive)
- Removed@types/minimatch@5.1.2(transitive)
- Removed@types/node@22.13.1(transitive)
- Removedansi-styles@3.2.1(transitive)
- Removedchalk@2.4.23.0.04.1.2(transitive)
- Removedcolor-convert@1.9.3(transitive)
- Removedcolor-name@1.1.3(transitive)
- Removeddom-serializer@0.2.2(transitive)
- Removeddomelementtype@1.3.1(transitive)
- Removeddomhandler@2.4.2(transitive)
- Removeddomutils@1.7.0(transitive)
- Removedentities@1.1.2(transitive)
- Removedglobby@10.0.1(transitive)
- Removedhas-flag@3.0.0(transitive)
- Removedhtmlparser2@3.10.1(transitive)
- Removedlodash._reinterpolate@3.0.0(transitive)
- Removedlodash.template@4.5.0(transitive)
- Removedlodash.templatesettings@4.2.0(transitive)
- Removedlog-symbols@3.0.0(transitive)
- Removedmeow@6.1.0(transitive)
- Removedora@4.0.4(transitive)
- Removedreadable-stream@3.6.2(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedstring_decoder@1.3.0(transitive)
- Removedsupports-color@5.5.0(transitive)
- Removedundici-types@6.20.0(transitive)
- Removedutil-deprecate@1.0.2(transitive)
Updated@linthtml/linthtml@0.5.x
Updatedchalk@4.1.0