...
 
Commits (10)
# html-validate changelog
## [2.0.1](https://gitlab.com/html-validate/html-validate/compare/v2.0.0...v2.0.1) (2019-11-19)
### Bug Fixes
- **config:** better error when loading missing transformer from plugin ([db48a01](https://gitlab.com/html-validate/html-validate/commit/db48a015888a18dc2f6a17fd8466a98d29882509))
- **config:** fix loading non-plugin transformer with plugin present ([c9ad080](https://gitlab.com/html-validate/html-validate/commit/c9ad08087305a4c36821a66552d4b7389fc42e86)), closes [#54](https://gitlab.com/html-validate/html-validate/issues/54)
# [2.0.0](https://gitlab.com/html-validate/html-validate/compare/v1.16.0...v2.0.0) (2019-11-17)
### Features
......
This diff is collapsed.
{
"name": "html-validate",
"version": "2.0.0",
"version": "2.0.1",
"description": "html linter",
"keywords": [
"html",
......@@ -85,7 +85,19 @@
},
"release": {
"plugins": [
"@semantic-release/commit-analyzer",
[
"@semantic-release/commit-analyzer",
{
"preset": "angular",
"releaseRules": [
{
"type": "chore",
"scope": "deps",
"release": "patch"
}
]
}
],
"@semantic-release/release-notes-generator",
"@semantic-release/npm",
"@semantic-release/gitlab",
......@@ -133,7 +145,7 @@
"@semantic-release/git": "7.0.18",
"@semantic-release/gitlab": "4.0.4",
"@semantic-release/npm": "5.3.4",
"@semantic-release/release-notes-generator": "7.3.2",
"@semantic-release/release-notes-generator": "7.3.3",
"@types/babel__code-frame": "7.0.1",
"@types/estree": "0.0.39",
"@types/glob": "7.1.1",
......@@ -142,8 +154,8 @@
"@types/json-merge-patch": "0.0.4",
"@types/minimist": "1.2.0",
"@types/node": "11.15.2",
"@typescript-eslint/eslint-plugin": "2.7.0",
"@typescript-eslint/parser": "2.7.0",
"@typescript-eslint/eslint-plugin": "2.8.0",
"@typescript-eslint/parser": "2.8.0",
"autoprefixer": "9.7.1",
"babelify": "10.0.0",
"bootstrap-sass": "3.4.1",
......@@ -151,7 +163,7 @@
"cssnano": "4.1.10",
"dgeni": "0.4.12",
"dgeni-packages": "0.28.1",
"eslint-config-prettier": "6.5.0",
"eslint-config-prettier": "6.6.0",
"eslint-config-sidvind": "1.3.2",
"eslint-plugin-array-func": "3.1.3",
"eslint-plugin-import": "2.18.2",
......@@ -169,7 +181,7 @@
"grunt-postcss": "0.9.0",
"grunt-sass": "3.1.0",
"highlight.js": "9.16.2",
"husky": "3.0.9",
"husky": "3.1.0",
"jest": "24.9.0",
"jest-diff": "24.9.0",
"jest-junit": "9.0.0",
......@@ -179,7 +191,7 @@
"minimatch": "3.0.4",
"prettier": "1.19.1",
"sass": "1.23.6",
"semantic-release": "15.13.30",
"semantic-release": "15.13.31",
"serve-static": "1.14.1",
"strip-ansi": "5.2.0",
"ts-jest": "24.1.0",
......
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`config transformSource() should throw error when trying to load named transform from plugin without any 1`] = `"Failed to load transformer \\"mock-plugin-notransform:named\\": Plugin does not expose any transformer"`;
exports[`config transformSource() should throw error when trying to load unnamed transform from plugin without any 1`] = `"Failed to load transformer \\"mock-plugin-notransform\\": Plugin does not expose any transformer"`;
exports[`config transformSource() should throw sane error when transformer fails 1`] = `"When transforming \\"/path/to/test.foo\\": Failed to frobnicate a baz"`;
exports[`config transformSource() should throw sane error when transformer fails to load 1`] = `"Failed to load transformer \\"missing-transformer\\""`;
......@@ -2,6 +2,7 @@ import fs from "fs";
import path from "path";
import { Source } from "../context";
import { UserError } from "../error/user-error";
import { Transformer, TRANSFORMER_API } from "../transform";
import { Config } from "./config";
import { Severity } from "./severity";
......@@ -349,6 +350,92 @@ describe("config", () => {
`);
});
describe("should handle transformers from plugins", () => {
let config: Config;
beforeEach(() => {
function transform(source: Source): Source[] {
return [
Object.assign(source, {
data: `transformed from ${source.filename}`,
}),
];
}
transform.api = TRANSFORMER_API.VERSION;
jest.mock(
"mock-plugin-unnamed",
() => ({
transformer: transform as Transformer,
}),
{ virtual: true }
);
jest.mock(
"mock-plugin-named",
() => ({
transformer: {
foobar: transform as Transformer,
},
}),
{ virtual: true }
);
config = Config.fromObject({
plugins: ["mock-plugin-unnamed", "mock-plugin-named"],
transform: {
"\\.unnamed$": "mock-plugin-unnamed",
"\\.named$": "mock-plugin-named:foobar",
"\\.nonplugin$": "mock-transform",
},
});
config.init();
});
it("unnamed", () => {
expect.assertions(1);
source.filename = "foo.unnamed";
expect(config.transformSource(source)).toMatchInlineSnapshot(`
Array [
Object {
"column": 3,
"data": "transformed from foo.unnamed",
"filename": "foo.unnamed",
"line": 2,
},
]
`);
});
it("named", () => {
expect.assertions(1);
source.filename = "bar.named";
expect(config.transformSource(source)).toMatchInlineSnapshot(`
Array [
Object {
"column": 3,
"data": "transformed from bar.named",
"filename": "bar.named",
"line": 2,
},
]
`);
});
it("non-plugin (regression test issue 54)", () => {
expect.assertions(1);
source.filename = "bar.nonplugin";
expect(config.transformSource(source)).toMatchInlineSnapshot(`
Array [
Object {
"column": 1,
"data": "transformed source (was: original data)",
"filename": "bar.nonplugin",
"line": 1,
"originalData": "original data",
},
]
`);
});
});
it("should throw error if transformer uses obsolete API", () => {
const config = Config.fromObject({
transform: {
......@@ -442,6 +529,28 @@ describe("config", () => {
});
expect(() => config.init()).toThrowErrorMatchingSnapshot();
});
it("should throw error when trying to load unnamed transform from plugin without any", () => {
jest.mock("mock-plugin-notransform", () => ({}), { virtual: true });
const config = Config.fromObject({
plugins: ["mock-plugin-notransform"],
transform: {
"^.*\\.foo$": "mock-plugin-notransform",
},
});
expect(() => config.init()).toThrowErrorMatchingSnapshot();
});
it("should throw error when trying to load named transform from plugin without any", () => {
jest.mock("mock-plugin-notransform", () => ({}), { virtual: true });
const config = Config.fromObject({
plugins: ["mock-plugin-notransform"],
transform: {
"^.*\\.foo$": "mock-plugin-notransform:named",
},
});
expect(() => config.init()).toThrowErrorMatchingSnapshot();
});
});
describe("transformFilename()", () => {
......
......@@ -425,6 +425,9 @@ export class Config {
if (match) {
const [, pluginName, key] = match;
const plugin = this.plugins.find(cur => cur.name === pluginName);
if (!plugin.transformer) {
throw new ConfigError(`Plugin does not expose any transformer`);
}
if (typeof plugin.transformer === "function") {
throw new ConfigError(
`Transformer "${name}" refers to named transformer but plugin exposes only unnamed, use "${pluginName}" instead.`
......@@ -439,8 +442,11 @@ export class Config {
}
/* try to match an unnamed transformer from plugin */
const plugin = this.plugins.find(cur => (cur.name = name));
const plugin = this.plugins.find(cur => cur.name === name);
if (plugin) {
if (!plugin.transformer) {
throw new ConfigError(`Plugin does not expose any transformer`);
}
if (typeof plugin.transformer !== "function") {
throw new ConfigError(
`Transformer "${name}" refers to unnamed transformer but plugin exposes only named.`
......
......@@ -73,7 +73,7 @@ export interface Plugin {
* "^.*\\.foo$": "my-plugin:foobar"
* }
*/
transformer: Transformer | Record<string, Transformer>;
transformer?: Transformer | Record<string, Transformer>;
/**
* Extend metadata validation schema.
......