html-validate 7.6.0 → 7.7.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.
@@ -1,7 +1,7 @@
1
1
  import path from 'path';
2
2
  import kleur from 'kleur';
3
3
  import minimist from 'minimist';
4
- import { t as name, v as version, e as SchemaValidationError, U as UserError, u as bugs } from './core.js';
4
+ import { w as name, v as version, e as SchemaValidationError, U as UserError, x as bugs } from './core.js';
5
5
  import 'fs';
6
6
  import 'ajv';
7
7
  import 'deepmerge';
@@ -1,5 +1,5 @@
1
- import { s as Report, c as ConfigLoader, H as HtmlValidate, a as ConfigData } from './core.js';
2
- export { A as AttributeData, a2 as AttributeEvent, f as CSSStyleDeclaration, af as CompatibilityOptions, a4 as ConditionalEvent, C as Config, a as ConfigData, b as ConfigError, c as ConfigLoader, Q as ConfigReadyEvent, a7 as DOMLoadEvent, a8 as DOMReadyEvent, x as DeferredMessage, a5 as DirectiveEvent, a6 as DoctypeEvent, D as DynamicValue, a1 as ElementReadyEvent, O as Event, K as EventCallback, E as EventDump, J as EventHandler, ab as FileSystemConfigLoader, ac as Formatter, e as HtmlElement, H as HtmlValidate, aa as ListenEventMap, L as Location, u as Message, m as MetaCopyableProperty, M as MetaData, j as MetaDataTable, k as MetaElement, l as MetaTable, i as NestedError, N as NodeClosed, G as Parser, F as Plugin, P as ProcessElementContext, s as Report, t as Reporter, w as Result, R as Rule, n as RuleDocumentation, h as SchemaValidationError, S as Severity, r as Source, V as SourceReadyEvent, d as StaticConfigLoader, $ as TagCloseEvent, _ as TagEndEvent, Z as TagOpenEvent, a0 as TagReadyEvent, Y as TagStartEvent, B as TemplateExtractor, q as TextClassification, T as TextNode, g as TokenDump, X as TokenEvent, y as TransformContext, z as Transformer, a9 as TriggerEventMap, U as UserError, a3 as WhitespaceEvent, W as WrappedError, o as classifyNodeText, ae as compatibilityCheck, p as configPresets, ad as formatterFactory, I as ruleExists, v as version } from './core.js';
1
+ import { x as Report, c as ConfigLoader, H as HtmlValidate, a as ConfigData } from './core.js';
2
+ export { A as AttributeData, a6 as AttributeEvent, f as CSSStyleDeclaration, aj as CompatibilityOptions, a8 as ConditionalEvent, C as Config, a as ConfigData, b as ConfigError, c as ConfigLoader, Z as ConfigReadyEvent, ab as DOMLoadEvent, ac as DOMReadyEvent, F as DeferredMessage, a9 as DirectiveEvent, aa as DoctypeEvent, D as DynamicValue, a5 as ElementReadyEvent, Y as Event, X as EventCallback, E as EventDump, V as EventHandler, af as FileSystemConfigLoader, ag as Formatter, e as HtmlElement, H as HtmlValidate, ae as ListenEventMap, L as Location, z as Message, l as MetaAttribute, m as MetaAttributeAllowedCallback, o as MetaCopyableProperty, M as MetaData, j as MetaDataTable, k as MetaElement, n as MetaTable, i as NestedError, N as NodeClosed, O as Parser, K as Plugin, P as ProcessElementContext, x as Report, y as Reporter, B as Result, R as Rule, s as RuleDocumentation, h as SchemaValidationError, S as Severity, w as Source, _ as SourceReadyEvent, d as StaticConfigLoader, a3 as TagCloseEvent, a2 as TagEndEvent, a1 as TagOpenEvent, a4 as TagReadyEvent, a0 as TagStartEvent, J as TemplateExtractor, u as TextClassification, T as TextNode, g as TokenDump, $ as TokenEvent, G as TransformContext, I as Transformer, ad as TriggerEventMap, U as UserError, a7 as WhitespaceEvent, W as WrappedError, t as classifyNodeText, ai as compatibilityCheck, p as configPresets, q as defineMetadata, ah as formatterFactory, r as metadataHelper, Q as ruleExists, v as version } from './core.js';
3
3
  import 'ajv';
4
4
 
5
5
  interface ExpandOptions {
package/dist/es/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { C as Config, a as ConfigError, b as ConfigLoader, D as DynamicValue, E as EventHandler, F as FileSystemConfigLoader, d as HtmlElement, H as HtmlValidate, g as MetaCopyableProperty, M as MetaTable, f as NestedError, N as NodeClosed, P as Parser, j as Reporter, R as Rule, e as SchemaValidationError, S as Severity, c as StaticConfigLoader, k as TemplateExtractor, i as TextClassification, T as TextNode, U as UserError, W as WrappedError, h as classifyNodeText, q as compatibilityCheck, p as configPresets, l as formatterFactory, r as ruleExists, v as version } from './core.js';
1
+ export { C as Config, a as ConfigError, b as ConfigLoader, D as DynamicValue, E as EventHandler, F as FileSystemConfigLoader, d as HtmlElement, H as HtmlValidate, g as MetaCopyableProperty, M as MetaTable, f as NestedError, N as NodeClosed, P as Parser, k as Reporter, R as Rule, e as SchemaValidationError, S as Severity, c as StaticConfigLoader, l as TemplateExtractor, j as TextClassification, T as TextNode, U as UserError, W as WrappedError, i as classifyNodeText, t as compatibilityCheck, p as configPresets, h as defineMetadata, n as formatterFactory, m as metadataHelper, r as ruleExists, v as version } from './core.js';
2
2
  import 'fs';
3
3
  export { C as CLI } from './cli.js';
4
4
  import '@sidvind/better-ajv-errors';
@@ -1,5 +1,5 @@
1
1
  import deepmerge from 'deepmerge';
2
- import { F as FileSystemConfigLoader, H as HtmlValidate, s as codeframe } from './core.js';
2
+ import { F as FileSystemConfigLoader, H as HtmlValidate, u as codeframe } from './core.js';
3
3
  import kleur from 'kleur';
4
4
  import { toMatchSnapshot, toMatchInlineSnapshot } from 'jest-snapshot';
5
5
  import * as jestDiffDefault from 'jest-diff';
package/dist/es/jest.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { u as Message, a as ConfigData } from './core.js';
1
+ import { z as Message, a as ConfigData } from './core.js';
2
2
  import 'ajv';
3
3
 
4
4
  declare global {
@@ -1,4 +1,4 @@
1
- import { z as Transformer, r as Source } from './core.js';
1
+ import { I as Transformer, w as Source } from './core.js';
2
2
  import 'ajv';
3
3
 
4
4
  /**
@@ -260,6 +260,10 @@
260
260
  "type": "object",
261
261
  "additionalProperties": false,
262
262
  "properties": {
263
+ "allowed": {
264
+ "function": true,
265
+ "title": "Set to a function to evaluate if this attribute is allowed in this context"
266
+ },
263
267
  "boolean": {
264
268
  "type": "boolean",
265
269
  "title": "Set to true if this is a boolean attribute"
package/elements/html5.js CHANGED
@@ -1,6 +1,11 @@
1
1
  /* eslint-disable sonarjs/no-duplicate-string */
2
2
 
3
- module.exports = {
3
+ const { defineMetadata, metadataHelper, DynamicValue } = require("html-validate");
4
+
5
+ const { allowedIfAttributeIsPresent, allowedIfAttributeIsAbsent, allowedIfAttributeHasValue } =
6
+ metadataHelper;
7
+
8
+ module.exports = defineMetadata({
4
9
  "*": {
5
10
  attributes: {
6
11
  contenteditable: {
@@ -47,21 +52,44 @@ module.exports = {
47
52
  deprecated: true,
48
53
  },
49
54
  download: {
55
+ allowed: allowedIfAttributeIsPresent("href"),
50
56
  omit: true,
51
57
  enum: ["/.+/"],
52
58
  },
53
59
  href: {
54
60
  enum: ["/.*/"],
55
61
  },
62
+ hreflang: {
63
+ allowed: allowedIfAttributeIsPresent("href"),
64
+ },
65
+ itemprop: {
66
+ allowed: allowedIfAttributeIsPresent("href"),
67
+ },
56
68
  methods: {
57
69
  deprecated: true,
58
70
  },
59
71
  name: {
60
72
  deprecated: true,
61
73
  },
74
+ ping: {
75
+ allowed: allowedIfAttributeIsPresent("href"),
76
+ },
77
+ referrerpolicy: {
78
+ allowed: allowedIfAttributeIsPresent("href"),
79
+ },
80
+ rel: {
81
+ allowed: allowedIfAttributeIsPresent("href"),
82
+ },
62
83
  shape: {
63
84
  deprecated: true,
64
85
  },
86
+ target: {
87
+ allowed: allowedIfAttributeIsPresent("href"),
88
+ enum: ["/[^_].*/", "_blank", "_self", "_parent", "_top"],
89
+ },
90
+ type: {
91
+ allowed: allowedIfAttributeIsPresent("href"),
92
+ },
65
93
  urn: {
66
94
  deprecated: true,
67
95
  },
@@ -108,12 +136,59 @@ module.exports = {
108
136
  phrasing: ["isDescendant", "map"],
109
137
  void: true,
110
138
  attributes: {
139
+ alt: {},
140
+ coords: {
141
+ allowed(node) {
142
+ const attr = node.getAttribute("shape");
143
+ if (attr && attr.valueMatches("default", false)) {
144
+ return `cannot be used when "shape" attribute is "default"`;
145
+ } else {
146
+ return null;
147
+ }
148
+ },
149
+ },
150
+ download: {
151
+ allowed: allowedIfAttributeIsPresent("href"),
152
+ },
111
153
  nohref: {
112
154
  deprecated: true,
113
155
  },
156
+ itemprop: {
157
+ allowed: allowedIfAttributeIsPresent("href"),
158
+ },
159
+ ping: {
160
+ allowed: allowedIfAttributeIsPresent("href"),
161
+ },
162
+ referrerpolicy: {
163
+ allowed: allowedIfAttributeIsPresent("href"),
164
+ },
165
+ rel: {
166
+ allowed: allowedIfAttributeIsPresent("href"),
167
+ },
114
168
  shape: {
169
+ allowed(node) {
170
+ const attr = node.getAttribute("shape");
171
+ if (!attr || attr.value instanceof DynamicValue) {
172
+ return null;
173
+ }
174
+ const shape = attr.value || "rect";
175
+ switch (shape) {
176
+ case "circ":
177
+ case "circle":
178
+ case "poly":
179
+ case "polygon":
180
+ case "rect":
181
+ case "rectangle":
182
+ return allowedIfAttributeIsPresent("coords")(node);
183
+ }
184
+ return null;
185
+ },
115
186
  enum: ["rect", "circle", "poly", "default"],
116
187
  },
188
+ target: {
189
+ allowed: allowedIfAttributeIsPresent("href"),
190
+ enum: ["/[^_].*/", "_blank", "_self", "_parent", "_top"],
191
+ },
117
192
  },
118
193
  requiredAncestors: ["map"],
119
194
  },
@@ -139,6 +214,13 @@ module.exports = {
139
214
  interactive: ["hasAttribute", "controls"],
140
215
  transparent: ["@flow"],
141
216
  attributes: {
217
+ crossorigin: {
218
+ omit: true,
219
+ enum: ["anonymous", "use-credentials"],
220
+ },
221
+ itemprop: {
222
+ allowed: allowedIfAttributeIsPresent("src"),
223
+ },
142
224
  preload: {
143
225
  omit: true,
144
226
  enum: ["none", "metadata", "auto"],
@@ -287,6 +369,24 @@ module.exports = {
287
369
  disabled: {
288
370
  boolean: true,
289
371
  },
372
+ formaction: {
373
+ allowed: allowedIfAttributeHasValue("type", ["submit"], { defaultValue: "submit" }),
374
+ },
375
+ formenctype: {
376
+ allowed: allowedIfAttributeHasValue("type", ["submit"], { defaultValue: "submit" }),
377
+ },
378
+ formmethod: {
379
+ allowed: allowedIfAttributeHasValue("type", ["submit"], { defaultValue: "submit" }),
380
+ enum: ["get", "post", "dialog"],
381
+ },
382
+ formnovalidate: {
383
+ allowed: allowedIfAttributeHasValue("type", ["submit"], { defaultValue: "submit" }),
384
+ boolean: true,
385
+ },
386
+ formtarget: {
387
+ allowed: allowedIfAttributeHasValue("type", ["submit"], { defaultValue: "submit" }),
388
+ enum: ["/[^_].*/", "_blank", "_self", "_parent", "_top"],
389
+ },
290
390
  type: {
291
391
  required: true,
292
392
  enum: ["submit", "reset", "button"],
@@ -547,6 +647,9 @@ module.exports = {
547
647
  novalidate: {
548
648
  boolean: true,
549
649
  },
650
+ target: {
651
+ enum: ["/[^_].*/", "_blank", "_self", "_parent", "_top"],
652
+ },
550
653
  },
551
654
  permittedContent: ["@flow"],
552
655
  permittedDescendants: [{ exclude: ["@form"] }],
@@ -837,6 +940,34 @@ module.exports = {
837
940
  disabled: {
838
941
  boolean: true,
839
942
  },
943
+ formaction: {
944
+ allowed: allowedIfAttributeHasValue("type", ["submit", "image"], {
945
+ defaultValue: "submit",
946
+ }),
947
+ },
948
+ formenctype: {
949
+ allowed: allowedIfAttributeHasValue("type", ["submit", "image"], {
950
+ defaultValue: "submit",
951
+ }),
952
+ },
953
+ formmethod: {
954
+ allowed: allowedIfAttributeHasValue("type", ["submit", "image"], {
955
+ defaultValue: "submit",
956
+ }),
957
+ enum: ["get", "post", "dialog"],
958
+ },
959
+ formnovalidate: {
960
+ allowed: allowedIfAttributeHasValue("type", ["submit", "image"], {
961
+ defaultValue: "submit",
962
+ }),
963
+ boolean: true,
964
+ },
965
+ formtarget: {
966
+ allowed: allowedIfAttributeHasValue("type", ["submit", "image"], {
967
+ defaultValue: "submit",
968
+ }),
969
+ enum: ["/[^_].*/", "_blank", "_self", "_parent", "_top"],
970
+ },
840
971
  hspace: {
841
972
  deprecated: true,
842
973
  },
@@ -918,6 +1049,7 @@ module.exports = {
918
1049
  interactive: true,
919
1050
  void: true,
920
1051
  labelable: true,
1052
+ deprecated: true,
921
1053
  },
922
1054
 
923
1055
  label: {
@@ -972,6 +1104,38 @@ module.exports = {
972
1104
  metadata: true,
973
1105
  void: true,
974
1106
  attributes: {
1107
+ as: {
1108
+ allowed: allowedIfAttributeHasValue("rel", ["preload", "modulepreload"]),
1109
+ enum: [
1110
+ "audio",
1111
+ "audioworklet",
1112
+ "document",
1113
+ "embed",
1114
+ "fetch",
1115
+ "font",
1116
+ "frame",
1117
+ "iframe",
1118
+ "image",
1119
+ "manifest",
1120
+ "object",
1121
+ "paintworklet",
1122
+ "report",
1123
+ "script",
1124
+ "serviceworker",
1125
+ "sharedworker",
1126
+ "style",
1127
+ "track",
1128
+ "video",
1129
+ "webidentity",
1130
+ "worker",
1131
+ "xslt",
1132
+ ],
1133
+ },
1134
+ blocking: {
1135
+ allowed: allowedIfAttributeHasValue("rel", ["stylesheet", "preload", "modulepreload"]),
1136
+ list: true,
1137
+ enum: ["render"],
1138
+ },
975
1139
  charset: {
976
1140
  deprecated: true,
977
1141
  },
@@ -979,11 +1143,16 @@ module.exports = {
979
1143
  omit: true,
980
1144
  enum: ["anonymous", "use-credentials"],
981
1145
  },
1146
+ disabled: {
1147
+ allowed: allowedIfAttributeHasValue("rel", ["stylesheet"]),
1148
+ boolean: true,
1149
+ },
982
1150
  href: {
983
1151
  required: true,
984
1152
  enum: ["/.+/"],
985
1153
  },
986
1154
  integrity: {
1155
+ allowed: allowedIfAttributeHasValue("rel", ["stylesheet", "preload", "modulepreload"]),
987
1156
  enum: ["/.+/"],
988
1157
  },
989
1158
  methods: {
@@ -1012,6 +1181,12 @@ module.exports = {
1012
1181
  flow: true,
1013
1182
  phrasing: true,
1014
1183
  transparent: true,
1184
+ attributes: {
1185
+ name: {
1186
+ required: true,
1187
+ enum: ["/\\S+/"],
1188
+ },
1189
+ },
1015
1190
  },
1016
1191
 
1017
1192
  mark: {
@@ -1080,6 +1255,21 @@ module.exports = {
1080
1255
  metadata: true,
1081
1256
  void: true,
1082
1257
  attributes: {
1258
+ charset: {
1259
+ enum: ["utf-8"],
1260
+ },
1261
+ content: {
1262
+ allowed: allowedIfAttributeIsPresent("name", "http-equiv", "itemprop"),
1263
+ },
1264
+ itemprop: {
1265
+ allowed: allowedIfAttributeIsAbsent("http-equiv", "name"),
1266
+ },
1267
+ name: {
1268
+ allowed: allowedIfAttributeIsAbsent("http-equiv", "itemprop"),
1269
+ },
1270
+ "http-equiv": {
1271
+ allowed: allowedIfAttributeIsAbsent("name", "itemprop"),
1272
+ },
1083
1273
  scheme: {
1084
1274
  deprecated: true,
1085
1275
  },
@@ -1156,6 +1346,10 @@ module.exports = {
1156
1346
  archive: {
1157
1347
  deprecated: true,
1158
1348
  },
1349
+ blocking: {
1350
+ list: true,
1351
+ enum: ["render"],
1352
+ },
1159
1353
  border: {
1160
1354
  deprecated: true,
1161
1355
  },
@@ -1173,6 +1367,7 @@ module.exports = {
1173
1367
  },
1174
1368
  data: {
1175
1369
  enum: ["/.+/"],
1370
+ required: true,
1176
1371
  },
1177
1372
  datafld: {
1178
1373
  deprecated: true,
@@ -1189,6 +1384,9 @@ module.exports = {
1189
1384
  hspace: {
1190
1385
  deprecated: true,
1191
1386
  },
1387
+ name: {
1388
+ enum: ["/[^_].*/"],
1389
+ },
1192
1390
  standby: {
1193
1391
  deprecated: true,
1194
1392
  },
@@ -1409,6 +1607,7 @@ module.exports = {
1409
1607
  deprecated: true,
1410
1608
  },
1411
1609
  integrity: {
1610
+ allowed: allowedIfAttributeIsPresent("src"),
1412
1611
  enum: ["/.+/"],
1413
1612
  },
1414
1613
  language: {
@@ -1888,6 +2087,13 @@ module.exports = {
1888
2087
  interactive: ["hasAttribute", "controls"],
1889
2088
  transparent: ["@flow"],
1890
2089
  attributes: {
2090
+ crossorigin: {
2091
+ omit: true,
2092
+ enum: ["anonymous", "use-credentials"],
2093
+ },
2094
+ itemprop: {
2095
+ allowed: allowedIfAttributeIsPresent("src"),
2096
+ },
1891
2097
  preload: {
1892
2098
  omit: true,
1893
2099
  enum: ["none", "metadata", "auto"],
@@ -1910,4 +2116,4 @@ module.exports = {
1910
2116
  source: "html32",
1911
2117
  },
1912
2118
  },
1913
- };
2119
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "html-validate",
3
- "version": "7.6.0",
3
+ "version": "7.7.0",
4
4
  "description": "Offline html5 validator",
5
5
  "keywords": [
6
6
  "html",
@@ -48,6 +48,7 @@
48
48
  "jest.{js,d.ts}",
49
49
  "test-utils.{js,d.ts}",
50
50
  "!dist/types/**",
51
+ "!tsconfig.json",
51
52
  "!**/*.snap",
52
53
  "!**/*.spec.{js,ts,d.ts}"
53
54
  ],
@@ -58,10 +59,10 @@
58
59
  "prebuild": "run-s codegen prebuild:*",
59
60
  "build": "run-s build:*",
60
61
  "postbuild": "bash scripts/pkg",
61
- "prebuild:tsc": "tsc --build src",
62
- "build:cjs": "rollup --config rollup.cjs.config.js",
63
- "build:dts": "rollup --config rollup.dts.config.js",
64
- "build:esm": "rollup --config rollup.esm.config.js",
62
+ "prebuild:tsc": "tsc --build src elements",
63
+ "build:cjs": "rollup --config rollup.cjs.config.mjs",
64
+ "build:dts": "rollup --config rollup.dts.config.mjs",
65
+ "build:esm": "rollup --config rollup.esm.config.mjs",
65
66
  "clean": "rm -rf dist public",
66
67
  "codegen": "node scripts/codegen",
67
68
  "compatibility": "scripts/compatibility.sh",
@@ -131,6 +132,9 @@
131
132
  "!src/jest/jest.ts",
132
133
  "!**/__fixtures__/**"
133
134
  ],
135
+ "moduleNameMapper": {
136
+ "^html-validate$": "<rootDir>/src/index.ts"
137
+ },
134
138
  "preset": "@html-validate/jest-config",
135
139
  "roots": [
136
140
  "<rootDir>/docs",
@@ -156,38 +160,38 @@
156
160
  },
157
161
  "devDependencies": {
158
162
  "@html-validate/commitlint-config": "3.0.6",
159
- "@html-validate/eslint-config": "5.5.4",
160
- "@html-validate/eslint-config-jest": "5.5.4",
161
- "@html-validate/eslint-config-typescript": "5.5.4",
163
+ "@html-validate/eslint-config": "5.5.6",
164
+ "@html-validate/eslint-config-jest": "5.5.6",
165
+ "@html-validate/eslint-config-typescript": "5.5.6",
162
166
  "@html-validate/eslint-config-typescript-typeinfo": "5.5.0",
163
167
  "@html-validate/jest-config": "3.5.1",
164
168
  "@html-validate/prettier-config": "2.3.0",
165
169
  "@html-validate/release-scripts": "3.5.9",
166
- "@rollup/plugin-json": "4.1.0",
167
- "@rollup/plugin-replace": "4.0.0",
168
- "@rollup/plugin-typescript": "8.5.0",
169
- "@rollup/plugin-virtual": "2.1.0",
170
+ "@rollup/plugin-json": "5.0.1",
171
+ "@rollup/plugin-replace": "5.0.1",
172
+ "@rollup/plugin-typescript": "9.0.2",
173
+ "@rollup/plugin-virtual": "3.0.1",
170
174
  "@types/babar": "0.2.1",
171
175
  "@types/babel__code-frame": "7.0.3",
172
176
  "@types/estree": "1.0.0",
173
177
  "@types/glob": "8.0.0",
174
- "@types/jest": "29.0.3",
178
+ "@types/jest": "29.2.0",
175
179
  "@types/minimist": "1.2.2",
176
- "@types/node": "14.18.31",
180
+ "@types/node": "14.18.32",
177
181
  "@types/prompts": "2.4.1",
178
182
  "@types/semver": "7.3.12",
179
183
  "@types/stream-buffers": "3.0.4",
180
184
  "babar": "0.2.3",
181
185
  "husky": "8.0.1",
182
- "jest": "29.0.3",
183
- "jest-diff": "29.0.3",
184
- "jest-environment-jsdom": "29.0.3",
185
- "jest-snapshot": "29.0.3",
186
+ "jest": "29.2.1",
187
+ "jest-diff": "29.2.1",
188
+ "jest-environment-jsdom": "29.2.1",
189
+ "jest-snapshot": "29.2.1",
186
190
  "npm-pkg-lint": "1.11.1",
187
191
  "npm-run-all": "4.1.5",
188
- "rollup": "2.79.1",
192
+ "rollup": "3.2.3",
189
193
  "rollup-plugin-copy": "3.4.0",
190
- "rollup-plugin-dts": "4.2.2",
194
+ "rollup-plugin-dts": "5.0.0",
191
195
  "stream-buffers": "3.0.2",
192
196
  "ts-jest": "29.0.3",
193
197
  "typescript": "4.8.4"