html-validate 7.16.0 → 7.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/core.js +86 -73
- package/dist/cjs/core.js.map +1 -1
- package/dist/cjs/tsdoc-metadata.json +1 -1
- package/dist/es/core.js +86 -73
- package/dist/es/core.js.map +1 -1
- package/dist/schema/config.json +1 -1
- package/dist/tsdoc-metadata.json +1 -1
- package/dist/types/browser.d.ts +3 -10
- package/dist/types/index.d.ts +3 -10
- package/package.json +9 -9
package/dist/cjs/core.js
CHANGED
|
@@ -1863,28 +1863,6 @@ function cyrb53(str) {
|
|
|
1863
1863
|
}
|
|
1864
1864
|
const computeHash = cyrb53;
|
|
1865
1865
|
|
|
1866
|
-
const legacyRequire = require;
|
|
1867
|
-
|
|
1868
|
-
/**
|
|
1869
|
-
* Similar to `require(..)` but removes the cached copy first.
|
|
1870
|
-
*/
|
|
1871
|
-
function requireUncached(moduleId) {
|
|
1872
|
-
const filename = legacyRequire.resolve(moduleId);
|
|
1873
|
-
/* remove references from the parent module to prevent memory leak */
|
|
1874
|
-
const m = legacyRequire.cache[filename];
|
|
1875
|
-
if (m && m.parent) {
|
|
1876
|
-
const { parent } = m;
|
|
1877
|
-
for (let i = parent.children.length - 1; i >= 0; i--) {
|
|
1878
|
-
if (parent.children[i].id === filename) {
|
|
1879
|
-
parent.children.splice(i, 1);
|
|
1880
|
-
}
|
|
1881
|
-
}
|
|
1882
|
-
}
|
|
1883
|
-
/* remove old module from cache */
|
|
1884
|
-
delete legacyRequire.cache[filename];
|
|
1885
|
-
return legacyRequire(filename);
|
|
1886
|
-
}
|
|
1887
|
-
|
|
1888
1866
|
const $schema$1 = "http://json-schema.org/draft-06/schema#";
|
|
1889
1867
|
const $id$1 = "https://html-validate.org/schemas/elements.json";
|
|
1890
1868
|
const type$1 = "object";
|
|
@@ -2534,29 +2512,18 @@ class MetaTable {
|
|
|
2534
2512
|
*/
|
|
2535
2513
|
loadFromObject(obj, filename = null) {
|
|
2536
2514
|
var _a;
|
|
2537
|
-
const validate = this.getSchemaValidator();
|
|
2538
|
-
if (!validate(obj)) {
|
|
2539
|
-
throw new SchemaValidationError(filename, `Element metadata is not valid`, obj, this.schema,
|
|
2540
|
-
/* istanbul ignore next: AJV sets .errors when validate returns false */
|
|
2541
|
-
(_a = validate.errors) !== null && _a !== void 0 ? _a : []);
|
|
2542
|
-
}
|
|
2543
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
2544
|
-
if (key === "$schema")
|
|
2545
|
-
continue;
|
|
2546
|
-
this.addEntry(key, migrateElement(value));
|
|
2547
|
-
}
|
|
2548
|
-
}
|
|
2549
|
-
/**
|
|
2550
|
-
* Load metadata table from filename
|
|
2551
|
-
*
|
|
2552
|
-
* @public
|
|
2553
|
-
* @param filename - Filename to load
|
|
2554
|
-
*/
|
|
2555
|
-
loadFromFile(filename) {
|
|
2556
2515
|
try {
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2516
|
+
const validate = this.getSchemaValidator();
|
|
2517
|
+
if (!validate(obj)) {
|
|
2518
|
+
throw new SchemaValidationError(filename, `Element metadata is not valid`, obj, this.schema,
|
|
2519
|
+
/* istanbul ignore next: AJV sets .errors when validate returns false */
|
|
2520
|
+
(_a = validate.errors) !== null && _a !== void 0 ? _a : []);
|
|
2521
|
+
}
|
|
2522
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
2523
|
+
if (key === "$schema")
|
|
2524
|
+
continue;
|
|
2525
|
+
this.addEntry(key, migrateElement(value));
|
|
2526
|
+
}
|
|
2560
2527
|
}
|
|
2561
2528
|
catch (err) {
|
|
2562
2529
|
if (err instanceof InheritError) {
|
|
@@ -2566,6 +2533,9 @@ class MetaTable {
|
|
|
2566
2533
|
if (err instanceof SchemaValidationError) {
|
|
2567
2534
|
throw err;
|
|
2568
2535
|
}
|
|
2536
|
+
if (!filename) {
|
|
2537
|
+
throw err;
|
|
2538
|
+
}
|
|
2569
2539
|
throw new UserError(`Failed to load element metadata from "${filename}"`, ensureError(err));
|
|
2570
2540
|
}
|
|
2571
2541
|
}
|
|
@@ -3107,7 +3077,14 @@ const properties = {
|
|
|
3107
3077
|
plugins: {
|
|
3108
3078
|
type: "array",
|
|
3109
3079
|
items: {
|
|
3110
|
-
|
|
3080
|
+
anyOf: [
|
|
3081
|
+
{
|
|
3082
|
+
type: "string"
|
|
3083
|
+
},
|
|
3084
|
+
{
|
|
3085
|
+
type: "object"
|
|
3086
|
+
}
|
|
3087
|
+
]
|
|
3111
3088
|
},
|
|
3112
3089
|
title: "Plugins to load",
|
|
3113
3090
|
description: "Array of plugins load. Use <rootDir> to refer to the folder with the package.json file.",
|
|
@@ -3414,6 +3391,29 @@ var TRANSFORMER_API;
|
|
|
3414
3391
|
TRANSFORMER_API[TRANSFORMER_API["VERSION"] = 1] = "VERSION";
|
|
3415
3392
|
})(TRANSFORMER_API || (TRANSFORMER_API = {}));
|
|
3416
3393
|
|
|
3394
|
+
/**
|
|
3395
|
+
* Similar to `require(..)` but removes the cached copy first.
|
|
3396
|
+
*/
|
|
3397
|
+
function requireUncached(require, moduleId) {
|
|
3398
|
+
const filename = require.resolve(moduleId);
|
|
3399
|
+
/* remove references from the parent module to prevent memory leak */
|
|
3400
|
+
const m = require.cache[filename];
|
|
3401
|
+
if (m && m.parent) {
|
|
3402
|
+
const { parent } = m;
|
|
3403
|
+
for (let i = parent.children.length - 1; i >= 0; i--) {
|
|
3404
|
+
if (parent.children[i].id === filename) {
|
|
3405
|
+
parent.children.splice(i, 1);
|
|
3406
|
+
}
|
|
3407
|
+
}
|
|
3408
|
+
}
|
|
3409
|
+
/* remove old module from cache */
|
|
3410
|
+
delete require.cache[filename];
|
|
3411
|
+
/* eslint-disable-next-line import/no-dynamic-require, security/detect-non-literal-require -- as expected but should be moved to upcoming resolver class */
|
|
3412
|
+
return require(filename);
|
|
3413
|
+
}
|
|
3414
|
+
|
|
3415
|
+
const legacyRequire = require;
|
|
3416
|
+
|
|
3417
3417
|
/**
|
|
3418
3418
|
* @public
|
|
3419
3419
|
*/
|
|
@@ -4118,6 +4118,29 @@ const whitelisted = [
|
|
|
4118
4118
|
"summary",
|
|
4119
4119
|
"figure",
|
|
4120
4120
|
];
|
|
4121
|
+
function isValidUsage(target, meta) {
|
|
4122
|
+
/* elements with explicit aria-label attribute are valid */
|
|
4123
|
+
if (meta.attributes["aria-label"]) {
|
|
4124
|
+
return true;
|
|
4125
|
+
}
|
|
4126
|
+
/* landmark and other whitelisted elements are valid */
|
|
4127
|
+
if (whitelisted.includes(target.tagName)) {
|
|
4128
|
+
return true;
|
|
4129
|
+
}
|
|
4130
|
+
/* elements with role are valid, @todo check if the role is widget or landmark */
|
|
4131
|
+
if (target.hasAttribute("role")) {
|
|
4132
|
+
return true;
|
|
4133
|
+
}
|
|
4134
|
+
/* elements with tabindex (implicit interactive) are valid */
|
|
4135
|
+
if (target.hasAttribute("tabindex")) {
|
|
4136
|
+
return true;
|
|
4137
|
+
}
|
|
4138
|
+
/* interactive and labelable elements are valid */
|
|
4139
|
+
if (meta.interactive || meta.labelable) {
|
|
4140
|
+
return true;
|
|
4141
|
+
}
|
|
4142
|
+
return false;
|
|
4143
|
+
}
|
|
4121
4144
|
class AriaLabelMisuse extends Rule {
|
|
4122
4145
|
documentation() {
|
|
4123
4146
|
const valid = [
|
|
@@ -4156,20 +4179,8 @@ class AriaLabelMisuse extends Rule {
|
|
|
4156
4179
|
if (!meta) {
|
|
4157
4180
|
return;
|
|
4158
4181
|
}
|
|
4159
|
-
/* ignore
|
|
4160
|
-
if (
|
|
4161
|
-
return;
|
|
4162
|
-
}
|
|
4163
|
-
/* ignore elements with role, @todo check if the role is widget or landmark */
|
|
4164
|
-
if (target.hasAttribute("role")) {
|
|
4165
|
-
return;
|
|
4166
|
-
}
|
|
4167
|
-
/* ignore elements with tabindex (implicit interactive) */
|
|
4168
|
-
if (target.hasAttribute("tabindex")) {
|
|
4169
|
-
return;
|
|
4170
|
-
}
|
|
4171
|
-
/* ignore interactive and labelable elements */
|
|
4172
|
-
if (meta.interactive || meta.labelable) {
|
|
4182
|
+
/* ignore elements which is valid usage */
|
|
4183
|
+
if (isValidUsage(target, meta)) {
|
|
4173
4184
|
return;
|
|
4174
4185
|
}
|
|
4175
4186
|
this.report(target, `"aria-label" cannot be used on this element`, attr.keyLocation);
|
|
@@ -9790,7 +9801,7 @@ function configDataFromFile(filename) {
|
|
|
9790
9801
|
try {
|
|
9791
9802
|
/* load using require as it can process both js and json */
|
|
9792
9803
|
/* eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- technical debt, should be refactored into something more typesafe */
|
|
9793
|
-
json = requireUncached(filename);
|
|
9804
|
+
json = requireUncached(legacyRequire, filename);
|
|
9794
9805
|
}
|
|
9795
9806
|
catch (err) {
|
|
9796
9807
|
throw new ConfigError(`Failed to read configuration from "${filename}"`, ensureError(err));
|
|
@@ -9961,7 +9972,6 @@ class Config {
|
|
|
9961
9972
|
/**
|
|
9962
9973
|
* Get element metadata.
|
|
9963
9974
|
*/
|
|
9964
|
-
/* eslint-disable-next-line complexity, sonarjs/cognitive-complexity -- technical debt, should be refactored */
|
|
9965
9975
|
getMetaTable() {
|
|
9966
9976
|
/* use cached table if it exists */
|
|
9967
9977
|
if (this.metaTable) {
|
|
@@ -9988,20 +9998,16 @@ class Config {
|
|
|
9988
9998
|
metaTable.loadFromObject(bundled);
|
|
9989
9999
|
continue;
|
|
9990
10000
|
}
|
|
9991
|
-
/* try as regular file */
|
|
9992
|
-
const filename = entry.replace("<rootDir>", this.rootDir);
|
|
9993
|
-
if (fs__default.default.existsSync(filename)) {
|
|
9994
|
-
metaTable.loadFromFile(filename);
|
|
9995
|
-
continue;
|
|
9996
|
-
}
|
|
9997
10001
|
/* assume it is loadable with require() */
|
|
10002
|
+
const id = entry.replace("<rootDir>", this.rootDir);
|
|
9998
10003
|
try {
|
|
9999
|
-
|
|
10004
|
+
const data = legacyRequire(id);
|
|
10005
|
+
metaTable.loadFromObject(data, id);
|
|
10000
10006
|
}
|
|
10001
10007
|
catch (err) {
|
|
10002
10008
|
/* istanbul ignore next: only used as a fallback */
|
|
10003
10009
|
const message = err instanceof Error ? err.message : String(err);
|
|
10004
|
-
throw new ConfigError(`Failed to load elements from "${
|
|
10010
|
+
throw new ConfigError(`Failed to load elements from "${id}": ${message}`, ensureError(err));
|
|
10005
10011
|
}
|
|
10006
10012
|
}
|
|
10007
10013
|
metaTable.init();
|
|
@@ -10071,7 +10077,13 @@ class Config {
|
|
|
10071
10077
|
return this.plugins;
|
|
10072
10078
|
}
|
|
10073
10079
|
loadPlugins(plugins) {
|
|
10074
|
-
return plugins.map((moduleName) => {
|
|
10080
|
+
return plugins.map((moduleName, index) => {
|
|
10081
|
+
if (typeof moduleName !== "string") {
|
|
10082
|
+
const plugin = moduleName;
|
|
10083
|
+
plugin.name = plugin.name || `:unnamedPlugin@${index + 1}`;
|
|
10084
|
+
plugin.originalName = `:unnamedPlugin@${index + 1}`;
|
|
10085
|
+
return plugin;
|
|
10086
|
+
}
|
|
10075
10087
|
try {
|
|
10076
10088
|
const plugin = legacyRequire(moduleName.replace("<rootDir>", this.rootDir));
|
|
10077
10089
|
plugin.name = plugin.name || moduleName;
|
|
@@ -10158,6 +10170,7 @@ class Config {
|
|
|
10158
10170
|
var _a;
|
|
10159
10171
|
try {
|
|
10160
10172
|
const fn = this.getTransformFunction(name);
|
|
10173
|
+
/* istanbul ignore next */
|
|
10161
10174
|
const version = (_a = fn.api) !== null && _a !== void 0 ? _a : 0;
|
|
10162
10175
|
/* check if transformer version is supported */
|
|
10163
10176
|
if (version !== TRANSFORMER_API.VERSION) {
|
|
@@ -11549,13 +11562,13 @@ class Engine {
|
|
|
11549
11562
|
* The static configuration loader does not do any per-handle lookup. Only the
|
|
11550
11563
|
* global or per-call configuration is used.
|
|
11551
11564
|
*
|
|
11552
|
-
* In practice this means no configuration is
|
|
11565
|
+
* In practice this means no configuration is fetched by traversing the
|
|
11553
11566
|
* filesystem.
|
|
11554
11567
|
*
|
|
11555
11568
|
* @public
|
|
11556
11569
|
*/
|
|
11557
11570
|
class StaticConfigLoader extends ConfigLoader {
|
|
11558
|
-
getConfigFor(
|
|
11571
|
+
getConfigFor(_handle, configOverride) {
|
|
11559
11572
|
const override = this.loadFromObject(configOverride || {});
|
|
11560
11573
|
if (override.isRootFound()) {
|
|
11561
11574
|
override.init();
|
|
@@ -11832,7 +11845,7 @@ class HtmlValidate {
|
|
|
11832
11845
|
/** @public */
|
|
11833
11846
|
const name = "html-validate";
|
|
11834
11847
|
/** @public */
|
|
11835
|
-
const version = "7.
|
|
11848
|
+
const version = "7.17.0";
|
|
11836
11849
|
/** @public */
|
|
11837
11850
|
const bugs = "https://gitlab.com/html-validate/html-validate/issues/new";
|
|
11838
11851
|
|