diff --git a/docs/.vuepress/categories.js b/docs/.vuepress/categories.js index d2ed6109..2c52ac26 100644 --- a/docs/.vuepress/categories.js +++ b/docs/.vuepress/categories.js @@ -50,7 +50,7 @@ module.exports = categoryIds.map((categoryId) => ({ categoryId, title: categoryTitles[categoryId], rules: (categoryRules[categoryId] || []).filter( - (rule) => !rule.meta.deprecated + (rule) => !rule.meta.deprecated, ), })); // .filter(category => category.rules.length >= 1) diff --git a/docs/.vuepress/components/components/EslintPluginEditor.vue b/docs/.vuepress/components/components/EslintPluginEditor.vue index 659e6d26..c2c8f159 100644 --- a/docs/.vuepress/components/components/EslintPluginEditor.vue +++ b/docs/.vuepress/components/components/EslintPluginEditor.vue @@ -147,14 +147,14 @@ export default { editor.$watch("codeEditor", () => { if (editor.codeEditor) { editor.codeEditor.onDidChangeModelDecorations(() => - this.onDidChangeModelDecorations(editor.codeEditor) + this.onDidChangeModelDecorations(editor.codeEditor), ); } }); editor.$watch("fixedCodeEditor", () => { if (editor.fixedCodeEditor) { editor.fixedCodeEditor.onDidChangeModelDecorations(() => - this.onDidChangeModelDecorations(editor.fixedCodeEditor) + this.onDidChangeModelDecorations(editor.fixedCodeEditor), ); } }); diff --git a/docs/.vuepress/components/components/RulesSettings.vue b/docs/.vuepress/components/components/RulesSettings.vue index 11f4b377..ea78f2c3 100644 --- a/docs/.vuepress/components/components/RulesSettings.vue +++ b/docs/.vuepress/components/components/RulesSettings.vue @@ -14,16 +14,16 @@ - r.ruleId.includes(this.filterValue) + r.ruleId.includes(this.filterValue), ); } return filteredRules; diff --git a/docs/.vuepress/components/rules/index.js b/docs/.vuepress/components/rules/index.js index ac219e73..40e98bb6 100644 --- a/docs/.vuepress/components/rules/index.js +++ b/docs/.vuepress/components/rules/index.js @@ -93,7 +93,7 @@ for (const k of Object.keys(coreRules)) { } allRules.sort((a, b) => - a.ruleId > b.ruleId ? 1 : a.ruleId < b.ruleId ? -1 : 0 + a.ruleId > b.ruleId ? 1 : a.ruleId < b.ruleId ? -1 : 0, ); export const categories = []; @@ -122,7 +122,7 @@ categories.sort((a, b) => ? 1 : a.title < b.title ? -1 - : 0 + : 0, ); export const DEFAULT_RULES_CONFIG = allRules.reduce((c, r) => { diff --git a/docs/.vuepress/components/state/serialize.js b/docs/.vuepress/components/state/serialize.js index dd77146b..f6bb34cf 100644 --- a/docs/.vuepress/components/state/serialize.js +++ b/docs/.vuepress/components/state/serialize.js @@ -35,7 +35,7 @@ export function serializeState(state) { `The compress rate of serialized string: ${( (100 * base64.length) / jsonString.length - ).toFixed(1)}% (${jsonString.length}B → ${base64.length}B)` + ).toFixed(1)}% (${jsonString.length}B → ${base64.length}B)`, ); return base64; diff --git a/docs/.vuepress/config.js b/docs/.vuepress/config.js index 51acf044..fea8b947 100644 --- a/docs/.vuepress/config.js +++ b/docs/.vuepress/config.js @@ -18,11 +18,11 @@ module.exports = { alias: { esquery: path.resolve( __dirname, - "../../node_modules/esquery/dist/esquery.min.js" + "../../node_modules/esquery/dist/esquery.min.js", ), "@eslint/eslintrc/universal": path.resolve( __dirname, - "../../node_modules/@eslint/eslintrc/dist/eslintrc-universal.cjs" + "../../node_modules/@eslint/eslintrc/dist/eslintrc-universal.cjs", ), eslint$: require.resolve("./shim/eslint"), // eslint-disable-next-line node/no-extraneous-require -- demo @@ -32,7 +32,7 @@ module.exports = { module: require.resolve("./shim/module"), postcss$: path.resolve( __dirname, - "../../node_modules/postcss/lib/postcss.mjs" + "../../node_modules/postcss/lib/postcss.mjs", ), }, }, @@ -80,7 +80,7 @@ module.exports = { meta: { docs: { ruleId, ruleName }, }, - }) => [`/rules/${ruleName}`, ruleId] + }) => [`/rules/${ruleName}`, ruleId], ), })) .filter((menu) => Boolean(menu.children.length)), diff --git a/lib/index.ts b/lib/index.ts index 5542716d..93ba9f31 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -8,10 +8,13 @@ const configs = { all: require("./configs/all"), }; -const rules = ruleList.reduce((obj, r) => { - obj[r.meta.docs?.ruleName || ""] = r; - return obj; -}, {} as { [key: string]: Rule }); +const rules = ruleList.reduce( + (obj, r) => { + obj[r.meta.docs?.ruleName || ""] = r; + return obj; + }, + {} as { [key: string]: Rule }, +); export = { configs, diff --git a/lib/options.ts b/lib/options.ts index 5988d938..941ed71e 100644 --- a/lib/options.ts +++ b/lib/options.ts @@ -14,7 +14,7 @@ export interface ParsedQueryOptions { * Parse options */ export function parseQueryOptions( - options: QueryOptions | undefined + options: QueryOptions | undefined, ): ParsedQueryOptions { const { ignoreBEMModifier, captureClassesFromDoc } = options || {}; diff --git a/lib/rules/enforce-style-type.ts b/lib/rules/enforce-style-type.ts index ebb4583f..358be8e1 100644 --- a/lib/rules/enforce-style-type.ts +++ b/lib/rules/enforce-style-type.ts @@ -78,7 +78,7 @@ export = { */ function removeAttr( fixer: RuleFixer, - node: AST.VAttribute | AST.VDirective + node: AST.VAttribute | AST.VDirective, ) { const { attributes } = node.parent; const prevToken = tokenStore.getTokenBefore(node); @@ -99,7 +99,7 @@ export = { */ function reportForbiddenStyle(node: AST.VElement, attribute: StyleTypes) { const forbiddenAttr = node.startTag.attributes.find( - (attr) => attr.key.name === attribute + (attr) => attr.key.name === attribute, ); const forbiddenAttrName = forbiddenAttr!.key.name as string; @@ -172,8 +172,8 @@ export = { const forbiddenAttrs = node.startTag.attributes.filter( (attr) => styleTypesAttrs.includes( - attr.key.name as (typeof styleTypesAttrs)[number] - ) && !allows.includes(attr.key.name as StyleTypes) + attr.key.name as (typeof styleTypesAttrs)[number], + ) && !allows.includes(attr.key.name as StyleTypes), ); reporter.report({ @@ -200,7 +200,7 @@ export = { }, fix(fixer: RuleFixer) { return lodash.flatMap(forbiddenAttrs, (attr) => - removeAttr(fixer, attr) + removeAttr(fixer, attr), ); }, }, diff --git a/lib/rules/no-deprecated-v-enter-v-leave-class.ts b/lib/rules/no-deprecated-v-enter-v-leave-class.ts index df9a3a3d..9701eeda 100644 --- a/lib/rules/no-deprecated-v-enter-v-leave-class.ts +++ b/lib/rules/no-deprecated-v-enter-v-leave-class.ts @@ -63,7 +63,7 @@ export = { function report( node: VCSSSelectorNode | AST.VIdentifier | AST.VDirectiveKey, messageId: "deprecatedClass" | "deprecatedProps", - kind: Kind + kind: Kind, ) { reporter.report({ node, @@ -206,7 +206,7 @@ export = { for (const transition of getElements( context, (element) => - isTransitionElement(element) || isTransitionGroupElement(element) + isTransitionElement(element) || isTransitionGroupElement(element), )) { const { hasEnterClass, hasLeaveClass } = verifyTransitionElementNode(transition); diff --git a/lib/rules/no-unused-selector.ts b/lib/rules/no-unused-selector.ts index ef63ff50..10477365 100644 --- a/lib/rules/no-unused-selector.ts +++ b/lib/rules/no-unused-selector.ts @@ -46,11 +46,11 @@ function getScopedSelectors(style: ValidStyleContext): VCSSSelectorNode[][] { * @returns scoped selector */ function getScopedSelector( - resolvedSelector: ResolvedSelector + resolvedSelector: ResolvedSelector, ): VCSSSelectorNode[] | null { const { selector } = resolvedSelector; const specialNodeIndex = selector.findIndex( - (s) => isDeepCombinator(s) || isVueSpecialPseudo(s) + (s) => isDeepCombinator(s) || isVueSpecialPseudo(s), ); let scopedCandidateSelector: VCSSSelectorNode[]; if (specialNodeIndex >= 0) { @@ -169,7 +169,7 @@ export = { */ function verifySelector( queryContext: QueryContext, - scopedSelector: VCSSSelectorNode[] + scopedSelector: VCSSSelectorNode[], ) { const reportSelectorNodes: VCSSSelectorNode[] = []; let targetsQueryContext = queryContext; @@ -203,7 +203,7 @@ export = { isTypeSelector(s) || isIDSelector(s) || isUniversalSelector(s) || - isVueSpecialPseudo(s) + isVueSpecialPseudo(s), ); for (const selectorNode of notClassSelectors) { @@ -247,7 +247,7 @@ export = { "Program:exit"() { const queryContext = createQueryContext( context, - parseQueryOptions(context.options[0]) + parseQueryOptions(context.options[0]), ); for (const style of styles) { diff --git a/lib/rules/require-scoped.ts b/lib/rules/require-scoped.ts index 56474aa6..ad41c1ee 100644 --- a/lib/rules/require-scoped.ts +++ b/lib/rules/require-scoped.ts @@ -70,7 +70,7 @@ export = { */ function reportNever(node: AST.VElement) { const scopedAttr = node.startTag.attributes.find( - (attr) => attr.key.name === "scoped" + (attr) => attr.key.name === "scoped", ); reporter.report({ node: scopedAttr!, diff --git a/lib/rules/require-selector-used-inside.ts b/lib/rules/require-selector-used-inside.ts index f1c930d1..e381afb9 100644 --- a/lib/rules/require-selector-used-inside.ts +++ b/lib/rules/require-selector-used-inside.ts @@ -42,11 +42,11 @@ function getScopedSelectors(style: ValidStyleContext): VCSSSelectorNode[][] { * @returns {VCSSSelectorNode[]} scoped selector */ function getScopedSelector( - resolvedSelector: ResolvedSelector + resolvedSelector: ResolvedSelector, ): VCSSSelectorNode[] | null { const { selector } = resolvedSelector; const specialNodeIndex = selector.findIndex( - (s) => isDeepCombinator(s) || isVueSpecialPseudo(s) + (s) => isDeepCombinator(s) || isVueSpecialPseudo(s), ); if (specialNodeIndex >= 0) { const specialNode = selector[specialNodeIndex]; @@ -148,7 +148,7 @@ export = { */ function verifySelector( queryContext: QueryContext, - scopedSelector: VCSSSelectorNode[] + scopedSelector: VCSSSelectorNode[], ) { let targetsQueryContext = queryContext; const selectorNodes = scopedSelector @@ -161,7 +161,7 @@ export = { isIDSelector(s) || isClassSelector(s) || isUniversalSelector(s) || - isVueSpecialPseudo(s) + isVueSpecialPseudo(s), ); for (let index = 0; index < selectorNodes.length; index++) { @@ -179,7 +179,7 @@ export = { "Program:exit"() { const queryContext = createQueryContext( context, - parseQueryOptions(context.options[0]) + parseQueryOptions(context.options[0]), ); for (const style of styles) { diff --git a/lib/rules/require-v-deep-argument.ts b/lib/rules/require-v-deep-argument.ts index 2e0871e5..89378587 100644 --- a/lib/rules/require-v-deep-argument.ts +++ b/lib/rules/require-v-deep-argument.ts @@ -52,7 +52,7 @@ export = { * Find VCSSStyleRule or nest VCSSAtRule */ function findHasSelectorsNode( - node: VCSSSelectorNode + node: VCSSSelectorNode, ): | (VCSSAtRule & { name: "nest"; selectors: VCSSSelectorNode[] }) | VCSSStyleRule @@ -102,7 +102,7 @@ export = { const ruleNode = findHasSelectorsNode(node); if ( !ruleNode?.nodes.every( - (n) => isVCSSDeclarationProperty(n) || isVCSSComment(n) + (n) => isVCSSDeclarationProperty(n) || isVCSSComment(n), ) ) { // Maybe includes nesting diff --git a/lib/rules/v-deep-pseudo-style.ts b/lib/rules/v-deep-pseudo-style.ts index a8d9c678..eeeb16ed 100644 --- a/lib/rules/v-deep-pseudo-style.ts +++ b/lib/rules/v-deep-pseudo-style.ts @@ -56,8 +56,8 @@ export = { nodeText.replace( /^(\s*)(?::deep|::v-deep)(\s*\()/u, (_, prefix: string, suffix: string) => - `${prefix}${expected}${suffix}` - ) + `${prefix}${expected}${suffix}`, + ), ); }, }); diff --git a/lib/rules/v-global-pseudo-style.ts b/lib/rules/v-global-pseudo-style.ts index d4425430..1a5e7d00 100644 --- a/lib/rules/v-global-pseudo-style.ts +++ b/lib/rules/v-global-pseudo-style.ts @@ -59,8 +59,8 @@ export = { nodeText.replace( /^(\s*)(?::global|::v-global)(\s*\()/u, (_, prefix: string, suffix: string) => - `${prefix}${expected}${suffix}` - ) + `${prefix}${expected}${suffix}`, + ), ); }, }); diff --git a/lib/rules/v-slotted-pseudo-style.ts b/lib/rules/v-slotted-pseudo-style.ts index 98f4c872..bd14aacf 100644 --- a/lib/rules/v-slotted-pseudo-style.ts +++ b/lib/rules/v-slotted-pseudo-style.ts @@ -59,8 +59,8 @@ export = { nodeText.replace( /^(\s*)(?::slotted|::v-slotted)(\s*\()/u, (_, prefix: string, suffix: string) => - `${prefix}${expected}${suffix}` - ) + `${prefix}${expected}${suffix}`, + ), ); }, }); diff --git a/lib/styles/ast.ts b/lib/styles/ast.ts index 70368b0c..239c87bf 100644 --- a/lib/styles/ast.ts +++ b/lib/styles/ast.ts @@ -59,7 +59,7 @@ class Node { loc: SourceLocation, start: number, end: number, - lang: string + lang: string, ) { this.type = type; this.loc = loc; @@ -76,7 +76,7 @@ class Node { */ class HasParentNode< T extends string, - P extends VCSSContainerNode | VCSSSelector | VCSSSelectorPseudo + P extends VCSSContainerNode | VCSSSelector | VCSSSelectorPseudo, > extends Node { public readonly parent: P; @@ -88,7 +88,7 @@ class HasParentNode< end: number, props: { parent: P; - } + }, ) { super(node, type, loc, start, end, props.parent.lang); this.parent = props.parent; @@ -117,7 +117,7 @@ export class VCSSParsingError extends Node<"VCSSParsingError"> { props: { lang: string; message: string; - } + }, ) { super(node, "VCSSParsingError", loc, start, end, props.lang); this.message = props.message; @@ -153,7 +153,7 @@ export class VCSSStyleSheet extends Node<"VCSSStyleSheet"> { comments?: VCSSCommentNode[]; errors?: VCSSParsingError[]; lang: string; - } + }, ) { super(node, "VCSSStyleSheet", loc, start, end, props.lang); this.nodes = props.nodes ?? []; @@ -205,7 +205,7 @@ export class VCSSStyleRule extends HasParentNode< rawSelectorText: string | null; selectors?: VCSSSelectorNode[]; nodes?: VCSSNode[]; - } + }, ) { super(node, "VCSSStyleRule", loc, start, end, props); @@ -261,7 +261,7 @@ export class VCSSDeclarationProperty extends HasParentNode< property?: string; important?: boolean; value?: string; - } + }, ) { super(node, "VCSSDeclarationProperty", loc, start, end, props); @@ -320,7 +320,7 @@ export class VCSSAtRule extends HasParentNode<"VCSSAtRule", VCSSContainerNode> { rawParamsText: string | null; selectors?: VCSSSelectorNode[]; nodes?: VCSSNode[]; - } + }, ) { super(node, "VCSSAtRule", loc, start, end, props); this.node = node; @@ -377,7 +377,7 @@ export class VCSSUnknown extends HasParentNode< parent: VCSSContainerNode; nodes?: VCSSNode[]; unknownType?: string; - } + }, ) { super(node, "VCSSUnknown", loc, start, end, props); @@ -423,7 +423,7 @@ export class VCSSSelector extends HasParentNode< props: { parent: VCSSStyleRule | VCSSAtRule | VCSSSelectorPseudo; nodes?: VCSSSelectorValueNode[]; - } + }, ) { super(node, "VCSSSelector", loc, start, end, props); @@ -472,7 +472,7 @@ export class VCSSTypeSelector extends HasParentNode< props: { parent: VCSSSelector; value?: string; - } + }, ) { super(node, "VCSSTypeSelector", loc, start, end, props); this.value = getProp(props, node, "value"); @@ -488,7 +488,7 @@ export class VCSSTypeSelector extends HasParentNode< props?: CopyProps & { parent?: VCSSSelector; value?: string; - } + }, ): VCSSTypeSelector { return copyStdNode(this, props); } @@ -518,7 +518,7 @@ export class VCSSIDSelector extends HasParentNode< loc: SourceLocation, start: number, end: number, - props: { parent: VCSSSelector; value?: string } + props: { parent: VCSSSelector; value?: string }, ) { super(node, "VCSSIDSelector", loc, start, end, props); this.value = getProp(props, node, "value"); @@ -534,7 +534,7 @@ export class VCSSIDSelector extends HasParentNode< props?: CopyProps & { parent?: VCSSSelector; value?: string; - } + }, ): VCSSIDSelector { return copyStdNode(this, props); } @@ -564,7 +564,7 @@ export class VCSSClassSelector extends HasParentNode< loc: SourceLocation, start: number, end: number, - props: { parent: VCSSSelector; value?: string } + props: { parent: VCSSSelector; value?: string }, ) { super(node, "VCSSClassSelector", loc, start, end, props); this.value = getProp(props, node, "value"); @@ -580,7 +580,7 @@ export class VCSSClassSelector extends HasParentNode< props?: CopyProps & { parent?: VCSSSelector; value?: string; - } + }, ): VCSSClassSelector { return copyStdNode(this, props); } @@ -610,7 +610,7 @@ export class VCSSNestingSelector extends HasParentNode< loc: SourceLocation, start: number, end: number, - props: { parent: VCSSSelector; value?: string } + props: { parent: VCSSSelector; value?: string }, ) { super(node, "VCSSNestingSelector", loc, start, end, props); this.value = getProp(props, node, "value"); @@ -626,7 +626,7 @@ export class VCSSNestingSelector extends HasParentNode< props?: CopyProps & { parent?: VCSSSelector; value?: string; - } + }, ): VCSSNestingSelector { return copyStdNode(this, props); } @@ -656,7 +656,7 @@ export class VCSSUniversalSelector extends HasParentNode< loc: SourceLocation, start: number, end: number, - props: { parent: VCSSSelector; value?: string } + props: { parent: VCSSSelector; value?: string }, ) { super(node, "VCSSUniversalSelector", loc, start, end, props); this.value = getProp(props, node, "value"); @@ -672,7 +672,7 @@ export class VCSSUniversalSelector extends HasParentNode< props?: CopyProps & { parent?: VCSSSelector; value?: string; - } + }, ): VCSSUniversalSelector { return copyStdNode(this, props); } @@ -714,7 +714,7 @@ export class VCSSAttributeSelector extends HasParentNode< parent: VCSSSelector; value?: string; insensitiveFlag?: string; - } + }, ) { super(node, "VCSSAttributeSelector", loc, start, end, props); @@ -765,7 +765,7 @@ export class VCSSAttributeSelector extends HasParentNode< props?: CopyProps & { parent?: VCSSSelector; value?: string; - } + }, ): VCSSAttributeSelector { return copyStdNode(this, props); } @@ -798,7 +798,7 @@ export class VCSSSelectorPseudo extends HasParentNode< props: { parent: VCSSSelector; nodes?: VCSSSelector[]; - } + }, ) { super(node, "VCSSSelectorPseudo", loc, start, end, props); this.value = getProp(props, node, "value"); @@ -815,7 +815,7 @@ export class VCSSSelectorPseudo extends HasParentNode< props?: CopyProps & { parent?: VCSSSelector; value?: string; - } + }, ): VCSSSelectorPseudo { return copyStdNode(this, props); } @@ -854,7 +854,7 @@ export class VCSSSelectorCombinator extends HasParentNode< loc: SourceLocation, start: number, end: number, - props: { parent: VCSSSelector; value?: string } + props: { parent: VCSSSelector; value?: string }, ) { super(node, "VCSSSelectorCombinator", loc, start, end, props); this.value = getProp(props, node, "value"); @@ -870,7 +870,7 @@ export class VCSSSelectorCombinator extends HasParentNode< props?: CopyProps & { parent?: VCSSSelector; value?: string; - } + }, ): VCSSSelectorCombinator { return copyStdNode(this, props); } @@ -903,7 +903,7 @@ export class VCSSUnknownSelector extends HasParentNode< end: number, props: { parent: VCSSSelector; - } + }, ) { super(node, "VCSSUnknownSelector", loc, start, end, props); this.value = getProp(props, node, "value") || ""; @@ -919,7 +919,7 @@ export class VCSSUnknownSelector extends HasParentNode< props?: CopyProps & { parent?: VCSSSelector; value?: string; - } + }, ): VCSSUnknownSelector { return copyStdNode(this, props); } @@ -952,7 +952,7 @@ export class VCSSComment extends HasParentNode< loc: SourceLocation, start: number, end: number, - props: { parent: VCSSContainerNode | VCSSSelector } + props: { parent: VCSSContainerNode | VCSSSelector }, ) { super(node, "VCSSComment", loc, start, end, props); this.node = node; @@ -969,7 +969,7 @@ export class VCSSComment extends HasParentNode< parent?: VCSSContainerNode | VCSSSelector; node?: PostCSSComment | PostCSSSPCommentNode; text?: string; - } + }, ): VCSSComment { const parent = props?.parent ?? this.parent; return new VCSSComment( @@ -978,7 +978,7 @@ export class VCSSComment extends HasParentNode< props?.loc ?? this.loc, props?.start ?? this.start, props?.end ?? this.end, - { ...this, ...props, parent } + { ...this, ...props, parent }, ); } } @@ -1009,7 +1009,7 @@ export class VCSSInlineComment extends HasParentNode< loc: SourceLocation, start: number, end: number, - props: { parent: VCSSContainerNode | VCSSSelector } + props: { parent: VCSSContainerNode | VCSSSelector }, ) { super(node, "VCSSInlineComment", loc, start, end, props); this.node = node; @@ -1026,7 +1026,7 @@ export class VCSSInlineComment extends HasParentNode< parent?: VCSSContainerNode | VCSSSelector; node?: PostCSSComment | PostCSSSPCommentNode; text?: string; - } + }, ): VCSSInlineComment { const parent = props?.parent ?? this.parent; return new VCSSInlineComment( @@ -1035,7 +1035,7 @@ export class VCSSInlineComment extends HasParentNode< props?.loc ?? this.loc, props?.start ?? this.start, props?.end ?? this.end, - { ...this, ...props, parent } + { ...this, ...props, parent }, ); } } @@ -1086,7 +1086,7 @@ function getProp( // eslint-disable-next-line @typescript-eslint/no-explicit-any -- ignore props: any, node: N, - name: K + name: K, ): N[K] { if (props?.[name] != null) { const v = props[name]; @@ -1102,7 +1102,7 @@ function getProp( */ function copyStdNode, T extends string, CP extends CopyProps>( astNode: N, - props?: CP + props?: CP, ): N & Required { // eslint-disable-next-line @typescript-eslint/no-explicit-any -- ignore const C = astNode.constructor as new (...args: any[]) => N & Required; @@ -1111,6 +1111,6 @@ function copyStdNode, T extends string, CP extends CopyProps>( props?.loc ?? astNode.loc, props?.start ?? astNode.start, props?.end ?? astNode.end, - { ...astNode, ...props } + { ...astNode, ...props }, ); } diff --git a/lib/styles/context/comment-directive/index.ts b/lib/styles/context/comment-directive/index.ts index 4ac00a91..07a75a7d 100644 --- a/lib/styles/context/comment-directive/index.ts +++ b/lib/styles/context/comment-directive/index.ts @@ -56,7 +56,7 @@ function parse(pattern: RegExp, comment: string): ParsingResult | null { function enable( commentDirectives: CommentDirectives, loc: LineAndColumnData, - rules: string[] + rules: string[], ) { if (rules.length === 0) { commentDirectives.enableAll(loc); @@ -75,7 +75,7 @@ function enable( function disable( commentDirectives: CommentDirectives, loc: LineAndColumnData, - rules: string[] + rules: string[], ) { if (rules.length === 0) { commentDirectives.disableAll(loc); @@ -93,7 +93,7 @@ function disable( */ function processBlock( commentDirectives: CommentDirectives, - comment: VCSSCommentNode + comment: VCSSCommentNode, ) { const parsed = parse(COMMENT_DIRECTIVE_B, comment.text); if (parsed != null) { @@ -114,7 +114,7 @@ function processBlock( */ function processLine( commentDirectives: CommentDirectives, - comment: VCSSCommentNode + comment: VCSSCommentNode, ) { const parsed = parse(COMMENT_DIRECTIVE_L, comment.text); if (parsed != null && comment.loc.start.line === comment.loc.end.line) { @@ -269,7 +269,7 @@ export class CommentDirectivesReporter { */ public constructor( context: RuleContext, - commentDirectives: CommentDirectives + commentDirectives: CommentDirectives, ) { this.context = context; this.commentDirectives = commentDirectives; @@ -294,7 +294,7 @@ export class CommentDirectivesReporter { * @returns {CommentDirectives} the comment directives context */ export function createCommentDirectives( - styleContexts: StyleContext[] + styleContexts: StyleContext[], ): CommentDirectives { return new CommentDirectives(styleContexts); } @@ -307,7 +307,7 @@ export function createCommentDirectives( */ export function createCommentDirectivesReporter( context: RuleContext, - commentDirectives: CommentDirectives + commentDirectives: CommentDirectives, ): CommentDirectivesReporter { return new CommentDirectivesReporter(context, commentDirectives); } @@ -321,7 +321,7 @@ function compare( // eslint-disable-next-line @typescript-eslint/no-explicit-any -- check compare a: any, // eslint-disable-next-line @typescript-eslint/no-explicit-any -- check compare - b: any + b: any, ) { return a === b ? 0 : a > b ? 1 : -1; } @@ -343,7 +343,7 @@ function compareLoc(a: LineAndColumnData, b: LineAndColumnData) { * Checks whether the given descriptor has loc property */ function hasSourceLocation( - descriptor: ReportDescriptor + descriptor: ReportDescriptor, ): descriptor is ReportDescriptor & ReportDescriptorSourceLocation { return (descriptor as ReportDescriptorSourceLocation).loc != null; } diff --git a/lib/styles/context/index.ts b/lib/styles/context/index.ts index 4bd7e05e..a1c6f3a9 100644 --- a/lib/styles/context/index.ts +++ b/lib/styles/context/index.ts @@ -60,11 +60,11 @@ export function getStyleContexts(context: RuleContext): StyleContext[] { * @returns {CommentDirectivesReporter} the comment directives */ export function getCommentDirectivesReporter( - context: RuleContext + context: RuleContext, ): CommentDirectivesReporter { return createCommentDirectivesReporter( context, - getCommentDirectives(context) + getCommentDirectives(context), ); } @@ -74,7 +74,7 @@ export function getCommentDirectivesReporter( * @returns {VueComponentContext} the Vue component context */ export function getVueComponentContext( - context: RuleContext + context: RuleContext, ): VueComponentContext | null { const cache = getCache(context); if (cache.vueComponent) { diff --git a/lib/styles/context/style/index.ts b/lib/styles/context/style/index.ts index 4f29453a..f50bb590 100644 --- a/lib/styles/context/style/index.ts +++ b/lib/styles/context/style/index.ts @@ -13,7 +13,7 @@ import { isVCSSContainerNode, hasSelectorNodes } from "../../utils/css-nodes"; */ function getInvalidEOFError( context: RuleContext, - style: AST.VElement + style: AST.VElement, ): { inDocumentFragment: boolean; error: AST.ParseError; @@ -41,10 +41,10 @@ function getInvalidEOFError( typeof err.code === "string" && err.code.startsWith("eof-") && style.range[0] <= err.index && - err.index < style.range[1] + err.index < style.range[1], ) || errors.find( - (err) => typeof err.code === "string" && err.code.startsWith("eof-") + (err) => typeof err.code === "string" && err.code.startsWith("eof-"), ); if (!error) { return null; @@ -159,7 +159,7 @@ export type StyleContext = InvalidStyleContext | ValidStyleContext; * Checks whether the given context is valid */ export function isValidStyleContext( - context: StyleContext + context: StyleContext, ): context is ValidStyleContext { return !context.invalid; } @@ -224,7 +224,7 @@ export class StyleContextImpl { sourceCode, startTag.loc.end, this.cssText, - this.lang + this.lang, ); } else { this.cssText = null; @@ -285,7 +285,7 @@ function traverseNodes(node: VCSSNode, visitor: VisitorVCSSNode): void { */ function traverseSelectorNodes( node: VCSSSelectorNode, - visitor: VisitorVCSSSelectorNode + visitor: VisitorVCSSSelectorNode, ): void { visitor.break = false; visitor.enterNode(node); @@ -317,7 +317,7 @@ export function createStyleContexts(context: RuleContext): StyleContext[] { const styles = getStyleElements(context); return styles.map( - (style) => new StyleContextImpl(style, context) as StyleContext + (style) => new StyleContextImpl(style, context) as StyleContext, ); } @@ -326,7 +326,7 @@ export function createStyleContexts(context: RuleContext): StyleContext[] { * @param node node to check */ function isVElement( - node: AST.VElement | AST.VText | AST.VExpressionContainer + node: AST.VElement | AST.VText | AST.VExpressionContainer, ): node is AST.VElement { return node?.type === "VElement"; } diff --git a/lib/styles/context/vue-components/find-vue.ts b/lib/styles/context/vue-components/find-vue.ts index c5315b03..5d61c562 100644 --- a/lib/styles/context/vue-components/find-vue.ts +++ b/lib/styles/context/vue-components/find-vue.ts @@ -9,7 +9,7 @@ const traverseNodes = AST.traverseNodes; * @param node Node to check */ function getVueComponentObject( - node: ASTNode + node: ASTNode, ): AST.ESLintObjectExpression | null { if (node.type !== "ExportDefaultDeclaration") { return null; @@ -66,7 +66,7 @@ const vueComponentCache = new WeakMap< * @returns {ASTNode|null} Vue component */ function findVueComponent( - context: RuleContext + context: RuleContext, ): AST.ESLintObjectExpression | null { const cached = vueComponentCache.get(context); if (cached !== undefined && cached.cachedAt > Date.now() - 1000) { @@ -107,7 +107,7 @@ function findVueComponent( if (node.type === "ObjectExpression") { if ( !componentComments.some( - (el) => el.loc.end.line === node.loc.start.line - 1 + (el) => el.loc.end.line === node.loc.start.line - 1, ) || isDuplicateNode(node) ) { diff --git a/lib/styles/context/vue-components/index.ts b/lib/styles/context/vue-components/index.ts index d13f4b47..d7237c55 100644 --- a/lib/styles/context/vue-components/index.ts +++ b/lib/styles/context/vue-components/index.ts @@ -47,7 +47,7 @@ export class VueComponentContext { this.properties || (this.properties = extractVueComponentProperties( this.node, - this.context + this.context, )); if (properties[UNKNOWN]) { @@ -76,13 +76,13 @@ export class VueComponentContext { */ public getClassesOperatedByClassList( refNames: Template[] | null, - isRoot: boolean + isRoot: boolean, ): (AST.ESLintExpression | AST.ESLintSpreadElement)[] { return getClassesOperatedByClassList( this.node, refNames, isRoot, - this.context + this.context, ); } } @@ -93,7 +93,7 @@ export class VueComponentContext { * @returns the component context */ export function createVueComponentContext( - context: RuleContext + context: RuleContext, ): VueComponentContext | null { const node = findVueComponent(context); if (!node) { @@ -107,7 +107,7 @@ export function createVueComponentContext( */ function extractVueComponentProperties( vueNode: AST.ESLintObjectExpression, - context: RuleContext + context: RuleContext, ): Properties { const result: Properties = { data: {}, @@ -122,12 +122,12 @@ function extractVueComponentProperties( if (keyName === "data") { result.data = extractVueComponentData( p.value as AST.ESLintExpression, - context + context, ); } else if (keyName === "computed") { result.computed = extractVueComponentComputed( p.value as AST.ESLintExpression, - context + context, ); } } @@ -139,7 +139,7 @@ function extractVueComponentProperties( */ function extractVueComponentData( dataNode: AST.ESLintExpression, - context: RuleContext + context: RuleContext, ): | { [key: string]: AST.ESLintExpression[]; @@ -207,7 +207,7 @@ function extractVueComponentData( */ function extractVueComponentComputed( computedNode: AST.ESLintExpression, - context: RuleContext + context: RuleContext, ): | { [key: string]: AST.ESLintExpression[]; @@ -284,7 +284,7 @@ function getClassesOperatedByClassList( vueNode: AST.ESLintObjectExpression, refNames: Template[] | null, isRoot: boolean, - context: RuleContext + context: RuleContext, ): (AST.ESLintExpression | AST.ESLintSpreadElement)[] { const results: (AST.ESLintExpression | AST.ESLintSpreadElement)[] = []; traverseNodes(vueNode, { @@ -342,7 +342,7 @@ function getClassesOperatedByClassList( */ function getReturnStatements( body: AST.ESLintBlockStatement, - context: RuleContext + context: RuleContext, ): AST.ESLintReturnStatement[] { const returnStatements: AST.ESLintReturnStatement[] = []; const skipNodes: ( @@ -423,7 +423,7 @@ function get$RefName(expr: AST.ESLintExpression): string | null { * Get the class name arguments for the given node. */ function getClassesArguments( - node: AST.ESLintCallExpression + node: AST.ESLintCallExpression, ): (AST.ESLintExpression | AST.ESLintSpreadElement)[] { const methodName = getPropertyOrIdentifierName(node.callee); if (methodName === "add" || methodName === "remove") { @@ -454,7 +454,7 @@ function isProperty( node: | AST.ESLintProperty | AST.ESLintSpreadElement - | AST.ESLintLegacySpreadProperty + | AST.ESLintLegacySpreadProperty, ): node is AST.ESLintProperty { return node.type === "Property"; } diff --git a/lib/styles/parser/css-parser.ts b/lib/styles/parser/css-parser.ts index ac6c50ed..e0e4a42b 100644 --- a/lib/styles/parser/css-parser.ts +++ b/lib/styles/parser/css-parser.ts @@ -71,7 +71,7 @@ export class CSSParser { const rootNode = this._postcssNodeToASTNode(offsetLocation, postcssRoot); rootNode.comments = this.commentContainer; rootNode.errors.push( - ...this.collectErrors(this.anyErrors, offsetLocation) + ...this.collectErrors(this.anyErrors, offsetLocation), ); return rootNode; @@ -96,7 +96,7 @@ export class CSSParser { private collectErrors( // eslint-disable-next-line @typescript-eslint/no-explicit-any -- ignore errors: any[], - offsetLocation: LineAndColumnData + offsetLocation: LineAndColumnData, ): VCSSParsingError[] { const errorNodes = []; const duplicate = new Set(); @@ -125,8 +125,8 @@ export class CSSParser { { lang: this.lang, message, - } - ) + }, + ), ); } return errorNodes; @@ -148,25 +148,25 @@ export class CSSParser { */ private _postcssNodeToASTNode( offsetLocation: LineAndColumnData, - node: PostCSSRoot + node: PostCSSRoot, ): VCSSStyleSheet; private _postcssNodeToASTNode( offsetLocation: LineAndColumnData, node: PostCSSNode, - parent: VCSSContainerNode + parent: VCSSContainerNode, ): VCSSNode | null; private _postcssNodeToASTNode( offsetLocation: LineAndColumnData, node: PostCSSNode, - parent?: VCSSContainerNode + parent?: VCSSContainerNode, ): VCSSNode | null { const { sourceCode } = this; const startLoc = getESLintLineAndColumnFromPostCSSNode( offsetLocation, node, - "start" + "start", ) || { line: 0, column: 1 }; const start = sourceCode.getIndexFromLoc(startLoc); const endLoc = @@ -174,7 +174,7 @@ export class CSSParser { // for node type: `root` sourceCode.getLocFromIndex( sourceCode.getIndexFromLoc(offsetLocation) + - (node as PostCSSRoot).source.input.css.length + (node as PostCSSRoot).source.input.css.length, ); const end = sourceCode.getIndexFromLoc(endLoc); const loc: SourceLocation = { @@ -187,7 +187,7 @@ export class CSSParser { loc, start, end, - parent as never + parent as never, ); if (astNode == null) { @@ -227,7 +227,7 @@ export class CSSParser { node: PostCSSRoot, loc: SourceLocation, start: number, - end: number + end: number, ): VCSSNode | null { return new VCSSStyleSheet(node, loc, start, end, { lang: this.lang }); } @@ -246,7 +246,7 @@ export class CSSParser { loc: SourceLocation, start: number, end: number, - parent: VCSSContainerNode + parent: VCSSContainerNode, ): VCSSNode | null { const astNode = new VCSSStyleRule(node, loc, start, end, { parent, @@ -255,7 +255,7 @@ export class CSSParser { astNode.selectors = this.selectorParser.parse( astNode.rawSelectorText, astNode.loc.start, - astNode + astNode, ); if (this.getRaw(node, "between")?.trim()) { @@ -273,7 +273,7 @@ export class CSSParser { this._postcssNodeToASTNode( this.sourceCode.getLocFromIndex(betweenStart), - postcssRoot + postcssRoot, ); } @@ -291,7 +291,7 @@ export class CSSParser { loc: SourceLocation, start: number, end: number, - parent: VCSSContainerNode + parent: VCSSContainerNode, ): VCSSNode | null { const astNode = new VCSSAtRule(node, loc, start, end, { parent, @@ -309,7 +309,7 @@ export class CSSParser { astNode.selectors = this.selectorParser.parse( astNode.rawParamsText, this.sourceCode.getLocFromIndex(paramsStartIndex), - astNode + astNode, ); } @@ -334,7 +334,7 @@ export class CSSParser { this._postcssNodeToASTNode( this.sourceCode.getLocFromIndex(afterNameStart), - postcssRoot + postcssRoot, ); } @@ -352,7 +352,7 @@ export class CSSParser { const postcssRoot = this.parseInternal(between || "") as PostCSSRoot; this._postcssNodeToASTNode( this.sourceCode.getLocFromIndex(betweenStart), - postcssRoot + postcssRoot, ); } @@ -370,7 +370,7 @@ export class CSSParser { loc: SourceLocation, start: number, end: number, - parent: VCSSContainerNode + parent: VCSSContainerNode, ): VCSSNode | null { // adjust star hack // `*color: red` @@ -405,10 +405,10 @@ export class CSSParser { loc: SourceLocation, start: number, end: number, - parent: VCSSContainerNode + parent: VCSSContainerNode, ): VCSSNode | null { this.commentContainer.push( - new VCSSComment(node, node.text, loc, start, end, { parent }) + new VCSSComment(node, node.text, loc, start, end, { parent }), ); return null; } @@ -427,7 +427,7 @@ export class CSSParser { loc: SourceLocation, start: number, end: number, - parent: VCSSContainerNode + parent: VCSSContainerNode, ): VCSSNode | null { return new VCSSUnknown(node, loc, start, end, { parent, @@ -437,7 +437,7 @@ export class CSSParser { protected getRaw( node: N, - keyName: K + keyName: K, ): N["raws"][K] { // eslint-disable-next-line @typescript-eslint/no-explicit-any -- ignore return (node.raws as any)[keyName]; @@ -452,7 +452,7 @@ export class CSSParser { */ function getESLintLineAndColumnFromPostCSSPosition( offsetLocation: LineAndColumnData, - loc: PostCSSLoc + loc: PostCSSLoc, ) { let { line } = loc; let column = loc.column - 1; // Change to 0 base. @@ -475,7 +475,7 @@ function getESLintLineAndColumnFromPostCSSPosition( function getESLintLineAndColumnFromPostCSSNode( offsetLocation: LineAndColumnData, node: PostCSSNode, - locName: "start" | "end" + locName: "start" | "end", ): LineAndColumnData | null { const sourceLoc = node.source[locName]; if (!sourceLoc) { @@ -483,7 +483,7 @@ function getESLintLineAndColumnFromPostCSSNode( } const { line, column } = getESLintLineAndColumnFromPostCSSPosition( offsetLocation, - sourceLoc + sourceLoc, ); if (locName === "end") { // End column is shifted by one. @@ -511,7 +511,7 @@ const convertNodeTypes: ConvertNodeTypes = { * Get convert method name from given type */ function typeToConvertMethodName( - type: keyof ConvertNodeTypes + type: keyof ConvertNodeTypes, ): "convertUnknownTypeNode" | ConvertNodeTypes[keyof ConvertNodeTypes] { return convertNodeTypes[type] || "convertUnknownTypeNode"; } diff --git a/lib/styles/parser/index.ts b/lib/styles/parser/index.ts index 6f3024fe..13c8d76b 100644 --- a/lib/styles/parser/index.ts +++ b/lib/styles/parser/index.ts @@ -23,7 +23,7 @@ export function parse( sourceCode: SourceCode, offsetLocation: LineAndColumnData, css: string, - lang: string + lang: string, ): VCSSStyleSheet { // eslint-disable-next-line @typescript-eslint/naming-convention -- class const Parser = isSupportedStyleLang(lang) ? PARSERS[lang] : CSSParser; diff --git a/lib/styles/parser/scss-parser.ts b/lib/styles/parser/scss-parser.ts index 5e1fba02..8d23d718 100644 --- a/lib/styles/parser/scss-parser.ts +++ b/lib/styles/parser/scss-parser.ts @@ -31,13 +31,13 @@ export class SCSSParser extends CSSParser { loc: SourceLocation, start: number, end: number, - parent: VCSSContainerNode + parent: VCSSContainerNode, ): VCSSNode | null { if (node.raws?.inline) { this.commentContainer.push( new VCSSInlineComment(node, node.text, loc, start, end, { parent, - }) + }), ); return null; } @@ -46,7 +46,7 @@ export class SCSSParser extends CSSParser { protected getRaw( node: N, - keyName: K + keyName: K, ): N["raws"][K] { const raw = super.getRaw(node, keyName); if (raw != null) { diff --git a/lib/styles/parser/selector/css-selector-parser.ts b/lib/styles/parser/selector/css-selector-parser.ts index ab8c6058..54c05148 100644 --- a/lib/styles/parser/selector/css-selector-parser.ts +++ b/lib/styles/parser/selector/css-selector-parser.ts @@ -64,7 +64,7 @@ export class CSSSelectorParser { */ public constructor( sourceCode: SourceCode, - commentContainer: VCSSCommentNode[] + commentContainer: VCSSCommentNode[], ) { this.sourceCode = sourceCode; this.commentContainer = commentContainer; @@ -80,14 +80,14 @@ export class CSSSelectorParser { public parse( rawSelector: string, offsetLocation: LineAndColumnData, - parent: VCSSStyleRule | VCSSAtRule + parent: VCSSStyleRule | VCSSAtRule, ): VCSSSelectorNode[] { const selectorParserRoot = this.parseInternal(rawSelector); return this._postcssSelectorParserNodeChiildrenToASTNodes( offsetLocation, selectorParserRoot, - parent + parent, ); } @@ -109,25 +109,25 @@ export class CSSSelectorParser { private _postcssSelectorParserNodeChiildrenToASTNodes( offsetLocation: LineAndColumnData, node: PostCSSSPRootNode, - parent: VCSSStyleRule | VCSSAtRule + parent: VCSSStyleRule | VCSSAtRule, ): VCSSSelector[]; private _postcssSelectorParserNodeChiildrenToASTNodes( offsetLocation: LineAndColumnData, node: PostCSSSPContainer, - parent: VCSSSelector + parent: VCSSSelector, ): VCSSSelectorValueNode[]; private _postcssSelectorParserNodeChiildrenToASTNodes( offsetLocation: LineAndColumnData, node: PostCSSSPPseudoNode, - parent: VCSSSelectorPseudo + parent: VCSSSelectorPseudo, ): VCSSSelector[]; private _postcssSelectorParserNodeChiildrenToASTNodes( offsetLocation: LineAndColumnData, node: PostCSSSPContainer | PostCSSSPPseudoNode, - parent: VCSSStyleRule | VCSSAtRule | VCSSSelector | VCSSSelectorPseudo + parent: VCSSStyleRule | VCSSAtRule | VCSSSelector | VCSSSelectorPseudo, ): VCSSSelectorNode[] { const astNodes = removeInvalidDescendantCombinator( node.nodes @@ -135,10 +135,10 @@ export class CSSSelectorParser { this._postcssSelectorParserNodeToASTNode( offsetLocation, child, - parent - ) + parent, + ), ) - .filter(isDefined) + .filter(isDefined), ); if (astNodes.length !== node.nodes.length) { // adjust locations @@ -170,7 +170,7 @@ export class CSSSelectorParser { private _postcssSelectorParserNodeToASTNode( offsetLocation: LineAndColumnData, node: PostCSSSPNode, - parent: VCSSStyleRule | VCSSAtRule | VCSSSelector | VCSSSelectorPseudo + parent: VCSSStyleRule | VCSSAtRule | VCSSSelector | VCSSSelectorPseudo, ): VCSSSelectorNode | null { const { sourceCode } = this; @@ -178,12 +178,12 @@ export class CSSSelectorParser { start: getESLintLineAndColumnFromPostCSSSelectorParserNode( offsetLocation, node, - "start" + "start", ), end: getESLintLineAndColumnFromPostCSSSelectorParserNode( offsetLocation, node, - "end" + "end", ), }; const start = sourceCode.getIndexFromLoc(loc.start); @@ -194,7 +194,7 @@ export class CSSSelectorParser { loc, start, end, - parent as never + parent as never, ); if (astNode == null) { @@ -210,14 +210,14 @@ export class CSSSelectorParser { this._postcssSelectorParserNodeChiildrenToASTNodes( offsetLocation, node as PostCSSSPPseudoNode, - astNode - ) + astNode, + ), ); } else if (astNode.type === "VCSSSelector") { astNode.nodes = this._postcssSelectorParserNodeChiildrenToASTNodes( offsetLocation, node, - astNode + astNode, ); } } @@ -228,7 +228,7 @@ export class CSSSelectorParser { protected parseRawsSpaces( astNode: VCSSSelectorNode, node: PostCSSSPNode, - parent: VCSSStyleRule | VCSSAtRule | VCSSSelector | VCSSSelectorPseudo + parent: VCSSStyleRule | VCSSAtRule | VCSSSelector | VCSSSelectorPseudo, ): void { if (!hasRaws(node) || !node.raws.spaces) { return; @@ -240,13 +240,13 @@ export class CSSSelectorParser { this._postcssSelectorParserNodeToASTNode( astNode.loc.end, comment, - parent + parent, ); }); } if (before?.trim()) { const startLoc = this.sourceCode.getLocFromIndex( - astNode.range[0] - before.length + astNode.range[0] - before.length, ); const selectorParserRoot = this.parseCommentsInternal(before); selectorParserRoot.walkComments((comment) => { @@ -269,7 +269,7 @@ export class CSSSelectorParser { loc: SourceLocation, start: number, end: number, - parent: VCSSNode + parent: VCSSNode, ): VCSSSelectorNode | null { let source = this.sourceCode.text.slice(start, end); const beforeSpaces = /^\s+/u.exec(source); @@ -326,7 +326,7 @@ export class CSSSelectorParser { loc: SourceLocation, start: number, end: number, - parent: VCSSSelector + parent: VCSSSelector, ): VCSSSelectorNode | null { return new VCSSTypeSelector(node, loc, start, end, { parent, @@ -347,7 +347,7 @@ export class CSSSelectorParser { loc: SourceLocation, start: number, end: number, - parent: VCSSSelector + parent: VCSSSelector, ): VCSSSelectorNode | null { return new VCSSIDSelector(node, loc, start, end, { parent, @@ -368,7 +368,7 @@ export class CSSSelectorParser { loc: SourceLocation, start: number, end: number, - parent: VCSSSelector + parent: VCSSSelector, ): VCSSSelectorNode | null { return new VCSSClassSelector(node, loc, start, end, { parent, @@ -389,7 +389,7 @@ export class CSSSelectorParser { loc: SourceLocation, start: number, end: number, - parent: VCSSSelector + parent: VCSSSelector, ): VCSSSelectorNode | null { return new VCSSNestingSelector(node, loc, start, end, { parent, @@ -410,7 +410,7 @@ export class CSSSelectorParser { loc: SourceLocation, start: number, end: number, - parent: VCSSSelector + parent: VCSSSelector, ): VCSSSelectorNode | null { return new VCSSUniversalSelector(node, loc, start, end, { parent, @@ -431,7 +431,7 @@ export class CSSSelectorParser { loc: SourceLocation, start: number, end: number, - parent: VCSSSelector + parent: VCSSSelector, ): VCSSSelectorNode | null { return new VCSSAttributeSelector(node, loc, start, end, { parent, @@ -452,7 +452,7 @@ export class CSSSelectorParser { loc: SourceLocation, start: number, end: number, - parent: VCSSSelector + parent: VCSSSelector, ): VCSSSelectorNode | null { return new VCSSSelectorPseudo(node, loc, start, end, { parent, @@ -473,7 +473,7 @@ export class CSSSelectorParser { loc: SourceLocation, start: number, end: number, - parent: VCSSSelector + parent: VCSSSelector, ): VCSSSelectorNode | null { const astNode = new VCSSSelectorCombinator(node, loc, start, end, { parent, @@ -497,7 +497,7 @@ export class CSSSelectorParser { loc: SourceLocation, start: number, end: number, - parent: VCSSSelector + parent: VCSSSelector, ): VCSSSelectorNode | null { // unknown string const astNode = new VCSSUnknownSelector(node, loc, start, end, { @@ -522,13 +522,13 @@ export class CSSSelectorParser { loc: SourceLocation, start: number, end: number, - parent: VCSSSelector + parent: VCSSSelector, ): VCSSSelectorNode | null { const text = node.value.replace(/^\s*\/\*/u, "").replace(/\*\/\s*$/u, ""); this.commentContainer.push( new VCSSComment(node, text, loc, start, end, { parent, - }) + }), ); return null; @@ -548,7 +548,7 @@ export class CSSSelectorParser { loc: SourceLocation, start: number, end: number, - parent: VCSSSelector + parent: VCSSSelector, ): VCSSUnknownSelector { return new VCSSUnknownSelector(node, loc, start, end, { parent, @@ -566,7 +566,7 @@ export class CSSSelectorParser { function getESLintLineAndColumnFromPostCSSSelectorParserNode( offsetLocation: LineAndColumnData, node: PostCSSSPNode, - locName: "start" | "end" + locName: "start" | "end", ) { const sourceLoc = (node.source && node.source[locName]) || { line: 0, @@ -593,7 +593,7 @@ function getESLintLineAndColumnFromPostCSSSelectorParserNode( function adjustEndLocation( astNode: VCSSSelectorCombinator | VCSSUnknownSelector, endIndex: number, - sourceCode: SourceCode + sourceCode: SourceCode, ) { if (astNode.range[1] === endIndex) { return; @@ -617,7 +617,7 @@ function adjustEndLocation( * Remove invalid descendant combinators */ function removeInvalidDescendantCombinator( - nodes: VCSSSelectorNode[] + nodes: VCSSSelectorNode[], ): VCSSSelectorNode[] { const results = []; @@ -643,8 +643,8 @@ function removeInvalidDescendantCombinator( node.loc, node.start, node.end, - { parent: node.parent, value: " " } - ) + { parent: node.parent, value: " " }, + ), ); } } @@ -686,7 +686,7 @@ const convertNodeTypes: ConvertNodeTypes = { * Get convert method name from given type */ function typeToConvertMethodName( - type: keyof ConvertNodeTypes | "root" + type: keyof ConvertNodeTypes | "root", ): "convertUnknownTypeNode" | ConvertNodeTypes[keyof ConvertNodeTypes] { if (type === "root") { return "convertUnknownTypeNode"; @@ -699,7 +699,7 @@ function typeToConvertMethodName( */ function hasRaws( // eslint-disable-next-line @typescript-eslint/no-explicit-any -- check to prop - node: any + node: any, ): node is { raws: { spaces: { after?: string; before?: string } } } { return node.raws != null; } diff --git a/lib/styles/parser/selector/replace-utils.ts b/lib/styles/parser/selector/replace-utils.ts index 63b40312..651e8d86 100644 --- a/lib/styles/parser/selector/replace-utils.ts +++ b/lib/styles/parser/selector/replace-utils.ts @@ -143,7 +143,7 @@ interface ReplaceInfo { restore?: ( node: PostCSSSPNode, random: string, - original: string + original: string, ) => PostCSSSPNode | null; } @@ -185,16 +185,16 @@ class Pattern { * Define generator to search patterns. */ export function* definePatternsSearchGenerator< - REGS extends { [name: string]: RegExp } + REGS extends { [name: string]: RegExp }, >( regexps: REGS, - str: string + str: string, ): Generator<{ name: keyof REGS & string; result: RegExpExecArray; }> { const patterns = Object.entries(regexps).map( - ([name, reg]) => new Pattern(name, reg) + ([name, reg]) => new Pattern(name, reg), ); let start = 0; while (true) { @@ -236,7 +236,7 @@ export class ReplaceSelectorContext { originalSelector: string, remapContext: RemapIndexContext, replaces: ReplaceInfo[], - comments: ReplaceInfo[] + comments: ReplaceInfo[], ) { this.cssSelector = cssSelector; this.remapContext = remapContext; @@ -259,12 +259,12 @@ export type SelectorReplacer = { replace: ( result: RegExpExecArray, random: string, - info: { beforeCss: string[] } + info: { beforeCss: string[] }, ) => string; restore?: ( node: PostCSSSPNode, random: string, - original: string + original: string, ) => PostCSSSPNode | null; }; /** @@ -277,7 +277,7 @@ export function replaceSelector( selector: string, regexps: SelectorReplacer[], commentRegexps: SelectorReplacer[] = [], - trivialRegexps: SelectorReplacer[] = [] + trivialRegexps: SelectorReplacer[] = [], ): ReplaceSelectorContext { const remapContext = new RemapIndexContext(); const replaces: ReplaceInfo[] = []; @@ -290,20 +290,29 @@ export function replaceSelector( block: /\/\*[\s\S]+?\*\//gu, // block comment dstr: /"(?:[^"\\]|\\.)*"/gu, // string sstr: /'(?:[^'\\]|\\.)*'/gu, // string - ...commentRegexps.reduce((o, r, i) => { - o[`${i}comment`] = r.regexp; - return o; - }, {} as { [name: string]: RegExp }), // inline comment - ...regexps.reduce((o, r, i) => { - o[`${i}text`] = r.regexp; - return o; - }, {} as { [name: string]: RegExp }), // interpolation - ...trivialRegexps.reduce((o, r, i) => { - o[`${i}trivial`] = r.regexp; - return o; - }, {} as { [name: string]: RegExp }), // trivial + ...commentRegexps.reduce( + (o, r, i) => { + o[`${i}comment`] = r.regexp; + return o; + }, + {} as { [name: string]: RegExp }, + ), // inline comment + ...regexps.reduce( + (o, r, i) => { + o[`${i}text`] = r.regexp; + return o; + }, + {} as { [name: string]: RegExp }, + ), // interpolation + ...trivialRegexps.reduce( + (o, r, i) => { + o[`${i}trivial`] = r.regexp; + return o; + }, + {} as { [name: string]: RegExp }, + ), // trivial } as { [name: string]: RegExp }, - selector + selector, )) { const plain = selector.slice(start, res.index); const text = res[0]; @@ -371,7 +380,7 @@ export function replaceSelector( selector, remapContext, replaces, - comments + comments, ); } @@ -380,7 +389,7 @@ export function replaceSelector( */ export function restoreReplacedSelector( orgNode: PostCSSSPNode, - replaceSelectorContext: ReplaceSelectorContext + replaceSelectorContext: ReplaceSelectorContext, ): PostCSSSPNode { let node = orgNode; const { @@ -434,7 +443,7 @@ export function restoreReplacedSelector( for (let index = 0; index < node.nodes.length; index++) { node.nodes[index] = restoreReplacedSelector( node.nodes[index], - replaceSelectorContext + replaceSelectorContext, ); } } @@ -447,7 +456,7 @@ export function restoreReplacedSelector( function restoreReplaceds( node: PostCSSSPNode, replaces: ReplaceInfo[], - cssText: string | null + cssText: string | null, ): PostCSSSPNode | null { if (!replaces.length) { return null; @@ -496,7 +505,7 @@ function restoreReplaceds( function restoreComments( node: PostCSSSPNode, comments: ReplaceInfo[], - cssText: string | null + cssText: string | null, ) { if (!comments.length) { return false; @@ -535,7 +544,7 @@ function restoreComments( function restoreReplaceNodeProp( node: PostCSSSPNode, prop: string, - replaceInfo: ReplaceInfo + replaceInfo: ReplaceInfo, ): boolean { const text = `${lodash.get(node, prop, "") || ""}`; if (text.includes(replaceInfo.replace)) { @@ -554,7 +563,7 @@ function restoreReplaceNodeProp( */ function hasRaws( // eslint-disable-next-line @typescript-eslint/no-explicit-any -- check to prop - node: any + node: any, ): node is { raws: { spaces: { after?: string; before?: string } } } { return node.raws != null; } diff --git a/lib/styles/parser/selector/scss-selector-parser.ts b/lib/styles/parser/selector/scss-selector-parser.ts index f9ca36e9..1760717a 100644 --- a/lib/styles/parser/selector/scss-selector-parser.ts +++ b/lib/styles/parser/selector/scss-selector-parser.ts @@ -24,18 +24,18 @@ export class SCSSSelectorParser extends CSSSelectorParser { regexp: /\/\/[^\n\r\u2028\u2029]*/gu, // inline comment replace: (_res, random) => `/*${random}*/`, }, - ] + ], ); const result: PostCSSSPRootNode = selectorParser().astSync( - replaceSelectorContext.cssSelector + replaceSelectorContext.cssSelector, ); if (!replaceSelectorContext.hasReplace()) { return result; } return restoreReplacedSelector( result, - replaceSelectorContext + replaceSelectorContext, ) as PostCSSSPRootNode; } @@ -57,7 +57,7 @@ export class SCSSSelectorParser extends CSSSelectorParser { loc: SourceLocation, start: number, end: number, - parent: VCSSSelector + parent: VCSSSelector, ): VCSSSelectorNode | null { if (node.value.startsWith("//")) { // inline comment @@ -65,7 +65,7 @@ export class SCSSSelectorParser extends CSSSelectorParser { this.commentContainer.push( new VCSSInlineComment(node, text, loc, start, end, { parent, - }) + }), ); return null; } diff --git a/lib/styles/parser/selector/stylus-selector-parser.ts b/lib/styles/parser/selector/stylus-selector-parser.ts index 232a80ce..f0754a82 100644 --- a/lib/styles/parser/selector/stylus-selector-parser.ts +++ b/lib/styles/parser/selector/stylus-selector-parser.ts @@ -16,7 +16,7 @@ import { replaceSelector, restoreReplacedSelector } from "./replace-utils"; */ function replaceStylusNesting( _result: RegExpExecArray, - random: string + random: string, ): string { return `[${random}]`; } @@ -27,7 +27,7 @@ function replaceStylusNesting( function restoreStylusNesting( attribute: PostCSSSPNode, random: string, - original: string + original: string, ): PostCSSSPNestingNode | null { if (attribute.type !== "attribute") { return null; @@ -107,18 +107,18 @@ export class StylusSelectorParser extends CSSSelectorParser { return `${res[1]},${res[2]}`; }, }, - ] + ], ); const result: PostCSSSPRootNode = selectorParser().astSync( - replaceSelectorContext.cssSelector + replaceSelectorContext.cssSelector, ); if (!replaceSelectorContext.hasReplace()) { return result; } return restoreReplacedSelector( result, - replaceSelectorContext + replaceSelectorContext, ) as PostCSSSPRootNode; } @@ -140,7 +140,7 @@ export class StylusSelectorParser extends CSSSelectorParser { loc: SourceLocation, start: number, end: number, - parent: VCSSSelector + parent: VCSSSelector, ): VCSSSelectorNode | null { if (node.value.startsWith("//")) { // inline comment @@ -148,7 +148,7 @@ export class StylusSelectorParser extends CSSSelectorParser { this.commentContainer.push( new VCSSInlineComment(node, text, loc, start, end, { parent, - }) + }), ); return null; } diff --git a/lib/styles/parser/stylus-parser.ts b/lib/styles/parser/stylus-parser.ts index faeb5fb1..e96fee27 100644 --- a/lib/styles/parser/stylus-parser.ts +++ b/lib/styles/parser/stylus-parser.ts @@ -31,13 +31,13 @@ export class StylusParser extends CSSParser { loc: SourceLocation, start: number, end: number, - parent: VCSSContainerNode + parent: VCSSContainerNode, ): VCSSNode | null { if (node.raws?.inline) { this.commentContainer.push( new VCSSInlineComment(node, node.text, loc, start, end, { parent, - }) + }), ); return null; } @@ -46,12 +46,12 @@ export class StylusParser extends CSSParser { protected getRaw( node: N, - keyName: K + keyName: K, ): N["raws"][K] { if (keyName === "between" || keyName === "before" || keyName === "after") { const stylus = super.getRaw( node as never, - `stylus${keyName[0].toUpperCase()}${keyName.slice(1)}` + `stylus${keyName[0].toUpperCase()}${keyName.slice(1)}`, ); if (stylus) { return stylus; diff --git a/lib/styles/parser/utils.ts b/lib/styles/parser/utils.ts index c4df8389..9de2ff57 100644 --- a/lib/styles/parser/utils.ts +++ b/lib/styles/parser/utils.ts @@ -9,7 +9,7 @@ import type { * Checks if the given node has nodes property. */ export function isPostCSSContainer( - node: PostCSSNode + node: PostCSSNode, ): node is PostCSSContainer { return (node as PostCSSContainer).nodes != null; } @@ -18,7 +18,7 @@ export function isPostCSSContainer( * Checks if the given node has nodes property. */ export function isPostCSSSPContainer( - node: PostCSSSPNode + node: PostCSSSPNode, ): node is PostCSSSPContainer { return (node as PostCSSSPContainer).nodes != null; } diff --git a/lib/styles/selectors/index.ts b/lib/styles/selectors/index.ts index 83f5945f..bdc1036d 100644 --- a/lib/styles/selectors/index.ts +++ b/lib/styles/selectors/index.ts @@ -20,7 +20,7 @@ const RESOLVERS = { * @returns {ResolvedSelectors[]} the selector that resolved the nesting. */ export function getResolvedSelectors( - style: ValidStyleContext + style: ValidStyleContext, ): ResolvedSelector[] { const lang = style.lang; // eslint-disable-next-line @typescript-eslint/naming-convention -- classes @@ -36,7 +36,7 @@ export { ResolvedSelector }; * Extracts the selectors from the given resolved selectors. */ function extractSelectors( - resolvedSelectorsList: ResolvedSelectors[] + resolvedSelectorsList: ResolvedSelectors[], ): ResolvedSelector[] { const result: ResolvedSelector[] = []; for (const resolvedSelectors of resolvedSelectorsList) { diff --git a/lib/styles/selectors/query/attribute-tracker.ts b/lib/styles/selectors/query/attribute-tracker.ts index fa76fff2..dcd2d26c 100644 --- a/lib/styles/selectors/query/attribute-tracker.ts +++ b/lib/styles/selectors/query/attribute-tracker.ts @@ -13,7 +13,7 @@ import { getReferenceExpressions } from "./reference-expression"; export function getAttributeValueNodes( element: AST.VElement, name: string, - context: RuleContext + context: RuleContext, ): AttributeValueExpressions[] | null { const results: AttributeValueExpressions[] = []; const { startTag } = element; diff --git a/lib/styles/selectors/query/elements.ts b/lib/styles/selectors/query/elements.ts index e3e16e2a..8150acae 100644 --- a/lib/styles/selectors/query/elements.ts +++ b/lib/styles/selectors/query/elements.ts @@ -10,7 +10,7 @@ import { * @returns {boolean} `true` if the given element is the root element. */ export function isRootElement( - element: AST.VElement | AST.VDocumentFragment + element: AST.VElement | AST.VDocumentFragment, ): element is AST.VElement & { parent: AST.VDocumentFragment; } { @@ -23,7 +23,7 @@ export function isRootElement( * @returns {boolean} `true` if the given element is the root `