|
| 1 | +/** |
| 2 | + * @file Shared path-suffix constants for fleet-canonical files that any |
| 3 | + * plugin rule may need to recognize. Centralizing these out of individual |
| 4 | + * rule files lets multiple rules share the same opt-in / opt-out list |
| 5 | + * without duplicating the path string + its rationale comment. |
| 6 | + * |
| 7 | + * Examples of consumers: |
| 8 | + * |
| 9 | + * - `no-file-scope-oxlint-disable` exempts `scripts/paths.mts` (deliberate |
| 10 | + * flow-ordered exports, see PATHS_FILE constant below). |
| 11 | + * - `socket/prefer-cached-for-loop` and `socket/no-cached-for-on-iterable` |
| 12 | + * share `lib/iterable-kind.mts` for the binding-kind heuristic — sibling |
| 13 | + * pattern. |
| 14 | + * |
| 15 | + * When a new rule needs to recognize one of these path patterns, add the |
| 16 | + * import here and use the constant, not a re-spelled literal. |
| 17 | + */ |
| 18 | + |
| 19 | +/** |
| 20 | + * The fleet's "1 path, 1 reference" source-of-truth file. Each fleet repo has |
| 21 | + * one. Its exports are ordered by path-resolution flow (REPO_ROOT → primary |
| 22 | + * roots → build paths → helpers) — deliberately not alphabetical, and the |
| 23 | + * order is load-bearing for code review. Anything keyed on per-file behavior |
| 24 | + * that recognizes `paths.mts` should match by suffix. |
| 25 | + */ |
| 26 | +export const PATHS_FILE = 'scripts/paths.mts' |
| 27 | + |
| 28 | +/** |
| 29 | + * Plugin-internal rule + test directories. Rule files often contain the |
| 30 | + * banned shape they ban as lookup-table data (e.g. `no-status-emoji.mts` |
| 31 | + * literally contains the emoji it bans). Same for the matching test files, |
| 32 | + * which intentionally exercise the banned shape. |
| 33 | + */ |
| 34 | +export const PLUGIN_RULE_DIR = '.config/oxlint-plugin/rules/' |
| 35 | +export const PLUGIN_TEST_DIR = '.config/oxlint-plugin/test/' |
| 36 | + |
| 37 | +/** |
| 38 | + * True when `filename` is inside the plugin's own rules / test directory. |
| 39 | + */ |
| 40 | +export function isPluginInternalPath(filename: string): boolean { |
| 41 | + return ( |
| 42 | + filename.includes(PLUGIN_RULE_DIR) || filename.includes(PLUGIN_TEST_DIR) |
| 43 | + ) |
| 44 | +} |
| 45 | + |
| 46 | +/** |
| 47 | + * True when `filename` points at the fleet-canonical `scripts/paths.mts`. |
| 48 | + */ |
| 49 | +export function isPathsModule(filename: string): boolean { |
| 50 | + return filename.endsWith(PATHS_FILE) |
| 51 | +} |
0 commit comments