markuplint
Advanced tools
Comparing version 0.3.0 to 0.4.0
@@ -38,4 +38,4 @@ #!/usr/bin/env node | ||
for (const filePath of cli.input) { | ||
const reports = await verifyFile(filePath, cli.flags.ruleset); | ||
await standardReporter(filePath, reports); | ||
const { html, reports } = await verifyFile(filePath, cli.flags.ruleset); | ||
await standardReporter(filePath, reports, html); | ||
} | ||
@@ -59,3 +59,3 @@ console.log(`🎉 markuplint CLI done.`); | ||
const reports = await verify(html, ruleset, rules); | ||
await standardReporter('STDIN_DATA', reports); | ||
await standardReporter('STDIN_DATA', reports, html); | ||
}); | ||
@@ -62,0 +62,0 @@ } |
import Rule, { VerifiedResult } from './rule'; | ||
import { Ruleset } from './ruleset'; | ||
export declare function verify(html: string, ruleset: Ruleset, rules: Rule[]): Promise<VerifiedResult[]>; | ||
export declare function verifyFile(filePath: string, ruleset?: Ruleset, rules?: Rule[]): Promise<VerifiedResult[]>; | ||
export declare function verifyFile(filePath: string, ruleset?: Ruleset, rules?: Rule[]): Promise<{ | ||
html: string; | ||
reports: VerifiedResult[]; | ||
}>; |
@@ -32,5 +32,9 @@ "use strict"; | ||
const html = yield readFile(filePath, 'utf-8'); | ||
return markuplint.verify(html, ruleset, rules); | ||
const reports = markuplint.verify(html, ruleset, rules); | ||
return { | ||
html, | ||
reports, | ||
}; | ||
}); | ||
} | ||
exports.verifyFile = verifyFile; |
import { VerifiedResult } from '../rule'; | ||
export declare function standardReporter(targetPath: string, results: VerifiedResult[]): Promise<void>; | ||
export declare function standardReporter(targetPath: string, results: VerifiedResult[], rawSource: string): Promise<void>; | ||
export declare function simpleReporter(targetPath: string, results: VerifiedResult[], rawSource: string): Promise<void>; |
"use strict"; | ||
// tslint:disable:no-magic-numbers | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -11,15 +12,51 @@ return new (P || (P = Promise))(function (resolve, reject) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function standardReporter(targetPath, results) { | ||
const c = require("cli-color"); | ||
function standardReporter(targetPath, results, rawSource) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const out = []; | ||
const loggerError = c.red; | ||
const loggerWarning = c.xterm(208); | ||
if (results.length) { | ||
console.log(`❌ : ${targetPath} [markuplint]`); | ||
const lines = rawSource.split(/\r?\n/g); | ||
for (const result of results) { | ||
console.warn(`\t${targetPath}:${result.line}:${result.col} ${result.message} [markuplint]`); | ||
const prev = lines[result.line - 2] || ''; | ||
const line = lines[result.line - 1] || ''; | ||
const next = lines[result.line - 0] || ''; | ||
const before = line.substring(0, result.col); | ||
const after = line.substring(result.col + result.raw.length); | ||
const logger = result.level === 'error' ? loggerError : loggerWarning; | ||
out.push(`${logger(`markuplint ${result.level}: ${result.message} [${targetPath}:${result.line}:${result.col}]`)} | ||
${c.cyan(result.line - 1).padStart(5)}: ${space(prev)} | ||
${c.cyan(result.line).padStart(5)}: ${space(before)}${c.bgRed(result.raw)}${space(after)} | ||
${c.cyan(result.line + 1).padStart(5)}: ${space(next)} | ||
`); | ||
} | ||
} | ||
else { | ||
console.log(`✅ : ${targetPath} [markuplint]`); | ||
out.push(`${c.green('markuplint passed')} [${targetPath}]`); | ||
} | ||
process.stdout.write(`${out.join('\n')}\n`); | ||
}); | ||
} | ||
exports.standardReporter = standardReporter; | ||
function simpleReporter(targetPath, results, rawSource) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const out = []; | ||
if (results.length) { | ||
out.push(`❌ : ${targetPath} [markuplint]`); | ||
for (const result of results) { | ||
out.push(`\t${targetPath}:${result.line}:${result.col} ${result.message} [markuplint]`); | ||
} | ||
} | ||
else { | ||
out.push(`✅ : ${targetPath} [markuplint]`); | ||
} | ||
process.stdout.write(`${out.join('\n')}\n`); | ||
}); | ||
} | ||
exports.simpleReporter = simpleReporter; | ||
function space(str) { | ||
return str.replace(/\s+/g, ($0) => { | ||
return c.xterm(8)($0); | ||
}).replace(/ /g, ($0) => `•`).replace(/\t/g, ($0) => `→ `); | ||
} |
{ | ||
"name": "markuplint", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "HTML linter for legacy/modern HTML, Web Components, SVG, MathML, AMP HTML and more.", | ||
"main": "lib/index.js", | ||
"types": "lib/index.d.ts", | ||
"bin": { | ||
@@ -23,2 +24,3 @@ "markuplint": "bin/index.js" | ||
"dependencies": { | ||
"cli-color": "^1.2.0", | ||
"meow": "^4.0.0", | ||
@@ -28,2 +30,3 @@ "parse5": "^3.0.3" | ||
"devDependencies": { | ||
"@types/cli-color": "^0.3.29", | ||
"@types/meow": "^3.6.2", | ||
@@ -30,0 +33,0 @@ "ava": "^0.24.0", |
58325
1663
3
12
+ Addedcli-color@^1.2.0
+ Addedansi-regex@2.1.1(transitive)
+ Addedcli-color@1.4.0(transitive)
+ Addedd@1.0.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)
+ Addedis-promise@2.2.2(transitive)
+ Addedlru-queue@0.1.0(transitive)
+ Addedmemoizee@0.4.17(transitive)
+ Addednext-tick@1.1.0(transitive)
+ Addedtimers-ext@0.1.8(transitive)
+ Addedtype@2.7.3(transitive)