Skip to content

Commit 0b9dd34

Browse files
committed
chore(lint): ban sparkles icons
1 parent 5e4f5fd commit 0b9dd34

4 files changed

Lines changed: 104 additions & 0 deletions

File tree

‎oxlint-plugin-t3code/index.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import noMobileUniwindThemeEscapeHatches from "./rules/no-mobile-uniwind-theme-e
1616
import noAmbiguousDetailNavigation from "./rules/no-ambiguous-detail-navigation.ts";
1717
import noMobilePullRequestGlyphLiterals from "./rules/no-mobile-pull-request-glyph-literals.ts";
1818
import noNativeTitleTooltip from "./rules/no-native-title-tooltip.ts";
19+
import noSparklesIcon from "./rules/no-sparkles-icon.ts";
1920
import noUnreasonedStateSync from "./rules/no-unreasoned-state-sync.ts";
2021
import requireRegisteredListScroll from "./rules/require-registered-list-scroll.ts";
2122
import noOutsetStateIndicators from "./rules/no-outset-state-indicators.ts";
@@ -55,6 +56,7 @@ export default definePlugin({
5556
"no-ambiguous-detail-navigation": noAmbiguousDetailNavigation,
5657
"no-mobile-pull-request-glyph-literals": noMobilePullRequestGlyphLiterals,
5758
"no-native-title-tooltip": noNativeTitleTooltip,
59+
"no-sparkles-icon": noSparklesIcon,
5860
"no-unreasoned-state-sync": noUnreasonedStateSync,
5961
"require-registered-list-scroll": requireRegisteredListScroll,
6062
"no-outset-state-indicators": noOutsetStateIndicators,
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { describe } from "@effect/vitest";
2+
3+
import { createOxlintRuleHarness } from "../test/utils.ts";
4+
5+
const rule = createOxlintRuleHarness("t3code/no-sparkles-icon", {
6+
filename: "apps/web/src/components/chat/Example.tsx",
7+
});
8+
9+
describe("t3code/no-sparkles-icon", () => {
10+
rule.valid(
11+
"allows icons that name the action",
12+
`
13+
import { BotIcon, ShieldCheckIcon } from "lucide-react";
14+
import IconRobot from "@tabler/icons-react-native/IconRobot";
15+
16+
const icon = <SymbolView name={{ ios: "puzzlepiece", android: "extension" }} />;
17+
`,
18+
);
19+
20+
rule.valid(
21+
"allows copy and identifiers that mention sparkles",
22+
`
23+
const NIGHTLY_SPARKLES = [];
24+
const label = "Add some sparkles to the release notes";
25+
`,
26+
);
27+
28+
rule.invalid("reports Lucide sparkles icons", `import { SparklesIcon } from "lucide-react";`);
29+
30+
rule.invalid(
31+
"reports every Lucide sparkle variant",
32+
`import { Sparkle, WandSparklesIcon, LucideSparkles } from "lucide-react";`,
33+
);
34+
35+
rule.invalid(
36+
"reports Tabler sparkles deep imports",
37+
`import IconSparkles from "@tabler/icons-react-native/IconSparkles";`,
38+
);
39+
40+
rule.invalid("reports SF Symbol sparkles names", `const icon = <SymbolView name="sparkles" />;`);
41+
42+
rule.invalid(
43+
"reports platform symbol objects",
44+
`const icon = { ios: "wand.and.sparkles", android: "auto_awesome" };`,
45+
);
46+
});
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { defineRule } from "@oxlint/plugins";
2+
3+
const SPARKLE_NAME = /sparkle/iu;
4+
// SF Symbol (`sparkles`, `sparkles.square.filled.on.square`, `wand.and.sparkles`) and
5+
// Material (`auto_awesome`) names reach native icons as plain strings.
6+
const SPARKLE_SYMBOL_NAME = /^(?:(?:[\w]+\.)*sparkles?(?:\.[\w.]+)?|auto_awesome(?:_\w+)?)$/u;
7+
const TABLER_SOURCE = /^@tabler\/icons(?:-react|-react-native)?(?:\/|$)/u;
8+
9+
const MESSAGE =
10+
"Sparkles says 'AI', not what the control does. Pick an icon for the action itself, such as Bot for agent work or ShieldCheck for Auto mode.";
11+
12+
export default defineRule({
13+
meta: {
14+
type: "problem",
15+
docs: {
16+
description:
17+
"Disallow sparkles icons; they label a control as AI instead of saying what it does.",
18+
},
19+
},
20+
create(context) {
21+
return {
22+
ImportDeclaration(node) {
23+
const source = node.source.value;
24+
if (source === "lucide-react" || TABLER_SOURCE.test(source)) {
25+
if (TABLER_SOURCE.test(source) && SPARKLE_NAME.test(source.split("/").at(-1) ?? "")) {
26+
context.report({ node: node.source, message: MESSAGE });
27+
return;
28+
}
29+
for (const specifier of node.specifiers) {
30+
if (specifier.type !== "ImportSpecifier") continue;
31+
const imported =
32+
specifier.imported.type === "Identifier"
33+
? specifier.imported.name
34+
: specifier.imported.value;
35+
if (SPARKLE_NAME.test(imported)) context.report({ node: specifier, message: MESSAGE });
36+
}
37+
}
38+
},
39+
Literal(node) {
40+
if (typeof node.value !== "string" || !SPARKLE_SYMBOL_NAME.test(node.value)) return;
41+
if (node.parent.type === "ImportDeclaration") return;
42+
context.report({ node, message: MESSAGE });
43+
},
44+
TemplateElement(node) {
45+
if (!SPARKLE_SYMBOL_NAME.test(node.value.cooked ?? "")) return;
46+
context.report({ node, message: MESSAGE });
47+
},
48+
};
49+
},
50+
});

‎vite.config.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,12 @@ export default defineConfig({
319319
],
320320
rules: { "t3code/prefer-effect-fn": "off" },
321321
},
322+
{
323+
files: ["apps/web/src/**", "apps/mobile/src/**", "apps/desktop/src/**"],
324+
// Users still pick their own project icon from the full Lucide set.
325+
excludeFiles: ["apps/web/src/projectIconOptions.ts"],
326+
rules: { "t3code/no-sparkles-icon": "error" },
327+
},
322328
{
323329
files: ["apps/web/**/*.test.{ts,tsx}"],
324330
rules: { "t3code/require-disposable-render": "error" },

0 commit comments

Comments
 (0)