@vllnt/eslint-config 1.0.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/LICENSE +21 -0
- package/README.md +237 -0
- package/flat/base.js +25 -0
- package/flat/boundaries.js +5 -0
- package/flat/convex-plugin.js +34 -0
- package/flat/convex-rules/_utils.js +71 -0
- package/flat/convex-rules/namespace-separation.js +90 -0
- package/flat/convex-rules/no-bare-v-any.js +61 -0
- package/flat/convex-rules/no-filter-on-query.js +85 -0
- package/flat/convex-rules/no-query-in-loop.js +114 -0
- package/flat/convex-rules/require-returns-validator.js +60 -0
- package/flat/convex-rules/snake-case-filenames.js +78 -0
- package/flat/convex-rules/standard-filenames.js +62 -0
- package/flat/convex.js +90 -0
- package/flat/core/boundaries.js +13 -0
- package/flat/core/format.js +21 -0
- package/flat/core/good-practices.js +58 -0
- package/flat/core/imports.js +33 -0
- package/flat/core/react.js +80 -0
- package/flat/core/typescript.js +140 -0
- package/flat/core/unicorn.js +165 -0
- package/flat/index.js +7 -0
- package/flat/nextjs.js +83 -0
- package/flat/nodejs.js +31 -0
- package/flat/react.js +36 -0
- package/flat/turbo.js +14 -0
- package/package.json +76 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 bntvllnt
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# @vllnt/eslint-config
|
|
4
|
+
|
|
5
|
+
**Strict, opinionated ESLint flat config for TypeScript projects.**
|
|
6
|
+
Every rule enforces `error` — no warnings, no compromises.
|
|
7
|
+
|
|
8
|
+
[](https://www.npmjs.com/package/@vllnt/eslint-config)
|
|
9
|
+
[](https://github.com/vllnt/eslint-config/actions/workflows/ci.yml)
|
|
10
|
+
[](LICENSE)
|
|
11
|
+
[](https://nodejs.org)
|
|
12
|
+
[](https://eslint.org)
|
|
13
|
+
|
|
14
|
+
</div>
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## Why
|
|
19
|
+
|
|
20
|
+
- **ESLint v9+ flat config only** — no legacy `.eslintrc`
|
|
21
|
+
- **TypeScript-first** with `strictTypeChecked` + `stylisticTypeChecked`
|
|
22
|
+
- **Prettier built-in** — formatting as lint errors, zero config
|
|
23
|
+
- **7 presets** — Base, React, Next.js, Node.js, Convex, Turbo, Boundaries
|
|
24
|
+
- **Composable** — spread arrays, override anything
|
|
25
|
+
|
|
26
|
+
## Install
|
|
27
|
+
|
|
28
|
+
```sh
|
|
29
|
+
pnpm add -D @vllnt/eslint-config eslint typescript prettier
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Quick start
|
|
33
|
+
|
|
34
|
+
```js
|
|
35
|
+
// eslint.config.js
|
|
36
|
+
import { nextjs } from '@vllnt/eslint-config/nextjs'
|
|
37
|
+
|
|
38
|
+
export default [...nextjs]
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Each preset is an array — spread it into your flat config. All presets include `projectService: true` for type-aware linting.
|
|
42
|
+
|
|
43
|
+
## Presets
|
|
44
|
+
|
|
45
|
+
| Import | Use case |
|
|
46
|
+
|--------|----------|
|
|
47
|
+
| `@vllnt/eslint-config` | Base — TypeScript strict + Prettier + import sorting |
|
|
48
|
+
| `@vllnt/eslint-config/nextjs` | Next.js apps (includes React + a11y + core web vitals) |
|
|
49
|
+
| `@vllnt/eslint-config/react` | React apps without Next.js |
|
|
50
|
+
| `@vllnt/eslint-config/nodejs` | Node.js backends |
|
|
51
|
+
| `@vllnt/eslint-config/convex` | Convex backends (4 official + 7 custom rules) |
|
|
52
|
+
| `@vllnt/eslint-config/turbo` | Turborepo cache rules (opt-in) |
|
|
53
|
+
| `@vllnt/eslint-config/boundaries` | Architecture boundary enforcement (opt-in) |
|
|
54
|
+
|
|
55
|
+
## Composing presets
|
|
56
|
+
|
|
57
|
+
Mix and match — presets are arrays:
|
|
58
|
+
|
|
59
|
+
```js
|
|
60
|
+
import { nodejs } from '@vllnt/eslint-config/nodejs'
|
|
61
|
+
import { turbo } from '@vllnt/eslint-config/turbo'
|
|
62
|
+
|
|
63
|
+
export default [...nodejs, ...turbo]
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Override any rule by appending a config object:
|
|
67
|
+
|
|
68
|
+
```js
|
|
69
|
+
import { nodejs } from '@vllnt/eslint-config/nodejs'
|
|
70
|
+
|
|
71
|
+
export default [
|
|
72
|
+
...nodejs,
|
|
73
|
+
{
|
|
74
|
+
rules: {
|
|
75
|
+
'max-lines-per-function': ['error', { max: 50 }],
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
]
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## What's included
|
|
84
|
+
|
|
85
|
+
### Base (all presets)
|
|
86
|
+
|
|
87
|
+
| Plugin | What it does |
|
|
88
|
+
|--------|-------------|
|
|
89
|
+
| [@eslint/js](https://eslint.org/docs/latest/rules/) | ESLint recommended rules |
|
|
90
|
+
| [typescript-eslint](https://typescript-eslint.io/) | `strictTypeChecked` + `stylisticTypeChecked` |
|
|
91
|
+
| [eslint-plugin-prettier](https://github.com/prettier/eslint-plugin-prettier) | Prettier as ESLint errors |
|
|
92
|
+
| [eslint-config-prettier](https://github.com/prettier/eslint-config-prettier) | Disables conflicting rules |
|
|
93
|
+
| [eslint-plugin-perfectionist](https://perfectionist.dev/) | Import/object/type sorting |
|
|
94
|
+
| [eslint-plugin-unicorn](https://github.com/sindresorhus/eslint-plugin-unicorn) | Modern JS best practices |
|
|
95
|
+
| [eslint-plugin-simple-import-sort](https://github.com/lydell/eslint-plugin-simple-import-sort) | Import ordering |
|
|
96
|
+
| [eslint-plugin-functional](https://github.com/eslint-functional/eslint-plugin-functional) | Functional patterns (no loops, readonly) |
|
|
97
|
+
| [eslint-plugin-write-good-comments](https://github.com/kantord/eslint-plugin-write-good-comments) | Comment quality |
|
|
98
|
+
|
|
99
|
+
Plus: strict naming conventions (camelCase, PascalCase types, T-prefixed generics), no enums (union types enforced via AST selector).
|
|
100
|
+
|
|
101
|
+
### React additions
|
|
102
|
+
|
|
103
|
+
| Plugin | What it does |
|
|
104
|
+
|--------|-------------|
|
|
105
|
+
| [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) | Recommended + jsx-runtime |
|
|
106
|
+
| [eslint-plugin-react-hooks](https://react.dev/reference/rules/rules-of-hooks) | Rules of hooks |
|
|
107
|
+
| [eslint-plugin-jsx-a11y](https://github.com/jsx-eslint/eslint-plugin-jsx-a11y) | Accessibility |
|
|
108
|
+
| [eslint-plugin-css-modules](https://github.com/atfzl/eslint-plugin-css-modules) | CSS module validation |
|
|
109
|
+
|
|
110
|
+
### Next.js additions
|
|
111
|
+
|
|
112
|
+
Everything in React, plus:
|
|
113
|
+
|
|
114
|
+
| Plugin | What it does |
|
|
115
|
+
|--------|-------------|
|
|
116
|
+
| [@next/eslint-plugin-next](https://nextjs.org/docs/app/api-reference/config/eslint) | Recommended + core web vitals (all `error`) |
|
|
117
|
+
|
|
118
|
+
Route handler method restrictions, page/layout `max-lines-per-function` override.
|
|
119
|
+
|
|
120
|
+
### Opt-in
|
|
121
|
+
|
|
122
|
+
| Preset | Plugin |
|
|
123
|
+
|--------|--------|
|
|
124
|
+
| Turbo | [eslint-plugin-turbo](https://turbo.build/repo/docs/reference/eslint-plugin-turbo) cache rules |
|
|
125
|
+
| Boundaries | [eslint-plugin-boundaries](https://github.com/javierbrea/eslint-plugin-boundaries) architecture enforcement |
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## Convex preset
|
|
130
|
+
|
|
131
|
+
The Convex preset enforces backend best practices with **4 official rules** + **7 custom rules** bundled as `eslint-plugin-convex-rules`.
|
|
132
|
+
|
|
133
|
+
### Setup
|
|
134
|
+
|
|
135
|
+
```js
|
|
136
|
+
// Standalone
|
|
137
|
+
import { convex } from '@vllnt/eslint-config/convex'
|
|
138
|
+
|
|
139
|
+
export default [...convex]
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
```js
|
|
143
|
+
// With base (recommended)
|
|
144
|
+
import { base } from '@vllnt/eslint-config'
|
|
145
|
+
import { convex } from '@vllnt/eslint-config/convex'
|
|
146
|
+
|
|
147
|
+
export default [...base, ...convex]
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### Official rules (`@convex-dev`)
|
|
151
|
+
|
|
152
|
+
| Rule | Catches |
|
|
153
|
+
|------|---------|
|
|
154
|
+
| `no-old-registered-function-syntax` | Deprecated function syntax |
|
|
155
|
+
| `require-args-validator` | Missing `args` validator |
|
|
156
|
+
| `explicit-table-ids` | Implicit table ID types |
|
|
157
|
+
| `import-wrong-runtime` | Wrong runtime imports (Node in Convex runtime) |
|
|
158
|
+
|
|
159
|
+
### Custom rules (`convex-rules`)
|
|
160
|
+
|
|
161
|
+
| Rule | Catches |
|
|
162
|
+
|------|---------|
|
|
163
|
+
| `standard-filenames` | Factories outside `queries.ts`, `mutations.ts`, `actions.ts` |
|
|
164
|
+
| `namespace-separation` | `query()` in `mutations.ts`, `mutation()` in `queries.ts` |
|
|
165
|
+
| `snake-case-filenames` | Hyphens in `convex/` filenames (must be `snake_case`) |
|
|
166
|
+
| `no-bare-v-any` | `v.any()` outside `validators.ts` |
|
|
167
|
+
| `require-returns-validator` | Missing `returns` validator in factory config |
|
|
168
|
+
| `no-query-in-loop` | N+1 queries (`ctx.db.query`/`get`/`runQuery` inside loops) |
|
|
169
|
+
| `no-filter-on-query` | `.filter()` on query chains (use `.withIndex()`) |
|
|
170
|
+
|
|
171
|
+
### Auto-applied overrides
|
|
172
|
+
|
|
173
|
+
- **Config files** (`auth.ts`, `auth.config.ts`, `convex.config.ts`) — exempt from `snake-case-filenames` and `explicit-module-boundary-types`
|
|
174
|
+
- **Migration files** (`convex/migrations/**`) — exempt from `standard-filenames`, `namespace-separation`, `no-query-in-loop`
|
|
175
|
+
- **Generated/test files** (`convex/_generated/**`, `*.test.ts`, `convex/testing/**`) — excluded entirely
|
|
176
|
+
|
|
177
|
+
### Project-specific overrides
|
|
178
|
+
|
|
179
|
+
```js
|
|
180
|
+
import { base } from '@vllnt/eslint-config'
|
|
181
|
+
import { convex } from '@vllnt/eslint-config/convex'
|
|
182
|
+
|
|
183
|
+
export default [
|
|
184
|
+
...base,
|
|
185
|
+
...convex,
|
|
186
|
+
|
|
187
|
+
// Exempt "use node" action files from import-wrong-runtime
|
|
188
|
+
{
|
|
189
|
+
files: ['convex/agents/actions.ts'],
|
|
190
|
+
rules: { '@convex-dev/import-wrong-runtime': 'off' },
|
|
191
|
+
},
|
|
192
|
+
]
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### Enforced file structure
|
|
196
|
+
|
|
197
|
+
```
|
|
198
|
+
convex/
|
|
199
|
+
{domain}/
|
|
200
|
+
queries.ts query(), internalQuery()
|
|
201
|
+
mutations.ts mutation(), internalMutation()
|
|
202
|
+
actions.ts action(), internalAction()
|
|
203
|
+
internal_mutations.ts internalMutation() (optional split)
|
|
204
|
+
validators.ts v.* validators + types
|
|
205
|
+
schema.ts table definitions
|
|
206
|
+
lib/
|
|
207
|
+
validators.ts shared v.any() aliases
|
|
208
|
+
_generated/ auto-generated (excluded)
|
|
209
|
+
migrations/ relaxed rules
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
---
|
|
213
|
+
|
|
214
|
+
## Peer dependencies
|
|
215
|
+
|
|
216
|
+
| Package | Required |
|
|
217
|
+
|---------|----------|
|
|
218
|
+
| `eslint` >= 9 | Yes |
|
|
219
|
+
| `prettier` >= 3 | Yes |
|
|
220
|
+
| `typescript` >= 5 | Optional |
|
|
221
|
+
|
|
222
|
+
## VS Code
|
|
223
|
+
|
|
224
|
+
Add to `.vscode/settings.json` for monorepo support:
|
|
225
|
+
|
|
226
|
+
```json
|
|
227
|
+
{
|
|
228
|
+
"eslint.workingDirectories": [
|
|
229
|
+
"./apps/your-app",
|
|
230
|
+
"./packages/your-package"
|
|
231
|
+
]
|
|
232
|
+
}
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
## License
|
|
236
|
+
|
|
237
|
+
[MIT](LICENSE)
|
package/flat/base.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import eslint from '@eslint/js'
|
|
2
|
+
import tseslint from 'typescript-eslint'
|
|
3
|
+
import { goodPractices } from './core/good-practices.js'
|
|
4
|
+
import { imports } from './core/imports.js'
|
|
5
|
+
import { format } from './core/format.js'
|
|
6
|
+
import { unicornConfig } from './core/unicorn.js'
|
|
7
|
+
import { typescriptConfig } from './core/typescript.js'
|
|
8
|
+
|
|
9
|
+
export const base = tseslint.config(
|
|
10
|
+
eslint.configs.recommended,
|
|
11
|
+
...tseslint.configs.strictTypeChecked,
|
|
12
|
+
...tseslint.configs.stylisticTypeChecked,
|
|
13
|
+
{
|
|
14
|
+
languageOptions: {
|
|
15
|
+
parserOptions: {
|
|
16
|
+
projectService: true,
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
goodPractices,
|
|
21
|
+
imports,
|
|
22
|
+
format,
|
|
23
|
+
unicornConfig,
|
|
24
|
+
typescriptConfig,
|
|
25
|
+
)
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* eslint-plugin-convex-rules
|
|
3
|
+
*
|
|
4
|
+
* Custom ESLint rules enforcing Convex backend best practices:
|
|
5
|
+
* structure, naming, query optimization, and type safety.
|
|
6
|
+
*
|
|
7
|
+
* Bundled with @vllnt/eslint-config — consumed via the convex preset.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import standardFilenames from './convex-rules/standard-filenames.js'
|
|
11
|
+
import namespaceSeparation from './convex-rules/namespace-separation.js'
|
|
12
|
+
import noBareVAny from './convex-rules/no-bare-v-any.js'
|
|
13
|
+
import requireReturnsValidator from './convex-rules/require-returns-validator.js'
|
|
14
|
+
import noQueryInLoop from './convex-rules/no-query-in-loop.js'
|
|
15
|
+
import noFilterOnQuery from './convex-rules/no-filter-on-query.js'
|
|
16
|
+
import snakeCaseFilenames from './convex-rules/snake-case-filenames.js'
|
|
17
|
+
|
|
18
|
+
const plugin = {
|
|
19
|
+
meta: {
|
|
20
|
+
name: 'eslint-plugin-convex-rules',
|
|
21
|
+
version: '1.0.0',
|
|
22
|
+
},
|
|
23
|
+
rules: {
|
|
24
|
+
'standard-filenames': standardFilenames,
|
|
25
|
+
'namespace-separation': namespaceSeparation,
|
|
26
|
+
'no-bare-v-any': noBareVAny,
|
|
27
|
+
'require-returns-validator': requireReturnsValidator,
|
|
28
|
+
'no-query-in-loop': noQueryInLoop,
|
|
29
|
+
'no-filter-on-query': noFilterOnQuery,
|
|
30
|
+
'snake-case-filenames': snakeCaseFilenames,
|
|
31
|
+
},
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export default plugin
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared utilities for convex-rules ESLint plugin.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/** Convex factory function names that create registered functions. */
|
|
6
|
+
export const CONVEX_FACTORIES = new Set([
|
|
7
|
+
'query',
|
|
8
|
+
'mutation',
|
|
9
|
+
'action',
|
|
10
|
+
'internalQuery',
|
|
11
|
+
'internalMutation',
|
|
12
|
+
'internalAction',
|
|
13
|
+
])
|
|
14
|
+
|
|
15
|
+
/** Standard filenames allowed to contain Convex factory exports. */
|
|
16
|
+
export const STANDARD_CONVEX_FILENAMES = new Set([
|
|
17
|
+
'queries.ts',
|
|
18
|
+
'mutations.ts',
|
|
19
|
+
'actions.ts',
|
|
20
|
+
'internal_mutations.ts',
|
|
21
|
+
])
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Check if a CallExpression node is a Convex factory call.
|
|
25
|
+
* Handles direct calls: query({...}), mutation({...}), etc.
|
|
26
|
+
*
|
|
27
|
+
* @param {import("eslint").Rule.Node} node
|
|
28
|
+
* @returns {{ factoryType: string } | null}
|
|
29
|
+
*/
|
|
30
|
+
export function getConvexFactory(node) {
|
|
31
|
+
if (node.type !== 'CallExpression') return null
|
|
32
|
+
const callee = node.callee
|
|
33
|
+
if (callee.type === 'Identifier' && CONVEX_FACTORIES.has(callee.name)) {
|
|
34
|
+
return { factoryType: callee.name }
|
|
35
|
+
}
|
|
36
|
+
return null
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @param {string} filePath
|
|
41
|
+
* @returns {string}
|
|
42
|
+
*/
|
|
43
|
+
export function getBasename(filePath) {
|
|
44
|
+
return filePath.split('/').pop() ?? filePath
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @param {string} filePath
|
|
49
|
+
* @returns {string}
|
|
50
|
+
*/
|
|
51
|
+
export function getBasenameNoExt(filePath) {
|
|
52
|
+
const base = getBasename(filePath)
|
|
53
|
+
const dot = base.lastIndexOf('.')
|
|
54
|
+
return dot === -1 ? base : base.slice(0, dot)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* @param {import("eslint").Rule.RuleContext} context
|
|
59
|
+
* @returns {string}
|
|
60
|
+
*/
|
|
61
|
+
export function getFilename(context) {
|
|
62
|
+
return context.physicalFilename ?? context.filename ?? ''
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* @param {string} filePath
|
|
67
|
+
* @returns {boolean}
|
|
68
|
+
*/
|
|
69
|
+
export function isTestFile(filePath) {
|
|
70
|
+
return filePath.includes('.test.ts') || filePath.includes('/testing/')
|
|
71
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rule: namespace-separation
|
|
3
|
+
* Enforces that Convex factory functions only appear in their designated files:
|
|
4
|
+
* - query / internalQuery -> queries.ts
|
|
5
|
+
* - mutation / internalMutation -> mutations.ts or internal_mutations.ts
|
|
6
|
+
* - action / internalAction -> actions.ts
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { getConvexFactory, getBasename, getFilename } from './_utils.js'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @param {string} factoryType
|
|
13
|
+
* @returns {{ expectedFile: string; isAllowed: (basename: string) => boolean } | null}
|
|
14
|
+
*/
|
|
15
|
+
function getAllowedFile(factoryType) {
|
|
16
|
+
switch (factoryType) {
|
|
17
|
+
case 'query':
|
|
18
|
+
case 'internalQuery':
|
|
19
|
+
return {
|
|
20
|
+
expectedFile: 'queries.ts',
|
|
21
|
+
isAllowed: (b) => b === 'queries.ts',
|
|
22
|
+
}
|
|
23
|
+
case 'mutation':
|
|
24
|
+
case 'internalMutation':
|
|
25
|
+
return {
|
|
26
|
+
expectedFile: 'mutations.ts or internal_mutations.ts',
|
|
27
|
+
isAllowed: (b) => b === 'mutations.ts' || b === 'internal_mutations.ts',
|
|
28
|
+
}
|
|
29
|
+
case 'action':
|
|
30
|
+
case 'internalAction':
|
|
31
|
+
return {
|
|
32
|
+
expectedFile: 'actions.ts',
|
|
33
|
+
isAllowed: (b) => b === 'actions.ts',
|
|
34
|
+
}
|
|
35
|
+
default:
|
|
36
|
+
return null
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** @type {import("eslint").Rule.RuleModule} */
|
|
41
|
+
const rule = {
|
|
42
|
+
meta: {
|
|
43
|
+
type: 'problem',
|
|
44
|
+
docs: {
|
|
45
|
+
description:
|
|
46
|
+
'Convex factory functions must be in their designated namespace files',
|
|
47
|
+
},
|
|
48
|
+
messages: {
|
|
49
|
+
wrongNamespace:
|
|
50
|
+
'{{factoryType}}() exports must be in {{expectedFile}}, not "{{actualFile}}". Move this function to the correct file.',
|
|
51
|
+
},
|
|
52
|
+
schema: [],
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
create(context) {
|
|
56
|
+
const filename = getFilename(context)
|
|
57
|
+
const basename = getBasename(filename)
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
ExportNamedDeclaration(node) {
|
|
61
|
+
const decl = node.declaration
|
|
62
|
+
if (!decl || decl.type !== 'VariableDeclaration') return
|
|
63
|
+
|
|
64
|
+
for (const declarator of decl.declarations) {
|
|
65
|
+
const init = declarator.init
|
|
66
|
+
if (!init) continue
|
|
67
|
+
const factory = getConvexFactory(init)
|
|
68
|
+
if (!factory) continue
|
|
69
|
+
|
|
70
|
+
const allowed = getAllowedFile(factory.factoryType)
|
|
71
|
+
if (!allowed) continue
|
|
72
|
+
|
|
73
|
+
if (!allowed.isAllowed(basename)) {
|
|
74
|
+
context.report({
|
|
75
|
+
node: declarator,
|
|
76
|
+
messageId: 'wrongNamespace',
|
|
77
|
+
data: {
|
|
78
|
+
factoryType: factory.factoryType,
|
|
79
|
+
expectedFile: allowed.expectedFile,
|
|
80
|
+
actualFile: basename,
|
|
81
|
+
},
|
|
82
|
+
})
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export default rule
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rule: no-bare-v-any
|
|
3
|
+
* Bans bare `v.any()` calls outside of validators.ts files and test files.
|
|
4
|
+
* Define named aliases in a validators.ts file instead.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { getFilename, isTestFile } from './_utils.js'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @param {string} filePath
|
|
11
|
+
* @returns {boolean}
|
|
12
|
+
*/
|
|
13
|
+
function isValidatorsFile(filePath) {
|
|
14
|
+
return filePath.endsWith('/validators.ts') || filePath.endsWith('\\validators.ts')
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** @type {import("eslint").Rule.RuleModule} */
|
|
18
|
+
const rule = {
|
|
19
|
+
meta: {
|
|
20
|
+
type: 'problem',
|
|
21
|
+
docs: {
|
|
22
|
+
description:
|
|
23
|
+
'Bare v.any() is not allowed outside of validators.ts. Use a named alias.',
|
|
24
|
+
},
|
|
25
|
+
messages: {
|
|
26
|
+
noBareVAny:
|
|
27
|
+
'Bare v.any() is not allowed. Define a named alias in a validators.ts file instead.',
|
|
28
|
+
},
|
|
29
|
+
schema: [],
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
create(context) {
|
|
33
|
+
const filename = getFilename(context)
|
|
34
|
+
|
|
35
|
+
if (isValidatorsFile(filename) || isTestFile(filename)) {
|
|
36
|
+
return {}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
CallExpression(node) {
|
|
41
|
+
const { callee } = node
|
|
42
|
+
|
|
43
|
+
if (
|
|
44
|
+
callee.type === 'MemberExpression' &&
|
|
45
|
+
!callee.computed &&
|
|
46
|
+
callee.object.type === 'Identifier' &&
|
|
47
|
+
callee.object.name === 'v' &&
|
|
48
|
+
callee.property.type === 'Identifier' &&
|
|
49
|
+
callee.property.name === 'any'
|
|
50
|
+
) {
|
|
51
|
+
context.report({
|
|
52
|
+
node,
|
|
53
|
+
messageId: 'noBareVAny',
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export default rule
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rule: no-filter-on-query
|
|
3
|
+
* Flags .filter() chained on a Convex query expression (after ctx.db.query()).
|
|
4
|
+
* Full table scans must be replaced with .withIndex().
|
|
5
|
+
*
|
|
6
|
+
* Flagged:
|
|
7
|
+
* ctx.db.query("table").filter(q => q.eq(q.field("x"), 1))
|
|
8
|
+
*
|
|
9
|
+
* NOT flagged (array .filter() after await):
|
|
10
|
+
* const rows = await ctx.db.query("table").collect();
|
|
11
|
+
* rows.filter(r => r.x === 1);
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @param {import("estree").Expression} node
|
|
16
|
+
* @returns {boolean}
|
|
17
|
+
*/
|
|
18
|
+
function chainContainsQuery(node) {
|
|
19
|
+
if (!node) return false
|
|
20
|
+
|
|
21
|
+
if (node.type === 'CallExpression') {
|
|
22
|
+
const { callee } = node
|
|
23
|
+
if (
|
|
24
|
+
callee.type === 'MemberExpression' &&
|
|
25
|
+
!callee.computed &&
|
|
26
|
+
callee.property.type === 'Identifier' &&
|
|
27
|
+
callee.property.name === 'query'
|
|
28
|
+
) {
|
|
29
|
+
return true
|
|
30
|
+
}
|
|
31
|
+
if (callee.type === 'MemberExpression') {
|
|
32
|
+
return chainContainsQuery(callee.object)
|
|
33
|
+
}
|
|
34
|
+
return false
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (node.type === 'MemberExpression') {
|
|
38
|
+
return chainContainsQuery(node.object)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return false
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** @type {import("eslint").Rule.RuleModule} */
|
|
45
|
+
const rule = {
|
|
46
|
+
meta: {
|
|
47
|
+
type: 'problem',
|
|
48
|
+
docs: {
|
|
49
|
+
description:
|
|
50
|
+
'Disallow .filter() on Convex queries — use .withIndex() for indexed lookups',
|
|
51
|
+
},
|
|
52
|
+
messages: {
|
|
53
|
+
noFilterOnQuery:
|
|
54
|
+
"Don't use .filter() on Convex queries — it causes full table scans. Use .withIndex() instead.",
|
|
55
|
+
},
|
|
56
|
+
schema: [],
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
create(context) {
|
|
60
|
+
return {
|
|
61
|
+
CallExpression(node) {
|
|
62
|
+
const { callee } = node
|
|
63
|
+
|
|
64
|
+
if (
|
|
65
|
+
callee.type !== 'MemberExpression' ||
|
|
66
|
+
callee.computed ||
|
|
67
|
+
callee.property.type !== 'Identifier' ||
|
|
68
|
+
callee.property.name !== 'filter'
|
|
69
|
+
) {
|
|
70
|
+
return
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const receiver = callee.object
|
|
74
|
+
if (chainContainsQuery(receiver)) {
|
|
75
|
+
context.report({
|
|
76
|
+
node,
|
|
77
|
+
messageId: 'noFilterOnQuery',
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export default rule
|