Skip to content

Commit

Permalink
Update tests and docs to mention that using a component with addStyle…
Browse files Browse the repository at this point in the history
… doesn't enforce the linting convention
  • Loading branch information
beaesguerra committed Dec 12, 2024
1 parent 1ac9cd8 commit e674d22
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Naming convention for addStyle variable (aphrodite-add-style-variable-name)

The variable name when using `addStyle` should be the same as the tag argument in the format `StyledTag`.
The variable name should match the tag name passed into `addStyle` and follow the format: `StyledTag`.

This is useful so that Aphrodite styled elements can be mapped to HTML elements for static code analysis. For example, if the `addStyle` variables are consistently named, we are able to provide [custom component mapping](https://github.com/jsx-eslint/eslint-plugin-jsx-a11y#component-mapping) to `eslint-plugin-jsx-a11y` so that it can identify linting issues based on the underlying HTML tag.

This naming convention only applies to string arguments for HTML tags. It is not enforced when a component is used as the addStyle argument.

## Rule Details

The following are considered warnings:
Expand Down Expand Up @@ -33,3 +35,9 @@ const StyledSpan = addStyle("span");
```ts
const StyledImg = addStyle("img");
```

```ts
// Any variable name can be used when addStyle is used with a component
const LinkWithStyle = addStyle(Link);
const Foo = addStyle(Bar);
```
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default createRule<Options, MessageIds>({
meta: {
docs: {
description:
"Ensure variable names match the tag name passed to addStyle and follow the format: StyledTag (ie. StyledDiv, StyledImg)",
"Variable name should match the tag name passed into addStyle and follow the format: StyledTag (ie. StyledDiv, StyledImg)",
recommended: true,
},
messages: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ ruleTester.run(ruleName, rule, {
// Handling custom html components
code: `const StyledFooBar = addStyle("foo-bar")`,
},
{
// Variable name can be anything if a component is used as the
// argument
code: `const LinkWithStyle = addStyle(Link)`,
},
{
// Another example where variable name can be anything if a
// component is used as the argument
code: `const Foo = addStyle(Bar)`,
},
],
invalid: [
{
Expand Down

0 comments on commit e674d22

Please sign in to comment.