html-validate 10.1.1 → 10.2.1

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.
Files changed (58) hide show
  1. package/dist/cjs/cli.js +201 -203
  2. package/dist/cjs/cli.js.map +1 -1
  3. package/dist/cjs/core-browser.js.map +1 -1
  4. package/dist/cjs/core-nodejs.js +3 -3
  5. package/dist/cjs/core-nodejs.js.map +1 -1
  6. package/dist/cjs/core.js +431 -368
  7. package/dist/cjs/core.js.map +1 -1
  8. package/dist/cjs/elements.js +2 -2
  9. package/dist/cjs/elements.js.map +1 -1
  10. package/dist/cjs/html-validate.js +2 -3
  11. package/dist/cjs/html-validate.js.map +1 -1
  12. package/dist/cjs/index.js +0 -1
  13. package/dist/cjs/index.js.map +1 -1
  14. package/dist/cjs/jest-diff.js +2 -0
  15. package/dist/cjs/jest-diff.js.map +1 -1
  16. package/dist/cjs/jest-worker.js.map +1 -1
  17. package/dist/cjs/jest.js +1 -1
  18. package/dist/cjs/jest.js.map +1 -1
  19. package/dist/cjs/matchers-jestonly.js +1 -1
  20. package/dist/cjs/matchers-jestonly.js.map +1 -1
  21. package/dist/cjs/matchers.js.map +1 -1
  22. package/dist/cjs/meta-helper.js +4 -4
  23. package/dist/cjs/meta-helper.js.map +1 -1
  24. package/dist/cjs/test-utils.js +2 -2
  25. package/dist/cjs/test-utils.js.map +2 -2
  26. package/dist/cjs/tsdoc-metadata.json +1 -1
  27. package/dist/cjs/vitest.js.map +1 -1
  28. package/dist/esm/browser.js +1 -1
  29. package/dist/esm/cli.js +201 -202
  30. package/dist/esm/cli.js.map +1 -1
  31. package/dist/esm/core-browser.js.map +1 -1
  32. package/dist/esm/core-nodejs.js +3 -3
  33. package/dist/esm/core-nodejs.js.map +1 -1
  34. package/dist/esm/core.js +432 -369
  35. package/dist/esm/core.js.map +1 -1
  36. package/dist/esm/elements.js +3 -3
  37. package/dist/esm/elements.js.map +1 -1
  38. package/dist/esm/html-validate.js +2 -3
  39. package/dist/esm/html-validate.js.map +1 -1
  40. package/dist/esm/index.js +1 -2
  41. package/dist/esm/index.js.map +1 -1
  42. package/dist/esm/jest-diff.js +2 -0
  43. package/dist/esm/jest-diff.js.map +1 -1
  44. package/dist/esm/jest-worker.js.map +1 -1
  45. package/dist/esm/jest.js +1 -1
  46. package/dist/esm/jest.js.map +1 -1
  47. package/dist/esm/matchers-jestonly.js +1 -1
  48. package/dist/esm/matchers-jestonly.js.map +1 -1
  49. package/dist/esm/matchers.js.map +1 -1
  50. package/dist/esm/meta-helper.js +4 -4
  51. package/dist/esm/meta-helper.js.map +1 -1
  52. package/dist/esm/test-utils.js +1 -1
  53. package/dist/esm/test-utils.js.map +1 -1
  54. package/dist/esm/vitest.js.map +1 -1
  55. package/dist/tsdoc-metadata.json +1 -1
  56. package/dist/types/browser.d.ts +1 -1
  57. package/dist/types/index.d.ts +1 -1
  58. package/package.json +2 -2
package/dist/esm/core.js CHANGED
@@ -496,27 +496,6 @@ class SchemaValidationError extends UserError {
496
496
  }
497
497
  }
498
498
 
499
- function cyrb53(str) {
500
- const a = 2654435761;
501
- const b = 1597334677;
502
- const c = 2246822507;
503
- const d = 3266489909;
504
- const e = 4294967296;
505
- const f = 2097151;
506
- const seed = 0;
507
- let h1 = 3735928559 ^ seed;
508
- let h2 = 1103547991 ^ seed;
509
- for (let i = 0, ch; i < str.length; i++) {
510
- ch = str.charCodeAt(i);
511
- h1 = Math.imul(h1 ^ ch, a);
512
- h2 = Math.imul(h2 ^ ch, b);
513
- }
514
- h1 = Math.imul(h1 ^ h1 >>> 16, c) ^ Math.imul(h2 ^ h2 >>> 13, d);
515
- h2 = Math.imul(h2 ^ h2 >>> 16, c) ^ Math.imul(h1 ^ h1 >>> 13, d);
516
- return e * (f & h2) + (h1 >>> 0);
517
- }
518
- const computeHash = cyrb53;
519
-
520
499
  const $schema$1 = "http://json-schema.org/draft-06/schema#";
521
500
  const $id$1 = "https://html-validate.org/schemas/elements.json";
522
501
  const type$1 = "object";
@@ -992,6 +971,27 @@ const ajvFunctionKeyword = {
992
971
  validate: ajvFunctionValidate
993
972
  };
994
973
 
974
+ function cyrb53(str) {
975
+ const a = 2654435761;
976
+ const b = 1597334677;
977
+ const c = 2246822507;
978
+ const d = 3266489909;
979
+ const e = 4294967296;
980
+ const f = 2097151;
981
+ const seed = 0;
982
+ let h1 = 3735928559 ^ seed;
983
+ let h2 = 1103547991 ^ seed;
984
+ for (let i = 0, ch; i < str.length; i++) {
985
+ ch = str.charCodeAt(i);
986
+ h1 = Math.imul(h1 ^ ch, a);
987
+ h2 = Math.imul(h2 ^ ch, b);
988
+ }
989
+ h1 = Math.imul(h1 ^ h1 >>> 16, c) ^ Math.imul(h2 ^ h2 >>> 13, d);
990
+ h2 = Math.imul(h2 ^ h2 >>> 16, c) ^ Math.imul(h1 ^ h1 >>> 13, d);
991
+ return e * (f & h2) + (h1 >>> 0);
992
+ }
993
+ const computeHash = cyrb53;
994
+
995
995
  var TextContent$1 = /* @__PURE__ */ ((TextContent2) => {
996
996
  TextContent2["NONE"] = "none";
997
997
  TextContent2["DEFAULT"] = "default";
@@ -1486,7 +1486,7 @@ function sliceLocation(location, begin, end, wrap) {
1486
1486
  if (wrap) {
1487
1487
  let index = -1;
1488
1488
  const col = sliced.column;
1489
- do {
1489
+ for (; ; ) {
1490
1490
  index = wrap.indexOf("\n", index + 1);
1491
1491
  if (index >= 0 && index < begin) {
1492
1492
  sliced.column = col - (index + 1);
@@ -1494,7 +1494,7 @@ function sliceLocation(location, begin, end, wrap) {
1494
1494
  } else {
1495
1495
  break;
1496
1496
  }
1497
- } while (true);
1497
+ }
1498
1498
  }
1499
1499
  return sliced;
1500
1500
  }
@@ -1592,7 +1592,6 @@ class DOMNode {
1592
1592
  * @internal
1593
1593
  */
1594
1594
  unique;
1595
- /* eslint-disable-next-line sonarjs/use-type-alias -- technical debt */
1596
1595
  cache;
1597
1596
  /**
1598
1597
  * Set of disabled rules for this node.
@@ -1632,8 +1631,8 @@ class DOMNode {
1632
1631
  *
1633
1632
  * @internal
1634
1633
  */
1635
- cacheEnable() {
1636
- this.cache = /* @__PURE__ */ new Map();
1634
+ cacheEnable(enable = true) {
1635
+ this.cache = enable ? /* @__PURE__ */ new Map() : null;
1637
1636
  }
1638
1637
  cacheGet(key) {
1639
1638
  if (this.cache) {
@@ -3320,172 +3319,6 @@ function parseQuantifier(quantifier) {
3320
3319
  }
3321
3320
  }
3322
3321
 
3323
- const $schema = "http://json-schema.org/draft-06/schema#";
3324
- const $id = "https://html-validate.org/schemas/config.json";
3325
- const type = "object";
3326
- const additionalProperties = false;
3327
- const properties = {
3328
- $schema: {
3329
- type: "string"
3330
- },
3331
- root: {
3332
- type: "boolean",
3333
- title: "Mark as root configuration",
3334
- description: "If this is set to true no further configurations will be searched.",
3335
- "default": false
3336
- },
3337
- "extends": {
3338
- type: "array",
3339
- items: {
3340
- type: "string"
3341
- },
3342
- title: "Configurations to extend",
3343
- description: "Array of shareable or builtin configurations to extend."
3344
- },
3345
- elements: {
3346
- type: "array",
3347
- items: {
3348
- anyOf: [
3349
- {
3350
- type: "string"
3351
- },
3352
- {
3353
- type: "object"
3354
- }
3355
- ]
3356
- },
3357
- title: "Element metadata to load",
3358
- description: "Array of modules, plugins or files to load element metadata from. Use <rootDir> to refer to the folder with the package.json file.",
3359
- examples: [
3360
- [
3361
- "html-validate:recommended",
3362
- "plugin:recommended",
3363
- "module",
3364
- "./local-file.json"
3365
- ]
3366
- ]
3367
- },
3368
- plugins: {
3369
- type: "array",
3370
- items: {
3371
- anyOf: [
3372
- {
3373
- type: "string"
3374
- },
3375
- {
3376
- type: "object"
3377
- }
3378
- ]
3379
- },
3380
- title: "Plugins to load",
3381
- description: "Array of plugins load. Use <rootDir> to refer to the folder with the package.json file.",
3382
- examples: [
3383
- [
3384
- "my-plugin",
3385
- "./local-plugin"
3386
- ]
3387
- ]
3388
- },
3389
- transform: {
3390
- type: "object",
3391
- additionalProperties: {
3392
- anyOf: [
3393
- {
3394
- type: "string"
3395
- },
3396
- {
3397
- "function": true
3398
- }
3399
- ]
3400
- },
3401
- title: "File transformations to use.",
3402
- description: "Object where key is regular expression to match filename and value is name of transformer or a function.",
3403
- examples: [
3404
- {
3405
- "^.*\\.foo$": "my-transformer",
3406
- "^.*\\.bar$": "my-plugin",
3407
- "^.*\\.baz$": "my-plugin:named"
3408
- }
3409
- ]
3410
- },
3411
- rules: {
3412
- type: "object",
3413
- patternProperties: {
3414
- ".*": {
3415
- anyOf: [
3416
- {
3417
- "enum": [
3418
- 0,
3419
- 1,
3420
- 2,
3421
- "off",
3422
- "warn",
3423
- "error"
3424
- ]
3425
- },
3426
- {
3427
- type: "array",
3428
- minItems: 1,
3429
- maxItems: 1,
3430
- items: [
3431
- {
3432
- "enum": [
3433
- 0,
3434
- 1,
3435
- 2,
3436
- "off",
3437
- "warn",
3438
- "error"
3439
- ]
3440
- }
3441
- ]
3442
- },
3443
- {
3444
- type: "array",
3445
- minItems: 2,
3446
- maxItems: 2,
3447
- items: [
3448
- {
3449
- "enum": [
3450
- 0,
3451
- 1,
3452
- 2,
3453
- "off",
3454
- "warn",
3455
- "error"
3456
- ]
3457
- },
3458
- {
3459
- }
3460
- ]
3461
- }
3462
- ]
3463
- }
3464
- },
3465
- title: "Rule configuration.",
3466
- description: "Enable/disable rules, set severity. Some rules have additional configuration like style or patterns to use.",
3467
- examples: [
3468
- {
3469
- foo: "error",
3470
- bar: "off",
3471
- baz: [
3472
- "error",
3473
- {
3474
- style: "camelcase"
3475
- }
3476
- ]
3477
- }
3478
- ]
3479
- }
3480
- };
3481
- var configurationSchema = {
3482
- $schema: $schema,
3483
- $id: $id,
3484
- type: type,
3485
- additionalProperties: additionalProperties,
3486
- properties: properties
3487
- };
3488
-
3489
3322
  var Severity = /* @__PURE__ */ ((Severity2) => {
3490
3323
  Severity2[Severity2["DISABLED"] = 0] = "DISABLED";
3491
3324
  Severity2[Severity2["WARN"] = 1] = "WARN";
@@ -3508,35 +3341,6 @@ function parseSeverity(value) {
3508
3341
  }
3509
3342
  }
3510
3343
 
3511
- function escape(value) {
3512
- return JSON.stringify(value);
3513
- }
3514
- function format(value, quote = false) {
3515
- if (value === null || value === void 0) {
3516
- return "null";
3517
- }
3518
- if (typeof value === "number") {
3519
- return value.toString();
3520
- }
3521
- if (typeof value === "string") {
3522
- return quote ? escape(value) : value;
3523
- }
3524
- if (Array.isArray(value)) {
3525
- const content = value.map((it) => format(it, true)).join(", ");
3526
- return `[ ${content} ]`;
3527
- }
3528
- if (typeof value === "object") {
3529
- const content = Object.entries(value).map(([key, nested]) => `${key}: ${format(nested, true)}`).join(", ");
3530
- return `{ ${content} }`;
3531
- }
3532
- return String(value);
3533
- }
3534
- function interpolate(text, data) {
3535
- return text.replace(/{{\s*([^\s{}]+)\s*}}/g, (match, key) => {
3536
- return typeof data[key] !== "undefined" ? format(data[key]) : match;
3537
- });
3538
- }
3539
-
3540
3344
  const cacheKey = Symbol("aria-naming");
3541
3345
  const defaultValue = "allowed";
3542
3346
  const prohibitedRoles = [
@@ -3578,6 +3382,31 @@ function ariaNaming(element) {
3578
3382
  return element.cacheSet(cacheKey, byMeta(element, meta));
3579
3383
  }
3580
3384
 
3385
+ const INPUT_DISABLED_CACHE = Symbol(isInputDisabled.name);
3386
+ function isInputDisabled(node, details) {
3387
+ const cached = node.cacheGet(INPUT_DISABLED_CACHE);
3388
+ if (cached) {
3389
+ return details ? cached : cached.byFieldset || cached.bySelf;
3390
+ }
3391
+ const result = node.cacheSet(INPUT_DISABLED_CACHE, isInputDisabledImpl(node));
3392
+ return details ? result : result.byFieldset || result.bySelf;
3393
+ }
3394
+ function isInputDisabledImpl(node) {
3395
+ const hasDisabledAttr = (node2) => {
3396
+ const disabled = node2.getAttribute("disabled");
3397
+ return Boolean(disabled?.isStatic);
3398
+ };
3399
+ const hasDisabledFieldset = (node2) => {
3400
+ const fieldset = node2.closest("fieldset[disabled]");
3401
+ const disabled = fieldset?.getAttribute("disabled");
3402
+ return Boolean(disabled?.isStatic);
3403
+ };
3404
+ return {
3405
+ byFieldset: hasDisabledFieldset(node),
3406
+ bySelf: hasDisabledAttr(node)
3407
+ };
3408
+ }
3409
+
3581
3410
  const patternCache = /* @__PURE__ */ new Map();
3582
3411
  function compileStringPattern(pattern) {
3583
3412
  const regexp = pattern.replace(/[*]+/g, ".+");
@@ -3642,7 +3471,7 @@ function inAccessibilityTree(node) {
3642
3471
  function isAriaHiddenImpl(node) {
3643
3472
  const getAriaHiddenAttr = (node2) => {
3644
3473
  const ariaHidden = node2.getAttribute("aria-hidden");
3645
- return Boolean(ariaHidden && ariaHidden.value === "true");
3474
+ return ariaHidden?.value === "true";
3646
3475
  };
3647
3476
  return {
3648
3477
  byParent: node.parent ? isAriaHidden(node.parent) : false,
@@ -3831,6 +3660,35 @@ function partition(values, predicate) {
3831
3660
  }, initial);
3832
3661
  }
3833
3662
 
3663
+ function escape(value) {
3664
+ return JSON.stringify(value);
3665
+ }
3666
+ function format(value, quote = false) {
3667
+ if (value === null || value === void 0) {
3668
+ return "null";
3669
+ }
3670
+ if (typeof value === "number") {
3671
+ return value.toString();
3672
+ }
3673
+ if (typeof value === "string") {
3674
+ return quote ? escape(value) : value;
3675
+ }
3676
+ if (Array.isArray(value)) {
3677
+ const content = value.map((it) => format(it, true)).join(", ");
3678
+ return `[ ${content} ]`;
3679
+ }
3680
+ if (typeof value === "object") {
3681
+ const content = Object.entries(value).map(([key, nested]) => `${key}: ${format(nested, true)}`).join(", ");
3682
+ return `{ ${content} }`;
3683
+ }
3684
+ return String(value);
3685
+ }
3686
+ function interpolate(text, data) {
3687
+ return text.replace(/{{\s*([^\s{}]+)\s*}}/g, (match, key) => {
3688
+ return typeof data[key] !== "undefined" ? format(data[key]) : match;
3689
+ });
3690
+ }
3691
+
3834
3692
  const ajv$1 = new Ajv({ strict: true, strictTuples: true, strictTypes: true });
3835
3693
  ajv$1.addMetaSchema(ajvSchemaDraft);
3836
3694
  function getSchemaValidator(ruleId, properties) {
@@ -3848,7 +3706,7 @@ function getSchemaValidator(ruleId, properties) {
3848
3706
  return ajv$1.compile(schema);
3849
3707
  }
3850
3708
  function isErrorDescriptor(value) {
3851
- return Boolean(value[0] && value[0].message);
3709
+ return Boolean(value[0] && value[0]["message"]);
3852
3710
  }
3853
3711
  function unpackErrorDescriptor(value) {
3854
3712
  if (isErrorDescriptor(value)) {
@@ -4119,8 +3977,7 @@ class Rule {
4119
3977
  * @returns Rule documentation and url with additional details or `null` if no
4120
3978
  * additional documentation is available.
4121
3979
  */
4122
- /* eslint-disable-next-line @typescript-eslint/no-unused-vars -- technical debt, prototype should be moved to interface */
4123
- documentation(context) {
3980
+ documentation(_context) {
4124
3981
  return null;
4125
3982
  }
4126
3983
  }
@@ -4449,7 +4306,7 @@ class AriaHiddenBody extends Rule {
4449
4306
  const defaults$w = {
4450
4307
  allowAnyNamable: false
4451
4308
  };
4452
- const whitelisted = [
4309
+ const allowlist = /* @__PURE__ */ new Set([
4453
4310
  "main",
4454
4311
  "nav",
4455
4312
  "table",
@@ -4462,18 +4319,19 @@ const whitelisted = [
4462
4319
  "article",
4463
4320
  "dialog",
4464
4321
  "form",
4322
+ "iframe",
4465
4323
  "img",
4466
4324
  "area",
4467
4325
  "fieldset",
4468
4326
  "summary",
4469
4327
  "figure"
4470
- ];
4328
+ ]);
4471
4329
  function isValidUsage(target, meta) {
4472
4330
  const explicit = meta.attributes["aria-label"];
4473
4331
  if (explicit) {
4474
4332
  return true;
4475
4333
  }
4476
- if (whitelisted.includes(target.tagName)) {
4334
+ if (allowlist.has(target.tagName)) {
4477
4335
  return true;
4478
4336
  }
4479
4337
  if (target.hasAttribute("role")) {
@@ -4491,7 +4349,7 @@ class AriaLabelMisuse extends Rule {
4491
4349
  constructor(options) {
4492
4350
  super({ ...defaults$w, ...options });
4493
4351
  }
4494
- documentation() {
4352
+ documentation(context) {
4495
4353
  const valid = [
4496
4354
  "Interactive elements",
4497
4355
  "Labelable elements",
@@ -4505,25 +4363,41 @@ class AriaLabelMisuse extends Rule {
4505
4363
  "`<summary>`",
4506
4364
  "`<table>`, `<td>` and `<th>`"
4507
4365
  ];
4508
- const lines = valid.map((it) => `- ${it}
4509
- `).join("");
4510
- return {
4511
- description: `\`aria-label\` can only be used on:
4512
-
4513
- ${lines}`,
4514
- url: "https://html-validate.org/rules/aria-label-misuse.html"
4515
- };
4366
+ const lines = valid.map((it) => `- ${it}`);
4367
+ const url = "https://html-validate.org/rules/aria-label-misuse.html";
4368
+ if (context.allowsNaming) {
4369
+ return {
4370
+ description: [
4371
+ `\`${context.attr}\` is strictly allowed but is not recommended to be used on this element.`,
4372
+ `\`${context.attr}\` can only be used on:`,
4373
+ "",
4374
+ ...lines
4375
+ ].join("\n"),
4376
+ url
4377
+ };
4378
+ } else {
4379
+ return {
4380
+ description: [`\`${context.attr}\` can only be used on:`, "", ...lines].join("\n"),
4381
+ url
4382
+ };
4383
+ }
4516
4384
  }
4517
4385
  setup() {
4518
4386
  this.on("dom:ready", (event) => {
4519
4387
  const { document } = event;
4520
- for (const target of document.querySelectorAll("[aria-label]")) {
4521
- this.validateElement(target);
4388
+ for (const target of document.querySelectorAll("[aria-label], [aria-labelledby]")) {
4389
+ const ariaLabel = target.getAttribute("aria-label");
4390
+ if (ariaLabel) {
4391
+ this.validateElement(target, ariaLabel, "aria-label");
4392
+ }
4393
+ const ariaLabelledby = target.getAttribute("aria-labelledby");
4394
+ if (ariaLabelledby) {
4395
+ this.validateElement(target, ariaLabelledby, "aria-labelledby");
4396
+ }
4522
4397
  }
4523
4398
  });
4524
4399
  }
4525
- validateElement(target) {
4526
- const attr = target.getAttribute("aria-label");
4400
+ validateElement(target, attr, key) {
4527
4401
  if (!attr.value || attr.valueMatches("", false)) {
4528
4402
  return;
4529
4403
  }
@@ -4534,10 +4408,26 @@ ${lines}`,
4534
4408
  if (isValidUsage(target, meta)) {
4535
4409
  return;
4536
4410
  }
4537
- if (this.options.allowAnyNamable && ariaNaming(target) === "allowed") {
4411
+ const allowsNaming = ariaNaming(target) === "allowed";
4412
+ if (allowsNaming && this.options.allowAnyNamable) {
4538
4413
  return;
4539
4414
  }
4540
- this.report(target, `"aria-label" cannot be used on this element`, attr.keyLocation);
4415
+ const context = { attr: key, allowsNaming };
4416
+ if (allowsNaming) {
4417
+ this.report({
4418
+ node: target,
4419
+ location: attr.keyLocation,
4420
+ context,
4421
+ message: `"{{ attr }}" is strictly allowed but is not recommended to be used on this element`
4422
+ });
4423
+ } else {
4424
+ this.report({
4425
+ node: target,
4426
+ location: attr.keyLocation,
4427
+ context,
4428
+ message: `"{{ attr }}" cannot be used on this element`
4429
+ });
4430
+ }
4541
4431
  }
4542
4432
  }
4543
4433
 
@@ -5232,9 +5122,6 @@ class AttributeAllowedValues extends Rule {
5232
5122
  description: "Attribute has invalid value.",
5233
5123
  url: "https://html-validate.org/rules/attribute-allowed-values.html"
5234
5124
  };
5235
- if (!context) {
5236
- return docs;
5237
- }
5238
5125
  const { allowed, attribute, element, value } = context;
5239
5126
  if (allowed.enum) {
5240
5127
  const allowedList = allowed.enum.map((value2) => {
@@ -6069,7 +5956,10 @@ class ElementName extends Rule {
6069
5956
 
6070
5957
  function isNativeTemplate(node) {
6071
5958
  const { tagName, meta } = node;
6072
- return Boolean(tagName === "template" && meta?.templateRoot && meta?.scriptSupporting);
5959
+ if (!meta) {
5960
+ return false;
5961
+ }
5962
+ return Boolean(tagName === "template" && meta.templateRoot && meta.scriptSupporting);
6073
5963
  }
6074
5964
  function getTransparentChildren(node, transparent) {
6075
5965
  if (typeof transparent === "boolean") {
@@ -6298,7 +6188,7 @@ class ElementPermittedParent extends Rule {
6298
6188
  }
6299
6189
  const rules = node.meta?.permittedParent;
6300
6190
  if (!rules) {
6301
- return false;
6191
+ return;
6302
6192
  }
6303
6193
  if (Validator.validatePermitted(parent, rules)) {
6304
6194
  return;
@@ -6365,14 +6255,10 @@ class ElementRequiredAncestor extends Rule {
6365
6255
 
6366
6256
  class ElementRequiredAttributes extends Rule {
6367
6257
  documentation(context) {
6368
- const docs = {
6369
- description: "Element is missing a required attribute",
6258
+ return {
6259
+ description: `The \`<${context.element}>\` element is required to have a \`${context.attribute}\` attribute.`,
6370
6260
  url: "https://html-validate.org/rules/element-required-attributes.html"
6371
6261
  };
6372
- if (context) {
6373
- docs.description = `The <${context.element}> element is required to have a "${context.attribute}" attribute.`;
6374
- }
6375
- return docs;
6376
6262
  }
6377
6263
  setup() {
6378
6264
  this.on("tag:end", (event) => {
@@ -6519,6 +6405,18 @@ const defaults$l = {
6519
6405
  };
6520
6406
  const UNIQUE_CACHE_KEY = Symbol("form-elements-unique");
6521
6407
  const SHARED_CACHE_KEY = Symbol("form-elements-shared");
6408
+ function isEnabled(element) {
6409
+ if (isHTMLHidden(element)) {
6410
+ return false;
6411
+ }
6412
+ if (isInert(element)) {
6413
+ return false;
6414
+ }
6415
+ if (isInputDisabled(element)) {
6416
+ return false;
6417
+ }
6418
+ return true;
6419
+ }
6522
6420
  function haveName(name) {
6523
6421
  return typeof name === "string" && name !== "";
6524
6422
  }
@@ -6589,7 +6487,7 @@ class FormDupName extends Rule {
6589
6487
  const { shared } = this.options;
6590
6488
  this.on("dom:ready", (event) => {
6591
6489
  const { document } = event;
6592
- const controls = document.querySelectorAll(selector);
6490
+ const controls = document.querySelectorAll(selector).filter(isEnabled);
6593
6491
  const [sharedControls, uniqueControls] = partition(controls, (it) => {
6594
6492
  return allowSharedName(it, shared);
6595
6493
  });
@@ -7345,69 +7243,6 @@ class LongTitle extends Rule {
7345
7243
  }
7346
7244
  }
7347
7245
 
7348
- const defaults$h = {
7349
- allowLongDelay: false
7350
- };
7351
- class MetaRefresh extends Rule {
7352
- constructor(options) {
7353
- super({ ...defaults$h, ...options });
7354
- }
7355
- documentation() {
7356
- return {
7357
- description: `Meta refresh directive must use the \`0;url=...\` format. Non-zero values for time interval is disallowed as people with assistive technology might be unable to read and understand the page content before automatically reloading. For the same reason skipping the url is disallowed as it would put the browser in an infinite loop reloading the same page over and over again.`,
7358
- url: "https://html-validate.org/rules/meta-refresh.html"
7359
- };
7360
- }
7361
- setup() {
7362
- this.on("element:ready", ({ target }) => {
7363
- if (!target.is("meta")) {
7364
- return;
7365
- }
7366
- const httpEquiv = target.getAttributeValue("http-equiv");
7367
- if (httpEquiv !== "refresh") {
7368
- return;
7369
- }
7370
- const content = target.getAttribute("content");
7371
- if (!content?.value || content.isDynamic) {
7372
- return;
7373
- }
7374
- const location = content.valueLocation;
7375
- const value = parseContent(content.value.toString());
7376
- if (!value) {
7377
- this.report(target, "Malformed meta refresh directive", location);
7378
- return;
7379
- }
7380
- const { delay, url } = value;
7381
- this.validateDelay(target, location, delay, url);
7382
- });
7383
- }
7384
- validateDelay(target, location, delay, url) {
7385
- const { allowLongDelay } = this.options;
7386
- if (allowLongDelay && delay > 72e3) {
7387
- return;
7388
- }
7389
- if (!url && delay === 0) {
7390
- this.report(target, "Don't use instant meta refresh to reload the page", location);
7391
- return;
7392
- }
7393
- if (delay !== 0) {
7394
- const message = allowLongDelay ? "Meta refresh must be instant (0 second delay) or greater than 20 hours (72000 second delay)" : "Meta refresh must be instant (0 second delay)";
7395
- this.report(target, message, location);
7396
- }
7397
- }
7398
- }
7399
- function parseContent(text) {
7400
- const match = /^(\d+)(?:\s*;\s*url=(.*))?/i.exec(text);
7401
- if (match) {
7402
- return {
7403
- delay: parseInt(match[1], 10),
7404
- url: match[2]
7405
- };
7406
- } else {
7407
- return null;
7408
- }
7409
- }
7410
-
7411
7246
  function getName(attr) {
7412
7247
  const name = attr.value;
7413
7248
  if (!name || name instanceof DynamicValue) {
@@ -7470,16 +7305,79 @@ class MapIdName extends Rule {
7470
7305
  if (!hasStaticValue(id) || !hasStaticValue(name)) {
7471
7306
  return;
7472
7307
  }
7473
- if (id.value === name.value) {
7308
+ if (id.value === name.value) {
7309
+ return;
7310
+ }
7311
+ this.report({
7312
+ node: event.target,
7313
+ message: `"id" and "name" attribute must be the same on <map> elements`,
7314
+ location: id.valueLocation ?? name.valueLocation
7315
+ });
7316
+ });
7317
+ }
7318
+ }
7319
+
7320
+ const defaults$h = {
7321
+ allowLongDelay: false
7322
+ };
7323
+ class MetaRefresh extends Rule {
7324
+ constructor(options) {
7325
+ super({ ...defaults$h, ...options });
7326
+ }
7327
+ documentation() {
7328
+ return {
7329
+ description: `Meta refresh directive must use the \`0;url=...\` format. Non-zero values for time interval is disallowed as people with assistive technology might be unable to read and understand the page content before automatically reloading. For the same reason skipping the url is disallowed as it would put the browser in an infinite loop reloading the same page over and over again.`,
7330
+ url: "https://html-validate.org/rules/meta-refresh.html"
7331
+ };
7332
+ }
7333
+ setup() {
7334
+ this.on("element:ready", ({ target }) => {
7335
+ if (!target.is("meta")) {
7336
+ return;
7337
+ }
7338
+ const httpEquiv = target.getAttributeValue("http-equiv");
7339
+ if (httpEquiv !== "refresh") {
7340
+ return;
7341
+ }
7342
+ const content = target.getAttribute("content");
7343
+ if (!content?.value || content.isDynamic) {
7344
+ return;
7345
+ }
7346
+ const location = content.valueLocation;
7347
+ const value = parseContent(content.value.toString());
7348
+ if (!value) {
7349
+ this.report(target, "Malformed meta refresh directive", location);
7474
7350
  return;
7475
7351
  }
7476
- this.report({
7477
- node: event.target,
7478
- message: `"id" and "name" attribute must be the same on <map> elements`,
7479
- location: id.valueLocation ?? name.valueLocation
7480
- });
7352
+ const { delay, url } = value;
7353
+ this.validateDelay(target, location, delay, url);
7481
7354
  });
7482
7355
  }
7356
+ validateDelay(target, location, delay, url) {
7357
+ const { allowLongDelay } = this.options;
7358
+ if (allowLongDelay && delay > 72e3) {
7359
+ return;
7360
+ }
7361
+ if (!url && delay === 0) {
7362
+ this.report(target, "Don't use instant meta refresh to reload the page", location);
7363
+ return;
7364
+ }
7365
+ if (delay !== 0) {
7366
+ const message = allowLongDelay ? "Meta refresh must be instant (0 second delay) or greater than 20 hours (72000 second delay)" : "Meta refresh must be instant (0 second delay)";
7367
+ this.report(target, message, location);
7368
+ }
7369
+ }
7370
+ }
7371
+ function parseContent(text) {
7372
+ const match = /^(\d+)(?:\s*;\s*url=(.*))?/i.exec(text);
7373
+ if (match) {
7374
+ return {
7375
+ delay: parseInt(match[1], 10),
7376
+ url: match[2]
7377
+ };
7378
+ } else {
7379
+ return null;
7380
+ }
7483
7381
  }
7484
7382
 
7485
7383
  class MissingDoctype extends Rule {
@@ -7878,30 +7776,6 @@ class NoImplicitButtonType extends Rule {
7878
7776
  }
7879
7777
  }
7880
7778
 
7881
- function isRelevant$1(event) {
7882
- return event.target.is("input");
7883
- }
7884
- class NoImplicitInputType extends Rule {
7885
- documentation() {
7886
- return {
7887
- description: ["`<input>` is missing recommended `type` attribute"].join("\n"),
7888
- url: "https://html-validate.org/rules/no-implicit-input-type.html"
7889
- };
7890
- }
7891
- setup() {
7892
- this.on("element:ready", isRelevant$1, (event) => {
7893
- const { target } = event;
7894
- const attr = target.getAttribute("type");
7895
- if (!attr) {
7896
- this.report({
7897
- node: event.target,
7898
- message: `<input> is missing recommended "type" attribute`
7899
- });
7900
- }
7901
- });
7902
- }
7903
- }
7904
-
7905
7779
  class NoImplicitClose extends Rule {
7906
7780
  documentation() {
7907
7781
  return {
@@ -7954,6 +7828,30 @@ Omitted end tags can be ambigious for humans to read and many editors have troub
7954
7828
  }
7955
7829
  }
7956
7830
 
7831
+ function isRelevant$1(event) {
7832
+ return event.target.is("input");
7833
+ }
7834
+ class NoImplicitInputType extends Rule {
7835
+ documentation() {
7836
+ return {
7837
+ description: ["`<input>` is missing recommended `type` attribute"].join("\n"),
7838
+ url: "https://html-validate.org/rules/no-implicit-input-type.html"
7839
+ };
7840
+ }
7841
+ setup() {
7842
+ this.on("element:ready", isRelevant$1, (event) => {
7843
+ const { target } = event;
7844
+ const attr = target.getAttribute("type");
7845
+ if (!attr) {
7846
+ this.report({
7847
+ node: event.target,
7848
+ message: `<input> is missing recommended "type" attribute`
7849
+ });
7850
+ }
7851
+ });
7852
+ }
7853
+ }
7854
+
7957
7855
  const defaults$e = {
7958
7856
  include: null,
7959
7857
  exclude: null,
@@ -8363,10 +8261,9 @@ class NoSelfClosing extends Rule {
8363
8261
  }
8364
8262
  };
8365
8263
  }
8366
- documentation(tagName) {
8367
- tagName = tagName || "element";
8264
+ documentation(context) {
8368
8265
  return {
8369
- description: `Self-closing elements are disallowed. Use regular end tag <${tagName}></${tagName}> instead of self-closing <${tagName}/>.`,
8266
+ description: `Self-closing elements are disallowed. Use regular end tag <${context}></${context}> instead of self-closing <${context}/>.`,
8370
8267
  url: "https://html-validate.org/rules/no-self-closing.html"
8371
8268
  };
8372
8269
  }
@@ -8944,7 +8841,7 @@ class ScriptElement extends Rule {
8944
8841
  setup() {
8945
8842
  this.on("tag:end", (event) => {
8946
8843
  const node = event.target;
8947
- if (!node || node.tagName !== "script") {
8844
+ if (node?.tagName !== "script") {
8948
8845
  return;
8949
8846
  }
8950
8847
  if (node.closed !== NodeClosed.EndTag) {
@@ -10157,13 +10054,13 @@ class ValidID extends Rule {
10157
10054
  }
10158
10055
 
10159
10056
  class VoidContent extends Rule {
10160
- documentation(tagName) {
10057
+ documentation(context) {
10161
10058
  const doc = {
10162
10059
  description: "HTML void elements cannot have any content and must not have content or end tag.",
10163
10060
  url: "https://html-validate.org/rules/void-content.html"
10164
10061
  };
10165
- if (tagName) {
10166
- doc.description = `<${tagName}> is a void element and must not have content or end tag.`;
10062
+ if (context) {
10063
+ doc.description = `<${context}> is a void element and must not have content or end tag.`;
10167
10064
  }
10168
10065
  return doc;
10169
10066
  }
@@ -10466,7 +10363,7 @@ class H37 extends Rule {
10466
10363
  const defaults$1 = {
10467
10364
  strict: false
10468
10365
  };
10469
- const { enum: validScopes } = html5.th.attributes?.scope;
10366
+ const { enum: validScopes } = html5.th.attributes.scope;
10470
10367
  const joinedScopes = naturalJoin(validScopes);
10471
10368
  const td = 0;
10472
10369
  const th = 1;
@@ -10564,7 +10461,7 @@ class H67 extends Rule {
10564
10461
  setup() {
10565
10462
  this.on("tag:end", (event) => {
10566
10463
  const node = event.target;
10567
- if (!node || node.tagName !== "img") {
10464
+ if (node?.tagName !== "img") {
10568
10465
  return;
10569
10466
  }
10570
10467
  const title = node.getAttribute("title");
@@ -10707,6 +10604,172 @@ const bundledRules = {
10707
10604
  ...bundledRules$1
10708
10605
  };
10709
10606
 
10607
+ const $schema = "http://json-schema.org/draft-06/schema#";
10608
+ const $id = "https://html-validate.org/schemas/config.json";
10609
+ const type = "object";
10610
+ const additionalProperties = false;
10611
+ const properties = {
10612
+ $schema: {
10613
+ type: "string"
10614
+ },
10615
+ root: {
10616
+ type: "boolean",
10617
+ title: "Mark as root configuration",
10618
+ description: "If this is set to true no further configurations will be searched.",
10619
+ "default": false
10620
+ },
10621
+ "extends": {
10622
+ type: "array",
10623
+ items: {
10624
+ type: "string"
10625
+ },
10626
+ title: "Configurations to extend",
10627
+ description: "Array of shareable or builtin configurations to extend."
10628
+ },
10629
+ elements: {
10630
+ type: "array",
10631
+ items: {
10632
+ anyOf: [
10633
+ {
10634
+ type: "string"
10635
+ },
10636
+ {
10637
+ type: "object"
10638
+ }
10639
+ ]
10640
+ },
10641
+ title: "Element metadata to load",
10642
+ description: "Array of modules, plugins or files to load element metadata from. Use <rootDir> to refer to the folder with the package.json file.",
10643
+ examples: [
10644
+ [
10645
+ "html-validate:recommended",
10646
+ "plugin:recommended",
10647
+ "module",
10648
+ "./local-file.json"
10649
+ ]
10650
+ ]
10651
+ },
10652
+ plugins: {
10653
+ type: "array",
10654
+ items: {
10655
+ anyOf: [
10656
+ {
10657
+ type: "string"
10658
+ },
10659
+ {
10660
+ type: "object"
10661
+ }
10662
+ ]
10663
+ },
10664
+ title: "Plugins to load",
10665
+ description: "Array of plugins load. Use <rootDir> to refer to the folder with the package.json file.",
10666
+ examples: [
10667
+ [
10668
+ "my-plugin",
10669
+ "./local-plugin"
10670
+ ]
10671
+ ]
10672
+ },
10673
+ transform: {
10674
+ type: "object",
10675
+ additionalProperties: {
10676
+ anyOf: [
10677
+ {
10678
+ type: "string"
10679
+ },
10680
+ {
10681
+ "function": true
10682
+ }
10683
+ ]
10684
+ },
10685
+ title: "File transformations to use.",
10686
+ description: "Object where key is regular expression to match filename and value is name of transformer or a function.",
10687
+ examples: [
10688
+ {
10689
+ "^.*\\.foo$": "my-transformer",
10690
+ "^.*\\.bar$": "my-plugin",
10691
+ "^.*\\.baz$": "my-plugin:named"
10692
+ }
10693
+ ]
10694
+ },
10695
+ rules: {
10696
+ type: "object",
10697
+ patternProperties: {
10698
+ ".*": {
10699
+ anyOf: [
10700
+ {
10701
+ "enum": [
10702
+ 0,
10703
+ 1,
10704
+ 2,
10705
+ "off",
10706
+ "warn",
10707
+ "error"
10708
+ ]
10709
+ },
10710
+ {
10711
+ type: "array",
10712
+ minItems: 1,
10713
+ maxItems: 1,
10714
+ items: [
10715
+ {
10716
+ "enum": [
10717
+ 0,
10718
+ 1,
10719
+ 2,
10720
+ "off",
10721
+ "warn",
10722
+ "error"
10723
+ ]
10724
+ }
10725
+ ]
10726
+ },
10727
+ {
10728
+ type: "array",
10729
+ minItems: 2,
10730
+ maxItems: 2,
10731
+ items: [
10732
+ {
10733
+ "enum": [
10734
+ 0,
10735
+ 1,
10736
+ 2,
10737
+ "off",
10738
+ "warn",
10739
+ "error"
10740
+ ]
10741
+ },
10742
+ {
10743
+ }
10744
+ ]
10745
+ }
10746
+ ]
10747
+ }
10748
+ },
10749
+ title: "Rule configuration.",
10750
+ description: "Enable/disable rules, set severity. Some rules have additional configuration like style or patterns to use.",
10751
+ examples: [
10752
+ {
10753
+ foo: "error",
10754
+ bar: "off",
10755
+ baz: [
10756
+ "error",
10757
+ {
10758
+ style: "camelcase"
10759
+ }
10760
+ ]
10761
+ }
10762
+ ]
10763
+ }
10764
+ };
10765
+ var configurationSchema = {
10766
+ $schema: $schema,
10767
+ $id: $id,
10768
+ type: type,
10769
+ additionalProperties: additionalProperties,
10770
+ properties: properties
10771
+ };
10772
+
10710
10773
  function dumpTree(root) {
10711
10774
  const lines = [];
10712
10775
  function decoration(node) {
@@ -11842,7 +11905,7 @@ class EventHandler {
11842
11905
  }
11843
11906
 
11844
11907
  const name = "html-validate";
11845
- const version = "10.1.1";
11908
+ const version = "10.2.1";
11846
11909
  const bugs = "https://gitlab.com/html-validate/html-validate/issues/new";
11847
11910
 
11848
11911
  function freeze(src) {
@@ -12575,9 +12638,9 @@ class Parser {
12575
12638
  * Trigger close events for any still open elements.
12576
12639
  */
12577
12640
  closeTree(source, location) {
12578
- let active;
12579
12641
  const documentElement = this.dom.root;
12580
- while ((active = this.dom.getActive()) && !active.isRootElement()) {
12642
+ let active = this.dom.getActive();
12643
+ while (!active.isRootElement()) {
12581
12644
  if (active.meta?.implicitClosed) {
12582
12645
  active.closed = NodeClosed.ImplicitClosed;
12583
12646
  this.closeElement(source, documentElement, active, location);
@@ -12585,6 +12648,7 @@ class Parser {
12585
12648
  this.closeElement(source, null, active, location);
12586
12649
  }
12587
12650
  this.dom.popActive();
12651
+ active = this.dom.getActive();
12588
12652
  }
12589
12653
  }
12590
12654
  }
@@ -12951,8 +13015,8 @@ function getUnnamedTransformerFromPlugin(name, plugin) {
12951
13015
  throw new ConfigError(`Plugin does not expose any transformers`);
12952
13016
  }
12953
13017
  if (typeof plugin.transformer !== "function") {
12954
- if (plugin.transformer.default) {
12955
- return plugin.transformer.default;
13018
+ if (plugin.transformer["default"]) {
13019
+ return plugin.transformer["default"];
12956
13020
  }
12957
13021
  throw new ConfigError(
12958
13022
  `Transformer "${name}" refers to unnamed transformer but plugin exposes only named.`
@@ -13181,7 +13245,7 @@ function checkstyleFormatter(results) {
13181
13245
  output += "</checkstyle>\n";
13182
13246
  return output;
13183
13247
  }
13184
- const formatter$3 = checkstyleFormatter;
13248
+ const formatter$2 = checkstyleFormatter;
13185
13249
 
13186
13250
  const defaults = {
13187
13251
  showLink: true,
@@ -13356,7 +13420,7 @@ function codeframe(results, options) {
13356
13420
  function jsonFormatter(results) {
13357
13421
  return JSON.stringify(results);
13358
13422
  }
13359
- const formatter$2 = jsonFormatter;
13423
+ const formatter$1 = jsonFormatter;
13360
13424
 
13361
13425
  function linkSummary(results) {
13362
13426
  const urls = results.reduce((result, it) => {
@@ -13385,7 +13449,6 @@ function stylish(results) {
13385
13449
  const links = linkSummary(results);
13386
13450
  return `${errors}${links}`;
13387
13451
  }
13388
- const formatter$1 = stylish;
13389
13452
 
13390
13453
  function textFormatter(results) {
13391
13454
  let output = "";
@@ -13415,10 +13478,10 @@ function textFormatter(results) {
13415
13478
  const formatter = textFormatter;
13416
13479
 
13417
13480
  const availableFormatters = {
13418
- checkstyle: formatter$3,
13481
+ checkstyle: formatter$2,
13419
13482
  codeframe,
13420
- json: formatter$2,
13421
- stylish: formatter$1,
13483
+ json: formatter$1,
13484
+ stylish,
13422
13485
  text: formatter
13423
13486
  };
13424
13487
  function getFormatter(name) {
@@ -14246,5 +14309,5 @@ const engines = {
14246
14309
 
14247
14310
  var workerPath = "./jest-worker.js";
14248
14311
 
14249
- export { compatibilityCheckImpl as $, Attribute as A, Reporter as B, Config as C, DOMNode as D, definePlugin as E, ruleExists as F, walk as G, HtmlElement as H, EventHandler as I, engines as J, normalizeSource as K, transformSource as L, MetaCopyableProperty as M, NodeClosed as N, Engine as O, Parser as P, transformSourceSync as Q, ResolvedConfig as R, Severity as S, TextNode as T, UserError as U, Validator as V, WrappedError as W, transformFilename as X, transformFilenameSync as Y, configurationSchema as Z, isThenable as _, ConfigError as a, workerPath as a0, codeframe as a1, name as a2, bugs as a3, ConfigLoader as b, defineConfig as c, deepmerge as d, ensureError as e, StaticConfigLoader as f, getFormatter as g, DOMTokenList as h, ignore as i, DOMTree as j, DynamicValue as k, NodeType as l, NestedError as m, SchemaValidationError as n, isUserError as o, presets as p, MetaTable as q, TextContent$1 as r, staticResolver as s, Rule as t, ariaNaming as u, version as v, TextClassification as w, classifyNodeText as x, keywordPatternMatcher as y, sliceLocation as z };
14312
+ export { compatibilityCheckImpl as $, Attribute as A, Reporter as B, Config as C, DOMNode as D, definePlugin as E, ruleExists as F, walk as G, HtmlElement as H, EventHandler as I, engines as J, normalizeSource as K, transformSource as L, MetaCopyableProperty as M, NodeClosed as N, Engine as O, Parser as P, transformSourceSync as Q, ResolvedConfig as R, Severity as S, TextNode as T, UserError as U, Validator as V, WrappedError as W, transformFilename as X, transformFilenameSync as Y, configurationSchema as Z, isThenable as _, ConfigError as a, workerPath as a0, codeframe as a1, name as a2, bugs as a3, ConfigLoader as b, defineConfig as c, deepmerge as d, ensureError as e, StaticConfigLoader as f, getFormatter as g, DOMTokenList as h, ignore as i, DOMTree as j, DynamicValue as k, NodeType as l, NestedError as m, SchemaValidationError as n, isUserError as o, presets as p, MetaTable as q, TextContent$1 as r, staticResolver as s, Rule as t, TextClassification as u, version as v, ariaNaming as w, classifyNodeText as x, keywordPatternMatcher as y, sliceLocation as z };
14250
14313
  //# sourceMappingURL=core.js.map