@lewishowles/lint-config 0.1.3 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @lewishowles/lint-config
2
2
 
3
- Shared oxlint configuration for Lewis Howles projects. One package that every repo extends, so lint setup stops being duplicated and drifting across the ecosystem.
3
+ Shared Oxlint configuration for Lewis Howles projects. Projects extend this package to keep their lint configuration consistent across projects, instead of copying and maintaining the same rules everywhere.
4
4
 
5
5
  ## Installation
6
6
 
@@ -8,7 +8,7 @@ Shared oxlint configuration for Lewis Howles projects. One package that every re
8
8
  bun add -d @lewishowles/lint-config @stylistic/eslint-plugin vite-plus
9
9
  ```
10
10
 
11
- `@stylistic/eslint-plugin` and `vite-plus` are peer dependencies — they must be installed in the consuming project so oxlint can resolve the JS plugins from `node_modules`.
11
+ `@stylistic/eslint-plugin` and `vite-plus` are peer dependencies: they must be installed in the consuming project so oxlint can resolve the JS plugins from `node_modules`.
12
12
 
13
13
  ## Usage
14
14
 
@@ -19,28 +19,86 @@ Create a `.oxlintrc.json` in your project root that extends the appropriate laye
19
19
  ```json
20
20
  {
21
21
  "extends": ["./node_modules/@lewishowles/lint-config/base.json"],
22
+ "env": { "builtin": true, "browser": true },
22
23
  "ignorePatterns": ["**/dist/*", ".codebase-memory/**"]
23
24
  }
24
25
  ```
25
26
 
27
+ Note that `env` has to be redeclared here: Oxlint doesn't yet merge it through `extends`, so `base.json`'s own `env` never reaches your project. See [known limitations](docs/limitations.md) for why.
28
+
26
29
  ### Vue layer (Vue 3 projects)
27
30
 
28
31
  ```json
29
32
  {
30
33
  "extends": ["./node_modules/@lewishowles/lint-config/vue.json"],
34
+ "env": { "builtin": true, "browser": true },
35
+ "globals": {
36
+ "defineEmits": "readonly",
37
+ "defineExpose": "readonly",
38
+ "defineModel": "readonly",
39
+ "defineOptions": "readonly",
40
+ "defineProps": "readonly",
41
+ "defineSlots": "readonly",
42
+ "withDefaults": "readonly"
43
+ },
44
+ "ignorePatterns": ["**/dist/*", ".codebase-memory/**"]
45
+ }
46
+ ```
47
+
48
+ The Vue layer extends `base.json` internally, so you only need to extend `vue.json`. The same `env`/`globals` limitation applies here too, which is why both are redeclared above.
49
+
50
+ ### Comment formatting (optional)
51
+
52
+ Add the comments layer alongside the base or Vue layer to enforce the comment-formatting rules, variable-declaration documentation, JSDoc on named functions and first-level object methods, documentation directly after each Vue `<script setup>` opening tag, and block comments for runtime `defineProps` properties:
53
+
54
+ ```json
55
+ {
56
+ "extends": [
57
+ "./node_modules/@lewishowles/lint-config/base.json",
58
+ "./node_modules/@lewishowles/lint-config/comments.json"
59
+ ],
60
+ "env": { "builtin": true, "browser": true },
31
61
  "ignorePatterns": ["**/dist/*", ".codebase-memory/**"]
32
62
  }
33
63
  ```
34
64
 
35
- The Vue layer extends `base.json` internally — you only need to extend `vue.json`.
65
+ The Vue component rule reads the raw `.vue` file because Oxlint's JS Plugin API only receives the extracted script block. The comments layer loads its plugin for you, so there's no relative `jsPlugins` path to add. To pick rules yourself instead, add the plugin directly:
66
+
67
+ ```json
68
+ {
69
+ "jsPlugins": [
70
+ {
71
+ "name": "comments",
72
+ "specifier": "@lewishowles/lint-config/comments/plugin"
73
+ }
74
+ ],
75
+ "rules": {
76
+ "comments/line-comments": "error"
77
+ }
78
+ }
79
+ ```
80
+
81
+ The `comments/vue-prop-documentation` rule requires an indented block comment immediately before every runtime property in `defineProps`. A matching comment on a `defineProps` property also documents its `withDefaults` entry; type-only props are not checked.
82
+
83
+ The `comments/vue-emit-documentation` rule requires an indented block comment immediately before every runtime property in `defineEmits`. Function-valued events also require the normal JSDoc tags; array-form and type-only emits are not checked.
84
+
85
+ The `comments/configured-api-calls` rule requires an immediately preceding line comment before configured bare-identifier calls such as Vue lifecycle hooks, reactive effects, and `onClickOutside`. A documented variable declaration covers a direct call initializer; member-expression calls are out of scope. Add project-specific APIs without replacing the built-in list:
86
+
87
+ ```json
88
+ {
89
+ "rules": {
90
+ "comments/configured-api-calls": ["error", { "additionalApis": ["subscribe"] }]
91
+ }
92
+ }
93
+ ```
36
94
 
37
95
  ## Customising
38
96
 
39
- Your `.oxlintrc.json` stub can override rules, add ignore patterns, add overrides, or add plugins on top of the shared layer.
97
+ Your project's `.oxlintrc.json` can override rules, add ignore patterns, add overrides, or add plugins on top of the shared layer.
40
98
 
41
99
  ### Overriding a rule
42
100
 
43
- To change the severity or options of a rule defined in the shared layer, redeclare it in your stub — your value wins:
101
+ To change the severity or options of a rule defined in the shared layer, redeclare it in your project config: your value wins.
44
102
 
45
103
  ```json
46
104
  {
@@ -53,7 +111,7 @@ To change the severity or options of a rule defined in the shared layer, redecla
53
111
 
54
112
  ### Adding ignore patterns
55
113
 
56
- Ignore patterns are repo-specific, so they always live in your stub:
114
+ Ignore patterns are project-specific, so they always live in your project config:
57
115
 
58
116
  ```json
59
117
  {
@@ -64,7 +122,7 @@ Ignore patterns are repo-specific, so they always live in your stub:
64
122
 
65
123
  ### Adding overrides
66
124
 
67
- Overrides are additive — shared overrides (if any) still apply, and your local ones are appended:
125
+ Overrides are additive: shared overrides (if any) still apply, and your local ones are appended.
68
126
 
69
127
  ```json
70
128
  {
@@ -84,69 +142,32 @@ Overrides are additive — shared overrides (if any) still apply, and your local
84
142
 
85
143
  ### Adding plugins
86
144
 
87
- Plugins are additive and deduplicated — your local plugins are added to the shared ones. Note that oxlint only supports its built-in plugin names (`oxc`, `typescript`, `unicorn`, `vue`, etc.) — there is no `playwright` or `vitest` plugin. Test-file-specific behaviour is handled via `overrides`, not plugins.
145
+ Plugins are additive and deduplicated: your local plugins are added to the shared ones. Oxlint's `plugins` field only accepts built-in plugin names, such as `oxc`, `typescript`, `unicorn`, and `vue`; there's no `playwright` or `vitest` plugin. Custom JS plugins, like this package's `comments` plugin, load through `jsPlugins` instead. Test-file-specific behaviour is handled via `overrides`, not plugins.
88
146
 
89
147
  ## Layers
90
148
 
91
- | Layer | File | Contents |
92
- | ------ | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
93
- | `base` | `base.json` | Correctness rules, `@stylistic` formatting rules, `vite-plus/prefer-vite-plus-imports`, `oxc` + `typescript` + `unicorn` plugins, browser env, node env for config files (`vite.config.*`, `vitest.config.*`, `playwright*.config.*`) |
94
- | `vue` | `vue.json` | Extends `base`. Adds `vue` plugin, Vue compiler macros as globals, Vue-specific rules |
95
-
96
- ## What stays repo-local
97
-
98
- - `ignorePatterns` — every repo has different build output and tool directories
99
- - `overrides` for repo-specific directories (e.g. `bin/**/*.js`, `src/cli/**/*.js`, `src/playwright/**/*.js`) — the file paths differ per repo, so they can't be generalised
100
- - Test-file rule relaxations (e.g. turning off `vite-plus/prefer-vite-plus-imports` in `*.d.ts`)
101
- - Additional plugins — only repos that need them
102
-
103
- ## Merge semantics
104
-
105
- When a consumer stub extends a shared layer:
106
-
107
- - **Rules** shallow-merge by key — the consumer's value wins for any rule defined in both
108
- - **Overrides** are additive — both shared and local `overrides` entries apply, including any `env` declared inside an override block
109
- - **Plugins** are additive — both shared and local `plugins`/`jsPlugins` are loaded (deduplicated)
110
-
111
- ### Known oxlint limitation: top-level `env`, `globals`, and `ignorePatterns` don't merge through `extends`
112
-
113
- oxlint currently drops top-level `env`, `globals`, and `ignorePatterns` from an extended config file entirely — they only take effect if declared directly in the file oxlint is invoked with. This is an open upstream bug: [oxc-project/oxc#20087](https://github.com/oxc-project/oxc/issues/20087) (open as of oxlint 1.72.0).
149
+ | Layer | File | Contents |
150
+ | ---------- | --------------- | -------------------------------------------------------------------------------------- |
151
+ | `base` | `base.json` | Correctness and formatting rules, import sorting, `oxc`/`typescript`/`unicorn` plugins |
152
+ | `comments` | `comments.json` | Optional comment-formatting rules, variable-declaration documentation, JSDoc checks |
153
+ | `vue` | `vue.json` | Extends `base`, adds the `vue` plugin, Vue compiler macro globals, Vue-specific rules |
114
154
 
115
- In practice this means:
116
-
117
- - `base.json`'s `env` (`builtin`, `browser`) and `vue.json`'s Vue macro `globals` (`defineProps`, `defineEmits`, etc.) will **not** reach a consumer that only does `{ "extends": ["./node_modules/@lewishowles/lint-config/vue.json"] }` — every global from the shared layer will be flagged by `no-undef`.
118
- - Any `ignorePatterns` this package might declare would be silently dropped the same way, so it deliberately ships none — see "What stays repo-local" below.
119
-
120
- Until this is fixed upstream, redeclare the `env`/`globals` you need directly in your project's `.oxlintrc.json`, even though `base.json`/`vue.json` already declare them:
121
-
122
- ```json
123
- {
124
- "extends": ["./node_modules/@lewishowles/lint-config/vue.json"],
125
- "env": { "builtin": true, "browser": true },
126
- "globals": {
127
- "defineEmits": "readonly",
128
- "defineExpose": "readonly",
129
- "defineModel": "readonly",
130
- "defineOptions": "readonly",
131
- "defineProps": "readonly",
132
- "defineSlots": "readonly",
133
- "withDefaults": "readonly"
134
- },
135
- "ignorePatterns": ["**/dist/*", ".codebase-memory/**"]
136
- }
137
- ```
155
+ ### Import sorting
138
156
 
139
- ### Known limitation: `vite-plus`'s `lint` config field requires resolved objects, not string paths
157
+ The base layer sorts named members within each import statement, but leaves declaration order (which import comes first) to Oxfmt: enable Oxfmt's `sortImports` option in your local `.oxfmtrc.json` if you want that sorted and fixed automatically.
140
158
 
141
- Raw oxlint (CLI, editor integrations) accepts `"extends": ["./node_modules/@lewishowles/lint-config/vue.json"]` as string paths and resolves them at load time. `vite-plus`, when a project routes its oxlint config through `vite.config.js`'s `lint` field (importing `.oxlintrc.json` as JSON and handing it to `vp check`/`vp lint`), does not resolve string paths in `extends`: every entry, at every nesting level, must already be a plain object. This means `vue.json`'s own internal `extends: ["./base.json"]` also breaks one level deeper.
159
+ ## What stays repo-local
142
160
 
143
- If your project uses `vite-plus`'s `lint` field rather than raw oxlint, resolve the chain yourself in `vite.config.js`:
161
+ - `ignorePatterns`, since every project has different build output and tool directories
162
+ - `overrides` for project-specific directories (e.g. `bin/**/*.js`, `src/cli/**/*.js`, `src/playwright/**/*.js`), since the file paths differ per project and can't be generalised
163
+ - Rule relaxations for specific file patterns (e.g. turning off `vite-plus/prefer-vite-plus-imports` in generated `.d.ts` files)
164
+ - Additional plugins, only for projects that need them
144
165
 
145
- ```js
146
- import base from "@lewishowles/lint-config/base.json" with { type: "json" };
147
- import vue from "@lewishowles/lint-config/vue.json" with { type: "json" };
166
+ ## Merge semantics
148
167
 
149
- const lint = { ...vue, extends: [base, ...(vue.extends ?? [])] };
150
- ```
168
+ When a project's `.oxlintrc.json` extends a shared layer:
151
169
 
152
- `.oxlintrc.json` itself should stay untouched (string `extends`) for raw oxlint/editor consumption; this only applies to the `vite-plus` config path.
170
+ - **Rules** shallow-merge by key: your value wins for any rule defined in both
171
+ - **Overrides** are additive: both shared and local `overrides` entries apply, including any `env` declared inside an override block
172
+ - **Plugins** are additive: both shared and local `plugins`/`jsPlugins` load, deduplicated
173
+ - **`env`, `globals`, and `ignorePatterns` don't merge through `extends` at all** (an open Oxlint bug), which is why the usage examples above redeclare `env`/`globals` directly. See [known limitations](docs/limitations.md) for the full detail, including the separate `vite-plus` caveat around resolving `extends` paths.
package/base.json CHANGED
@@ -1,55 +1,61 @@
1
1
  {
2
- "plugins": ["oxc", "typescript", "unicorn"],
3
- "jsPlugins": [
4
- "@stylistic/eslint-plugin",
5
- {
6
- "name": "vite-plus",
7
- "specifier": "vite-plus/oxlint-plugin"
8
- }
9
- ],
10
- "categories": {
11
- "correctness": "error"
12
- },
13
- "env": {
14
- "builtin": true,
15
- "browser": true
16
- },
17
- "rules": {
18
- "no-case-declarations": "error",
19
- "no-empty": "error",
20
- "no-fallthrough": "error",
21
- "no-prototype-builtins": "error",
22
- "no-redeclare": "error",
23
- "no-regex-spaces": "error",
24
- "no-undef": "error",
25
- "no-unexpected-multiline": "error",
26
- "no-useless-assignment": "error",
27
- "preserve-caught-error": "error",
2
+ "plugins": ["oxc", "typescript", "unicorn"],
3
+ "jsPlugins": [
4
+ "@stylistic/eslint-plugin",
5
+ {
6
+ "name": "vite-plus",
7
+ "specifier": "vite-plus/oxlint-plugin"
8
+ }
9
+ ],
10
+ "categories": {
11
+ "correctness": "error"
12
+ },
13
+ "env": {
14
+ "builtin": true,
15
+ "browser": true
16
+ },
17
+ "rules": {
18
+ "no-case-declarations": "error",
19
+ "no-empty": "error",
20
+ "no-fallthrough": "error",
21
+ "no-prototype-builtins": "error",
22
+ "no-redeclare": "error",
23
+ "no-regex-spaces": "error",
24
+ "no-undef": "error",
25
+ "no-unexpected-multiline": "error",
26
+ "no-useless-assignment": "error",
27
+ "preserve-caught-error": "error",
28
+ "sort-imports": [
29
+ "error",
30
+ {
31
+ "ignoreDeclarationSort": true
32
+ }
33
+ ],
28
34
 
29
- "@stylistic/no-confusing-arrow": "error",
30
- "@stylistic/padding-line-between-statements": [
31
- "error",
32
- { "blankLine": "always", "prev": "const", "next": "let" },
33
- { "blankLine": "always", "prev": "let", "next": "const" },
34
- { "blankLine": "always", "prev": "*", "next": "break" },
35
- { "blankLine": "always", "prev": ["const", "let"], "next": "*" },
36
- { "blankLine": "always", "prev": "*", "next": "return" },
37
- { "blankLine": "any", "prev": "const", "next": "const" },
38
- { "blankLine": "any", "prev": "let", "next": "let" },
39
- { "blankLine": "always", "prev": "multiline-const", "next": "*" },
40
- { "blankLine": "always", "prev": "*", "next": "multiline-const" }
41
- ],
35
+ "@stylistic/no-confusing-arrow": "error",
36
+ "@stylistic/padding-line-between-statements": [
37
+ "error",
38
+ { "blankLine": "always", "prev": "const", "next": "let" },
39
+ { "blankLine": "always", "prev": "let", "next": "const" },
40
+ { "blankLine": "always", "prev": "*", "next": "break" },
41
+ { "blankLine": "always", "prev": ["const", "let"], "next": "*" },
42
+ { "blankLine": "always", "prev": "*", "next": "return" },
43
+ { "blankLine": "any", "prev": "const", "next": "const" },
44
+ { "blankLine": "any", "prev": "let", "next": "let" },
45
+ { "blankLine": "always", "prev": "multiline-const", "next": "*" },
46
+ { "blankLine": "always", "prev": "*", "next": "multiline-const" }
47
+ ],
42
48
 
43
- "vite-plus/prefer-vite-plus-imports": "error"
44
- },
45
- "overrides": [
46
- {
47
- "files": ["**/vite.config.*", "**/vitest.config.*", "**/playwright*.config.*"],
48
- "env": { "node": true }
49
- }
50
- ],
51
- "options": {
52
- "typeAware": false,
53
- "typeCheck": false
54
- }
49
+ "vite-plus/prefer-vite-plus-imports": "error"
50
+ },
51
+ "overrides": [
52
+ {
53
+ "files": ["**/vite.config.*", "**/vitest.config.*", "**/playwright*.config.*"],
54
+ "env": { "node": true }
55
+ }
56
+ ],
57
+ "options": {
58
+ "typeAware": false,
59
+ "typeCheck": false
60
+ }
55
61
  }
@@ -0,0 +1,30 @@
1
+ import blockComments from "./rules/block-comments.js";
2
+ import configuredApiCalls from "./rules/configured-api-calls.js";
3
+ import functionDocumentation from "./rules/function-documentation.js";
4
+ import jsdocTagFormatting from "./rules/jsdoc-tag-formatting.js";
5
+ import lineComments from "./rules/line-comments.js";
6
+ import maxLineLength from "./rules/max-line-length.js";
7
+ import placement from "./rules/placement.js";
8
+ import sentencePunctuation from "./rules/sentence-punctuation.js";
9
+ import variableDeclarations from "./rules/variable-declarations.js";
10
+ import vueComponentDocumentation from "./rules/vue-component-documentation.js";
11
+ import vueEmitDocumentation from "./rules/vue-emit-documentation.js";
12
+ import vuePropDocumentation from "./rules/vue-prop-documentation.js";
13
+
14
+ export default {
15
+ meta: { name: "comments" },
16
+ rules: {
17
+ "block-comments": blockComments,
18
+ "configured-api-calls": configuredApiCalls,
19
+ "function-documentation": functionDocumentation,
20
+ "jsdoc-tag-formatting": jsdocTagFormatting,
21
+ "line-comments": lineComments,
22
+ "max-line-length": maxLineLength,
23
+ placement,
24
+ "sentence-punctuation": sentencePunctuation,
25
+ "variable-declarations": variableDeclarations,
26
+ "vue-component-documentation": vueComponentDocumentation,
27
+ "vue-emit-documentation": vueEmitDocumentation,
28
+ "vue-prop-documentation": vuePropDocumentation,
29
+ },
30
+ };
@@ -0,0 +1,70 @@
1
+ import { formatJSDocBlockStructure, isJSDoc } from "../utils/jsdoc.js";
2
+ import { getCommentText, replaceMinimalComment } from "../utils/source.js";
3
+
4
+ /**
5
+ * Create the JSDoc block-comment formatting rule.
6
+ *
7
+ * @returns {object}
8
+ * The Oxlint rule definition.
9
+ */
10
+ export default {
11
+ meta: {
12
+ docs: { description: "Format JSDoc block comments." },
13
+ fixable: "code",
14
+ type: "layout",
15
+ },
16
+ /**
17
+ * Create the rule's node visitors.
18
+ *
19
+ * @param {object} context
20
+ * The Oxlint rule context.
21
+ *
22
+ * @returns {object}
23
+ * The visitor functions for this rule.
24
+ */
25
+ createOnce(context) {
26
+ return {
27
+ /**
28
+ * Format every JSDoc comment's block structure in the file.
29
+ */
30
+ Program() {
31
+ for (const comment of context.sourceCode.getAllComments()) {
32
+ if (comment.type !== "Block") {
33
+ continue;
34
+ }
35
+
36
+ // The comment's raw source text.
37
+ const commentText = getCommentText(context.sourceCode, comment);
38
+
39
+ if (!isJSDoc(commentText)) {
40
+ continue;
41
+ }
42
+
43
+ // The comment, with its block structure and delimiters normalised.
44
+ const formattedComment = formatJSDocBlockStructure(context.sourceCode, comment);
45
+
46
+ if (formattedComment === commentText) {
47
+ continue;
48
+ }
49
+
50
+ context.report({
51
+ /**
52
+ * Apply the formatted replacement to the comment.
53
+ *
54
+ * @param {object} fixer
55
+ * The Oxlint fixer.
56
+ *
57
+ * @returns {object}
58
+ * The fix to apply.
59
+ */
60
+ fix: (fixer) => {
61
+ return replaceMinimalComment(fixer, comment, commentText, formattedComment);
62
+ },
63
+ message: "JSDoc comments must use the configured block format.",
64
+ node: comment,
65
+ });
66
+ }
67
+ },
68
+ };
69
+ },
70
+ };
@@ -0,0 +1,137 @@
1
+ import { hasImmediateLineComment } from "../utils/source.js";
2
+
3
+ // The built-in APIs that require a preceding comment by default.
4
+ const builtInApis = new Set([
5
+ "onBeforeMount",
6
+ "onMounted",
7
+ "onBeforeUpdate",
8
+ "onUpdated",
9
+ "onBeforeUnmount",
10
+ "onUnmounted",
11
+ "onActivated",
12
+ "onDeactivated",
13
+ "onErrorCaptured",
14
+ "onRenderTracked",
15
+ "onRenderTriggered",
16
+ "onServerPrefetch",
17
+ "watch",
18
+ "watchEffect",
19
+ "watchPostEffect",
20
+ "watchSyncEffect",
21
+ "onClickOutside",
22
+ ]);
23
+
24
+ /**
25
+ * Return whether a call is the documented initializer of a variable
26
+ * declaration.
27
+ *
28
+ * @param {object} sourceCode
29
+ * The Oxlint source code object.
30
+ * @param {object} node
31
+ * The call expression node.
32
+ *
33
+ * @returns {boolean}
34
+ * Whether the call is directly initialized by a documented declaration.
35
+ */
36
+ function hasDocumentedVariableDeclaration(sourceCode, node) {
37
+ // The call's enclosing variable declarator, when there is one.
38
+ const declarator = node.parent;
39
+
40
+ if (declarator?.type !== "VariableDeclarator" || declarator.init !== node) {
41
+ return false;
42
+ }
43
+
44
+ // The declarator's enclosing variable declaration.
45
+ const declaration = declarator.parent;
46
+
47
+ return (
48
+ declaration?.type === "VariableDeclaration" && hasImmediateLineComment(sourceCode, declaration)
49
+ );
50
+ }
51
+
52
+ /**
53
+ * Return the configured API names for the rule.
54
+ *
55
+ * @param {object} context
56
+ * The Oxlint rule context.
57
+ *
58
+ * @returns {Set<string>}
59
+ * The built-in and configured API names.
60
+ */
61
+ function getConfiguredApis(context) {
62
+ // The rule's resolved options for the file currently being visited.
63
+ const options = context.options?.[0];
64
+ // The project-configured API names to add to the built-in list.
65
+ const additionalApis = options?.additionalApis ?? [];
66
+
67
+ return new Set([...builtInApis, ...additionalApis]);
68
+ }
69
+
70
+ /**
71
+ * Create the configured API call comment rule.
72
+ *
73
+ * @returns {object}
74
+ * The Oxlint rule definition.
75
+ */
76
+ export default {
77
+ meta: {
78
+ docs: { description: "Require comments before configured API calls." },
79
+ type: "suggestion",
80
+ schema: [
81
+ {
82
+ type: "object",
83
+ properties: {
84
+ additionalApis: {
85
+ type: "array",
86
+ items: { type: "string" },
87
+ uniqueItems: true,
88
+ },
89
+ },
90
+ additionalProperties: false,
91
+ },
92
+ ],
93
+ defaultOptions: [{ additionalApis: [] }],
94
+ },
95
+
96
+ /**
97
+ * Create the rule's node visitors.
98
+ *
99
+ * @param {object} context
100
+ * The Oxlint rule context.
101
+ *
102
+ * @returns {object}
103
+ * The visitor functions for this rule.
104
+ */
105
+ createOnce(context) {
106
+ return {
107
+ /**
108
+ * Check a configured API call for a preceding comment.
109
+ *
110
+ * @param {object} node
111
+ * The call expression node.
112
+ */
113
+ CallExpression(node) {
114
+ // Read fresh for every call: createOnce's visitor is shared across every file
115
+ // in the run, so caching this at closure-creation time would freeze the first
116
+ // file's options.
117
+ const configuredApis = getConfiguredApis(context);
118
+
119
+ if (node.callee.type !== "Identifier" || !configuredApis.has(node.callee.name)) {
120
+ return;
121
+ }
122
+
123
+ if (
124
+ hasDocumentedVariableDeclaration(context.sourceCode, node) ||
125
+ hasImmediateLineComment(context.sourceCode, node)
126
+ ) {
127
+ return;
128
+ }
129
+
130
+ context.report({
131
+ message: "Configured API calls require an immediately preceding line comment.",
132
+ node,
133
+ });
134
+ },
135
+ };
136
+ },
137
+ };