The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { defineRule, type ESTree } from "@oxlint/plugins"; |
| 2 | |
| 3 | const EM_DASH = "\u2014"; |
| 4 | |
| 5 | const 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. |
| 8 | export 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 | }); |