...
 
Commits (7)
# html-validate changelog
## [1.7.1](https://gitlab.com/html-validate/html-validate/compare/v1.7.0...v1.7.1) (2019-09-15)
### Bug Fixes
- **config:** better error message when transformer fails to load ([c5a4f38](https://gitlab.com/html-validate/html-validate/commit/c5a4f38))
# [1.7.0](https://gitlab.com/html-validate/html-validate/compare/v1.6.0...v1.7.0) (2019-09-11)
### Bug Fixes
......
{
"name": "html-validate",
"version": "1.7.0",
"version": "1.7.1",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
......@@ -4446,9 +4446,9 @@
},
"dependencies": {
"anymatch": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.0.3.tgz",
"integrity": "sha512-c6IvoeBECQlMVuYUjSwimnhmztImpErfxJzWZhIQinIvQWoGOnB0dLIgifbPHQt5heS6mNlaZG16f06H3C8t1g==",
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.0.tgz",
"integrity": "sha512-Ozz7l4ixzI7Oxj2+cw+p0tVUt27BpaJ+1+q1TCeANWxHpvyn2+Un+YamBdfKu0uh8xLodGhoa1v7595NhKDAuA==",
"dev": true,
"requires": {
"normalize-path": "^3.0.0",
......@@ -19597,9 +19597,9 @@
}
},
"sass": {
"version": "1.22.10",
"resolved": "https://registry.npmjs.org/sass/-/sass-1.22.10.tgz",
"integrity": "sha512-DUpS1tVMGCH6gr/N9cXCoemrjoNdOLhAHfQ37fJw2A5ZM4gSI9ej/8Xi95Xwus03RqZ2zdSnKZGULL7oS+jfMA==",
"version": "1.22.12",
"resolved": "https://registry.npmjs.org/sass/-/sass-1.22.12.tgz",
"integrity": "sha512-u5Rxn+dKTPCW5/11kMNxtmqKsxCjcpnqj9CaJoru1NqeJ0DOa9rOM00e0HqmseTAatGkKoLY+jaNecMYevu1gg==",
"dev": true,
"requires": {
"chokidar": ">=2.0.0 <4.0.0"
......@@ -21207,15 +21207,16 @@
"dev": true
},
"ts-jest": {
"version": "24.0.2",
"resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-24.0.2.tgz",
"integrity": "sha512-h6ZCZiA1EQgjczxq+uGLXQlNgeg02WWJBbeT8j6nyIBRQdglqbvzDoHahTEIiS6Eor6x8mK6PfZ7brQ9Q6tzHw==",
"version": "24.1.0",
"resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-24.1.0.tgz",
"integrity": "sha512-HEGfrIEAZKfu1pkaxB9au17b1d9b56YZSqz5eCVE8mX68+5reOvlM93xGOzzCREIov9mdH7JBG+s0UyNAqr0tQ==",
"dev": true,
"requires": {
"bs-logger": "0.x",
"buffer-from": "1.x",
"fast-json-stable-stringify": "2.x",
"json5": "2.x",
"lodash.memoize": "4.x",
"make-error": "1.x",
"mkdirp": "0.x",
"resolve": "1.x",
......@@ -21340,9 +21341,9 @@
"dev": true
},
"typescript": {
"version": "3.6.2",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.6.2.tgz",
"integrity": "sha512-lmQ4L+J6mnu3xweP8+rOrUwzmN+MRAj7TgtJtDaXE5PMyX2kCrklhg3rvOsOIfNeAWMQWO2F1GPc1kMD2vLAfw==",
"version": "3.6.3",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.6.3.tgz",
"integrity": "sha512-N7bceJL1CtRQ2RiG0AQME13ksR7DiuQh/QehubYcghzv20tnh+MQnQIuJddTmsbqYj+dztchykemz0zFzlvdQw==",
"dev": true
},
"uglify-js": {
......
{
"name": "html-validate",
"version": "1.7.0",
"version": "1.7.1",
"description": "html linter",
"keywords": [
"html",
......@@ -155,14 +155,14 @@
"lint-staged": "9.2.5",
"load-grunt-tasks": "5.1.0",
"prettier": "1.18.2",
"sass": "1.22.10",
"sass": "1.22.12",
"semantic-release": "15.13.24",
"serve-static": "1.14.1",
"strip-ansi": "5.2.0",
"ts-jest": "24.0.2",
"ts-jest": "24.1.0",
"tslint": "5.20.0",
"tslint-config-prettier": "1.18.0",
"typescript": "3.6.2"
"typescript": "3.6.3"
},
"jest": {
"collectCoverage": true,
......
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`config transform() should throw sane error when transformer fails 1`] = `"When transforming \\"/path/to/test.foo\\": Failed to frobnicate a baz"`;
exports[`config transform() should throw sane error when transformer fails 1`] = `"When transforming \\"/path/to/test.foo\\": Failed to frobnicate a baz"`;
exports[`config transform() should throw sane error when transformer fails to load 1`] = `"Failed to load transformer \\"missing-transformer\\""`;
......@@ -381,7 +381,7 @@ describe("config", () => {
]);
});
it("should throw sane error when transformer fails ", () => {
it("should throw sane error when transformer fails", () => {
const config = Config.fromObject({
transform: {
"^.*\\.foo$":
......@@ -393,6 +393,16 @@ describe("config", () => {
config.transform("/path/to/test.foo")
).toThrowErrorMatchingSnapshot();
});
it("should throw sane error when transformer fails to load", () => {
const config = Config.fromObject({
transform: {
"^.*\\.foo$":
"missing-transformer" /* mocked transformer, see top of file */,
},
});
expect(() => config.init()).toThrowErrorMatchingSnapshot();
});
});
describe("init()", () => {
......
......@@ -2,13 +2,13 @@ import deepmerge from "deepmerge";
import fs from "fs";
import path from "path";
import { Source } from "../context";
import { NestedError } from "../error/nested-error";
import { UserError } from "../error/user-error";
import { NestedError } from "../error";
import { MetaTable } from "../meta";
import { MetaDataTable } from "../meta/element";
import { Plugin } from "../plugin";
import { ConfigData, TransformMap } from "./config-data";
import defaultConfig from "./default";
import { ConfigError } from "./error";
import { parseSeverity, Severity } from "./severity";
interface Transformer {
......@@ -43,7 +43,10 @@ function loadFromFile(filename: string): ConfigData {
// eslint-disable-next-line security/detect-non-literal-require
json = require(filename);
} catch (err) {
throw new UserError(`Failed to read configuration from "${filename}"`, err);
throw new ConfigError(
`Failed to read configuration from "${filename}"`,
err
);
}
/* expand any relative paths */
......@@ -337,13 +340,17 @@ export class Config {
private precompileTransformers(transform: TransformMap): Transformer[] {
return Object.entries(transform).map(([pattern, module]) => {
return {
// eslint-disable-next-line security/detect-non-literal-regexp
pattern: new RegExp(pattern),
try {
return {
// eslint-disable-next-line security/detect-non-literal-regexp
pattern: new RegExp(pattern),
// eslint-disable-next-line security/detect-non-literal-require
fn: require(module.replace("<rootDir>", this.rootDir)),
};
// eslint-disable-next-line security/detect-non-literal-require
fn: require(module.replace("<rootDir>", this.rootDir)),
};
} catch (err) {
throw new ConfigError(`Failed to load transformer "${module}"`, err);
}
});
}
......
import { UserError } from "../error";
export class ConfigError extends UserError {}
export { UserError } from "./user-error";
export { NestedError } from "./nested-error";
......@@ -25,6 +25,11 @@ describe("rule no-deprecated-attr", () => {
});
it("should not report when regular element has no deprecated attributes", () => {
/* use custom meta as html5 has global deprecations */
const htmlvalidate = new HtmlValidate({
elements: [{ abbr: {} }],
rules: { "no-deprecated-attr": "error" },
});
const report = htmlvalidate.validateString(
'<abbr style="background: red;"></abbr>'
);
......