Skip to content

Commit

Permalink
fix: parameter names
Browse files Browse the repository at this point in the history
  • Loading branch information
schoero committed Jan 19, 2025
1 parent eae9ece commit c294b8e
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 35 deletions.
10 changes: 5 additions & 5 deletions src/parsers/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import type { Attributes } from "readable-tailwind:types:rule.js";


export function getLiteralsByHTMLAttributes(ctx: Rule.RuleContext, attribute: AttributeNode, attributes: Attributes): Literal[] {
const literals = attributes.reduce<Literal[]>((literals, Attributes) => {
if(isAttributesName(Attributes)){
if(Attributes.toLowerCase() !== attribute.key.value.toLowerCase()){ return literals; }
const literals = attributes.reduce<Literal[]>((literals, attributes) => {
if(isAttributesName(attributes)){
if(attributes.toLowerCase() !== attribute.key.value.toLowerCase()){ return literals; }
literals.push(...getLiteralsByHTMLAttributeNode(ctx, attribute));
} else if(isAttributesRegex(Attributes)){
} else if(isAttributesRegex(attributes)){
console.warn("Regex not supported in HTML");
} else if(isAttributesMatchers(Attributes)){
} else if(isAttributesMatchers(attributes)){
console.warn("Matchers not supported in HTML");
}

Expand Down
16 changes: 8 additions & 8 deletions src/parsers/jsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ import type { Attributes } from "readable-tailwind:types:rule.js";
export function getLiteralsByJSXAttributes(ctx: Rule.RuleContext, attribute: JSXAttribute, attributes: Attributes): Literal[] {
const value = attribute.value;

const literals = attributes.reduce<Literal[]>((literals, Attributes) => {
const literals = attributes.reduce<Literal[]>((literals, attributes) => {
if(!value){ return literals; }

if(isAttributesName(Attributes)){
if(typeof attribute.name.name !== "string" || !matchesName(Attributes.toLowerCase(), attribute.name.name.toLowerCase())){ return literals; }
if(isAttributesName(attributes)){
if(typeof attribute.name.name !== "string" || !matchesName(attributes.toLowerCase(), attribute.name.name.toLowerCase())){ return literals; }
literals.push(...getLiteralsByJSXAttributeValue(ctx, value));
} else if(isAttributesRegex(Attributes)){
literals.push(...getLiteralsByESNodeAndRegex(ctx, attribute, Attributes));
} else if(isAttributesMatchers(Attributes)){
if(typeof attribute.name.name !== "string" || !matchesName(Attributes[0].toLowerCase(), attribute.name.name.toLowerCase())){ return literals; }
literals.push(...getLiteralsByESMatchers(ctx, value, Attributes[1]));
} else if(isAttributesRegex(attributes)){
literals.push(...getLiteralsByESNodeAndRegex(ctx, attribute, attributes));
} else if(isAttributesMatchers(attributes)){
if(typeof attribute.name.name !== "string" || !matchesName(attributes[0].toLowerCase(), attribute.name.name.toLowerCase())){ return literals; }
literals.push(...getLiteralsByESMatchers(ctx, value, attributes[1]));
}

return literals;
Expand Down
16 changes: 8 additions & 8 deletions src/parsers/svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ export function getLiteralsBySvelteAttributes(ctx: Rule.RuleContext, attribute:
return [];
}

const literals = attributes.reduce<Literal[]>((literals, Attributes) => {
if(isAttributesName(Attributes)){
if(!matchesName(Attributes.toLowerCase(), attribute.key.name.toLowerCase())){ return literals; }
const literals = attributes.reduce<Literal[]>((literals, attributes) => {
if(isAttributesName(attributes)){
if(!matchesName(attributes.toLowerCase(), attribute.key.name.toLowerCase())){ return literals; }
literals.push(...getLiteralsBySvelteLiteralNode(ctx, value));
} else if(isAttributesRegex(Attributes)){
literals.push(...getLiteralsByESNodeAndRegex(ctx, attribute, Attributes));
} else if(isAttributesMatchers(Attributes)){
if(!matchesName(Attributes[0].toLowerCase(), attribute.key.name.toLowerCase())){ return literals; }
literals.push(...getLiteralsBySvelteMatchers(ctx, value, Attributes[1]));
} else if(isAttributesRegex(attributes)){
literals.push(...getLiteralsByESNodeAndRegex(ctx, attribute, attributes));
} else if(isAttributesMatchers(attributes)){
if(!matchesName(attributes[0].toLowerCase(), attribute.key.name.toLowerCase())){ return literals; }
literals.push(...getLiteralsBySvelteMatchers(ctx, value, attributes[1]));
}

return literals;
Expand Down
16 changes: 8 additions & 8 deletions src/parsers/vue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ export function getLiteralsByVueAttributes(ctx: Rule.RuleContext, attribute: AST

const value = attribute.value;

const literals = attributes.reduce<Literal[]>((literals, Attributes) => {
if(isAttributesName(Attributes)){
if(!matchesName(getVueBoundName(Attributes).toLowerCase(), getVueAttributeName(attribute)?.toLowerCase())){ return literals; }
const literals = attributes.reduce<Literal[]>((literals, attributes) => {
if(isAttributesName(attributes)){
if(!matchesName(getVueBoundName(attributes).toLowerCase(), getVueAttributeName(attribute)?.toLowerCase())){ return literals; }
literals.push(...getLiteralsByVueLiteralNode(ctx, value));
} else if(isAttributesRegex(Attributes)){
literals.push(...getLiteralsByESNodeAndRegex(ctx, attribute, Attributes));
} else if(isAttributesMatchers(Attributes)){
if(!matchesName(getVueBoundName(Attributes[0]).toLowerCase(), getVueAttributeName(attribute)?.toLowerCase())){ return literals; }
literals.push(...getLiteralsByVueMatchers(ctx, value, Attributes[1]));
} else if(isAttributesRegex(attributes)){
literals.push(...getLiteralsByESNodeAndRegex(ctx, attribute, attributes));
} else if(isAttributesMatchers(attributes)){
if(!matchesName(getVueBoundName(attributes[0]).toLowerCase(), getVueAttributeName(attribute)?.toLowerCase())){ return literals; }
literals.push(...getLiteralsByVueMatchers(ctx, value, attributes[1]));
}

return literals;
Expand Down
12 changes: 6 additions & 6 deletions src/utils/matchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,16 +195,16 @@ export function isTagMatchers(tag: Tags[number]): tag is TagMatchers {
return Array.isArray(tag) && typeof tag[0] === "string" && Array.isArray(tag[1]);
}

export function isAttributesName(Attributes: Attributes[number]): Attributes is AttributeName {
return typeof Attributes === "string";
export function isAttributesName(attributes: Attributes[number]): attributes is AttributeName {
return typeof attributes === "string";
}

export function isAttributesRegex(Attributes: Attributes[number]): Attributes is AttributeRegex {
return Array.isArray(Attributes) && typeof Attributes[0] === "string" && typeof Attributes[1] === "string";
export function isAttributesRegex(attributes: Attributes[number]): attributes is AttributeRegex {
return Array.isArray(attributes) && typeof attributes[0] === "string" && typeof attributes[1] === "string";
}

export function isAttributesMatchers(Attributes: Attributes[number]): Attributes is AttributeMatchers {
return Array.isArray(Attributes) && typeof Attributes[0] === "string" && Array.isArray(Attributes[1]);
export function isAttributesMatchers(attributes: Attributes[number]): attributes is AttributeMatchers {
return Array.isArray(attributes) && typeof attributes[0] === "string" && Array.isArray(attributes[1]);
}

export function isInsideConditionalExpressionTest(node: ESNode & Partial<Rule.NodeParentExtension>): boolean {
Expand Down

0 comments on commit c294b8e

Please sign in to comment.