html-validate 10.3.1 → 10.5.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 +60 -27
- package/dist/cjs/core.js.map +1 -1
- package/dist/cjs/elements.js +40 -2
- package/dist/cjs/elements.js.map +1 -1
- package/dist/cjs/matchers.js.map +1 -1
- package/dist/cjs/meta-helper.js +5 -1
- package/dist/cjs/meta-helper.js.map +1 -1
- package/dist/cjs/tsdoc-metadata.json +1 -1
- package/dist/esm/core.js +60 -27
- package/dist/esm/core.js.map +1 -1
- package/dist/esm/elements.js +40 -2
- package/dist/esm/elements.js.map +1 -1
- package/dist/esm/matchers.js.map +1 -1
- package/dist/esm/meta-helper.js +5 -1
- package/dist/esm/meta-helper.js.map +1 -1
- package/dist/schema/elements.json +2 -2
- package/dist/tsdoc-metadata.json +1 -1
- package/dist/types/browser.d.ts +23 -1
- package/dist/types/index.d.ts +23 -1
- package/package.json +4 -4
package/dist/cjs/matchers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"matchers.js","sources":["../../src/jest/matchers/to-be-valid.ts","../../src/jest/matchers/to-be-invalid.ts","../../src/jest/matchers/to-htmlvalidate.ts","../../src/jest/matchers/to-have-error.ts","../../src/jest/matchers/to-have-errors.ts","../../src/jest/matchers/get-results.ts"],"sourcesContent":["import { type Report } from \"../../reporter\";\nimport { type MatcherResult, type MaybeAsyncCallback, diverge } from \"../utils\";\n\nfunction createMatcher(): MaybeAsyncCallback<Report, []> {\n\tfunction toBeValid(report: Report): MatcherResult {\n\t\tif (report.valid) {\n\t\t\treturn {\n\t\t\t\tpass: true,\n\t\t\t\tmessage: /* istanbul ignore next */ () => \"Result should not contain error\",\n\t\t\t};\n\t\t} else {\n\t\t\tconst firstError = report.results[0].messages[0];\n\t\t\treturn {\n\t\t\t\tpass: false,\n\t\t\t\tmessage: () => `Result should be valid but had error \"${firstError.message}\"`,\n\t\t\t};\n\t\t}\n\t}\n\treturn diverge(toBeValid);\n}\n\nexport { createMatcher as toBeValid };\n","import { type Report } from \"../../reporter\";\nimport { type MatcherResult, type MaybeAsyncCallback, diverge } from \"../utils\";\n\nfunction createMatcher(): MaybeAsyncCallback<Report, []> {\n\tfunction toBeInvalid(report: Report): MatcherResult {\n\t\tif (report.valid) {\n\t\t\treturn {\n\t\t\t\tpass: false,\n\t\t\t\tmessage: () => \"Result should be invalid but had no errors\",\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\tpass: true,\n\t\t\t\tmessage: /* istanbul ignore next */ () => \"Result should not contain error\",\n\t\t\t};\n\t\t}\n\t}\n\treturn diverge(toBeInvalid);\n}\n\nexport { createMatcher as toBeInvalid };\n","import deepmerge from \"deepmerge\";\nimport { type ConfigData } from \"../../config\";\nimport { type Message } from \"../../message\";\nimport {\n\ttype DiffFunction,\n\ttype MatcherContext,\n\ttype MatcherExpect,\n\ttype MatcherResult,\n\ttype MaybeAsyncCallback,\n\tdiverge,\n} from \"../utils\";\nimport { type ValidateStringFn, createSyncFn, workerPath } from \"../worker\";\n\nfunction isMessage(arg: any): arg is Partial<Message> {\n\tif (!arg) {\n\t\treturn false;\n\t}\n\treturn Boolean(\n\t\targ.ruleId ??\n\t\t\targ.severity ??\n\t\t\targ.message ??\n\t\t\targ.offset ??\n\t\t\targ.line ??\n\t\t\targ.column ??\n\t\t\targ.size ??\n\t\t\targ.selector ??\n\t\t\targ.context,\n\t);\n}\n\nfunction isConfig(arg: any): arg is ConfigData {\n\tif (!arg) {\n\t\treturn false;\n\t}\n\treturn Boolean(\n\t\targ.root ?? arg.extends ?? arg.elements ?? arg.plugin ?? arg.transform ?? arg.rules,\n\t);\n}\n\nfunction isString(arg: any): arg is string {\n\treturn typeof arg === \"string\";\n}\n\nfunction getMarkup(src: unknown): string {\n\tif (typeof HTMLElement !== \"undefined\" && src instanceof HTMLElement) {\n\t\treturn (src as { outerHTML: string }).outerHTML;\n\t}\n\t/* istanbul ignore else: prototype only allows string or HTMLElement */\n\tif (typeof src === \"string\") {\n\t\treturn src;\n\t} else {\n\t\tthrow new Error(`Failed to get markup from \"${typeof src}\" argument`);\n\t}\n}\n\ntype Arg1 = Partial<Message> | ConfigData | string;\ntype Arg2 = ConfigData | string;\ntype Arg3 = string;\n\nfunction createMatcher(\n\texpect: MatcherExpect,\n\tdiff: DiffFunction | undefined,\n): MaybeAsyncCallback<unknown, [Arg1?, Arg2?, Arg3?]> {\n\tfunction toHTMLValidate(\n\t\tthis: MatcherContext,\n\t\tactual: unknown,\n\t\targ0?: Arg1,\n\t\targ1?: Arg2,\n\t\targ2?: Arg3,\n\t): MatcherResult {\n\t\tconst markup = getMarkup(actual);\n\t\tconst message = isMessage(arg0) ? arg0 : undefined;\n\t\tconst config = isConfig(arg0) ? arg0 : isConfig(arg1) ? arg1 : undefined; // eslint-disable-line sonarjs/no-nested-conditional -- easier to read than the alternative */\n\t\tconst filename = isString(arg0) ? arg0 : isString(arg1) ? arg1 : arg2; // eslint-disable-line sonarjs/no-nested-conditional -- easier to read than the alternative */\n\t\treturn toHTMLValidateImpl.call(this, expect, diff, markup, message, config, filename);\n\t}\n\treturn diverge(toHTMLValidate);\n}\n\nfunction toHTMLValidateImpl(\n\tthis: MatcherContext,\n\texpect: MatcherExpect,\n\tdiff: DiffFunction | undefined,\n\tactual: string,\n\texpectedError?: Partial<Message>,\n\tuserConfig?: ConfigData,\n\tfilename?: string,\n): MatcherResult {\n\tconst defaultConfig = {\n\t\trules: {\n\t\t\t/* jsdom normalizes style so disabling rule when using this matcher or it\n\t\t\t * gets quite noisy when configured with self-closing */\n\t\t\t\"void-style\": \"off\",\n\t\t},\n\t};\n\tconst config = deepmerge(defaultConfig, userConfig ?? {});\n\t/* istanbul ignore next: cant figure out when this would be unset */\n\tconst actualFilename = filename ?? this.testPath ?? \"inline\";\n\n\tconst syncFn = createSyncFn<ValidateStringFn>(workerPath);\n\tconst report = syncFn(actual, actualFilename, config);\n\tconst pass = report.valid;\n\tconst result = report.results[0];\n\tif (pass) {\n\t\treturn { pass, message: () => \"HTML is valid when an error was expected\" };\n\t} else {\n\t\tif (expectedError) {\n\t\t\tconst actual = result.messages;\n\t\t\tconst expected = expect.arrayContaining([expect.objectContaining(expectedError)]);\n\t\t\tconst errorPass = this.equals(actual, expected);\n\t\t\tconst diffString = diff\n\t\t\t\t? diff(expected, actual, {\n\t\t\t\t\t\texpand: this.expand,\n\t\t\t\t\t\taAnnotation: \"Expected error\",\n\t\t\t\t\t\tbAnnotation: \"Actual error\",\n\t\t\t\t\t})\n\t\t\t\t: /* istanbul ignore next */ undefined;\n\t\t\tconst hint = this.utils.matcherHint(\".not.toHTMLValidate\", undefined, undefined, {\n\t\t\t\tcomment: \"expected error\",\n\t\t\t});\n\t\t\tconst expectedErrorMessage = (): string =>\n\t\t\t\t[\n\t\t\t\t\thint,\n\t\t\t\t\t\"\",\n\t\t\t\t\t\"Expected error to be present:\",\n\t\t\t\t\tthis.utils.printExpected(expectedError),\n\t\t\t\t\t/* istanbul ignore next */ diffString ? `\\n${diffString}` : \"\",\n\t\t\t\t].join(\"\\n\");\n\t\t\treturn { pass: !errorPass, message: expectedErrorMessage, actual, expected };\n\t\t}\n\n\t\tconst errors = result.messages.map((message) => ` ${message.message} [${message.ruleId}]`);\n\t\treturn {\n\t\t\tpass,\n\t\t\tmessage: () =>\n\t\t\t\t[\"Expected HTML to be valid but had the following errors:\", \"\"].concat(errors).join(\"\\n\"),\n\t\t};\n\t}\n}\n\nexport { createMatcher as toHTMLValidate };\n","import { type Message } from \"../../message\";\nimport { type Report } from \"../../reporter\";\nimport {\n\ttype DiffFunction,\n\ttype MatcherContext,\n\ttype MatcherExpect,\n\ttype MatcherResult,\n\ttype MaybeAsyncCallback,\n\tdiverge,\n} from \"../utils\";\nimport { flattenMessages } from \"../utils/flatten-messages\";\n\nfunction toHaveErrorImpl(\n\tcontext: MatcherContext,\n\texpect: MatcherExpect,\n\tdiff: DiffFunction | undefined,\n\tactual: Report,\n\texpected: Partial<Message>,\n): MatcherResult {\n\tconst flattened = flattenMessages(actual);\n\tconst matcher = [expect.objectContaining(expected)];\n\tconst pass = context.equals(flattened, matcher);\n\tconst diffString = diff\n\t\t? diff(matcher, flattened, { expand: context.expand })\n\t\t: /* istanbul ignore next */ undefined;\n\tconst hint = context.utils.matcherHint(\".toHaveError\");\n\tconst prettyExpected = context.utils.printExpected(matcher);\n\tconst prettyReceived = context.utils.printReceived(flattened);\n\tconst resultMessage = (): string => {\n\t\treturn [\n\t\t\thint,\n\t\t\t\"\",\n\t\t\t\"Expected error to equal:\",\n\t\t\t` ${prettyExpected}`,\n\t\t\t\"Received:\",\n\t\t\t` ${prettyReceived}`,\n\t\t\t/* istanbul ignore next */ diffString ? `\\nDifference:\\n\\n${diffString}` : \"\",\n\t\t].join(\"\\n\");\n\t};\n\treturn { pass, message: resultMessage, actual: flattened, expected: matcher };\n}\n\nfunction createMatcher(\n\texpect: MatcherExpect,\n\tdiff: DiffFunction | undefined,\n):\n\t| MaybeAsyncCallback<Report, [Partial<Message>]>\n\t| MaybeAsyncCallback<Report, [string, string, any?]> {\n\tfunction toHaveError(\n\t\tthis: MatcherContext,\n\t\tactual: Report,\n\t\terror: Partial<Message>,\n\t): MatcherResult;\n\tfunction toHaveError(\n\t\tthis: MatcherContext,\n\t\tactual: Report,\n\t\truleId: string,\n\t\tmessage: string,\n\t\tcontext?: any,\n\t): MatcherResult;\n\tfunction toHaveError(\n\t\tthis: MatcherContext,\n\t\tactual: Report,\n\t\targ1: string | Partial<Message>,\n\t\targ2?: string,\n\t\targ3?: any,\n\t): MatcherResult {\n\t\tif (typeof arg1 === \"string\") {\n\t\t\tconst expected: Partial<Message> = {\n\t\t\t\truleId: arg1,\n\t\t\t\tmessage: arg2,\n\t\t\t};\n\t\t\tif (arg3) {\n\t\t\t\t/* eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- this is supposed to accept anything */\n\t\t\t\texpected.context = arg3;\n\t\t\t}\n\t\t\treturn toHaveErrorImpl(this, expect, diff, actual, expected);\n\t\t} else {\n\t\t\treturn toHaveErrorImpl(this, expect, diff, actual, arg1);\n\t\t}\n\t}\n\treturn diverge(toHaveError);\n}\n\nexport { createMatcher as toHaveError };\n","/* eslint-disable prefer-template -- technical debt, should be refactored */\n\nimport { type Report } from \"../../reporter\";\nimport {\n\ttype DiffFunction,\n\ttype MatcherContext,\n\ttype MatcherExpect,\n\ttype MatcherResult,\n\ttype MaybeAsyncCallback,\n\tdiverge,\n\tflattenMessages,\n} from \"../utils\";\n\nfunction createMatcher(\n\texpect: MatcherExpect,\n\tdiff: DiffFunction | undefined,\n): MaybeAsyncCallback<Report, [Array<[string, string] | Record<string, unknown>>]> {\n\tfunction toHaveErrors(\n\t\tthis: MatcherContext,\n\t\treport: Report,\n\t\terrors: Array<[string, string] | Record<string, unknown>>,\n\t): MatcherResult {\n\t\tconst flattened = flattenMessages(report);\n\t\tconst matcher = errors.map((entry) => {\n\t\t\tif (Array.isArray(entry)) {\n\t\t\t\tconst [ruleId, message] = entry;\n\t\t\t\treturn expect.objectContaining({ ruleId, message });\n\t\t\t} else {\n\t\t\t\treturn expect.objectContaining(entry);\n\t\t\t}\n\t\t});\n\t\tconst pass = this.equals(flattened, matcher);\n\t\tconst diffString = diff\n\t\t\t? diff(matcher, flattened, { expand: this.expand })\n\t\t\t: /* istanbul ignore next */ undefined;\n\t\tconst resultMessage = (): string =>\n\t\t\tthis.utils.matcherHint(\".toHaveErrors\") +\n\t\t\t\"\\n\\n\" +\n\t\t\t\"Expected error to equal:\\n\" +\n\t\t\t` ${this.utils.printExpected(matcher)}\\n` +\n\t\t\t\"Received:\\n\" +\n\t\t\t` ${this.utils.printReceived(flattened)}` +\n\t\t\t/* istanbul ignore next */ (diffString ? `\\n\\nDifference:\\n\\n${diffString}` : \"\");\n\n\t\treturn { pass, message: resultMessage };\n\t}\n\treturn diverge(toHaveErrors);\n}\n\nexport { createMatcher as toHaveErrors };\n","import { type Report, type Result } from \"../../reporter\";\nimport { type ValidateStringFn, createSyncFn, workerPath } from \"../worker\";\n\n/**\n * @internal\n */\nexport function getResults(filename: string, value: Report | string): Result[] {\n\tif (typeof value === \"string\") {\n\t\tconst syncFn = createSyncFn<ValidateStringFn>(workerPath);\n\t\tconst report = syncFn(value, filename, {\n\t\t\trules: {\n\t\t\t\t\"void-style\": \"off\",\n\t\t\t},\n\t\t});\n\t\treturn report.results.map((it) => {\n\t\t\treturn { ...it, filePath: \"inline\" };\n\t\t});\n\t} else {\n\t\treturn value.results;\n\t}\n}\n"],"names":["createMatcher","diverge","deepmerge","createSyncFn","workerPath","actual","flattenMessages"],"mappings":";;;;;AAGA,SAASA,eAAA,GAAgD;AACxD,EAAA,SAAS,UAAU,MAAA,EAA+B;AACjD,IAAA,IAAI,OAAO,KAAA,EAAO;AACjB,MAAA,OAAO;AAAA,QACN,IAAA,EAAM,IAAA;AAAA,QACN,OAAA;AAAA;AAAA,UAAoC,MAAM;AAAA;AAAA,OAC3C;AAAA,IACD,CAAA,MAAO;AACN,MAAA,MAAM,aAAa,MAAA,CAAO,OAAA,CAAQ,CAAC,CAAA,CAAE,SAAS,CAAC,CAAA;AAC/C,MAAA,OAAO;AAAA,QACN,IAAA,EAAM,KAAA;AAAA,QACN,OAAA,EAAS,MAAM,CAAA,sCAAA,EAAyC,UAAA,CAAW,OAAO,CAAA,CAAA;AAAA,OAC3E;AAAA,IACD;AAAA,EACD;AACA,EAAA,OAAOC,qBAAQ,SAAS,CAAA;AACzB;;AChBA,SAASD,eAAA,GAAgD;AACxD,EAAA,SAAS,YAAY,MAAA,EAA+B;AACnD,IAAA,IAAI,OAAO,KAAA,EAAO;AACjB,MAAA,OAAO;AAAA,QACN,IAAA,EAAM,KAAA;AAAA,QACN,SAAS,MAAM;AAAA,OAChB;AAAA,IACD,CAAA,MAAO;AACN,MAAA,OAAO;AAAA,QACN,IAAA,EAAM,IAAA;AAAA,QACN,OAAA;AAAA;AAAA,UAAoC,MAAM;AAAA;AAA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,EAAQ,IAAA,CAAK,MAAA,EAAQ,CAAA;AAAA;AAAA,MACrB;AAAA,KAAA;AAC9B,IAAA,MAAM,gBAAgB,MACrB,IAAA,CAAK,KAAA,CAAM,WAAA,CAAY,eAAe,CAAA,GACtC;;AAAA;AAAA,EAAA,EAEK,IAAA,CAAK,KAAA,CAAM,aAAA,CAAc,OAAO,CAAC;AAAA;AAAA,EAAA,EAEjC,IAAA,CAAK,KAAA,CAAM,aAAA,CAAc,SAAS,CAAC,CAAA,CAAA;AAAA,KACZ,UAAA,GAAa;;AAAA;;AAAA,EAAsB,UAAU,CAAA,CAAA,GAAK,EAAA,CAAA;AAE/E,IAAA,OAAO,EAAE,IAAA,EAAM,OAAA,EAAS,aAAA,EAAc;AAAA,EACvC;AACA,EAAA,OAAOL,qBAAQ,YAAY,CAAA;AAC5B;;ACzCO,SAAS,UAAA,CAAW,UAAkB,KAAA,EAAkC;AAC9E,EAAA,IAAI,OAAO,UAAU,QAAA,EAAU;AAC9B,IAAA,MAAM,MAAA,GAASE,0BAA+BC,eAAU,CAAA;AACxD,IAAA,MAAM,MAAA,GAAS,MAAA,CAAO,KAAA,EAAO,QAAA,EAAU;AAAA,MACtC,KAAA,EAAO;AAAA,QACN,YAAA,EAAc;AAAA;AACf,KACA,CAAA;AACD,IAAA,OAAO,MAAA,CAAO,OAAA,CAAQ,GAAA,CAAI,CAAC,EAAA,KAAO;AACjC,MAAA,OAAO,EAAE,GAAG,EAAA,EAAI,QAAA,EAAU,QAAA,EAAS;AAAA,IACpC,CAAC,CAAA;AAAA,EACF,CAAA,MAAO;AACN,IAAA,OAAO,KAAA,CAAM,OAAA;AAAA,EACd;AACD;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"matchers.js","sources":["../../src/jest/matchers/to-be-valid.ts","../../src/jest/matchers/to-be-invalid.ts","../../src/jest/matchers/to-htmlvalidate.ts","../../src/jest/matchers/to-have-error.ts","../../src/jest/matchers/to-have-errors.ts","../../src/jest/matchers/get-results.ts"],"sourcesContent":["import { type Report } from \"../../reporter\";\nimport { type MatcherResult, type MaybeAsyncCallback, diverge } from \"../utils\";\n\nfunction createMatcher(): MaybeAsyncCallback<Report, []> {\n\tfunction toBeValid(report: Report): MatcherResult {\n\t\tif (report.valid) {\n\t\t\treturn {\n\t\t\t\tpass: true,\n\t\t\t\tmessage: /* istanbul ignore next */ () => \"Result should not contain error\",\n\t\t\t};\n\t\t} else {\n\t\t\tconst firstError = report.results[0].messages[0];\n\t\t\treturn {\n\t\t\t\tpass: false,\n\t\t\t\tmessage: () => `Result should be valid but had error \"${firstError.message}\"`,\n\t\t\t};\n\t\t}\n\t}\n\treturn diverge(toBeValid);\n}\n\nexport { createMatcher as toBeValid };\n","import { type Report } from \"../../reporter\";\nimport { type MatcherResult, type MaybeAsyncCallback, diverge } from \"../utils\";\n\nfunction createMatcher(): MaybeAsyncCallback<Report, []> {\n\tfunction toBeInvalid(report: Report): MatcherResult {\n\t\tif (report.valid) {\n\t\t\treturn {\n\t\t\t\tpass: false,\n\t\t\t\tmessage: () => \"Result should be invalid but had no errors\",\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\tpass: true,\n\t\t\t\tmessage: /* istanbul ignore next */ () => \"Result should not contain error\",\n\t\t\t};\n\t\t}\n\t}\n\treturn diverge(toBeInvalid);\n}\n\nexport { createMatcher as toBeInvalid };\n","import deepmerge from \"deepmerge\";\nimport { type ConfigData } from \"../../config\";\nimport { type Message } from \"../../message\";\nimport {\n\ttype DiffFunction,\n\ttype MatcherContext,\n\ttype MatcherExpect,\n\ttype MatcherResult,\n\ttype MaybeAsyncCallback,\n\tdiverge,\n} from \"../utils\";\nimport { type ValidateStringFn, createSyncFn, workerPath } from \"../worker\";\n\nfunction isMessage(arg: any): arg is Partial<Message> {\n\tif (!arg) {\n\t\treturn false;\n\t}\n\treturn Boolean(\n\t\targ.ruleId ??\n\t\targ.severity ??\n\t\targ.message ??\n\t\targ.offset ??\n\t\targ.line ??\n\t\targ.column ??\n\t\targ.size ??\n\t\targ.selector ??\n\t\targ.context,\n\t);\n}\n\nfunction isConfig(arg: any): arg is ConfigData {\n\tif (!arg) {\n\t\treturn false;\n\t}\n\treturn Boolean(\n\t\targ.root ?? arg.extends ?? arg.elements ?? arg.plugin ?? arg.transform ?? arg.rules,\n\t);\n}\n\nfunction isString(arg: any): arg is string {\n\treturn typeof arg === \"string\";\n}\n\nfunction getMarkup(src: unknown): string {\n\tif (typeof HTMLElement !== \"undefined\" && src instanceof HTMLElement) {\n\t\treturn (src as { outerHTML: string }).outerHTML;\n\t}\n\t/* istanbul ignore else: prototype only allows string or HTMLElement */\n\tif (typeof src === \"string\") {\n\t\treturn src;\n\t} else {\n\t\tthrow new Error(`Failed to get markup from \"${typeof src}\" argument`);\n\t}\n}\n\ntype Arg1 = Partial<Message> | ConfigData | string;\ntype Arg2 = ConfigData | string;\ntype Arg3 = string;\n\nfunction createMatcher(\n\texpect: MatcherExpect,\n\tdiff: DiffFunction | undefined,\n): MaybeAsyncCallback<unknown, [Arg1?, Arg2?, Arg3?]> {\n\tfunction toHTMLValidate(\n\t\tthis: MatcherContext,\n\t\tactual: unknown,\n\t\targ0?: Arg1,\n\t\targ1?: Arg2,\n\t\targ2?: Arg3,\n\t): MatcherResult {\n\t\tconst markup = getMarkup(actual);\n\t\tconst message = isMessage(arg0) ? arg0 : undefined;\n\t\tconst config = isConfig(arg0) ? arg0 : isConfig(arg1) ? arg1 : undefined; // eslint-disable-line sonarjs/no-nested-conditional -- easier to read than the alternative */\n\t\tconst filename = isString(arg0) ? arg0 : isString(arg1) ? arg1 : arg2; // eslint-disable-line sonarjs/no-nested-conditional -- easier to read than the alternative */\n\t\treturn toHTMLValidateImpl.call(this, expect, diff, markup, message, config, filename);\n\t}\n\treturn diverge(toHTMLValidate);\n}\n\nfunction toHTMLValidateImpl(\n\tthis: MatcherContext,\n\texpect: MatcherExpect,\n\tdiff: DiffFunction | undefined,\n\tactual: string,\n\texpectedError?: Partial<Message>,\n\tuserConfig?: ConfigData,\n\tfilename?: string,\n): MatcherResult {\n\tconst defaultConfig = {\n\t\trules: {\n\t\t\t/* jsdom normalizes style so disabling rule when using this matcher or it\n\t\t\t * gets quite noisy when configured with self-closing */\n\t\t\t\"void-style\": \"off\",\n\t\t},\n\t};\n\tconst config = deepmerge(defaultConfig, userConfig ?? {});\n\t/* istanbul ignore next: cant figure out when this would be unset */\n\tconst actualFilename = filename ?? this.testPath ?? \"inline\";\n\n\tconst syncFn = createSyncFn<ValidateStringFn>(workerPath);\n\tconst report = syncFn(actual, actualFilename, config);\n\tconst pass = report.valid;\n\tconst result = report.results[0];\n\tif (pass) {\n\t\treturn { pass, message: () => \"HTML is valid when an error was expected\" };\n\t} else {\n\t\tif (expectedError) {\n\t\t\tconst actual = result.messages;\n\t\t\tconst expected = expect.arrayContaining([expect.objectContaining(expectedError)]);\n\t\t\tconst errorPass = this.equals(actual, expected);\n\t\t\tconst diffString = diff\n\t\t\t\t? diff(expected, actual, {\n\t\t\t\t\t\texpand: this.expand,\n\t\t\t\t\t\taAnnotation: \"Expected error\",\n\t\t\t\t\t\tbAnnotation: \"Actual error\",\n\t\t\t\t\t})\n\t\t\t\t: /* istanbul ignore next */ undefined;\n\t\t\tconst hint = this.utils.matcherHint(\".not.toHTMLValidate\", undefined, undefined, {\n\t\t\t\tcomment: \"expected error\",\n\t\t\t});\n\t\t\tconst expectedErrorMessage = (): string =>\n\t\t\t\t[\n\t\t\t\t\thint,\n\t\t\t\t\t\"\",\n\t\t\t\t\t\"Expected error to be present:\",\n\t\t\t\t\tthis.utils.printExpected(expectedError),\n\t\t\t\t\t/* istanbul ignore next */ diffString ? `\\n${diffString}` : \"\",\n\t\t\t\t].join(\"\\n\");\n\t\t\treturn { pass: !errorPass, message: expectedErrorMessage, actual, expected };\n\t\t}\n\n\t\tconst errors = result.messages.map((message) => ` ${message.message} [${message.ruleId}]`);\n\t\treturn {\n\t\t\tpass,\n\t\t\tmessage: () =>\n\t\t\t\t[\"Expected HTML to be valid but had the following errors:\", \"\"].concat(errors).join(\"\\n\"),\n\t\t};\n\t}\n}\n\nexport { createMatcher as toHTMLValidate };\n","import { type Message } from \"../../message\";\nimport { type Report } from \"../../reporter\";\nimport {\n\ttype DiffFunction,\n\ttype MatcherContext,\n\ttype MatcherExpect,\n\ttype MatcherResult,\n\ttype MaybeAsyncCallback,\n\tdiverge,\n} from \"../utils\";\nimport { flattenMessages } from \"../utils/flatten-messages\";\n\nfunction toHaveErrorImpl(\n\tcontext: MatcherContext,\n\texpect: MatcherExpect,\n\tdiff: DiffFunction | undefined,\n\tactual: Report,\n\texpected: Partial<Message>,\n): MatcherResult {\n\tconst flattened = flattenMessages(actual);\n\tconst matcher = [expect.objectContaining(expected)];\n\tconst pass = context.equals(flattened, matcher);\n\tconst diffString = diff\n\t\t? diff(matcher, flattened, { expand: context.expand })\n\t\t: /* istanbul ignore next */ undefined;\n\tconst hint = context.utils.matcherHint(\".toHaveError\");\n\tconst prettyExpected = context.utils.printExpected(matcher);\n\tconst prettyReceived = context.utils.printReceived(flattened);\n\tconst resultMessage = (): string => {\n\t\treturn [\n\t\t\thint,\n\t\t\t\"\",\n\t\t\t\"Expected error to equal:\",\n\t\t\t` ${prettyExpected}`,\n\t\t\t\"Received:\",\n\t\t\t` ${prettyReceived}`,\n\t\t\t/* istanbul ignore next */ diffString ? `\\nDifference:\\n\\n${diffString}` : \"\",\n\t\t].join(\"\\n\");\n\t};\n\treturn { pass, message: resultMessage, actual: flattened, expected: matcher };\n}\n\nfunction createMatcher(\n\texpect: MatcherExpect,\n\tdiff: DiffFunction | undefined,\n):\n\t| MaybeAsyncCallback<Report, [Partial<Message>]>\n\t| MaybeAsyncCallback<Report, [string, string, any?]> {\n\tfunction toHaveError(\n\t\tthis: MatcherContext,\n\t\tactual: Report,\n\t\terror: Partial<Message>,\n\t): MatcherResult;\n\tfunction toHaveError(\n\t\tthis: MatcherContext,\n\t\tactual: Report,\n\t\truleId: string,\n\t\tmessage: string,\n\t\tcontext?: any,\n\t): MatcherResult;\n\tfunction toHaveError(\n\t\tthis: MatcherContext,\n\t\tactual: Report,\n\t\targ1: string | Partial<Message>,\n\t\targ2?: string,\n\t\targ3?: any,\n\t): MatcherResult {\n\t\tif (typeof arg1 === \"string\") {\n\t\t\tconst expected: Partial<Message> = {\n\t\t\t\truleId: arg1,\n\t\t\t\tmessage: arg2,\n\t\t\t};\n\t\t\tif (arg3) {\n\t\t\t\t/* eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- this is supposed to accept anything */\n\t\t\t\texpected.context = arg3;\n\t\t\t}\n\t\t\treturn toHaveErrorImpl(this, expect, diff, actual, expected);\n\t\t} else {\n\t\t\treturn toHaveErrorImpl(this, expect, diff, actual, arg1);\n\t\t}\n\t}\n\treturn diverge(toHaveError);\n}\n\nexport { createMatcher as toHaveError };\n","/* eslint-disable prefer-template -- technical debt, should be refactored */\n\nimport { type Report } from \"../../reporter\";\nimport {\n\ttype DiffFunction,\n\ttype MatcherContext,\n\ttype MatcherExpect,\n\ttype MatcherResult,\n\ttype MaybeAsyncCallback,\n\tdiverge,\n\tflattenMessages,\n} from \"../utils\";\n\nfunction createMatcher(\n\texpect: MatcherExpect,\n\tdiff: DiffFunction | undefined,\n): MaybeAsyncCallback<Report, [Array<[string, string] | Record<string, unknown>>]> {\n\tfunction toHaveErrors(\n\t\tthis: MatcherContext,\n\t\treport: Report,\n\t\terrors: Array<[string, string] | Record<string, unknown>>,\n\t): MatcherResult {\n\t\tconst flattened = flattenMessages(report);\n\t\tconst matcher = errors.map((entry) => {\n\t\t\tif (Array.isArray(entry)) {\n\t\t\t\tconst [ruleId, message] = entry;\n\t\t\t\treturn expect.objectContaining({ ruleId, message });\n\t\t\t} else {\n\t\t\t\treturn expect.objectContaining(entry);\n\t\t\t}\n\t\t});\n\t\tconst pass = this.equals(flattened, matcher);\n\t\tconst diffString = diff\n\t\t\t? diff(matcher, flattened, { expand: this.expand })\n\t\t\t: /* istanbul ignore next */ undefined;\n\t\tconst resultMessage = (): string =>\n\t\t\tthis.utils.matcherHint(\".toHaveErrors\") +\n\t\t\t\"\\n\\n\" +\n\t\t\t\"Expected error to equal:\\n\" +\n\t\t\t` ${this.utils.printExpected(matcher)}\\n` +\n\t\t\t\"Received:\\n\" +\n\t\t\t` ${this.utils.printReceived(flattened)}` +\n\t\t\t/* istanbul ignore next */ (diffString ? `\\n\\nDifference:\\n\\n${diffString}` : \"\");\n\n\t\treturn { pass, message: resultMessage };\n\t}\n\treturn diverge(toHaveErrors);\n}\n\nexport { createMatcher as toHaveErrors };\n","import { type Report, type Result } from \"../../reporter\";\nimport { type ValidateStringFn, createSyncFn, workerPath } from \"../worker\";\n\n/**\n * @internal\n */\nexport function getResults(filename: string, value: Report | string): Result[] {\n\tif (typeof value === \"string\") {\n\t\tconst syncFn = createSyncFn<ValidateStringFn>(workerPath);\n\t\tconst report = syncFn(value, filename, {\n\t\t\trules: {\n\t\t\t\t\"void-style\": \"off\",\n\t\t\t},\n\t\t});\n\t\treturn report.results.map((it) => {\n\t\t\treturn { ...it, filePath: \"inline\" };\n\t\t});\n\t} else {\n\t\treturn value.results;\n\t}\n}\n"],"names":["createMatcher","diverge","deepmerge","createSyncFn","workerPath","actual","flattenMessages"],"mappings":";;;;;AAGA,SAASA,eAAA,GAAgD;AACxD,EAAA,SAAS,UAAU,MAAA,EAA+B;AACjD,IAAA,IAAI,OAAO,KAAA,EAAO;AACjB,MAAA,OAAO;AAAA,QACN,IAAA,EAAM,IAAA;AAAA,QACN,OAAA;AAAA;AAAA,UAAoC,MAAM;AAAA;AAAA,OAC3C;AAAA,IACD,CAAA,MAAO;AACN,MAAA,MAAM,aAAa,MAAA,CAAO,OAAA,CAAQ,CAAC,CAAA,CAAE,SAAS,CAAC,CAAA;AAC/C,MAAA,OAAO;AAAA,QACN,IAAA,EAAM,KAAA;AAAA,QACN,OAAA,EAAS,MAAM,CAAA,sCAAA,EAAyC,UAAA,CAAW,OAAO,CAAA,CAAA;AAAA,OAC3E;AA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O;AACjC,MAAA,OAAO,EAAE,GAAG,EAAA,EAAI,QAAA,EAAU,QAAA,EAAS;AAAA,IACpC,CAAC,CAAA;AAAA,EACF,CAAA,MAAO;AACN,IAAA,OAAO,KAAA,CAAM,OAAA;AAAA,EACd;AACD;;;;;;;;;"}
|
package/dist/cjs/meta-helper.js
CHANGED
|
@@ -45,11 +45,15 @@ function allowedIfParentIsPresent(...tags) {
|
|
|
45
45
|
return `requires ${expected} as parent`;
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
|
+
function hasKeyword(attr, keyword) {
|
|
49
|
+
return attr.toLowerCase().split(/\s+/).includes(keyword);
|
|
50
|
+
}
|
|
48
51
|
const metadataHelper = {
|
|
49
52
|
allowedIfAttributeIsPresent,
|
|
50
53
|
allowedIfAttributeIsAbsent,
|
|
51
54
|
allowedIfAttributeHasValue,
|
|
52
|
-
allowedIfParentIsPresent
|
|
55
|
+
allowedIfParentIsPresent,
|
|
56
|
+
hasKeyword
|
|
53
57
|
};
|
|
54
58
|
|
|
55
59
|
function defineMetadata(metatable) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"meta-helper.js","sources":["../../src/meta/helper.ts","../../src/meta/define-metadata.ts"],"sourcesContent":["import { naturalJoin } from \"../utils/natural-join\";\nimport { type MetaAttributeAllowedCallback } from \"./element\";\nimport { type HtmlElementLike } from \"./html-element-like\";\n\n/**\n * Helpers when writing element metadata.\n *\n * @public\n */\nexport interface MetadataHelper {\n\t/** Returns an error if another attribute is omitted, i.e. it requires another attribute to be present to pass. */\n\tallowedIfAttributeIsPresent(this: void, ...attr: string[]): MetaAttributeAllowedCallback;\n\n\t/** Returns an error if another attribute is present, i.e. it requires another attribute to be omitted to pass. */\n\tallowedIfAttributeIsAbsent(this: void, ...attr: string[]): MetaAttributeAllowedCallback;\n\n\t/** Returns an error if another attribute does not have one of the listed values */\n\tallowedIfAttributeHasValue(\n\t\tthis: void,\n\t\tattr: string,\n\t\tvalue: string[],\n\t\toptions?: { defaultValue?: string | null },\n\t): MetaAttributeAllowedCallback;\n\n\t/**\n\t * Returns an error if the node doesn't have any of the given elements as parent\n\t *\n\t * @since 8.2.0\n\t **/\n\tallowedIfParentIsPresent(this: void, ...tags: string[]): MetaAttributeAllowedCallback;\n}\n\n/**\n * @internal\n */\nexport function allowedIfAttributeIsPresent(...attr: string[]) {\n\treturn (node: HtmlElementLike) => {\n\t\tif (attr.some((it) => node.hasAttribute(it))) {\n\t\t\treturn null;\n\t\t}\n\t\tconst expected = naturalJoin(attr.map((it) => `\"${it}\"`));\n\t\treturn `requires ${expected} attribute to be present`;\n\t};\n}\n\n/**\n * @internal\n */\nexport function allowedIfAttributeIsAbsent(...attr: string[]): MetaAttributeAllowedCallback {\n\treturn (node: HtmlElementLike) => {\n\t\tconst present = attr.filter((it) => node.hasAttribute(it));\n\t\tif (present.length === 0) {\n\t\t\treturn null;\n\t\t}\n\t\tconst expected = naturalJoin(present.map((it) => `\"${it}\"`));\n\t\treturn `cannot be used at the same time as ${expected}`;\n\t};\n}\n\n/**\n * @internal\n */\nexport function allowedIfAttributeHasValue(\n\tkey: string,\n\texpectedValue: string[],\n\t{ defaultValue }: { defaultValue?: string | null } = {},\n): MetaAttributeAllowedCallback {\n\treturn (node: HtmlElementLike) => {\n\t\tconst attr = node.getAttribute(key);\n\t\tif (attr && typeof attr !== \"string\") {\n\t\t\treturn null;\n\t\t}\n\t\tconst actualValue = attr ?? defaultValue;\n\t\tif (actualValue && expectedValue.includes(actualValue.toLocaleLowerCase())) {\n\t\t\treturn null;\n\t\t}\n\t\tconst expected = naturalJoin(expectedValue.map((it) => `\"${it}\"`));\n\t\treturn `\"${key}\" attribute must be ${expected}`;\n\t};\n}\n\n/**\n * @internal\n */\nexport function allowedIfParentIsPresent(\n\tthis: void,\n\t...tags: string[]\n): MetaAttributeAllowedCallback {\n\treturn (node: HtmlElementLike) => {\n\t\tconst match = tags.some((it) => node.closest(it));\n\t\tif (match) {\n\t\t\treturn null;\n\t\t}\n\t\tconst expected = naturalJoin(tags.map((it) => `<${it}>`));\n\t\treturn `requires ${expected} as parent`;\n\t};\n}\n\n/**\n * @public\n */\nexport const metadataHelper: MetadataHelper = {\n\tallowedIfAttributeIsPresent,\n\tallowedIfAttributeIsAbsent,\n\tallowedIfAttributeHasValue,\n\tallowedIfParentIsPresent,\n};\n","import { type MetaDataTable } from \"./element\";\n\n/**\n * Helper function to assist IDE with completion and type-checking.\n *\n * @public\n */\nexport function defineMetadata(metatable: MetaDataTable): MetaDataTable {\n\treturn metatable;\n}\n"],"names":["naturalJoin"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"meta-helper.js","sources":["../../src/meta/helper.ts","../../src/meta/define-metadata.ts"],"sourcesContent":["import { naturalJoin } from \"../utils/natural-join\";\nimport { type MetaAttributeAllowedCallback } from \"./element\";\nimport { type HtmlElementLike } from \"./html-element-like\";\n\n/**\n * Helpers when writing element metadata.\n *\n * @public\n */\nexport interface MetadataHelper {\n\t/** Returns an error if another attribute is omitted, i.e. it requires another attribute to be present to pass. */\n\tallowedIfAttributeIsPresent(this: void, ...attr: string[]): MetaAttributeAllowedCallback;\n\n\t/** Returns an error if another attribute is present, i.e. it requires another attribute to be omitted to pass. */\n\tallowedIfAttributeIsAbsent(this: void, ...attr: string[]): MetaAttributeAllowedCallback;\n\n\t/** Returns an error if another attribute does not have one of the listed values */\n\tallowedIfAttributeHasValue(\n\t\tthis: void,\n\t\tattr: string,\n\t\tvalue: string[],\n\t\toptions?: { defaultValue?: string | null },\n\t): MetaAttributeAllowedCallback;\n\n\t/**\n\t * Returns an error if the node doesn't have any of the given elements as parent\n\t *\n\t * @since 8.2.0\n\t **/\n\tallowedIfParentIsPresent(this: void, ...tags: string[]): MetaAttributeAllowedCallback;\n\n\t/**\n\t * Returns true if an attribute with space-separated tokens includes given\n\t * keyword.\n\t *\n\t * @since 10.4.0\n\t * @param attr - Attribute value.\n\t * @param keyword - Keyword to look for.\n\t */\n\thasKeyword(this: void, attr: string, keyword: string): boolean;\n}\n\n/**\n * @internal\n */\nexport function allowedIfAttributeIsPresent(...attr: string[]) {\n\treturn (node: HtmlElementLike) => {\n\t\tif (attr.some((it) => node.hasAttribute(it))) {\n\t\t\treturn null;\n\t\t}\n\t\tconst expected = naturalJoin(attr.map((it) => `\"${it}\"`));\n\t\treturn `requires ${expected} attribute to be present`;\n\t};\n}\n\n/**\n * @internal\n */\nexport function allowedIfAttributeIsAbsent(...attr: string[]): MetaAttributeAllowedCallback {\n\treturn (node: HtmlElementLike) => {\n\t\tconst present = attr.filter((it) => node.hasAttribute(it));\n\t\tif (present.length === 0) {\n\t\t\treturn null;\n\t\t}\n\t\tconst expected = naturalJoin(present.map((it) => `\"${it}\"`));\n\t\treturn `cannot be used at the same time as ${expected}`;\n\t};\n}\n\n/**\n * @internal\n */\nexport function allowedIfAttributeHasValue(\n\tkey: string,\n\texpectedValue: string[],\n\t{ defaultValue }: { defaultValue?: string | null } = {},\n): MetaAttributeAllowedCallback {\n\treturn (node: HtmlElementLike) => {\n\t\tconst attr = node.getAttribute(key);\n\t\tif (attr && typeof attr !== \"string\") {\n\t\t\treturn null;\n\t\t}\n\t\tconst actualValue = attr ?? defaultValue;\n\t\tif (actualValue && expectedValue.includes(actualValue.toLocaleLowerCase())) {\n\t\t\treturn null;\n\t\t}\n\t\tconst expected = naturalJoin(expectedValue.map((it) => `\"${it}\"`));\n\t\treturn `\"${key}\" attribute must be ${expected}`;\n\t};\n}\n\n/**\n * @internal\n */\nexport function allowedIfParentIsPresent(\n\tthis: void,\n\t...tags: string[]\n): MetaAttributeAllowedCallback {\n\treturn (node: HtmlElementLike) => {\n\t\tconst match = tags.some((it) => node.closest(it));\n\t\tif (match) {\n\t\t\treturn null;\n\t\t}\n\t\tconst expected = naturalJoin(tags.map((it) => `<${it}>`));\n\t\treturn `requires ${expected} as parent`;\n\t};\n}\n\n/**\n * @internal\n */\nexport function hasKeyword(attr: string, keyword: string): boolean {\n\treturn attr.toLowerCase().split(/\\s+/).includes(keyword);\n}\n\n/**\n * @public\n */\nexport const metadataHelper: MetadataHelper = {\n\tallowedIfAttributeIsPresent,\n\tallowedIfAttributeIsAbsent,\n\tallowedIfAttributeHasValue,\n\tallowedIfParentIsPresent,\n\thasKeyword,\n};\n","import { type MetaDataTable } from \"./element\";\n\n/**\n * Helper function to assist IDE with completion and type-checking.\n *\n * @public\n */\nexport function defineMetadata(metatable: MetaDataTable): MetaDataTable {\n\treturn metatable;\n}\n"],"names":["naturalJoin"],"mappings":";;;;AA6CO,SAAS,+BAA+B,IAAA,EAAgB;AAC9D,EAAA,OAAO,CAAC,IAAA,KAA0B;AACjC,IAAA,IAAI,IAAA,CAAK,KAAK,CAAC,EAAA,KAAO,KAAK,YAAA,CAAa,EAAE,CAAC,CAAA,EAAG;AAC7C,MAAA,OAAO,IAAA;AAAA,IACR;AACA,IAAA,MAAM,QAAA,GAAWA,8BAAY,IAAA,CAAK,GAAA,CAAI,CAAC,EAAA,KAAO,CAAA,CAAA,EAAI,EAAE,CAAA,CAAA,CAAG,CAAC,CAAA;AACxD,IAAA,OAAO,YAAY,QAAQ,CAAA,wBAAA,CAAA;AAAA,EAC5B,CAAA;AACD;AAKO,SAAS,8BAA8B,IAAA,EAA8C;AAC3F,EAAA,OAAO,CAAC,IAAA,KAA0B;AACjC,IAAA,MAAM,OAAA,GAAU,KAAK,MAAA,CAAO,CAAC,OAAO,IAAA,CAAK,YAAA,CAAa,EAAE,CAAC,CAAA;AACzD,IAAA,IAAI,OAAA,CAAQ,WAAW,CAAA,EAAG;AACzB,MAAA,OAAO,IAAA;AAAA,IACR;AACA,IAAA,MAAM,QAAA,GAAWA,8BAAY,OAAA,CAAQ,GAAA,CAAI,CAAC,EAAA,KAAO,CAAA,CAAA,EAAI,EAAE,CAAA,CAAA,CAAG,CAAC,CAAA;AAC3D,IAAA,OAAO,sCAAsC,QAAQ,CAAA,CAAA;AAAA,EACtD,CAAA;AACD;AAKO,SAAS,2BACf,GAAA,EACA,aAAA,EACA,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AAM,cAAA,GAAiC;AAAA,EAC7C,2BAAA;AAAA,EACA,0BAAA;AAAA,EACA,0BAAA;AAAA,EACA,wBAAA;AAAA,EACA;AACD;;ACrHO,SAAS,eAAe,SAAA,EAAyC;AACvE,EAAA,OAAO,SAAA;AACR;;;;;"}
|
package/dist/esm/core.js
CHANGED
|
@@ -854,8 +854,15 @@ const definitions = {
|
|
|
854
854
|
title: "Set to true if this attribute can optionally omit its value"
|
|
855
855
|
},
|
|
856
856
|
required: {
|
|
857
|
-
|
|
858
|
-
|
|
857
|
+
title: "Set to true or a function to evaluate if this attribute is required",
|
|
858
|
+
oneOf: [
|
|
859
|
+
{
|
|
860
|
+
type: "boolean"
|
|
861
|
+
},
|
|
862
|
+
{
|
|
863
|
+
"function": true
|
|
864
|
+
}
|
|
865
|
+
]
|
|
859
866
|
}
|
|
860
867
|
}
|
|
861
868
|
},
|
|
@@ -1583,7 +1590,7 @@ var NodeType = /* @__PURE__ */ ((NodeType2) => {
|
|
|
1583
1590
|
})(NodeType || {});
|
|
1584
1591
|
|
|
1585
1592
|
const DOCUMENT_NODE_NAME = "#document";
|
|
1586
|
-
const TEXT_CONTENT = Symbol("textContent");
|
|
1593
|
+
const TEXT_CONTENT = /* @__PURE__ */ Symbol("textContent");
|
|
1587
1594
|
let counter = 0;
|
|
1588
1595
|
class DOMNode {
|
|
1589
1596
|
nodeName;
|
|
@@ -2386,8 +2393,8 @@ class TextNode extends DOMNode {
|
|
|
2386
2393
|
}
|
|
2387
2394
|
}
|
|
2388
2395
|
|
|
2389
|
-
const ROLE = Symbol("role");
|
|
2390
|
-
const TABINDEX = Symbol("tabindex");
|
|
2396
|
+
const ROLE = /* @__PURE__ */ Symbol("role");
|
|
2397
|
+
const TABINDEX = /* @__PURE__ */ Symbol("tabindex");
|
|
2391
2398
|
var NodeClosed = /* @__PURE__ */ ((NodeClosed2) => {
|
|
2392
2399
|
NodeClosed2[NodeClosed2["Open"] = 0] = "Open";
|
|
2393
2400
|
NodeClosed2[NodeClosed2["EndTag"] = 1] = "EndTag";
|
|
@@ -3343,7 +3350,7 @@ function parseSeverity(value) {
|
|
|
3343
3350
|
}
|
|
3344
3351
|
}
|
|
3345
3352
|
|
|
3346
|
-
const cacheKey = Symbol("aria-naming");
|
|
3353
|
+
const cacheKey = /* @__PURE__ */ Symbol("aria-naming");
|
|
3347
3354
|
const defaultValue = "allowed";
|
|
3348
3355
|
const prohibitedRoles = [
|
|
3349
3356
|
"caption",
|
|
@@ -3562,10 +3569,10 @@ function isPresentation(node) {
|
|
|
3562
3569
|
}
|
|
3563
3570
|
|
|
3564
3571
|
const cachePrefix = classifyNodeText.name;
|
|
3565
|
-
const HTML_CACHE_KEY = Symbol(`${cachePrefix}|html`);
|
|
3566
|
-
const A11Y_CACHE_KEY = Symbol(`${cachePrefix}|a11y`);
|
|
3567
|
-
const IGNORE_HIDDEN_ROOT_HTML_CACHE_KEY = Symbol(`${cachePrefix}|html|ignore-hidden-root`);
|
|
3568
|
-
const IGNORE_HIDDEN_ROOT_A11Y_CACHE_KEY = Symbol(`${cachePrefix}|a11y|ignore-hidden-root`);
|
|
3572
|
+
const HTML_CACHE_KEY = /* @__PURE__ */ Symbol(`${cachePrefix}|html`);
|
|
3573
|
+
const A11Y_CACHE_KEY = /* @__PURE__ */ Symbol(`${cachePrefix}|a11y`);
|
|
3574
|
+
const IGNORE_HIDDEN_ROOT_HTML_CACHE_KEY = /* @__PURE__ */ Symbol(`${cachePrefix}|html|ignore-hidden-root`);
|
|
3575
|
+
const IGNORE_HIDDEN_ROOT_A11Y_CACHE_KEY = /* @__PURE__ */ Symbol(`${cachePrefix}|a11y|ignore-hidden-root`);
|
|
3569
3576
|
var TextClassification = /* @__PURE__ */ ((TextClassification2) => {
|
|
3570
3577
|
TextClassification2[TextClassification2["EMPTY_TEXT"] = 0] = "EMPTY_TEXT";
|
|
3571
3578
|
TextClassification2[TextClassification2["DYNAMIC_TEXT"] = 1] = "DYNAMIC_TEXT";
|
|
@@ -6278,10 +6285,30 @@ class ElementRequiredAncestor extends Rule {
|
|
|
6278
6285
|
}
|
|
6279
6286
|
}
|
|
6280
6287
|
|
|
6288
|
+
const defaultMessage = `{{ tagName }} is missing required "{{ attr }}" attribute`;
|
|
6289
|
+
function normalizeRequired(element, attr) {
|
|
6290
|
+
const { required } = attr;
|
|
6291
|
+
if (typeof required === "function") {
|
|
6292
|
+
const result = required(element._adapter);
|
|
6293
|
+
switch (result) {
|
|
6294
|
+
case void 0:
|
|
6295
|
+
case null:
|
|
6296
|
+
case false:
|
|
6297
|
+
case "":
|
|
6298
|
+
return false;
|
|
6299
|
+
case true:
|
|
6300
|
+
return defaultMessage;
|
|
6301
|
+
default:
|
|
6302
|
+
return result;
|
|
6303
|
+
}
|
|
6304
|
+
} else {
|
|
6305
|
+
return required ? defaultMessage : false;
|
|
6306
|
+
}
|
|
6307
|
+
}
|
|
6281
6308
|
class ElementRequiredAttributes extends Rule {
|
|
6282
6309
|
documentation(context) {
|
|
6283
6310
|
return {
|
|
6284
|
-
description: `The
|
|
6311
|
+
description: `The \`${context.tagName}\` element is required to have a \`${context.attr}\` attribute.`,
|
|
6285
6312
|
url: "https://html-validate.org/rules/element-required-attributes.html"
|
|
6286
6313
|
};
|
|
6287
6314
|
}
|
|
@@ -6293,23 +6320,29 @@ class ElementRequiredAttributes extends Rule {
|
|
|
6293
6320
|
return;
|
|
6294
6321
|
}
|
|
6295
6322
|
for (const [key, attr] of Object.entries(meta.attributes)) {
|
|
6296
|
-
|
|
6323
|
+
const required = normalizeRequired(node, attr);
|
|
6324
|
+
if (!required) {
|
|
6297
6325
|
continue;
|
|
6298
6326
|
}
|
|
6299
|
-
|
|
6300
|
-
const context = {
|
|
6301
|
-
element: node.tagName,
|
|
6302
|
-
attribute: key
|
|
6303
|
-
};
|
|
6304
|
-
this.report(
|
|
6305
|
-
node,
|
|
6306
|
-
`${node.annotatedName} is missing required "${key}" attribute`,
|
|
6307
|
-
node.location,
|
|
6308
|
-
context
|
|
6309
|
-
);
|
|
6327
|
+
this.validateRequiredAttribute(node, key, required);
|
|
6310
6328
|
}
|
|
6311
6329
|
});
|
|
6312
6330
|
}
|
|
6331
|
+
validateRequiredAttribute(node, attr, message) {
|
|
6332
|
+
if (node.hasAttribute(attr)) {
|
|
6333
|
+
return;
|
|
6334
|
+
}
|
|
6335
|
+
const context = {
|
|
6336
|
+
tagName: node.annotatedName,
|
|
6337
|
+
attr
|
|
6338
|
+
};
|
|
6339
|
+
this.report({
|
|
6340
|
+
node,
|
|
6341
|
+
message,
|
|
6342
|
+
location: node.location,
|
|
6343
|
+
context
|
|
6344
|
+
});
|
|
6345
|
+
}
|
|
6313
6346
|
}
|
|
6314
6347
|
|
|
6315
6348
|
function isCategory(value) {
|
|
@@ -6428,8 +6461,8 @@ const defaults$l = {
|
|
|
6428
6461
|
allowCheckboxDefault: true,
|
|
6429
6462
|
shared: ["radio", "button", "reset", "submit"]
|
|
6430
6463
|
};
|
|
6431
|
-
const UNIQUE_CACHE_KEY = Symbol("form-elements-unique");
|
|
6432
|
-
const SHARED_CACHE_KEY = Symbol("form-elements-shared");
|
|
6464
|
+
const UNIQUE_CACHE_KEY = /* @__PURE__ */ Symbol("form-elements-unique");
|
|
6465
|
+
const SHARED_CACHE_KEY = /* @__PURE__ */ Symbol("form-elements-shared");
|
|
6433
6466
|
function isEnabled(element) {
|
|
6434
6467
|
if (isHTMLHidden(element)) {
|
|
6435
6468
|
return false;
|
|
@@ -7719,7 +7752,7 @@ class NoDupClass extends Rule {
|
|
|
7719
7752
|
}
|
|
7720
7753
|
}
|
|
7721
7754
|
|
|
7722
|
-
const CACHE_KEY = Symbol("no-dup-id");
|
|
7755
|
+
const CACHE_KEY = /* @__PURE__ */ Symbol("no-dup-id");
|
|
7723
7756
|
class NoDupID extends Rule {
|
|
7724
7757
|
documentation() {
|
|
7725
7758
|
return {
|
|
@@ -11936,7 +11969,7 @@ class EventHandler {
|
|
|
11936
11969
|
}
|
|
11937
11970
|
|
|
11938
11971
|
const name = "html-validate";
|
|
11939
|
-
const version = "10.
|
|
11972
|
+
const version = "10.5.0";
|
|
11940
11973
|
const bugs = "https://gitlab.com/html-validate/html-validate/issues/new";
|
|
11941
11974
|
|
|
11942
11975
|
function freeze(src) {
|