Skip to content
Source
Sign inSign up
Open History to see the last commit

no-em-dash-copy.ts

31 lines902 Bytes

1import { defineRule, type ESTree } from "@oxlint/plugins";
2​
3const EM_DASH = "\u2014";
4​
5const MESSAGE = "No em dashes in product copy. Use a period, comma, colon, or parentheses instead.";
6​
7// Comments are not product copy, so only string and JSX text nodes are checked.
8export default defineRule({
9 meta: {
10 type: "suggestion",
11 docs: {
12 description: "Disallow em dashes in strings and JSX text that users or agents read.",
13 },
14 },
15 create(context) {
16 const check = (node: ESTree.Node, text: string | null | undefined) => {
17 if (text?.includes(EM_DASH)) context.report({ node, message: MESSAGE });
18 };
19 return {
20 Literal(node) {
21 if (typeof node.value === "string") check(node, node.value);
22 },
23 TemplateElement(node) {
24 check(node, node.value.cooked);
25 },
26 JSXText(node) {
27 check(node, node.value);
28 },
29 };
30 },
31});