From e77ce12cbd8e9058a0d7f44c002e8dca8124e118 Mon Sep 17 00:00:00 2001 From: gabriel miranda Date: Thu, 21 Dec 2023 13:43:21 -0300 Subject: [PATCH] chore(eslint-plugin): Format --- .../src/utils/create-no-style-property-rule.ts | 12 +++++++----- .../create-no-style-value-for-property.ts | 5 ++--- .../create-no-style-value-keyword-rule.ts | 8 +++++--- packages/eslint-plugin/src/utils/esquery.d.ts | 8 ++++++-- ...-rule-listeners-for-jsx-style-properties.ts | 18 +++++++++++++----- .../src/utils/tailwind-internals.d.ts | 18 ++++++++---------- .../get-source-code-tailwind-metadata.ts | 8 ++++---- 7 files changed, 45 insertions(+), 32 deletions(-) diff --git a/packages/eslint-plugin/src/utils/create-no-style-property-rule.ts b/packages/eslint-plugin/src/utils/create-no-style-property-rule.ts index 0f510b2a92..8105c96f8d 100644 --- a/packages/eslint-plugin/src/utils/create-no-style-property-rule.ts +++ b/packages/eslint-plugin/src/utils/create-no-style-property-rule.ts @@ -15,11 +15,13 @@ export const createNoStylePropertyRule = ( type: "suggestion", schema: [], messages: { - "not-supported-on-most-email-clients": `The CSS ${isRuleForMultipleProperties ? "properties" : "property" - } ${propertyNames.join(", ")} ${isRuleForMultipleProperties ? "are" : "is" - } only supported on ${supportPercentage.toFixed( - 2, - )}% of email clients, see ${caniemailLink}`, + "not-supported-on-most-email-clients": `The CSS ${ + isRuleForMultipleProperties ? "properties" : "property" + } ${propertyNames.join(", ")} ${ + isRuleForMultipleProperties ? "are" : "is" + } only supported on ${supportPercentage.toFixed( + 2, + )}% of email clients, see ${caniemailLink}`, }, }, create(context) { diff --git a/packages/eslint-plugin/src/utils/create-no-style-value-for-property.ts b/packages/eslint-plugin/src/utils/create-no-style-value-for-property.ts index 1a7041301f..7c087c7bb2 100644 --- a/packages/eslint-plugin/src/utils/create-no-style-value-for-property.ts +++ b/packages/eslint-plugin/src/utils/create-no-style-value-for-property.ts @@ -24,8 +24,7 @@ export const createNoStyleValueForProperty = ( const isStylePropertyDisallowed = (name: string, value: string) => { return ( - value.trim() === valueToDisallow && - camelCasedPropertyName === name + value.trim() === valueToDisallow && camelCasedPropertyName === name ); }; @@ -33,7 +32,7 @@ export const createNoStyleValueForProperty = ( isStylePropertyDisallowed, context.sourceCode, (nodeOrLocation) => { - if ('start' in nodeOrLocation) { + if ("start" in nodeOrLocation) { const location = nodeOrLocation; context.report({ loc: location, diff --git a/packages/eslint-plugin/src/utils/create-no-style-value-keyword-rule.ts b/packages/eslint-plugin/src/utils/create-no-style-value-keyword-rule.ts index 12d8d8bfd6..bb7765b54e 100644 --- a/packages/eslint-plugin/src/utils/create-no-style-value-keyword-rule.ts +++ b/packages/eslint-plugin/src/utils/create-no-style-value-keyword-rule.ts @@ -14,8 +14,10 @@ export const createNoStyleValueKeywordRule = ( const definedMessageOrDefault = message ?? - `The CSS ${isRuleForMultipleValues ? "values" : "value" - } ${valueKeywords.join(", ")} ${isRuleForMultipleValues ? "are" : "is" + `The CSS ${ + isRuleForMultipleValues ? "values" : "value" + } ${valueKeywords.join(", ")} ${ + isRuleForMultipleValues ? "are" : "is" } only supported on ${supportPercentage.toFixed( 2, )}% of email clients, see ${caniemailLink}`; @@ -37,7 +39,7 @@ export const createNoStyleValueKeywordRule = ( isStylePropertyDisallowed, context.sourceCode, (nodeOrLocation) => { - if ('start' in nodeOrLocation) { + if ("start" in nodeOrLocation) { const location = nodeOrLocation; context.report({ loc: location, diff --git a/packages/eslint-plugin/src/utils/esquery.d.ts b/packages/eslint-plugin/src/utils/esquery.d.ts index 5d5ad84d66..013fb3753f 100644 --- a/packages/eslint-plugin/src/utils/esquery.d.ts +++ b/packages/eslint-plugin/src/utils/esquery.d.ts @@ -1,5 +1,5 @@ // taken from @types/esquery but slightly modified -declare module 'esquery' { +declare module "esquery" { import type { TSESTree } from "@typescript-eslint/utils"; type Node = TSESTree.Node; @@ -35,7 +35,11 @@ declare module 'esquery' { options?: ESQueryOptions, ): boolean; /** Query the code AST using the selector string. */ - function query(ast: Node, selector: string, options?: ESQueryOptions): Node[]; + function query( + ast: Node, + selector: string, + options?: ESQueryOptions, + ): Node[]; /** From a JS AST and a selector AST, collect all JS AST nodes that match the selector. */ function traverse( diff --git a/packages/eslint-plugin/src/utils/get-rule-listeners-for-jsx-style-properties.ts b/packages/eslint-plugin/src/utils/get-rule-listeners-for-jsx-style-properties.ts index 611db2ed1a..2daf25cadd 100644 --- a/packages/eslint-plugin/src/utils/get-rule-listeners-for-jsx-style-properties.ts +++ b/packages/eslint-plugin/src/utils/get-rule-listeners-for-jsx-style-properties.ts @@ -1,5 +1,5 @@ import { AST_NODE_TYPES, type TSESTree } from "@typescript-eslint/utils"; -import esquery from 'esquery'; +import esquery from "esquery"; import type { RuleListener, SourceCode, @@ -49,7 +49,10 @@ export const getRuleListenersForJSXStyleProperties = ( const propertiesPerClassname = new Map(); for (const className of classNameAttribute.split(" ")) { - for (const rule of generateTailwindCssRules([className], tailwindContext).rules) { + for (const rule of generateTailwindCssRules( + [className], + tailwindContext, + ).rules) { const properties = [] as Property[]; rule.walk((node) => { if (node.type === "decl") { @@ -63,7 +66,9 @@ export const getRuleListenersForJSXStyleProperties = ( return propertiesPerClassname; }; - ruleListener['JSXAttribute[name.name="className"] Literal'] = (node: TSESTree.Literal) => { + ruleListener['JSXAttribute[name.name="className"] Literal'] = ( + node: TSESTree.Literal, + ) => { const classNameAttribute = node.value; if (typeof classNameAttribute === "string") { const propertiesForClassName = @@ -91,7 +96,7 @@ export const getRuleListenersForJSXStyleProperties = ( } } } - } + }; } const accumulatedProblemPropertiesPerVariableName = new Map< @@ -102,7 +107,10 @@ export const getRuleListenersForJSXStyleProperties = ( // we can't directly get the ObjectExpression from VariableDeclarator // because it can be wrapped with something like TSAsExpression // which might cause issues here - for (const node of (esquery(sourceCode.ast, "VariableDeclarator ObjectExpression > Property") as TSESTree.Property[])) { + for (const node of esquery( + sourceCode.ast, + "VariableDeclarator ObjectExpression > Property", + ) as TSESTree.Property[]) { const [propertyName, propertyValue] = metadataFromPropertyNode(node); if (isStylePropertyDisallowed(propertyName, propertyValue)) { const variableNode = sourceCode.getAncestors!(node).findLast( diff --git a/packages/eslint-plugin/src/utils/tailwind-internals.d.ts b/packages/eslint-plugin/src/utils/tailwind-internals.d.ts index 87485a1d7e..fd5a6ba32c 100644 --- a/packages/eslint-plugin/src/utils/tailwind-internals.d.ts +++ b/packages/eslint-plugin/src/utils/tailwind-internals.d.ts @@ -1,26 +1,24 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ declare module "tailwindcss/lib/lib/evaluateTailwindFunctions" { - import type { JitContext } from 'tailwindcss/lib/lib/setupContextUtils'; - import type { Root } from 'postcss'; + import type { JitContext } from "tailwindcss/lib/lib/setupContextUtils"; + import type { Root } from "postcss"; - function evaluateTailwindFunctions( - context: JITContext, - ): ((root: Root) => void); + function evaluateTailwindFunctions(context: JITContext): (root: Root) => void; export default { - default: evaluateTailwindFunctions - } + default: evaluateTailwindFunctions, + }; } declare module "tailwindcss/lib/lib/generateRules" { - import type { JitContext } from 'tailwindcss/lib/lib/setupContextUtils'; - import type { Rule } from 'postcss'; + import type { JitContext } from "tailwindcss/lib/lib/setupContextUtils"; + import type { Rule } from "postcss"; export function generateRules( classNames: Set, context: JITContext, - ): ([bigint, Rule])[]; + ): [bigint, Rule][]; } // taken from https://github.com/vinicoder/tw-to-css/blob/main/types.d.ts diff --git a/packages/eslint-plugin/src/utils/tailwind/get-source-code-tailwind-metadata.ts b/packages/eslint-plugin/src/utils/tailwind/get-source-code-tailwind-metadata.ts index 53ded03a58..771aae781c 100644 --- a/packages/eslint-plugin/src/utils/tailwind/get-source-code-tailwind-metadata.ts +++ b/packages/eslint-plugin/src/utils/tailwind/get-source-code-tailwind-metadata.ts @@ -14,10 +14,10 @@ export const getSourceCodeTailwindMetadata = ( ): | { hasTailwind: false } | { - hasTailwind: true; - tailwindConfig: TailwindComponentConfig; - tailwindContext: JitContext; - } => { + hasTailwind: true; + tailwindConfig: TailwindComponentConfig; + tailwindContext: JitContext; + } => { const tailwindComponentNode = esquery( sourceCode.ast, 'JSXOpeningElement[name.name="Tailwind"]',