Skip to content

Commit 3d8fea4

Browse files
authored
Add aphrodite-add-style-variable-name lint rule (#1091)
## Summary: Adding a custom lint rule to ensure consistent naming for when we use `addStyle` for aphrodite styling. Variable naming should be in the format `StyledTag`. By having predictable names for styled elements, we are able to use [component mapping](https://github.com/jsx-eslint/eslint-plugin-jsx-a11y?tab=readme-ov-file#component-mapping) more effectively for `eslint-plugin-jsx-a11y` so it can use the underlying HTML for accessibility checks. Issue: FEI-5952 Related ADR: [ADR-781](https://khanacademy.atlassian.net/wiki/x/IoBVyg) ## Test plan: - Tests pass - Linting works in the demo project (will need some help with this!) [ADR-781]: https://khanacademy.atlassian.net/browse/ADR-781?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ Author: beaesguerra Reviewers: beaesguerra, kevinb-khan Required Reviewers: Approved By: kevinb-khan Checks: ✅ gerald, ✅ Test (macos-latest, 20.x), ✅ codecov/project, ✅ CodeQL, ✅ Lint, typecheck, and coverage check (ubuntu-latest, 20.x), ✅ Prime node_modules cache for primary configuration (ubuntu-latest, 20.x), ✅ Analyze (javascript), ✅ gerald, ⏭️ dependabot Pull Request URL: #1091
1 parent 4cba5ba commit 3d8fea4

17 files changed

+588
-269
lines changed

.changeset/brave-scissors-repair.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@khanacademy/eslint-config": patch
3+
"@khanacademy/eslint-plugin": patch
4+
---
5+
6+
Update eslint to ^8.55.0

.changeset/dirty-islands-bake.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@khanacademy/eslint-plugin": minor
3+
---
4+
5+
Add `aphrodite-add-style-variable-name` lint rule

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ coverage
55
**/package.json
66
**/*.md
77
docs/assets/main.js
8+
packages/eslint-plugin-khan/demo

lint_ignore.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.eslintignore

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"@typescript-eslint/parser": "8.17.0",
4242
"babel-jest": "^29.7.0",
4343
"babel-watch": "^7.8.1",
44-
"eslint": "^8.52.0",
44+
"eslint": "^8.55.0",
4545
"eslint-config-prettier": "^9.0.0",
4646
"eslint-import-resolver-typescript": "^3.7.0",
4747
"eslint-plugin-disable": "^2.0.3",

packages/eslint-config-khan/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"@khanacademy/eslint-plugin": "^3.0.1",
1919
"@typescript-eslint/eslint-plugin": "8.17.0",
2020
"@typescript-eslint/parser": "8.17.0",
21-
"eslint": "^8.44.0",
21+
"eslint": "^8.55.0",
2222
"eslint-config-prettier": "^8.3.0",
2323
"eslint-import-resolver-typescript": "^3.5.3",
2424
"eslint-plugin-import": "^2.23.4",

packages/eslint-plugin-khan/README.md

+9
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,12 @@ eslint plugin with our set of custom rules for various things
1212
- [khan/react-no-subscriptions-before-mount](docs/react-no-subscriptions-before-mount.md)
1313
- [khan/react-svg-path-precision](docs/react-svg-path-precision.md)
1414
- [khan/sync-tag](docs/sync-tag.md)
15+
- [khan/aphrodite-add-style-variable-name](docs/aphrodite-add-style-variable-name.md)
16+
17+
## Creating a new lint rule
18+
19+
Here are some helpful resources for setting up a new lint rule:
20+
21+
- [TypeScript Eslint custom rules](https://typescript-eslint.io/developers/custom-rules/)
22+
- [AST Explorer](https://astexplorer.net/): A tool for showing what the abstract syntax tree (AST) looks like based on code
23+
- [ESTree Spec](https://github.com/estree/estree/tree/master): The spec for learning more about the AST node types

packages/eslint-plugin-khan/demo/.eslintrc.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
/* eslint-disable import/no-commonjs */
21
module.exports = {
2+
root: true,
33
plugins: ["@khanacademy"],
4+
parser: "@typescript-eslint/parser",
45
rules: {
56
"@khanacademy/jest-await-async-matchers": [
67
"error",
@@ -22,5 +23,7 @@ module.exports = {
2223
rootDir: __dirname,
2324
},
2425
],
26+
// TODO(kevinb): re-enable after publishing @khanacademy/eslint-plugin
27+
// "@khanacademy/aphrodite-add-style-variable-name": "error",
2528
},
2629
};

packages/eslint-plugin-khan/demo/package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
"version": "0.0.1",
44
"main": "index.js",
55
"license": "MIT",
6+
"scripts": {
7+
"lint": "eslint --ext .ts --ext .js --ext .tsx --ext .jsx ."
8+
},
69
"devDependencies": {
7-
"@khanacademy/eslint-plugin": "../",
8-
"eslint": "^8.40.0",
10+
"@khanacademy/eslint-plugin": "^3.0.1",
11+
"eslint": "^8.55.0",
912
"typescript": "^5.0.4"
1013
},
1114
"dependencies": {

packages/eslint-plugin-khan/demo/src/foo.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import * as React from "react";
22

3+
function addStyle(str: string) {
4+
// Placeholder example for calling addStyle for aphrodite
5+
}
6+
7+
const div = addStyle("div");
8+
39
export const Icon = (): React.ReactNode => {
410
return (
511
<svg>

0 commit comments

Comments
 (0)