html-validate 7.16.0 → 7.18.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 +108 -92
- package/dist/cjs/core.js.map +1 -1
- package/dist/cjs/jest-lib.js +21 -4
- package/dist/cjs/jest-lib.js.map +1 -1
- package/dist/cjs/tsdoc-metadata.json +1 -1
- package/dist/es/core.js +108 -92
- package/dist/es/core.js.map +1 -1
- package/dist/es/jest-lib.js +21 -4
- package/dist/es/jest-lib.js.map +1 -1
- package/dist/schema/config.json +1 -1
- package/dist/tsdoc-metadata.json +1 -1
- package/dist/types/browser.d.ts +11 -75
- package/dist/types/index.d.ts +11 -75
- package/package.json +11 -11
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);
|
|
@@ -9484,7 +9495,7 @@ var rules = bundledRules;
|
|
|
9484
9495
|
|
|
9485
9496
|
var defaultConfig = {};
|
|
9486
9497
|
|
|
9487
|
-
const config$
|
|
9498
|
+
const config$4 = {
|
|
9488
9499
|
rules: {
|
|
9489
9500
|
"area-alt": ["error", { accessible: true }],
|
|
9490
9501
|
"aria-hidden-body": "error",
|
|
@@ -9510,9 +9521,9 @@ const config$3 = {
|
|
|
9510
9521
|
"wcag/h71": "error",
|
|
9511
9522
|
},
|
|
9512
9523
|
};
|
|
9513
|
-
var a11y = config$
|
|
9524
|
+
var a11y = config$4;
|
|
9514
9525
|
|
|
9515
|
-
const config$
|
|
9526
|
+
const config$3 = {
|
|
9516
9527
|
rules: {
|
|
9517
9528
|
"input-missing-label": "error",
|
|
9518
9529
|
"heading-level": "error",
|
|
@@ -9521,7 +9532,15 @@ const config$2 = {
|
|
|
9521
9532
|
"require-sri": "error",
|
|
9522
9533
|
},
|
|
9523
9534
|
};
|
|
9524
|
-
var document = config$
|
|
9535
|
+
var document = config$3;
|
|
9536
|
+
|
|
9537
|
+
const config$2 = {
|
|
9538
|
+
rules: {
|
|
9539
|
+
"attr-quotes": "off",
|
|
9540
|
+
"void-style": "off",
|
|
9541
|
+
},
|
|
9542
|
+
};
|
|
9543
|
+
var prettier = config$2;
|
|
9525
9544
|
|
|
9526
9545
|
const config$1 = {
|
|
9527
9546
|
rules: {
|
|
@@ -9642,6 +9661,7 @@ var standard = config;
|
|
|
9642
9661
|
const presets = {
|
|
9643
9662
|
"html-validate:a11y": a11y,
|
|
9644
9663
|
"html-validate:document": document,
|
|
9664
|
+
"html-validate:prettier": prettier,
|
|
9645
9665
|
"html-validate:recommended": recommended,
|
|
9646
9666
|
"html-validate:standard": standard,
|
|
9647
9667
|
/* @deprecated aliases */
|
|
@@ -9790,7 +9810,7 @@ function configDataFromFile(filename) {
|
|
|
9790
9810
|
try {
|
|
9791
9811
|
/* load using require as it can process both js and json */
|
|
9792
9812
|
/* eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- technical debt, should be refactored into something more typesafe */
|
|
9793
|
-
json = requireUncached(filename);
|
|
9813
|
+
json = requireUncached(legacyRequire, filename);
|
|
9794
9814
|
}
|
|
9795
9815
|
catch (err) {
|
|
9796
9816
|
throw new ConfigError(`Failed to read configuration from "${filename}"`, ensureError(err));
|
|
@@ -9839,8 +9859,8 @@ class Config {
|
|
|
9839
9859
|
* Note: this reads configuration data from a file. If you intent to load
|
|
9840
9860
|
* configuration for a file to validate use `ConfigLoader.fromTarget()`.
|
|
9841
9861
|
*
|
|
9842
|
-
* @
|
|
9843
|
-
*
|
|
9862
|
+
* @internal
|
|
9863
|
+
* @param filename - The file to read from
|
|
9844
9864
|
*/
|
|
9845
9865
|
static fromFile(filename) {
|
|
9846
9866
|
const configdata = configDataFromFile(filename);
|
|
@@ -9960,8 +9980,9 @@ class Config {
|
|
|
9960
9980
|
}
|
|
9961
9981
|
/**
|
|
9962
9982
|
* Get element metadata.
|
|
9983
|
+
*
|
|
9984
|
+
* @internal
|
|
9963
9985
|
*/
|
|
9964
|
-
/* eslint-disable-next-line complexity, sonarjs/cognitive-complexity -- technical debt, should be refactored */
|
|
9965
9986
|
getMetaTable() {
|
|
9966
9987
|
/* use cached table if it exists */
|
|
9967
9988
|
if (this.metaTable) {
|
|
@@ -9988,20 +10009,16 @@ class Config {
|
|
|
9988
10009
|
metaTable.loadFromObject(bundled);
|
|
9989
10010
|
continue;
|
|
9990
10011
|
}
|
|
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
10012
|
/* assume it is loadable with require() */
|
|
10013
|
+
const id = entry.replace("<rootDir>", this.rootDir);
|
|
9998
10014
|
try {
|
|
9999
|
-
|
|
10015
|
+
const data = legacyRequire(id);
|
|
10016
|
+
metaTable.loadFromObject(data, id);
|
|
10000
10017
|
}
|
|
10001
10018
|
catch (err) {
|
|
10002
10019
|
/* istanbul ignore next: only used as a fallback */
|
|
10003
10020
|
const message = err instanceof Error ? err.message : String(err);
|
|
10004
|
-
throw new ConfigError(`Failed to load elements from "${
|
|
10021
|
+
throw new ConfigError(`Failed to load elements from "${id}": ${message}`, ensureError(err));
|
|
10005
10022
|
}
|
|
10006
10023
|
}
|
|
10007
10024
|
metaTable.init();
|
|
@@ -10023,19 +10040,7 @@ class Config {
|
|
|
10023
10040
|
*/
|
|
10024
10041
|
/* istanbul ignore next: used for testing only */
|
|
10025
10042
|
get() {
|
|
10026
|
-
|
|
10027
|
-
if (config.elements) {
|
|
10028
|
-
config.elements = config.elements.map((cur) => {
|
|
10029
|
-
if (typeof cur === "string") {
|
|
10030
|
-
return cur.replace(this.rootDir, "<rootDir>");
|
|
10031
|
-
}
|
|
10032
|
-
else {
|
|
10033
|
-
return cur;
|
|
10034
|
-
}
|
|
10035
|
-
});
|
|
10036
|
-
}
|
|
10037
|
-
delete config.extends;
|
|
10038
|
-
return config;
|
|
10043
|
+
return { ...this.config };
|
|
10039
10044
|
}
|
|
10040
10045
|
/**
|
|
10041
10046
|
* Get all configured rules, their severity and options.
|
|
@@ -10071,7 +10076,13 @@ class Config {
|
|
|
10071
10076
|
return this.plugins;
|
|
10072
10077
|
}
|
|
10073
10078
|
loadPlugins(plugins) {
|
|
10074
|
-
return plugins.map((moduleName) => {
|
|
10079
|
+
return plugins.map((moduleName, index) => {
|
|
10080
|
+
if (typeof moduleName !== "string") {
|
|
10081
|
+
const plugin = moduleName;
|
|
10082
|
+
plugin.name = plugin.name || `:unnamedPlugin@${index + 1}`;
|
|
10083
|
+
plugin.originalName = `:unnamedPlugin@${index + 1}`;
|
|
10084
|
+
return plugin;
|
|
10085
|
+
}
|
|
10075
10086
|
try {
|
|
10076
10087
|
const plugin = legacyRequire(moduleName.replace("<rootDir>", this.rootDir));
|
|
10077
10088
|
plugin.name = plugin.name || moduleName;
|
|
@@ -10158,6 +10169,7 @@ class Config {
|
|
|
10158
10169
|
var _a;
|
|
10159
10170
|
try {
|
|
10160
10171
|
const fn = this.getTransformFunction(name);
|
|
10172
|
+
/* istanbul ignore next */
|
|
10161
10173
|
const version = (_a = fn.api) !== null && _a !== void 0 ? _a : 0;
|
|
10162
10174
|
/* check if transformer version is supported */
|
|
10163
10175
|
if (version !== TRANSFORMER_API.VERSION) {
|
|
@@ -11549,13 +11561,13 @@ class Engine {
|
|
|
11549
11561
|
* The static configuration loader does not do any per-handle lookup. Only the
|
|
11550
11562
|
* global or per-call configuration is used.
|
|
11551
11563
|
*
|
|
11552
|
-
* In practice this means no configuration is
|
|
11564
|
+
* In practice this means no configuration is fetched by traversing the
|
|
11553
11565
|
* filesystem.
|
|
11554
11566
|
*
|
|
11555
11567
|
* @public
|
|
11556
11568
|
*/
|
|
11557
11569
|
class StaticConfigLoader extends ConfigLoader {
|
|
11558
|
-
getConfigFor(
|
|
11570
|
+
getConfigFor(_handle, configOverride) {
|
|
11559
11571
|
const override = this.loadFromObject(configOverride || {});
|
|
11560
11572
|
if (override.isRootFound()) {
|
|
11561
11573
|
override.init();
|
|
@@ -11675,6 +11687,7 @@ class HtmlValidate {
|
|
|
11675
11687
|
* Using CLI this is enabled with `--dump-tokens`. Mostly useful for
|
|
11676
11688
|
* debugging.
|
|
11677
11689
|
*
|
|
11690
|
+
* @internal
|
|
11678
11691
|
* @param filename - Filename to tokenize.
|
|
11679
11692
|
*/
|
|
11680
11693
|
dumpTokens(filename) {
|
|
@@ -11689,6 +11702,7 @@ class HtmlValidate {
|
|
|
11689
11702
|
* Using CLI this is enabled with `--dump-events`. Mostly useful for
|
|
11690
11703
|
* debugging.
|
|
11691
11704
|
*
|
|
11705
|
+
* @internal
|
|
11692
11706
|
* @param filename - Filename to dump events from.
|
|
11693
11707
|
*/
|
|
11694
11708
|
dumpEvents(filename) {
|
|
@@ -11703,6 +11717,7 @@ class HtmlValidate {
|
|
|
11703
11717
|
* Using CLI this is enabled with `--dump-tree`. Mostly useful for
|
|
11704
11718
|
* debugging.
|
|
11705
11719
|
*
|
|
11720
|
+
* @internal
|
|
11706
11721
|
* @param filename - Filename to dump DOM tree from.
|
|
11707
11722
|
*/
|
|
11708
11723
|
dumpTree(filename) {
|
|
@@ -11717,6 +11732,7 @@ class HtmlValidate {
|
|
|
11717
11732
|
* Using CLI this is enabled with `--dump-source`. Mostly useful for
|
|
11718
11733
|
* debugging.
|
|
11719
11734
|
*
|
|
11735
|
+
* @internal
|
|
11720
11736
|
* @param filename - Filename to dump source from.
|
|
11721
11737
|
*/
|
|
11722
11738
|
dumpSource(filename) {
|
|
@@ -11832,7 +11848,7 @@ class HtmlValidate {
|
|
|
11832
11848
|
/** @public */
|
|
11833
11849
|
const name = "html-validate";
|
|
11834
11850
|
/** @public */
|
|
11835
|
-
const version = "7.
|
|
11851
|
+
const version = "7.18.0";
|
|
11836
11852
|
/** @public */
|
|
11837
11853
|
const bugs = "https://gitlab.com/html-validate/html-validate/issues/new";
|
|
11838
11854
|
|