diff --git a/docs/api/defaults.md b/docs/api/defaults.md
index c8af4a9..d2d6bf1 100644
--- a/docs/api/defaults.md
+++ b/docs/api/defaults.md
@@ -1,7 +1,7 @@
# Defaults
-Every [rule](../../README.md#rules) can target multiple class attributes, callee names, variable names or template literal tags.
+Every [rule](../../README.md#rules) can target multiple attributes, callee names, variable names or template literal tags.
Read the [concepts documentation](../concepts/concepts.md) first to learn why this is important and what different options there are to define where to look for tailwind classes.
@@ -28,8 +28,8 @@ If an utility is not supported or you have built your own, you can change the ma
```ts
import {
+ getDefaultAttributes,
getDefaultCallees,
- getDefaultClassAttributes,
getDefaultTags,
getDefaultVariables
} from "eslint-plugin-readable-tailwind/api/defaults";
@@ -43,8 +43,8 @@ import {
```ts
import eslintPluginReadableTailwind from "eslint-plugin-readable-tailwind";
import {
+ getDefaultAttributes,
getDefaultCallees,
- getDefaultClassAttributes,
getDefaultVariables
} from "eslint-plugin-readable-tailwind/api/defaults";
import { MatcherType } from "eslint-plugin-readable-tailwind/api/types";
@@ -69,8 +69,8 @@ export default [
]
}],
"readable-tailwind/no-duplicate-classes": ["warn", {
- classAttributes: [
- ...getDefaultClassAttributes(),
+ attributes: [
+ ...getDefaultAttributes(),
[
"myAttribute", [
{
@@ -93,7 +93,7 @@ export default [
]
}],
"readable-tailwind/sort-classes": ["warn", {
- classAttributes: [
+ attributes: [
...getDefaultTags(),
[
"myTag", [
diff --git a/docs/concepts/concepts.md b/docs/concepts/concepts.md
index 6859470..698b5a7 100644
--- a/docs/concepts/concepts.md
+++ b/docs/concepts/concepts.md
@@ -4,7 +4,7 @@ The [rules](../../README.md#rules) of this plugin can't apply to every string li
There are different ways to define where to look for tailwind classes.
-- [Name](#name): Matches a single string literal by the name of the callee, variable or class attribute.
+- [Name](#name): Matches a single string literal by the name of the callee, variable or attribute.
- [Regular expressions](#regular-expressions): Matches multiple string literals by regular expressions.
- [Matchers](#matchers): Matches multiple string literals by the abstract syntax tree.
@@ -18,7 +18,7 @@ It is possible that you never have to change this configuration, but if you do n
## Name
-The simplest form to define string literals to lint is by their name. Callees, variables or class attributes with that name will be linted. The name can be a string or a regular expression.
+The simplest form to define string literals to lint is by their name. Callees, variables or attributes with that name will be linted. The name can be a string or a regular expression.
@@ -34,7 +34,7 @@ type Name = string;
```jsonc
{
- "classAttributes": ["myAttribute"]
+ "attributes": ["myAttribute"]
}
```
@@ -101,7 +101,7 @@ type Regex = [
```jsonc
{
- "classAttributes": [
+ "attributes": [
[
// matches the attribute name and the attribute value
"myAttribute={([\\S\\s]*)}",
@@ -254,7 +254,7 @@ For example, the object path for the `value` key in the following object would b
```jsonc
{
- "classAttributes": [
+ "attributes": [
[
// matches attributes with the name `myAttribute`
"myAttribute",
diff --git a/docs/rules/multiline.md b/docs/rules/multiline.md
index 7d0879b..0f2ea12 100644
--- a/docs/rules/multiline.md
+++ b/docs/rules/multiline.md
@@ -61,7 +61,7 @@ Enforce tailwind classes to be broken up into multiple lines. It is possible to
-- `classAttributes`
+- `attributes`
The name of the attribute that contains the tailwind classes. This can also be set globally via the [`settings` object](../settings/settings.md).
diff --git a/docs/rules/no-duplicate-classes.md b/docs/rules/no-duplicate-classes.md
index f69ab15..e9aa500 100644
--- a/docs/rules/no-duplicate-classes.md
+++ b/docs/rules/no-duplicate-classes.md
@@ -6,7 +6,7 @@ Disallow duplicate classes in tailwindcss class strings.
## Options
-- `classAttributes`
+- `attributes`
The name of the attribute that contains the tailwind classes. This can also be set globally via the [`settings` object](../settings/settings.md).
diff --git a/docs/rules/no-unnecessary-whitespace.md b/docs/rules/no-unnecessary-whitespace.md
index 34cda2b..28facf9 100644
--- a/docs/rules/no-unnecessary-whitespace.md
+++ b/docs/rules/no-unnecessary-whitespace.md
@@ -16,7 +16,7 @@ Disallow unnecessary whitespace in between and around tailwind classes.
-- `classAttributes`
+- `attributes`
The name of the attribute that contains the tailwind classes. This can also be set globally via the [`settings` object](../settings/settings.md).
diff --git a/docs/rules/sort-classes.md b/docs/rules/sort-classes.md
index 6d44fcb..e4270c7 100644
--- a/docs/rules/sort-classes.md
+++ b/docs/rules/sort-classes.md
@@ -31,7 +31,7 @@ Enforce the order of tailwind classes. It is possible to sort classes alphabetic
-- `classAttributes`
+- `attributes`
The name of the attribute that contains the tailwind classes. This can also be set globally via the [`settings` object](../settings/settings.md).
diff --git a/docs/settings/settings.md b/docs/settings/settings.md
index 87899b7..830f1d7 100644
--- a/docs/settings/settings.md
+++ b/docs/settings/settings.md
@@ -2,7 +2,7 @@
## Table of Contents
-- [classAttributes](#classattributes)
+- [attributes](#attributes)
- [callees](#callees)
- [variables](#variables)
@@ -21,7 +21,7 @@ To set the settings object, add a `settings` key to the eslint config.
"rules": { /* ... */ },
"settings": {
"readable-tailwind": {
- "classAttributes": [/* ... */],
+ "attributes": [/* ... */],
"callees": [/* ... */],
"variables": [/* ... */],
"tags": [/* ... */]
@@ -33,7 +33,7 @@ To set the settings object, add a `settings` key to the eslint config.
-### `classAttributes`
+### `attributes`
The name of the attribute that contains the tailwind classes.
diff --git a/src/api/defaults.ts b/src/api/defaults.ts
index 07c6b7d..34e2d0f 100644
--- a/src/api/defaults.ts
+++ b/src/api/defaults.ts
@@ -10,7 +10,7 @@ export function getDefaultCallees() {
return DEFAULT_CALLEE_NAMES;
}
-export function getDefaultClassAttributes() {
+export function getDefaultAttributes() {
return DEFAULT_ATTRIBUTE_NAMES;
}
diff --git a/src/options/default-options.ts b/src/options/default-options.ts
index a3ec496..508352d 100644
--- a/src/options/default-options.ts
+++ b/src/options/default-options.ts
@@ -13,7 +13,7 @@ import { TW_JOIN } from "readable-tailwind:options:callees/twJoin.js";
import { TW_MERGE } from "readable-tailwind:options:callees/twMerge.js";
import { MatcherType } from "readable-tailwind:types:rule.js";
-import type { Callees, ClassAttributes, Tags, Variables } from "readable-tailwind:types:rule.js";
+import type { Attributes, Callees, Tags, Variables } from "readable-tailwind:types:rule.js";
export const DEFAULT_CALLEE_NAMES = [
@@ -58,7 +58,7 @@ export const DEFAULT_ATTRIBUTE_NAMES = [
}
]
]
-] satisfies ClassAttributes;
+] satisfies Attributes;
export const DEFAULT_VARIABLE_NAMES = [
[
diff --git a/src/options/descriptions.test.ts b/src/options/descriptions.test.ts
index 9534174..fb21ce0 100644
--- a/src/options/descriptions.test.ts
+++ b/src/options/descriptions.test.ts
@@ -1,29 +1,25 @@
import { validate } from "json-schema";
import { describe, expect, test } from "vitest";
-import {
- getCalleeSchema,
- getClassAttributeSchema,
- getVariableSchema
-} from "readable-tailwind:options:descriptions.js";
+import { getAttributesSchema, getCalleeSchema, getVariableSchema } from "readable-tailwind:options:descriptions.js";
import { MatcherType } from "readable-tailwind:types:rule.js";
-import type { CalleeOption, ClassAttributeOption, VariableOption } from "readable-tailwind:types:rule.js";
+import type { AttributeOption, CalleeOption, VariableOption } from "readable-tailwind:types:rule.js";
describe("descriptions", () => {
test("name config", () => {
- const classAttributes = {
- classAttributes: [
+ const attributes = {
+ attributes: [
"class",
"className"
]
- } satisfies ClassAttributeOption;
+ } satisfies AttributeOption;
expect(
- validate(classAttributes, getClassAttributeSchema(classAttributes))
+ validate(attributes, getAttributesSchema(attributes))
).toStrictEqual(
{ errors: [], valid: true }
);
@@ -57,15 +53,15 @@ describe("descriptions", () => {
test("regex config", () => {
- const classAttributes = {
- classAttributes: [
+ const attributes = {
+ attributes: [
"(class|className)",
"(.*)"
]
- } satisfies ClassAttributeOption;
+ } satisfies AttributeOption;
expect(
- validate(classAttributes, getClassAttributeSchema(classAttributes))
+ validate(attributes, getAttributesSchema(attributes))
).toStrictEqual(
{ errors: [], valid: true }
);
@@ -100,8 +96,8 @@ describe("descriptions", () => {
test("matcher config", () => {
- const classAttributes: ClassAttributeOption = {
- classAttributes: [
+ const attributes: AttributeOption = {
+ attributes: [
[
"class",
[
@@ -121,7 +117,7 @@ describe("descriptions", () => {
};
expect(
- validate(classAttributes, getClassAttributeSchema(classAttributes))
+ validate(attributes, getAttributesSchema(attributes))
).toStrictEqual(
{ errors: [], valid: true }
);
diff --git a/src/options/descriptions.ts b/src/options/descriptions.ts
index 3a9e1b3..71ce032 100644
--- a/src/options/descriptions.ts
+++ b/src/options/descriptions.ts
@@ -3,16 +3,16 @@ import { MatcherType } from "readable-tailwind:types:rule.js";
import type { Rule } from "eslint";
-export function getClassAttributeSchema(defaultValue: unknown) {
+export function getAttributesSchema(defaultValue: unknown) {
return {
- classAttributes: {
+ attributes: {
default: defaultValue,
description: "List of attribute names that should get linted.",
items: {
anyOf: [
- CLASS_ATTRIBUTE_NAME_CONFIG,
- CLASS_ATTRIBUTE_REGEX_CONFIG,
- CLASS_ATTRIBUTE_MATCHER_CONFIG
+ ATTRIBUTE_NAME_CONFIG,
+ ATTRIBUTE_REGEX_CONFIG,
+ ATTRIBUTE_MATCHER_CONFIG
]
},
type: "array"
@@ -112,7 +112,7 @@ const OBJECT_VALUE_MATCHER_SCHEMA = {
type: "object"
} satisfies Rule.RuleMetaData["schema"];
-const CLASS_ATTRIBUTE_REGEX_CONFIG = {
+const ATTRIBUTE_REGEX_CONFIG = {
description: "List of regular expressions that matches string literals which should get linted.",
items: [
{
@@ -127,7 +127,7 @@ const CLASS_ATTRIBUTE_REGEX_CONFIG = {
type: "array"
};
-const CLASS_ATTRIBUTE_MATCHER_CONFIG = {
+const ATTRIBUTE_MATCHER_CONFIG = {
description: "List of matchers that will automatically be matched.",
items: [
{
@@ -150,7 +150,7 @@ const CLASS_ATTRIBUTE_MATCHER_CONFIG = {
type: "array"
};
-const CLASS_ATTRIBUTE_NAME_CONFIG = {
+const ATTRIBUTE_NAME_CONFIG = {
description: "Attribute name that for which children get linted.",
type: "string"
};
diff --git a/src/parsers/es.test.ts b/src/parsers/es.test.ts
index 5d2e423..b58696d 100644
--- a/src/parsers/es.test.ts
+++ b/src/parsers/es.test.ts
@@ -44,7 +44,7 @@ describe("es", () => {
});
});
- it("should match classAttributes via regex", () => {
+ it("should match attributes via regex", () => {
lint(tailwindNoUnnecessaryWhitespace, TEST_SYNTAXES, {
invalid: [
{
@@ -52,7 +52,7 @@ describe("es", () => {
jsx: ``,
jsxOutput: ``,
options: [{
- classAttributes: ["^.*Styles$"]
+ attributes: ["^.*Styles$"]
}],
svelte: ``,
svelteOutput: ``,
diff --git a/src/parsers/html.ts b/src/parsers/html.ts
index 76ede92..548747d 100644
--- a/src/parsers/html.ts
+++ b/src/parsers/html.ts
@@ -1,25 +1,21 @@
-import {
- isClassAttributeMatchers,
- isClassAttributeName,
- isClassAttributeRegex
-} from "readable-tailwind:utils:matchers.js";
+import { isAttributesMatchers, isAttributesName, isAttributesRegex } from "readable-tailwind:utils:matchers.js";
import { deduplicateLiterals } from "readable-tailwind:utils:utils.js";
import type { AttributeNode, TagNode } from "es-html-parser";
import type { Rule } from "eslint";
import type { Literal, QuoteMeta } from "readable-tailwind:types:ast.js";
-import type { ClassAttributes } from "readable-tailwind:types:rule.js";
+import type { Attributes } from "readable-tailwind:types:rule.js";
-export function getLiteralsByHTMLClassAttribute(ctx: Rule.RuleContext, attribute: AttributeNode, classAttributes: ClassAttributes): Literal[] {
- const literals = classAttributes.reduce((literals, classAttribute) => {
- if(isClassAttributeName(classAttribute)){
- if(classAttribute.toLowerCase() !== attribute.key.value.toLowerCase()){ return literals; }
+export function getLiteralsByHTMLAttributes(ctx: Rule.RuleContext, attribute: AttributeNode, attributes: Attributes): Literal[] {
+ const literals = attributes.reduce((literals, Attributes) => {
+ if(isAttributesName(Attributes)){
+ if(Attributes.toLowerCase() !== attribute.key.value.toLowerCase()){ return literals; }
literals.push(...getLiteralsByHTMLAttributeNode(ctx, attribute));
- } else if(isClassAttributeRegex(classAttribute)){
+ } else if(isAttributesRegex(Attributes)){
console.warn("Regex not supported in HTML");
- } else if(isClassAttributeMatchers(classAttribute)){
+ } else if(isAttributesMatchers(Attributes)){
console.warn("Matchers not supported in HTML");
}
diff --git a/src/parsers/jsx.ts b/src/parsers/jsx.ts
index a5d8938..605e05b 100644
--- a/src/parsers/jsx.ts
+++ b/src/parsers/jsx.ts
@@ -6,11 +6,7 @@ import {
isESSimpleStringLiteral,
isESTemplateLiteral
} from "readable-tailwind:parsers:es.js";
-import {
- isClassAttributeMatchers,
- isClassAttributeName,
- isClassAttributeRegex
-} from "readable-tailwind:utils:matchers.js";
+import { isAttributesMatchers, isAttributesName, isAttributesRegex } from "readable-tailwind:utils:matchers.js";
import { getLiteralsByESNodeAndRegex } from "readable-tailwind:utils:regex.js";
import { deduplicateLiterals, matchesName } from "readable-tailwind:utils:utils.js";
@@ -20,23 +16,23 @@ import type { JSXAttribute, BaseNode as JSXBaseNode, JSXExpressionContainer, JSX
import type { ESSimpleStringLiteral } from "readable-tailwind:parsers:es.js";
import type { Literal } from "readable-tailwind:types:ast.js";
-import type { ClassAttributes } from "readable-tailwind:types:rule.js";
+import type { Attributes } from "readable-tailwind:types:rule.js";
-export function getLiteralsByJSXClassAttribute(ctx: Rule.RuleContext, attribute: JSXAttribute, classAttributes: ClassAttributes): Literal[] {
+export function getLiteralsByJSXAttributes(ctx: Rule.RuleContext, attribute: JSXAttribute, attributes: Attributes): Literal[] {
const value = attribute.value;
- const literals = classAttributes.reduce((literals, classAttribute) => {
+ const literals = attributes.reduce((literals, Attributes) => {
if(!value){ return literals; }
- if(isClassAttributeName(classAttribute)){
- if(typeof attribute.name.name !== "string" || !matchesName(classAttribute.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(isClassAttributeRegex(classAttribute)){
- literals.push(...getLiteralsByESNodeAndRegex(ctx, attribute, classAttribute));
- } else if(isClassAttributeMatchers(classAttribute)){
- if(typeof attribute.name.name !== "string" || !matchesName(classAttribute[0].toLowerCase(), attribute.name.name.toLowerCase())){ return literals; }
- literals.push(...getLiteralsByESMatchers(ctx, value, classAttribute[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;
diff --git a/src/parsers/svelte.ts b/src/parsers/svelte.ts
index 12ad36e..3bb7c77 100644
--- a/src/parsers/svelte.ts
+++ b/src/parsers/svelte.ts
@@ -9,9 +9,9 @@ import { MatcherType } from "readable-tailwind:types:rule.js";
import {
getLiteralNodesByMatchers,
getObjectPath,
- isClassAttributeMatchers,
- isClassAttributeName,
- isClassAttributeRegex,
+ isAttributesMatchers,
+ isAttributesName,
+ isAttributesRegex,
isInsideConditionalExpressionTest,
isInsideLogicalExpressionLeft,
matchesPathPattern
@@ -35,7 +35,7 @@ import type {
} from "svelte-eslint-parser/lib/ast/index.js";
import type { Literal, Node, StringLiteral } from "readable-tailwind:types:ast.js";
-import type { ClassAttributes, Matcher, MatcherFunctions } from "readable-tailwind:types:rule.js";
+import type { Attributes, Matcher, MatcherFunctions } from "readable-tailwind:types:rule.js";
export function getAttributesBySvelteTag(ctx: Rule.RuleContext, node: SvelteStartTag): SvelteAttribute[] {
@@ -47,7 +47,7 @@ export function getAttributesBySvelteTag(ctx: Rule.RuleContext, node: SvelteStar
}, []);
}
-export function getLiteralsBySvelteClassAttribute(ctx: Rule.RuleContext, attribute: SvelteAttribute, classAttributes: ClassAttributes): Literal[] {
+export function getLiteralsBySvelteAttributes(ctx: Rule.RuleContext, attribute: SvelteAttribute, attributes: Attributes): Literal[] {
// skip shorthand attributes #42
if(!Array.isArray(attribute.value)){
@@ -60,15 +60,15 @@ export function getLiteralsBySvelteClassAttribute(ctx: Rule.RuleContext, attribu
return [];
}
- const literals = classAttributes.reduce((literals, classAttribute) => {
- if(isClassAttributeName(classAttribute)){
- if(!matchesName(classAttribute.toLowerCase(), attribute.key.name.toLowerCase())){ return literals; }
+ const literals = attributes.reduce((literals, Attributes) => {
+ if(isAttributesName(Attributes)){
+ if(!matchesName(Attributes.toLowerCase(), attribute.key.name.toLowerCase())){ return literals; }
literals.push(...getLiteralsBySvelteLiteralNode(ctx, value));
- } else if(isClassAttributeRegex(classAttribute)){
- literals.push(...getLiteralsByESNodeAndRegex(ctx, attribute, classAttribute));
- } else if(isClassAttributeMatchers(classAttribute)){
- if(!matchesName(classAttribute[0].toLowerCase(), attribute.key.name.toLowerCase())){ return literals; }
- literals.push(...getLiteralsBySvelteMatchers(ctx, value, classAttribute[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;
diff --git a/src/parsers/vue.test.ts b/src/parsers/vue.test.ts
index adf68c7..ffaa542 100644
--- a/src/parsers/vue.test.ts
+++ b/src/parsers/vue.test.ts
@@ -69,13 +69,13 @@ describe(tailwindSortClasses.name, () => {
invalid: [
{
errors: 1,
- options: [{ classAttributes: [[":custom-class", [{ match: MatcherType.String }]]], order: "asc" }],
+ options: [{ attributes: [[":custom-class", [{ match: MatcherType.String }]]], order: "asc" }],
vue: ``,
vueOutput: ``
},
{
errors: 1,
- options: [{ classAttributes: [["v-bind:custom-class", [{ match: MatcherType.String }]]], order: "asc" }],
+ options: [{ attributes: [["v-bind:custom-class", [{ match: MatcherType.String }]]], order: "asc" }],
vue: ``,
vueOutput: ``
}
@@ -88,7 +88,7 @@ describe(tailwindSortClasses.name, () => {
invalid: [
{
errors: 1,
- options: [{ classAttributes: [[":.*Styles$", [{ match: MatcherType.String }]]], order: "asc" }],
+ options: [{ attributes: [[":.*Styles$", [{ match: MatcherType.String }]]], order: "asc" }],
vue: ``,
vueOutput: ``
}
diff --git a/src/parsers/vue.ts b/src/parsers/vue.ts
index 4c2dc82..552838e 100644
--- a/src/parsers/vue.ts
+++ b/src/parsers/vue.ts
@@ -9,9 +9,9 @@ import { MatcherType } from "readable-tailwind:types:rule.js";
import {
getLiteralNodesByMatchers,
getObjectPath,
- isClassAttributeMatchers,
- isClassAttributeName,
- isClassAttributeRegex,
+ isAttributesMatchers,
+ isAttributesName,
+ isAttributesRegex,
isInsideConditionalExpressionTest,
isInsideLogicalExpressionLeft,
matchesPathPattern
@@ -24,7 +24,7 @@ import type { BaseNode as ESBaseNode, Node as ESNode } from "estree";
import type { AST } from "vue-eslint-parser";
import type { Literal, Node, StringLiteral } from "readable-tailwind:types:ast.js";
-import type { ClassAttributes, Matcher, MatcherFunctions } from "readable-tailwind:types:rule.js";
+import type { Attributes, Matcher, MatcherFunctions } from "readable-tailwind:types:rule.js";
export function getAttributesByVueStartTag(ctx: Rule.RuleContext, node: AST.VStartTag): (AST.VAttribute | AST.VDirective)[] {
@@ -32,7 +32,7 @@ export function getAttributesByVueStartTag(ctx: Rule.RuleContext, node: AST.VSta
}
-export function getLiteralsByVueClassAttribute(ctx: Rule.RuleContext, attribute: AST.VAttribute | AST.VDirective, classAttributes: ClassAttributes): Literal[] {
+export function getLiteralsByVueAttributes(ctx: Rule.RuleContext, attribute: AST.VAttribute | AST.VDirective, attributes: Attributes): Literal[] {
if(attribute.value === null){
return [];
@@ -40,15 +40,15 @@ export function getLiteralsByVueClassAttribute(ctx: Rule.RuleContext, attribute:
const value = attribute.value;
- const literals = classAttributes.reduce((literals, classAttribute) => {
- if(isClassAttributeName(classAttribute)){
- if(!matchesName(getVueBoundName(classAttribute).toLowerCase(), getVueAttributeName(attribute)?.toLowerCase())){ return literals; }
+ const literals = attributes.reduce((literals, Attributes) => {
+ if(isAttributesName(Attributes)){
+ if(!matchesName(getVueBoundName(Attributes).toLowerCase(), getVueAttributeName(attribute)?.toLowerCase())){ return literals; }
literals.push(...getLiteralsByVueLiteralNode(ctx, value));
- } else if(isClassAttributeRegex(classAttribute)){
- literals.push(...getLiteralsByESNodeAndRegex(ctx, attribute, classAttribute));
- } else if(isClassAttributeMatchers(classAttribute)){
- if(!matchesName(getVueBoundName(classAttribute[0]).toLowerCase(), getVueAttributeName(attribute)?.toLowerCase())){ return literals; }
- literals.push(...getLiteralsByVueMatchers(ctx, value, classAttribute[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;
diff --git a/src/rules/tailwind-multiline.ts b/src/rules/tailwind-multiline.ts
index 4dc3788..0a5c71e 100644
--- a/src/rules/tailwind-multiline.ts
+++ b/src/rules/tailwind-multiline.ts
@@ -5,8 +5,8 @@ import {
DEFAULT_VARIABLE_NAMES
} from "readable-tailwind:options:default-options.js";
import {
+ getAttributesSchema,
getCalleeSchema,
- getClassAttributeSchema,
getTagsSchema,
getVariableSchema
} from "readable-tailwind:options:descriptions.js";
@@ -16,10 +16,10 @@ import {
getLiteralsByTaggedTemplateExpression,
isESObjectKey
} from "readable-tailwind:parsers:es.js";
-import { getAttributesByHTMLTag, getLiteralsByHTMLClassAttribute } from "readable-tailwind:parsers:html.js";
-import { getAttributesByJSXElement, getLiteralsByJSXClassAttribute } from "readable-tailwind:parsers:jsx.js";
-import { getAttributesBySvelteTag, getLiteralsBySvelteClassAttribute } from "readable-tailwind:parsers:svelte.js";
-import { getAttributesByVueStartTag, getLiteralsByVueClassAttribute } from "readable-tailwind:parsers:vue.js";
+import { getAttributesByHTMLTag, getLiteralsByHTMLAttributes } from "readable-tailwind:parsers:html.js";
+import { getAttributesByJSXElement, getLiteralsByJSXAttributes } from "readable-tailwind:parsers:jsx.js";
+import { getAttributesBySvelteTag, getLiteralsBySvelteAttributes } from "readable-tailwind:parsers:svelte.js";
+import { getAttributesByVueStartTag, getLiteralsByVueAttributes } from "readable-tailwind:parsers:vue.js";
import { escapeNestedQuotes } from "readable-tailwind:utils:quotes.js";
import {
display,
@@ -37,8 +37,8 @@ import type { AST } from "vue-eslint-parser";
import type { Literal, Meta } from "readable-tailwind:types:ast.js";
import type {
+ AttributeOption,
CalleeOption,
- ClassAttributeOption,
ESLintRule,
TagOption,
VariableOption
@@ -47,8 +47,8 @@ import type {
export type Options = [
Partial<
+ AttributeOption &
CalleeOption &
- ClassAttributeOption &
TagOption &
VariableOption &
{
@@ -63,8 +63,8 @@ export type Options = [
];
const defaultOptions = {
+ attributes: DEFAULT_ATTRIBUTE_NAMES,
callees: DEFAULT_CALLEE_NAMES,
- classAttributes: DEFAULT_ATTRIBUTE_NAMES,
classesPerLine: 0,
group: "emptyLine",
indent: 2,
@@ -80,7 +80,7 @@ export const tailwindMultiline: ESLintRule = {
rule: {
create(ctx) {
- const { callees, classAttributes, tags, variables } = getOptions(ctx);
+ const { attributes, callees, tags, variables } = getOptions(ctx);
const callExpression = {
CallExpression(node: Node) {
@@ -122,7 +122,7 @@ export const tailwindMultiline: ESLintRule = {
if(!attributeValue){ continue; }
if(typeof attributeName !== "string"){ continue; }
- const literals = getLiteralsByJSXClassAttribute(ctx, jsxAttribute, classAttributes);
+ const literals = getLiteralsByJSXAttributes(ctx, jsxAttribute, attributes);
lintLiterals(ctx, literals);
}
}
@@ -138,7 +138,7 @@ export const tailwindMultiline: ESLintRule = {
if(typeof attributeName !== "string"){ continue; }
- const literals = getLiteralsBySvelteClassAttribute(ctx, svelteAttribute, classAttributes);
+ const literals = getLiteralsBySvelteAttributes(ctx, svelteAttribute, attributes);
lintLiterals(ctx, literals);
}
}
@@ -150,7 +150,7 @@ export const tailwindMultiline: ESLintRule = {
const vueAttributes = getAttributesByVueStartTag(ctx, vueNode);
for(const attribute of vueAttributes){
- const literals = getLiteralsByVueClassAttribute(ctx, attribute, classAttributes);
+ const literals = getLiteralsByVueAttributes(ctx, attribute, attributes);
lintLiterals(ctx, literals);
}
}
@@ -162,7 +162,7 @@ export const tailwindMultiline: ESLintRule = {
const htmlAttributes = getAttributesByHTMLTag(ctx, htmlTagNode);
for(const htmlAttribute of htmlAttributes){
- const literals = getLiteralsByHTMLClassAttribute(ctx, htmlAttribute, classAttributes);
+ const literals = getLiteralsByHTMLAttributes(ctx, htmlAttribute, attributes);
lintLiterals(ctx, literals);
}
}
@@ -208,7 +208,7 @@ export const tailwindMultiline: ESLintRule = {
additionalProperties: false,
properties: {
...getCalleeSchema(defaultOptions.callees),
- ...getClassAttributeSchema(defaultOptions.classAttributes),
+ ...getAttributesSchema(defaultOptions.attributes),
...getVariableSchema(defaultOptions.variables),
...getTagsSchema(defaultOptions.tags),
classesPerLine: {
@@ -658,10 +658,10 @@ function getOptions(ctx?: Rule.RuleContext) {
const group = options.group ?? defaultOptions.group;
const preferSingleLine = options.preferSingleLine ?? defaultOptions.preferSingleLine;
- const classAttributes = options.classAttributes ??
- ctx?.settings["eslint-plugin-readable-tailwind"]?.classAttributes ??
- ctx?.settings["readable-tailwind"]?.classAttributes ??
- defaultOptions.classAttributes;
+ const attributes = options.attributes ??
+ ctx?.settings["eslint-plugin-readable-tailwind"]?.attributes ??
+ ctx?.settings["readable-tailwind"]?.attributes ??
+ defaultOptions.attributes;
const callees = options.callees ??
ctx?.settings["eslint-plugin-readable-tailwind"]?.callees ??
@@ -681,8 +681,8 @@ function getOptions(ctx?: Rule.RuleContext) {
const lineBreakStyle = options.lineBreakStyle ?? defaultOptions.lineBreakStyle;
return {
+ attributes,
callees,
- classAttributes,
classesPerLine,
group,
indent,
diff --git a/src/rules/tailwind-no-duplicate-classes.ts b/src/rules/tailwind-no-duplicate-classes.ts
index c7bd883..8c065bd 100644
--- a/src/rules/tailwind-no-duplicate-classes.ts
+++ b/src/rules/tailwind-no-duplicate-classes.ts
@@ -5,8 +5,8 @@ import {
DEFAULT_VARIABLE_NAMES
} from "readable-tailwind:options:default-options.js";
import {
+ getAttributesSchema,
getCalleeSchema,
- getClassAttributeSchema,
getTagsSchema,
getVariableSchema
} from "readable-tailwind:options:descriptions.js";
@@ -18,10 +18,10 @@ import {
isESCallExpression,
isESVariableDeclarator
} from "readable-tailwind:parsers:es.js";
-import { getAttributesByHTMLTag, getLiteralsByHTMLClassAttribute } from "readable-tailwind:parsers:html.js";
-import { getAttributesByJSXElement, getLiteralsByJSXClassAttribute } from "readable-tailwind:parsers:jsx.js";
-import { getAttributesBySvelteTag, getLiteralsBySvelteClassAttribute } from "readable-tailwind:parsers:svelte.js";
-import { getAttributesByVueStartTag, getLiteralsByVueClassAttribute } from "readable-tailwind:parsers:vue.js";
+import { getAttributesByHTMLTag, getLiteralsByHTMLAttributes } from "readable-tailwind:parsers:html.js";
+import { getAttributesByJSXElement, getLiteralsByJSXAttributes } from "readable-tailwind:parsers:jsx.js";
+import { getAttributesBySvelteTag, getLiteralsBySvelteAttributes } from "readable-tailwind:parsers:svelte.js";
+import { getAttributesByVueStartTag, getLiteralsByVueAttributes } from "readable-tailwind:parsers:vue.js";
import { escapeNestedQuotes } from "readable-tailwind:utils:quotes.js";
import { splitClasses, splitWhitespaces } from "readable-tailwind:utils:utils.js";
@@ -34,8 +34,8 @@ import type { AST } from "vue-eslint-parser";
import type { Literal } from "readable-tailwind:types:ast.js";
import type {
+ AttributeOption,
CalleeOption,
- ClassAttributeOption,
ESLintRule,
TagOption,
VariableOption
@@ -44,8 +44,8 @@ import type {
export type Options = [
Partial<
+ AttributeOption &
CalleeOption &
- ClassAttributeOption &
TagOption &
VariableOption &
{
@@ -55,8 +55,8 @@ export type Options = [
];
const defaultOptions = {
+ attributes: DEFAULT_ATTRIBUTE_NAMES,
callees: DEFAULT_CALLEE_NAMES,
- classAttributes: DEFAULT_ATTRIBUTE_NAMES,
tags: DEFAULT_TAG_NAMES,
variables: DEFAULT_VARIABLE_NAMES
} as const satisfies Options[0];
@@ -66,7 +66,7 @@ export const tailwindNoDuplicateClasses: ESLintRule = {
rule: {
create(ctx) {
- const { callees, classAttributes, tags, variables } = getOptions(ctx);
+ const { attributes, callees, tags, variables } = getOptions(ctx);
const callExpression = {
CallExpression(node: ESNode) {
@@ -101,7 +101,7 @@ export const tailwindNoDuplicateClasses: ESLintRule = {
const jsxAttributes = getAttributesByJSXElement(ctx, jsxNode);
for(const attribute of jsxAttributes){
- const literals = getLiteralsByJSXClassAttribute(ctx, attribute, classAttributes);
+ const literals = getLiteralsByJSXAttributes(ctx, attribute, attributes);
lintLiterals(ctx, literals);
}
}
@@ -113,7 +113,7 @@ export const tailwindNoDuplicateClasses: ESLintRule = {
const svelteAttributes = getAttributesBySvelteTag(ctx, svelteNode);
for(const attribute of svelteAttributes){
- const literals = getLiteralsBySvelteClassAttribute(ctx, attribute, classAttributes);
+ const literals = getLiteralsBySvelteAttributes(ctx, attribute, attributes);
lintLiterals(ctx, literals);
}
}
@@ -125,7 +125,7 @@ export const tailwindNoDuplicateClasses: ESLintRule = {
const vueAttributes = getAttributesByVueStartTag(ctx, vueNode);
for(const attribute of vueAttributes){
- const literals = getLiteralsByVueClassAttribute(ctx, attribute, classAttributes);
+ const literals = getLiteralsByVueAttributes(ctx, attribute, attributes);
lintLiterals(ctx, literals);
}
}
@@ -137,7 +137,7 @@ export const tailwindNoDuplicateClasses: ESLintRule = {
const htmlAttributes = getAttributesByHTMLTag(ctx, htmlTagNode);
for(const htmlAttribute of htmlAttributes){
- const literals = getLiteralsByHTMLClassAttribute(ctx, htmlAttribute, classAttributes);
+ const literals = getLiteralsByHTMLAttributes(ctx, htmlAttribute, attributes);
lintLiterals(ctx, literals);
}
}
@@ -182,7 +182,7 @@ export const tailwindNoDuplicateClasses: ESLintRule = {
additionalProperties: false,
properties: {
...getCalleeSchema(defaultOptions.callees),
- ...getClassAttributeSchema(defaultOptions.classAttributes),
+ ...getAttributesSchema(defaultOptions.attributes),
...getVariableSchema(defaultOptions.variables),
...getTagsSchema(defaultOptions.tags)
},
@@ -351,10 +351,10 @@ function getOptions(ctx?: Rule.RuleContext) {
const options: Options[0] = ctx?.options[0] ?? {};
- const classAttributes = options.classAttributes ??
- ctx?.settings["eslint-plugin-readable-tailwind"]?.classAttributes ??
- ctx?.settings["readable-tailwind"]?.classAttributes ??
- defaultOptions.classAttributes;
+ const attributes = options.attributes ??
+ ctx?.settings["eslint-plugin-readable-tailwind"]?.attributes ??
+ ctx?.settings["readable-tailwind"]?.attributes ??
+ defaultOptions.attributes;
const callees = options.callees ??
ctx?.settings["eslint-plugin-readable-tailwind"]?.callees ??
@@ -372,8 +372,8 @@ function getOptions(ctx?: Rule.RuleContext) {
defaultOptions.tags;
return {
+ attributes,
callees,
- classAttributes,
tags,
variables
};
diff --git a/src/rules/tailwind-no-unnecessary-whitespace.ts b/src/rules/tailwind-no-unnecessary-whitespace.ts
index 345b9c6..6d21c24 100644
--- a/src/rules/tailwind-no-unnecessary-whitespace.ts
+++ b/src/rules/tailwind-no-unnecessary-whitespace.ts
@@ -5,8 +5,8 @@ import {
DEFAULT_VARIABLE_NAMES
} from "readable-tailwind:options:default-options.js";
import {
+ getAttributesSchema,
getCalleeSchema,
- getClassAttributeSchema,
getTagsSchema,
getVariableSchema
} from "readable-tailwind:options:descriptions.js";
@@ -15,10 +15,10 @@ import {
getLiteralsByESVariableDeclarator,
getLiteralsByTaggedTemplateExpression
} from "readable-tailwind:parsers:es.js";
-import { getAttributesByHTMLTag, getLiteralsByHTMLClassAttribute } from "readable-tailwind:parsers:html.js";
-import { getAttributesByJSXElement, getLiteralsByJSXClassAttribute } from "readable-tailwind:parsers:jsx.js";
-import { getAttributesBySvelteTag, getLiteralsBySvelteClassAttribute } from "readable-tailwind:parsers:svelte.js";
-import { getAttributesByVueStartTag, getLiteralsByVueClassAttribute } from "readable-tailwind:parsers:vue.js";
+import { getAttributesByHTMLTag, getLiteralsByHTMLAttributes } from "readable-tailwind:parsers:html.js";
+import { getAttributesByJSXElement, getLiteralsByJSXAttributes } from "readable-tailwind:parsers:jsx.js";
+import { getAttributesBySvelteTag, getLiteralsBySvelteAttributes } from "readable-tailwind:parsers:svelte.js";
+import { getAttributesByVueStartTag, getLiteralsByVueAttributes } from "readable-tailwind:parsers:vue.js";
import { escapeNestedQuotes } from "readable-tailwind:utils:quotes.js";
import { display, splitClasses, splitWhitespaces } from "readable-tailwind:utils:utils.js";
@@ -31,8 +31,8 @@ import type { AST } from "vue-eslint-parser";
import type { Literal } from "readable-tailwind:types:ast.js";
import type {
+ AttributeOption,
CalleeOption,
- ClassAttributeOption,
ESLintRule,
TagOption,
VariableOption
@@ -41,8 +41,8 @@ import type {
export type Options = [
Partial<
+ AttributeOption &
CalleeOption &
- ClassAttributeOption &
TagOption &
VariableOption &
{
@@ -53,8 +53,8 @@ export type Options = [
const defaultOptions = {
allowMultiline: true,
+ attributes: DEFAULT_ATTRIBUTE_NAMES,
callees: DEFAULT_CALLEE_NAMES,
- classAttributes: DEFAULT_ATTRIBUTE_NAMES,
tags: DEFAULT_TAG_NAMES,
variables: DEFAULT_VARIABLE_NAMES
} as const satisfies Options[0];
@@ -64,7 +64,7 @@ export const tailwindNoUnnecessaryWhitespace: ESLintRule = {
rule: {
create(ctx) {
- const { callees, classAttributes, tags, variables } = getOptions(ctx);
+ const { attributes, callees, tags, variables } = getOptions(ctx);
const callExpression = {
CallExpression(node: Node) {
@@ -99,7 +99,7 @@ export const tailwindNoUnnecessaryWhitespace: ESLintRule = {
const jsxAttributes = getAttributesByJSXElement(ctx, jsxNode);
for(const attribute of jsxAttributes){
- const literals = getLiteralsByJSXClassAttribute(ctx, attribute, classAttributes);
+ const literals = getLiteralsByJSXAttributes(ctx, attribute, attributes);
lintLiterals(ctx, literals);
}
}
@@ -111,7 +111,7 @@ export const tailwindNoUnnecessaryWhitespace: ESLintRule = {
const svelteAttributes = getAttributesBySvelteTag(ctx, svelteNode);
for(const attribute of svelteAttributes){
- const literals = getLiteralsBySvelteClassAttribute(ctx, attribute, classAttributes);
+ const literals = getLiteralsBySvelteAttributes(ctx, attribute, attributes);
lintLiterals(ctx, literals);
}
}
@@ -123,7 +123,7 @@ export const tailwindNoUnnecessaryWhitespace: ESLintRule = {
const vueAttributes = getAttributesByVueStartTag(ctx, vueNode);
for(const attribute of vueAttributes){
- const literals = getLiteralsByVueClassAttribute(ctx, attribute, classAttributes);
+ const literals = getLiteralsByVueAttributes(ctx, attribute, attributes);
lintLiterals(ctx, literals);
}
}
@@ -135,7 +135,7 @@ export const tailwindNoUnnecessaryWhitespace: ESLintRule = {
const htmlAttributes = getAttributesByHTMLTag(ctx, htmlTagNode);
for(const htmlAttribute of htmlAttributes){
- const literals = getLiteralsByHTMLClassAttribute(ctx, htmlAttribute, classAttributes);
+ const literals = getLiteralsByHTMLAttributes(ctx, htmlAttribute, attributes);
lintLiterals(ctx, literals);
}
}
@@ -185,7 +185,7 @@ export const tailwindNoUnnecessaryWhitespace: ESLintRule = {
type: "boolean"
},
...getCalleeSchema(defaultOptions.callees),
- ...getClassAttributeSchema(defaultOptions.classAttributes),
+ ...getAttributesSchema(defaultOptions.attributes),
...getVariableSchema(defaultOptions.variables),
...getTagsSchema(defaultOptions.tags)
},
@@ -288,10 +288,10 @@ function getOptions(ctx?: Rule.RuleContext) {
const allowMultiline = options.allowMultiline ?? defaultOptions.allowMultiline;
- const classAttributes = options.classAttributes ??
- ctx?.settings["eslint-plugin-readable-tailwind"]?.classAttributes ??
- ctx?.settings["readable-tailwind"]?.classAttributes ??
- defaultOptions.classAttributes;
+ const attributes = options.attributes ??
+ ctx?.settings["eslint-plugin-readable-tailwind"]?.attributes ??
+ ctx?.settings["readable-tailwind"]?.attributes ??
+ defaultOptions.attributes;
const callees = options.callees ??
ctx?.settings["eslint-plugin-readable-tailwind"]?.callees ??
@@ -310,8 +310,8 @@ function getOptions(ctx?: Rule.RuleContext) {
return {
allowMultiline,
+ attributes,
callees,
- classAttributes,
tags,
variables
};
diff --git a/src/rules/tailwind-sort-classes.ts b/src/rules/tailwind-sort-classes.ts
index 7de2c3f..b686df3 100644
--- a/src/rules/tailwind-sort-classes.ts
+++ b/src/rules/tailwind-sort-classes.ts
@@ -12,8 +12,8 @@ import {
DEFAULT_VARIABLE_NAMES
} from "readable-tailwind:options:default-options.js";
import {
+ getAttributesSchema,
getCalleeSchema,
- getClassAttributeSchema,
getTagsSchema,
getVariableSchema
} from "readable-tailwind:options:descriptions.js";
@@ -22,10 +22,10 @@ import {
getLiteralsByESVariableDeclarator,
getLiteralsByTaggedTemplateExpression
} from "readable-tailwind:parsers:es.js";
-import { getAttributesByHTMLTag, getLiteralsByHTMLClassAttribute } from "readable-tailwind:parsers:html.js";
-import { getAttributesByJSXElement, getLiteralsByJSXClassAttribute } from "readable-tailwind:parsers:jsx.js";
-import { getAttributesBySvelteTag, getLiteralsBySvelteClassAttribute } from "readable-tailwind:parsers:svelte.js";
-import { getAttributesByVueStartTag, getLiteralsByVueClassAttribute } from "readable-tailwind:parsers:vue.js";
+import { getAttributesByHTMLTag, getLiteralsByHTMLAttributes } from "readable-tailwind:parsers:html.js";
+import { getAttributesByJSXElement, getLiteralsByJSXAttributes } from "readable-tailwind:parsers:jsx.js";
+import { getAttributesBySvelteTag, getLiteralsBySvelteAttributes } from "readable-tailwind:parsers:svelte.js";
+import { getAttributesByVueStartTag, getLiteralsByVueAttributes } from "readable-tailwind:parsers:vue.js";
import { escapeNestedQuotes } from "readable-tailwind:utils:quotes.js";
import { display, splitClasses, splitWhitespaces } from "readable-tailwind:utils:utils.js";
@@ -39,8 +39,8 @@ import type { AST } from "vue-eslint-parser";
import type { Literal } from "readable-tailwind:types:ast.js";
import type {
+ AttributeOption,
CalleeOption,
- ClassAttributeOption,
ESLintRule,
TagOption,
VariableOption
@@ -49,8 +49,8 @@ import type {
export type Options = [
Partial<
+ AttributeOption &
CalleeOption &
- ClassAttributeOption &
TagOption &
VariableOption &
{
@@ -61,8 +61,8 @@ export type Options = [
];
const defaultOptions = {
+ attributes: DEFAULT_ATTRIBUTE_NAMES,
callees: DEFAULT_CALLEE_NAMES,
- classAttributes: DEFAULT_ATTRIBUTE_NAMES,
order: "improved",
tags: DEFAULT_TAG_NAMES,
variables: DEFAULT_VARIABLE_NAMES
@@ -76,7 +76,7 @@ export const tailwindSortClasses: ESLintRule = {
rule: {
create(ctx) {
- const { callees, classAttributes, tags, variables } = getOptions(ctx);
+ const { attributes, callees, tags, variables } = getOptions(ctx);
const tailwindConfig = findTailwindConfig(ctx);
const tailwindContext = createTailwindContext(tailwindConfig);
@@ -179,7 +179,7 @@ export const tailwindSortClasses: ESLintRule = {
const jsxAttributes = getAttributesByJSXElement(ctx, jsxNode);
for(const attribute of jsxAttributes){
- const literals = getLiteralsByJSXClassAttribute(ctx, attribute, classAttributes);
+ const literals = getLiteralsByJSXAttributes(ctx, attribute, attributes);
lintLiterals(ctx, literals);
}
}
@@ -191,7 +191,7 @@ export const tailwindSortClasses: ESLintRule = {
const svelteAttributes = getAttributesBySvelteTag(ctx, svelteNode);
for(const attribute of svelteAttributes){
- const literals = getLiteralsBySvelteClassAttribute(ctx, attribute, classAttributes);
+ const literals = getLiteralsBySvelteAttributes(ctx, attribute, attributes);
lintLiterals(ctx, literals);
}
}
@@ -203,7 +203,7 @@ export const tailwindSortClasses: ESLintRule = {
const vueAttributes = getAttributesByVueStartTag(ctx, vueNode);
for(const attribute of vueAttributes){
- const literals = getLiteralsByVueClassAttribute(ctx, attribute, classAttributes);
+ const literals = getLiteralsByVueAttributes(ctx, attribute, attributes);
lintLiterals(ctx, literals);
}
}
@@ -215,7 +215,7 @@ export const tailwindSortClasses: ESLintRule = {
const htmlAttributes = getAttributesByHTMLTag(ctx, htmlNode);
for(const htmlAttribute of htmlAttributes){
- const literals = getLiteralsByHTMLClassAttribute(ctx, htmlAttribute, classAttributes);
+ const literals = getLiteralsByHTMLAttributes(ctx, htmlAttribute, attributes);
lintLiterals(ctx, literals);
}
}
@@ -260,7 +260,7 @@ export const tailwindSortClasses: ESLintRule = {
additionalProperties: false,
properties: {
...getCalleeSchema(defaultOptions.callees),
- ...getClassAttributeSchema(defaultOptions.classAttributes),
+ ...getAttributesSchema(defaultOptions.attributes),
...getVariableSchema(defaultOptions.variables),
...getTagsSchema(defaultOptions.tags),
order: {
@@ -383,10 +383,10 @@ export function getOptions(ctx?: Rule.RuleContext) {
const order = options.order ?? defaultOptions.order;
- const classAttributes = options.classAttributes ??
- ctx?.settings["eslint-plugin-readable-tailwind"]?.classAttributes ??
- ctx?.settings["readable-tailwind"]?.classAttributes ??
- defaultOptions.classAttributes;
+ const attributes = options.attributes ??
+ ctx?.settings["eslint-plugin-readable-tailwind"]?.attributes ??
+ ctx?.settings["readable-tailwind"]?.attributes ??
+ defaultOptions.attributes;
const callees = options.callees ??
ctx?.settings["eslint-plugin-readable-tailwind"]?.callees ??
@@ -406,8 +406,8 @@ export function getOptions(ctx?: Rule.RuleContext) {
const tailwindConfig = options.tailwindConfig;
return {
+ attributes,
callees,
- classAttributes,
order,
tags,
tailwindConfig,
diff --git a/src/types/rule.ts b/src/types/rule.ts
index 9831890..c8e3856 100644
--- a/src/types/rule.ts
+++ b/src/types/rule.ts
@@ -56,17 +56,17 @@ export type TagOption = {
tags: Tags;
};
-export type ClassAttributeName = string;
-export type ClassAttributeMatchers = [classAttribute: ClassAttributeName, matchers: Matcher[]];
-export type ClassAttributeRegex = [classAttributeRegex: Regex, literalRegex: Regex];
-export type ClassAttributes = (ClassAttributeMatchers | ClassAttributeName | ClassAttributeRegex)[];
-export type ClassAttributeOption = {
- classAttributes: ClassAttributes;
+export type AttributeName = string;
+export type AttributeMatchers = [attribute: AttributeName, matchers: Matcher[]];
+export type AttributeRegex = [attributeRegex: Regex, literalRegex: Regex];
+export type Attributes = (AttributeMatchers | AttributeName | AttributeRegex)[];
+export type AttributeOption = {
+ attributes: Attributes;
};
-export type NameConfig = CalleeName | ClassAttributeName | VariableName;
-export type RegexConfig = CalleeRegex | ClassAttributeRegex | VariableRegex;
-export type MatchersConfig = CalleeMatchers | ClassAttributeMatchers | VariableMatchers;
+export type NameConfig = AttributeName | CalleeName | VariableName;
+export type RegexConfig = AttributeRegex | CalleeRegex | VariableRegex;
+export type MatchersConfig = AttributeMatchers | CalleeMatchers | VariableMatchers;
export interface ESLintRule {
name: string;
diff --git a/src/utils/matchers.test.ts b/src/utils/matchers.test.ts
index 244db0d..4e28d85 100644
--- a/src/utils/matchers.test.ts
+++ b/src/utils/matchers.test.ts
@@ -239,7 +239,7 @@ describe("matchers", () => {
});
});
- it("should match classAttributes via regex", () => {
+ it("should match attributes via regex", () => {
lint(tailwindNoUnnecessaryWhitespace, TEST_SYNTAXES, {
invalid: [
{
@@ -247,7 +247,7 @@ describe("matchers", () => {
jsx: ``,
jsxOutput: ``,
options: [{
- classAttributes: [["^.*Styles$", [{ match: MatcherType.String }]]]
+ attributes: [["^.*Styles$", [{ match: MatcherType.String }]]]
}],
svelte: ``,
svelteOutput: ``,
@@ -335,9 +335,9 @@ describe("matchers", () => {
});
- describe("class attributes", () => {
+ describe("attributes", () => {
- it("should lint literals in class attributes", () => {
+ it("should lint literals in attributes", () => {
const dirtyDefined = `{
"nested": {
@@ -385,7 +385,7 @@ describe("matchers", () => {
jsx: ``,
jsxOutput: ``,
options: [{
- classAttributes: [
+ attributes: [
[
"defined",
[
@@ -605,8 +605,8 @@ describe("matchers", () => {
jsx: "",
jsxOutput: "",
options: [{
- callees: [["defined", [{ match: MatcherType.String }]]],
- classAttributes: [["class", [{ match: MatcherType.ObjectValue }]]]
+ attributes: [["class", [{ match: MatcherType.ObjectValue }]]],
+ callees: [["defined", [{ match: MatcherType.String }]]]
}]
}
]
diff --git a/src/utils/matchers.ts b/src/utils/matchers.ts
index 73747d6..b73e811 100644
--- a/src/utils/matchers.ts
+++ b/src/utils/matchers.ts
@@ -11,14 +11,14 @@ import type { Rule } from "eslint";
import type { BaseNode as ESBaseNode, Node as ESNode, Program } from "estree";
import type {
+ AttributeMatchers,
+ AttributeName,
+ AttributeRegex,
+ Attributes,
CalleeMatchers,
CalleeName,
CalleeRegex,
Callees,
- ClassAttributeMatchers,
- ClassAttributeName,
- ClassAttributeRegex,
- ClassAttributes,
MatcherFunctions,
Regex,
TagMatchers,
@@ -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 isClassAttributeName(classAttribute: ClassAttributes[number]): classAttribute is ClassAttributeName {
- return typeof classAttribute === "string";
+export function isAttributesName(Attributes: Attributes[number]): Attributes is AttributeName {
+ return typeof Attributes === "string";
}
-export function isClassAttributeRegex(classAttribute: ClassAttributes[number]): classAttribute is ClassAttributeRegex {
- return Array.isArray(classAttribute) && typeof classAttribute[0] === "string" && typeof classAttribute[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 isClassAttributeMatchers(classAttribute: ClassAttributes[number]): classAttribute is ClassAttributeMatchers {
- return Array.isArray(classAttribute) && typeof classAttribute[0] === "string" && Array.isArray(classAttribute[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): boolean {
diff --git a/src/utils/regex.test.ts b/src/utils/regex.test.ts
index 6d5720e..2f5e50d 100644
--- a/src/utils/regex.test.ts
+++ b/src/utils/regex.test.ts
@@ -146,9 +146,9 @@ describe("regex", () => {
});
- describe("class attributes", () => {
+ describe("attributes", () => {
- it("should lint literals in class attributes", () => {
+ it("should lint literals in attributes", () => {
const dirtyDefined = `{
"nested": {
@@ -196,7 +196,7 @@ describe("regex", () => {
jsx: ``,
jsxOutput: ``,
options: [{
- classAttributes: [
+ attributes: [
[
"defined={([\\S\\s]*)}",
"\"matched\"?:\\s*[\"'`]([^\"'`]+)[\"'`]"
diff --git a/tests/unit/settings.test.ts b/tests/unit/settings.test.ts
index f3ed8d7..0063652 100644
--- a/tests/unit/settings.test.ts
+++ b/tests/unit/settings.test.ts
@@ -16,7 +16,7 @@ describe("settings", () => {
htmlOutput: ``,
jsx: `() => `,
jsxOutput: `() => `,
- settings: { "readable-tailwind": { classAttributes: ["settings"] } },
+ settings: { "readable-tailwind": { attributes: ["settings"] } },
svelte: ``,
svelteOutput: ``,
vue: ``,
@@ -32,7 +32,7 @@ describe("settings", () => {
htmlOutput: ``,
jsx: `() => `,
jsxOutput: `() => `,
- settings: { "eslint-plugin-readable-tailwind": { classAttributes: ["settings"] } },
+ settings: { "eslint-plugin-readable-tailwind": { attributes: ["settings"] } },
svelte: ``,
svelteOutput: ``,
vue: ``,
@@ -51,8 +51,8 @@ describe("settings", () => {
htmlOutput: ``,
jsx: `() => `,
jsxOutput: `() => `,
- options: [{ classAttributes: ["options"] }],
- settings: { "readable-tailwind": { classAttributes: ["settings"] } },
+ options: [{ attributes: ["options"] }],
+ settings: { "readable-tailwind": { attributes: ["settings"] } },
svelte: ``,
svelteOutput: ``,
vue: ``,
@@ -68,8 +68,8 @@ describe("settings", () => {
htmlOutput: ``,
jsx: `() => `,
jsxOutput: `() => `,
- options: [{ classAttributes: ["options"] }],
- settings: { "eslint-plugin-readable-tailwind": { classAttributes: ["settings"] } },
+ options: [{ attributes: ["options"] }],
+ settings: { "eslint-plugin-readable-tailwind": { attributes: ["settings"] } },
svelte: ``,
svelteOutput: ``,
vue: ``,