html-validate 9.0.0-rc.7 → 9.0.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/es/core.js CHANGED
@@ -645,7 +645,7 @@ const patternProperties = {
645
645
  type: "boolean"
646
646
  },
647
647
  {
648
- $ref: "#/definitions/expression"
648
+ "function": true
649
649
  }
650
650
  ]
651
651
  },
@@ -746,59 +746,11 @@ const definitions = {
746
746
  {
747
747
  type: "boolean"
748
748
  },
749
- {
750
- $ref: "#/definitions/expression"
751
- },
752
749
  {
753
750
  "function": true
754
751
  }
755
752
  ]
756
753
  },
757
- expression: {
758
- type: "array",
759
- minItems: 2,
760
- maxItems: 2,
761
- items: [
762
- {
763
- type: "string",
764
- "enum": [
765
- "isDescendant",
766
- "hasAttribute",
767
- "matchAttribute"
768
- ]
769
- },
770
- {
771
- anyOf: [
772
- {
773
- type: "string"
774
- },
775
- {
776
- $ref: "#/definitions/operation"
777
- }
778
- ]
779
- }
780
- ]
781
- },
782
- operation: {
783
- type: "array",
784
- minItems: 3,
785
- maxItems: 3,
786
- items: [
787
- {
788
- type: "string"
789
- },
790
- {
791
- type: "string",
792
- "enum": [
793
- "!=",
794
- "="
795
- ]
796
- },
797
- {
798
- type: "string"
799
- }
800
- ]
801
- },
802
754
  deprecatedElement: {
803
755
  type: "object",
804
756
  additionalProperties: false,
@@ -1158,31 +1110,6 @@ function migrateElement(src) {
1158
1110
  return result;
1159
1111
  }
1160
1112
 
1161
- function isDescendant(node, tagName) {
1162
- let cur = node.parent;
1163
- while (cur && !cur.isRootElement()) {
1164
- if (cur.is(tagName)) {
1165
- return true;
1166
- }
1167
- cur = cur.parent;
1168
- }
1169
- return false;
1170
- }
1171
-
1172
- function hasAttribute(node, attr) {
1173
- return node.hasAttribute(attr);
1174
- }
1175
-
1176
- function matchAttribute(node, key, op, value) {
1177
- const nodeValue = (node.getAttributeValue(key) ?? "").toLowerCase();
1178
- switch (op) {
1179
- case "!=":
1180
- return nodeValue !== value;
1181
- case "=":
1182
- return nodeValue === value;
1183
- }
1184
- }
1185
-
1186
1113
  const dynamicKeys = [
1187
1114
  "metadata",
1188
1115
  "flow",
@@ -1193,16 +1120,11 @@ const dynamicKeys = [
1193
1120
  "interactive",
1194
1121
  "labelable"
1195
1122
  ];
1196
- const functionTable = {
1197
- isDescendant: isDescendantFacade,
1198
- hasAttribute: hasAttributeFacade,
1199
- matchAttribute: matchAttributeFacade
1200
- };
1201
1123
  const schemaCache = /* @__PURE__ */ new Map();
1202
1124
  function clone(src) {
1203
1125
  return JSON.parse(JSON.stringify(src));
1204
1126
  }
1205
- function overwriteMerge$1(a, b) {
1127
+ function overwriteMerge$1(_a, b) {
1206
1128
  return b;
1207
1129
  }
1208
1130
  class MetaTable {
@@ -1396,13 +1318,8 @@ class MetaTable {
1396
1318
  function expandProperties(node, entry) {
1397
1319
  for (const key of dynamicKeys) {
1398
1320
  const property = entry[key];
1399
- if (!property) {
1400
- continue;
1401
- }
1402
1321
  if (typeof property === "function") {
1403
1322
  setMetaProperty(entry, key, property(node._adapter));
1404
- } else if (typeof property !== "boolean") {
1405
- setMetaProperty(entry, key, evaluateProperty(node, property));
1406
1323
  }
1407
1324
  }
1408
1325
  if (typeof entry.focusable === "function") {
@@ -1432,55 +1349,6 @@ function expandRegex(entry) {
1432
1349
  }
1433
1350
  }
1434
1351
  }
1435
- function evaluateProperty(node, expr) {
1436
- const [func, options] = parseExpression(expr);
1437
- return func(node, options);
1438
- }
1439
- function parseExpression(expr) {
1440
- if (typeof expr === "string") {
1441
- return parseExpression([expr, {}]);
1442
- } else {
1443
- const [funcName, options] = expr;
1444
- const func = functionTable[funcName];
1445
- if (!func) {
1446
- throw new Error(`Failed to find function "${funcName}" when evaluating property expression`);
1447
- }
1448
- return [func, options];
1449
- }
1450
- }
1451
- function isDescendantFacade(node, tagName) {
1452
- if (typeof tagName !== "string") {
1453
- throw new Error(
1454
- `Property expression "isDescendant" must take string argument when evaluating metadata for <${node.tagName}>`
1455
- );
1456
- }
1457
- return isDescendant(node, tagName);
1458
- }
1459
- function hasAttributeFacade(node, attr) {
1460
- if (typeof attr !== "string") {
1461
- throw new Error(
1462
- `Property expression "hasAttribute" must take string argument when evaluating metadata for <${node.tagName}>`
1463
- );
1464
- }
1465
- return hasAttribute(node, attr);
1466
- }
1467
- function matchAttributeFacade(node, match) {
1468
- if (!Array.isArray(match) || match.length !== 3) {
1469
- throw new Error(
1470
- `Property expression "matchAttribute" must take [key, op, value] array as argument when evaluating metadata for <${node.tagName}>`
1471
- );
1472
- }
1473
- const [key, op, value] = match.map((x) => x.toLowerCase());
1474
- switch (op) {
1475
- case "!=":
1476
- case "=":
1477
- return matchAttribute(node, key, op, value);
1478
- default:
1479
- throw new Error(
1480
- `Property expression "matchAttribute" has invalid operator "${op}" when evaluating metadata for <${node.tagName}>`
1481
- );
1482
- }
1483
- }
1484
1352
 
1485
1353
  class DynamicValue {
1486
1354
  expr;
@@ -3416,10 +3284,17 @@ const properties = {
3416
3284
  transform: {
3417
3285
  type: "object",
3418
3286
  additionalProperties: {
3419
- type: "string"
3287
+ anyOf: [
3288
+ {
3289
+ type: "string"
3290
+ },
3291
+ {
3292
+ "function": true
3293
+ }
3294
+ ]
3420
3295
  },
3421
3296
  title: "File transformations to use.",
3422
- description: "Object where key is regular expression to match filename and value is name of transformer.",
3297
+ description: "Object where key is regular expression to match filename and value is name of transformer or a function.",
3423
3298
  examples: [
3424
3299
  {
3425
3300
  "^.*\\.foo$": "my-transformer",
@@ -3853,10 +3728,6 @@ function partition(values, predicate) {
3853
3728
  }, initial);
3854
3729
  }
3855
3730
 
3856
- const remapEvents = {
3857
- "tag:open": "tag:start",
3858
- "tag:close": "tag:end"
3859
- };
3860
3731
  const ajv$1 = new Ajv({ strict: true, strictTuples: true, strictTypes: true });
3861
3732
  ajv$1.addMetaSchema(ajvSchemaDraft);
3862
3733
  function getSchemaValidator(ruleId, properties) {
@@ -4076,10 +3947,6 @@ class Rule {
4076
3947
  return {};
4077
3948
  }
4078
3949
  on(event, ...args) {
4079
- const remap = remapEvents[event];
4080
- if (remap) {
4081
- event = remap;
4082
- }
4083
3950
  const callback = args.pop();
4084
3951
  const filter = args.pop() ?? (() => true);
4085
3952
  return this.parser.on(event, (_event, data) => {
@@ -11157,18 +11024,14 @@ class ResolvedConfig {
11157
11024
  if (!transformer) {
11158
11025
  return Promise.resolve([source]);
11159
11026
  }
11160
- const fn = await getCachedTransformerFunction(
11161
- this.cache,
11162
- resolvers,
11163
- transformer.name,
11164
- this.plugins
11165
- );
11027
+ const fn = transformer.kind === "import" ? await getCachedTransformerFunction(this.cache, resolvers, transformer.name, this.plugins) : transformer.function;
11028
+ const name = transformer.kind === "import" ? transformer.name : transformer.function.name;
11166
11029
  try {
11167
11030
  const result = await fn.call(context, source);
11168
11031
  const transformedSources = await Promise.all(toArray$1(result));
11169
11032
  for (const source2 of transformedSources) {
11170
11033
  source2.transformedBy ??= [];
11171
- source2.transformedBy.push(transformer.name);
11034
+ source2.transformedBy.push(name);
11172
11035
  }
11173
11036
  return transformedSources;
11174
11037
  } catch (err) {
@@ -11187,6 +11050,9 @@ class ResolvedConfig {
11187
11050
  * transformer. Default is to use filename from source.
11188
11051
  * @returns A list of transformed sources ready for validation.
11189
11052
  */
11053
+ /* eslint-disable-next-line complexity -- there is many ifs'n buts here but
11054
+ * hard to break this down without loosing the little clarity that is still
11055
+ * left */
11190
11056
  transformSourceSync(resolvers, source, filename) {
11191
11057
  const transformer = this.findTransformer(filename ?? source.filename);
11192
11058
  const context = {
@@ -11200,7 +11066,8 @@ class ResolvedConfig {
11200
11066
  if (!transformer) {
11201
11067
  return [source];
11202
11068
  }
11203
- const fn = getCachedTransformerFunction(this.cache, resolvers, transformer.name, this.plugins);
11069
+ const fn = transformer.kind === "import" ? getCachedTransformerFunction(this.cache, resolvers, transformer.name, this.plugins) : transformer.function;
11070
+ const name = transformer.kind === "import" ? transformer.name : transformer.function.name;
11204
11071
  if (isThenable(fn)) {
11205
11072
  throw new UserError(asyncInSyncTransformError);
11206
11073
  }
@@ -11215,7 +11082,7 @@ class ResolvedConfig {
11215
11082
  }
11216
11083
  for (const source2 of transformedSources) {
11217
11084
  source2.transformedBy ??= [];
11218
- source2.transformedBy.push(transformer.name);
11085
+ source2.transformedBy.push(name);
11219
11086
  }
11220
11087
  return transformedSources;
11221
11088
  } catch (err) {
@@ -11286,8 +11153,9 @@ class ResolvedConfig {
11286
11153
 
11287
11154
  const ajv = new Ajv({ strict: true, strictTuples: true, strictTypes: true });
11288
11155
  ajv.addMetaSchema(ajvSchemaDraft);
11156
+ ajv.addKeyword(ajvFunctionKeyword);
11289
11157
  const validator = ajv.compile(configurationSchema);
11290
- function overwriteMerge(a, b) {
11158
+ function overwriteMerge(_a, b) {
11291
11159
  return b;
11292
11160
  }
11293
11161
  function mergeInternal(base, rhs) {
@@ -11309,9 +11177,13 @@ function toArray(value) {
11309
11177
  }
11310
11178
  }
11311
11179
  function transformerEntries(transform) {
11312
- return Object.entries(transform).map(([pattern, name]) => {
11180
+ return Object.entries(transform).map(([pattern, value]) => {
11313
11181
  const regex = new RegExp(pattern);
11314
- return { pattern: regex, name };
11182
+ if (typeof value === "string") {
11183
+ return { kind: "import", pattern: regex, name: value };
11184
+ } else {
11185
+ return { kind: "function", pattern: regex, function: value };
11186
+ }
11315
11187
  });
11316
11188
  }
11317
11189
  class Config {
@@ -11491,9 +11363,6 @@ class Config {
11491
11363
  return mergeInternal(base, this.config);
11492
11364
  }
11493
11365
  async extendConfigAsync(entries) {
11494
- if (entries.length === 0) {
11495
- return this.config;
11496
- }
11497
11366
  let base = {};
11498
11367
  for (const entry of entries) {
11499
11368
  let extended;
@@ -11795,32 +11664,15 @@ class ConfigLoader {
11795
11664
  if (this._globalConfig) {
11796
11665
  return this._globalConfig;
11797
11666
  }
11798
- const defaults = Config.empty();
11799
11667
  const config = this._configData ? this.loadFromObject(this._configData) : this.defaultConfig();
11800
11668
  if (isThenable(config)) {
11801
11669
  return config.then((config2) => {
11802
- const merged = defaults.merge(this.resolvers, config2);
11803
- if (isThenable(merged)) {
11804
- return merged.then((merged2) => {
11805
- this._globalConfig = merged2;
11806
- return this._globalConfig;
11807
- });
11808
- } else {
11809
- this._globalConfig = merged;
11810
- return this._globalConfig;
11811
- }
11670
+ this._globalConfig = config2;
11671
+ return this._globalConfig;
11812
11672
  });
11813
11673
  } else {
11814
- const merged = defaults.merge(this.resolvers, config);
11815
- if (isThenable(merged)) {
11816
- return merged.then((merged2) => {
11817
- this._globalConfig = merged2;
11818
- return this._globalConfig;
11819
- });
11820
- } else {
11821
- this._globalConfig = merged;
11822
- return this._globalConfig;
11823
- }
11674
+ this._globalConfig = config;
11675
+ return this._globalConfig;
11824
11676
  }
11825
11677
  }
11826
11678
  /**
@@ -11834,16 +11686,11 @@ class ConfigLoader {
11834
11686
  if (this._globalConfig) {
11835
11687
  return this._globalConfig;
11836
11688
  }
11837
- const defaults = Config.empty();
11838
11689
  const config = this._configData ? this.loadFromObject(this._configData) : this.defaultConfig();
11839
11690
  if (isThenable(config)) {
11840
11691
  throw new UserError("Cannot load async config from sync function");
11841
11692
  }
11842
- const merged = defaults.merge(this.resolvers, config);
11843
- if (isThenable(merged)) {
11844
- throw new UserError("Cannot load async config from sync function");
11845
- }
11846
- this._globalConfig = merged;
11693
+ this._globalConfig = config;
11847
11694
  return this._globalConfig;
11848
11695
  }
11849
11696
  /**
@@ -13501,7 +13348,7 @@ class HtmlValidate {
13501
13348
  }
13502
13349
 
13503
13350
  const name = "html-validate";
13504
- const version = "9.0.0-rc.7";
13351
+ const version = "9.0.0";
13505
13352
  const bugs = "https://gitlab.com/html-validate/html-validate/issues/new";
13506
13353
 
13507
13354
  function definePlugin(plugin) {
@@ -14465,8 +14312,12 @@ function requireIgnore () {
14465
14312
  var ignoreExports = /*@__PURE__*/ requireIgnore();
14466
14313
  var ignore = /*@__PURE__*/getDefaultExportFromCjs(ignoreExports);
14467
14314
 
14315
+ function importFunction(id) {
14316
+ return import(id);
14317
+ }
14318
+
14468
14319
  async function internalImport(id) {
14469
- const { default: defaultImport } = await import(id);
14320
+ const { default: defaultImport } = await importFunction(id);
14470
14321
  if (!defaultImport) {
14471
14322
  throw new UserError(`"${id}" does not have a default export`);
14472
14323
  }