Skip to content

Commit aec5f5f

Browse files
author
Mendes Hugo
committed
fix: remove direct es-html-parser dependence
Only loaded if it is the default parser
1 parent 15611cd commit aec5f5f

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/rules/sort-attribute-content/sort-attribute-content.rule.ts

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { type TmplAstTextAttribute } from "@angular/compiler";
2-
import { type TemplateParserServices } from "@angular-eslint/utils";
3-
import { AttributeNode, AttributeValueNode, TokenTypes } from "es-html-parser";
1+
import type { TmplAstTextAttribute } from "@angular/compiler";
2+
import type { TemplateParserServices } from "@angular-eslint/utils";
3+
import type { AttributeNode, AttributeValueNode } from "es-html-parser";
44
import { Rule } from "eslint";
55

66
import {
@@ -174,11 +174,16 @@ export const sortAttributeContentRule: Rule.RuleModule = {
174174
);
175175
}
176176

177-
// Default choice, use of the `@html-eslint/parser`. TODO: throw error if not set
177+
// Default choice, use of the `@html-eslint/parser` with dynamic modules.
178+
179+
// Throw an error if the module does not exist
180+
require("@html-eslint/parser");
181+
// eslint-disable-next-line @typescript-eslint/no-var-requires -- Dynamic loading
182+
const { TokenTypes } = require("es-html-parser") as typeof import("es-html-parser");
183+
178184
type HtmlNode<T, P = never> = T & { parent?: HtmlNode<P> };
179185
return {
180186
[TokenTypes.AttributeValue](nodeRaw: Rule.Node) {
181-
// Only to satisfy TS
182187
const node = nodeRaw as unknown as HtmlNode<AttributeValueNode, AttributeNode>;
183188

184189
const attributeName = node.parent?.key.value;

0 commit comments

Comments
 (0)