@kamaal111/kamaal-quality-config 0.8.0 → 0.10.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 +119 -4
- package/dist/index.d.ts +2 -2
- package/dist/oxlint.d.ts +2 -2
- package/dist/oxlint.d.ts.map +1 -1
- package/dist/oxlint.js +29 -8
- package/dist/oxlint.js.map +1 -1
- package/dist/oxlintrc.json +23 -4
- package/dist/plugins/anti-slop.d.ts +3 -0
- package/dist/plugins/anti-slop.d.ts.map +1 -0
- package/dist/plugins/anti-slop.js +3 -0
- package/dist/plugins/anti-slop.js.map +1 -0
- package/dist/plugins/consistent-inline-type-imports.js +5 -3
- package/dist/plugins/consistent-inline-type-imports.js.map +1 -1
- package/dist/plugins/import.d.ts +3 -0
- package/dist/plugins/import.d.ts.map +1 -0
- package/dist/plugins/import.js +3 -0
- package/dist/plugins/import.js.map +1 -0
- package/dist/plugins/no-nested-try.d.ts +27 -0
- package/dist/plugins/no-nested-try.d.ts.map +1 -0
- package/dist/plugins/no-nested-try.js +42 -0
- package/dist/plugins/no-nested-try.js.map +1 -0
- package/dist/plugins/prefer-nonempty.d.ts +4 -0
- package/dist/plugins/prefer-nonempty.d.ts.map +1 -0
- package/dist/plugins/prefer-nonempty.js +135 -0
- package/dist/plugins/prefer-nonempty.js.map +1 -0
- package/dist/plugins/prefer-nullish.d.ts +3 -32
- package/dist/plugins/prefer-nullish.d.ts.map +1 -1
- package/dist/plugins/prefer-nullish.js +24 -28
- package/dist/plugins/prefer-nullish.js.map +1 -1
- package/dist/plugins/prefer-while-true.d.ts +26 -0
- package/dist/plugins/prefer-while-true.d.ts.map +1 -0
- package/dist/plugins/prefer-while-true.js +26 -0
- package/dist/plugins/prefer-while-true.js.map +1 -0
- package/dist/plugins/require-multiline-arrow-braces.d.ts +30 -0
- package/dist/plugins/require-multiline-arrow-braces.d.ts.map +1 -0
- package/dist/plugins/require-multiline-arrow-braces.js +51 -0
- package/dist/plugins/require-multiline-arrow-braces.js.map +1 -0
- package/dist/plugins/rule-context.d.ts +11 -0
- package/dist/plugins/rule-context.d.ts.map +1 -1
- package/dist/plugins/stylistic.d.ts +3 -0
- package/dist/plugins/stylistic.d.ts.map +1 -0
- package/dist/plugins/stylistic.js +3 -0
- package/dist/plugins/stylistic.js.map +1 -0
- package/dist/plugins/zod.d.ts +11 -0
- package/dist/plugins/zod.d.ts.map +1 -0
- package/dist/plugins/zod.js +10 -0
- package/dist/plugins/zod.js.map +1 -0
- package/package.json +9 -3
- package/swift/SwiftLintChecks/Sources/SwiftLintChecks/LintViolation.swift +12 -0
- package/swift/SwiftLintChecks/Sources/SwiftLintChecks/NoNestedDoCatchVisitor.swift +29 -0
- package/swift/SwiftLintChecks/Sources/SwiftLintChecks/SingleTryPerDoCatchVisitor.swift +34 -0
- package/swift/SwiftLintChecks/Sources/SwiftLintChecks/SwiftLint.swift +6 -1
- package/swift/SwiftLintChecks/Tests/SwiftLintChecksTests/NoNestedDoCatchTests.swift +138 -0
- package/swift/SwiftLintChecks/Tests/SwiftLintChecksTests/SingleTryPerDoCatchTests.swift +286 -0
package/README.md
CHANGED
|
@@ -5,21 +5,54 @@ Kamaal Farah's shared quality configs for [oxlint and oxfmt](https://oxc.rs), Sw
|
|
|
5
5
|
Currently enables every rule from [`@kamaal111/oxlint-plugin-anti-slop`](https://github.com/kamaal111/anti-slop),
|
|
6
6
|
Kamaal's fork of [`dmmulroy/anti-slop`](https://github.com/dmmulroy/anti-slop), plus a curated set of
|
|
7
7
|
rules from oxlint's built-in `typescript`, `unicorn`, `oxc`, and `vitest` plugins and from
|
|
8
|
-
`eslint-plugin-import` (via oxlint's `jsPlugins`), plus selected rules from `@stylistic/eslint-plugin` and
|
|
8
|
+
`eslint-plugin-import` (via oxlint's `jsPlugins`), plus selected rules from `@stylistic/eslint-plugin` and seven hand-written local rules:
|
|
9
9
|
|
|
10
10
|
- `kamaal-imports/no-all-inline-type-imports` — forbids `import { type A, type B } from 'x'` in favor
|
|
11
11
|
of a top-level `import type { A, B } from 'x'`.
|
|
12
12
|
- `kamaal-ternary/no-nullish-check-first-ternary` — forbids ternaries that check for a nullish value
|
|
13
13
|
first (e.g. `x == null ? undefined : x.trim()`), requiring the value-producing branch first instead
|
|
14
14
|
(`x != null ? x.trim() : undefined`).
|
|
15
|
+
- `kamaal-arrows/require-multiline-arrow-braces` — requires braces for multiline expression bodies,
|
|
16
|
+
except direct object-literal returns.
|
|
17
|
+
- `kamaal-zod/prefer-nonempty` — requires `.nonempty()` instead of `.min(1)` on verified
|
|
18
|
+
inline Zod 4 string, array, and set schemas, with autofix preserving custom errors and comments.
|
|
19
|
+
Supports imports and aliases from `zod` and `zod/v4`; the root import is assumed to be Zod 4.
|
|
20
|
+
Numeric schemas, schema variables, unsupported intermediate methods, and explicit Zod 3/Mini/Core
|
|
21
|
+
imports are left unchanged. Known chains such as `z.string().trim().min(1)` are supported.
|
|
15
22
|
- `kamaal-zod/prefer-nullish` — requires `.nullish()` instead of consecutive `.nullable()` and
|
|
16
23
|
`.optional()` calls in either order. This syntax-based rule applies to any receiver and has no autofix.
|
|
24
|
+
- `kamaal-loops/prefer-while-true` — requires `while (true)` instead of `for (;;)` when all three
|
|
25
|
+
header parts are empty. Autofix replaces comment-free headers; headers containing comments are
|
|
26
|
+
reported without a fix. Other `for` loops are unchanged.
|
|
27
|
+
- `kamaal-errors/no-nested-try` — rejects nested JavaScript and TypeScript `try` statements,
|
|
28
|
+
including handlers in `catch` and `finally` and `try/finally` without `catch`.
|
|
29
|
+
Functions, closures, and classes start independent scopes. Use sequential handlers or extract
|
|
30
|
+
error handling into a helper; the rule does not autofix.
|
|
31
|
+
|
|
32
|
+
The error-handling plugin is exported at
|
|
33
|
+
`@kamaal111/kamaal-quality-config/plugins/no-nested-try`.
|
|
34
|
+
|
|
35
|
+
The Zod plugin is exported at `@kamaal111/kamaal-quality-config/plugins/zod`.
|
|
17
36
|
|
|
18
37
|
The shared defaults also require blank lines around class methods and constructors (with autofix),
|
|
19
38
|
allow consecutive fields to stay grouped, require default imports for `node:` modules, and prohibit
|
|
20
39
|
`Object.assign` in favor of explicit typed assignments or object spread. Vitest globals and
|
|
21
40
|
project-specific server restrictions remain consumer choices.
|
|
22
41
|
|
|
42
|
+
Multiline arrow bodies require braces and an explicit return, with autofix through
|
|
43
|
+
`kamaal-arrows/require-multiline-arrow-braces`. Single-line expression bodies, wrapped parameters,
|
|
44
|
+
and direct object-literal returns (including multiline objects) remain allowed:
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
const double = x => x * 2;
|
|
48
|
+
const makeUser = () => ({
|
|
49
|
+
name: 'Kamaal',
|
|
50
|
+
});
|
|
51
|
+
const readAnswer = () => {
|
|
52
|
+
return fetchAnswer('Kamaal');
|
|
53
|
+
};
|
|
54
|
+
```
|
|
55
|
+
|
|
23
56
|
More rule sources will be folded in over time.
|
|
24
57
|
|
|
25
58
|
## Table of contents
|
|
@@ -53,6 +86,21 @@ Extend it from your `.oxlintrc.json`:
|
|
|
53
86
|
}
|
|
54
87
|
```
|
|
55
88
|
|
|
89
|
+
The shared config owns its external JavaScript plugins, including
|
|
90
|
+
`@stylistic/eslint-plugin`, `eslint-plugin-import`, and
|
|
91
|
+
`@kamaal111/oxlint-plugin-anti-slop`. Consumers do not need to declare those plugins
|
|
92
|
+
directly or repeat their rule settings. Install `oxlint` and `oxlint-tsgolint`
|
|
93
|
+
as development tools if your project does not already provide them:
|
|
94
|
+
|
|
95
|
+
```sh
|
|
96
|
+
pnpm add -D oxlint oxlint-tsgolint
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Plugin entry points are exported by this package so both JSON and TypeScript
|
|
100
|
+
configs resolve plugins through the shared package's own dependencies. This
|
|
101
|
+
resolution fix requires a release after v0.8.0; v0.8.0 and earlier can require
|
|
102
|
+
plugins to be exposed at the consumer root under isolated dependency layouts.
|
|
103
|
+
|
|
56
104
|
The package ships a plain, statically-generated `dist/oxlintrc.json` — no `oxlint.config.ts` or
|
|
57
105
|
package-import support is needed, since `.oxlintrc.json`'s `extends` field accepts plain file paths.
|
|
58
106
|
|
|
@@ -158,12 +206,78 @@ Without paths, the command checks the current directory recursively. Explicit fi
|
|
|
158
206
|
paths are relative to your working directory. Recursive scanning skips hidden paths (including
|
|
159
207
|
`.build`), `node_modules`, symlinks, and non-Swift files. Use `--` before paths starting with a dash.
|
|
160
208
|
|
|
161
|
-
All
|
|
209
|
+
All five checks are enabled:
|
|
162
210
|
|
|
163
211
|
- `member_spacing`: separate methods and initializers from adjacent members with a blank line.
|
|
164
212
|
- `multiline_chain_spacing`: put each chained call on its own line in multiline expressions.
|
|
165
213
|
- `view_body_declarations`: move local `let` and `var` declarations out of SwiftUI
|
|
166
214
|
`var body: some View`, including nested builder closures. Conditional bindings remain allowed.
|
|
215
|
+
- `no_nested_do_catch`: reject a `do/catch` nested anywhere in another `do/catch`,
|
|
216
|
+
including its catch clauses. Plain `do` blocks do not count, but do not hide nesting.
|
|
217
|
+
Functions, closures, initializers, accessors, and nested types start independent scopes;
|
|
218
|
+
their own handlers are still checked. Use sequential handlers or extract a helper.
|
|
219
|
+
- `single_try_per_do_catch`: allow at most one plain `try` expression per `do/catch` body.
|
|
220
|
+
Count across branches and loops; `try?` and `try!` do not count. Each `do/catch` body
|
|
221
|
+
is counted independently, while catchless `do` blocks contribute to the enclosing count.
|
|
222
|
+
Nesting handlers is rejected separately by `no_nested_do_catch`.
|
|
223
|
+
Closures, local functions, and nested types have separate scopes; their own `do/catch` blocks
|
|
224
|
+
are still checked. A `try` in a nested catch contributes to an enclosing handler, if present.
|
|
225
|
+
All conditional-compilation branches count, including inactive branches.
|
|
226
|
+
|
|
227
|
+
For example, this shares error handling between two throwing operations and is rejected at the second `try`:
|
|
228
|
+
|
|
229
|
+
```swift
|
|
230
|
+
do {
|
|
231
|
+
try load()
|
|
232
|
+
try save()
|
|
233
|
+
} catch {
|
|
234
|
+
reportError(error)
|
|
235
|
+
}
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
Give each operation its own error handling, or extract a helper that handles its error. Decide whether
|
|
239
|
+
each failure should recover, propagate, or gain more context. For operations without a returned value:
|
|
240
|
+
|
|
241
|
+
```swift
|
|
242
|
+
do {
|
|
243
|
+
try load()
|
|
244
|
+
} catch {
|
|
245
|
+
reportLoad(error)
|
|
246
|
+
return
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
do {
|
|
250
|
+
try save()
|
|
251
|
+
} catch {
|
|
252
|
+
reportSave(error)
|
|
253
|
+
}
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
Here the early return prevents saving after loading fails. Choose continuation based on the operation.
|
|
257
|
+
|
|
258
|
+
For an operation that returns a value, declare a typed `let` before the `do` and assign it inside:
|
|
259
|
+
|
|
260
|
+
```swift
|
|
261
|
+
let result: SaveResult
|
|
262
|
+
do {
|
|
263
|
+
result = try save()
|
|
264
|
+
} catch {
|
|
265
|
+
reportError(error)
|
|
266
|
+
return
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
display(result)
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
If the value is used afterward, the catch must exit, rethrow the error, or assign a meaningful fallback
|
|
273
|
+
so the value is initialized on every continuing path. Reporting the error alone is sufficient only
|
|
274
|
+
when no subsequent path reads the uninitialized value. `SaveResult` is the operation's return type;
|
|
275
|
+
it is not Swift's generic `Result<Success, Failure>`.
|
|
276
|
+
|
|
277
|
+
Diagnostics explain these alternatives. The rule has no autofix because choosing error handling
|
|
278
|
+
requires judgment. It counts explicit plain `try` expressions rather than throwing calls: one
|
|
279
|
+
`try` covering multiple calls counts as one, but combining calls merely to silence the rule
|
|
280
|
+
defeats its purpose.
|
|
167
281
|
|
|
168
282
|
The CLI runs `swift run --package-path` against the bundled `SwiftLintChecks` package and does not
|
|
169
283
|
modify source files. Diagnostics include file, line, column, and rule identifier. Exit codes are
|
|
@@ -188,8 +302,9 @@ pnpm test
|
|
|
188
302
|
Vitest also checks the packed package. To select a consumer runtime, run
|
|
189
303
|
`CONSUMER_NODE=/absolute/path/to/node pnpm test src/packed-consumer.test.ts` inside the devcontainer.
|
|
190
304
|
CI selects the latest Node.js 22 release while building and running Vitest on Node.js 26.
|
|
191
|
-
The
|
|
192
|
-
|
|
305
|
+
The fixture installs only the packed shared package and Oxlint tooling. It checks
|
|
306
|
+
both JSON and TypeScript configs without declaring external plugin dependencies
|
|
307
|
+
at the consumer root, so package-owned plugin resolution stays covered.
|
|
193
308
|
|
|
194
309
|
The dependency-free example package in `fixtures/swift-format` verifies the installed Swift config.
|
|
195
310
|
CI's Swift consumer job supplies Swift 6.4.1 and runs `pnpm test:swift-format`: it builds the package,
|
package/dist/index.d.ts
CHANGED
package/dist/oxlint.d.ts
CHANGED
package/dist/oxlint.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oxlint.d.ts","sourceRoot":"","sources":["../src/oxlint.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"oxlint.d.ts","sourceRoot":"","sources":["../src/oxlint.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gBA6JuB,KAAK;gBAAS,eAAe"}
|
package/dist/oxlint.js
CHANGED
|
@@ -1,25 +1,43 @@
|
|
|
1
1
|
import antiSlopPlugin from '@kamaal111/oxlint-plugin-anti-slop';
|
|
2
2
|
import { defineConfig } from 'oxlint';
|
|
3
3
|
import consistentInlineTypeImportsPlugin from './plugins/consistent-inline-type-imports.js';
|
|
4
|
+
import noNestedTryPlugin from './plugins/no-nested-try.js';
|
|
4
5
|
import noNullishCheckFirstTernaryPlugin from './plugins/no-nullish-check-first-ternary.js';
|
|
5
|
-
import
|
|
6
|
+
import preferWhileTruePlugin from './plugins/prefer-while-true.js';
|
|
7
|
+
import requireMultilineArrowBracesPlugin from './plugins/require-multiline-arrow-braces.js';
|
|
8
|
+
import zodPlugin from './plugins/zod.js';
|
|
6
9
|
function pluginRules(namespace, ruleNames) {
|
|
7
10
|
return Object.fromEntries(ruleNames.map(ruleName => [`${namespace}/${ruleName}`, 'error']));
|
|
8
11
|
}
|
|
9
12
|
const antiSlopRules = pluginRules('anti-slop', Object.keys(antiSlopPlugin.rules));
|
|
10
13
|
const consistentInlineTypeImportsRules = pluginRules(consistentInlineTypeImportsPlugin.meta.name, Object.keys(consistentInlineTypeImportsPlugin.rules));
|
|
11
14
|
const noNullishCheckFirstTernaryRules = pluginRules(noNullishCheckFirstTernaryPlugin.meta.name, Object.keys(noNullishCheckFirstTernaryPlugin.rules));
|
|
12
|
-
const
|
|
15
|
+
const noNestedTryRules = pluginRules(noNestedTryPlugin.meta.name, Object.keys(noNestedTryPlugin.rules));
|
|
16
|
+
const zodRules = pluginRules(zodPlugin.meta.name, Object.keys(zodPlugin.rules));
|
|
17
|
+
const preferWhileTrueRules = pluginRules(preferWhileTruePlugin.meta.name, Object.keys(preferWhileTruePlugin.rules));
|
|
18
|
+
const requireMultilineArrowBracesRules = pluginRules(requireMultilineArrowBracesPlugin.meta.name, Object.keys(requireMultilineArrowBracesPlugin.rules));
|
|
13
19
|
export default defineConfig({
|
|
14
20
|
plugins: ['typescript', 'unicorn', 'oxc', 'vitest'],
|
|
15
21
|
jsPlugins: [
|
|
16
|
-
'@stylistic/eslint-plugin',
|
|
17
22
|
{
|
|
18
|
-
name:
|
|
19
|
-
specifier: '@kamaal111/kamaal-quality-config/plugins/
|
|
23
|
+
name: noNestedTryPlugin.meta.name,
|
|
24
|
+
specifier: '@kamaal111/kamaal-quality-config/plugins/no-nested-try',
|
|
20
25
|
},
|
|
21
|
-
{ name: '
|
|
22
|
-
{
|
|
26
|
+
{ name: '@stylistic', specifier: '@kamaal111/kamaal-quality-config/plugins/stylistic' },
|
|
27
|
+
{
|
|
28
|
+
name: requireMultilineArrowBracesPlugin.meta.name,
|
|
29
|
+
specifier: '@kamaal111/kamaal-quality-config/plugins/require-multiline-arrow-braces',
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
name: preferWhileTruePlugin.meta.name,
|
|
33
|
+
specifier: '@kamaal111/kamaal-quality-config/plugins/prefer-while-true',
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: zodPlugin.meta.name,
|
|
37
|
+
specifier: '@kamaal111/kamaal-quality-config/plugins/zod',
|
|
38
|
+
},
|
|
39
|
+
{ name: 'anti-slop', specifier: '@kamaal111/kamaal-quality-config/plugins/anti-slop' },
|
|
40
|
+
{ name: 'import-js', specifier: '@kamaal111/kamaal-quality-config/plugins/import' },
|
|
23
41
|
{
|
|
24
42
|
name: consistentInlineTypeImportsPlugin.meta.name,
|
|
25
43
|
specifier: '@kamaal111/kamaal-quality-config/plugins/consistent-inline-type-imports',
|
|
@@ -33,7 +51,10 @@ export default defineConfig({
|
|
|
33
51
|
categories: { correctness: 'error' },
|
|
34
52
|
rules: {
|
|
35
53
|
...antiSlopRules,
|
|
36
|
-
...
|
|
54
|
+
...noNestedTryRules,
|
|
55
|
+
...zodRules,
|
|
56
|
+
...preferWhileTrueRules,
|
|
57
|
+
...requireMultilineArrowBracesRules,
|
|
37
58
|
'@stylistic/lines-between-class-members': [
|
|
38
59
|
'error',
|
|
39
60
|
{
|
package/dist/oxlint.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oxlint.js","sourceRoot":"","sources":["../src/oxlint.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,oCAAoC,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC,OAAO,iCAAiC,MAAM,6CAA6C,CAAC;AAC5F,OAAO,gCAAgC,MAAM,6CAA6C,CAAC;AAC3F,OAAO,
|
|
1
|
+
{"version":3,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
6
6
|
"vitest"
|
|
7
7
|
],
|
|
8
8
|
"jsPlugins": [
|
|
9
|
-
|
|
9
|
+
{
|
|
10
|
+
"name": "kamaal-errors",
|
|
11
|
+
"specifier": "@kamaal111/kamaal-quality-config/plugins/no-nested-try"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"name": "@stylistic",
|
|
15
|
+
"specifier": "@kamaal111/kamaal-quality-config/plugins/stylistic"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"name": "kamaal-arrows",
|
|
19
|
+
"specifier": "@kamaal111/kamaal-quality-config/plugins/require-multiline-arrow-braces"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"name": "kamaal-loops",
|
|
23
|
+
"specifier": "@kamaal111/kamaal-quality-config/plugins/prefer-while-true"
|
|
24
|
+
},
|
|
10
25
|
{
|
|
11
26
|
"name": "kamaal-zod",
|
|
12
|
-
"specifier": "@kamaal111/kamaal-quality-config/plugins/
|
|
27
|
+
"specifier": "@kamaal111/kamaal-quality-config/plugins/zod"
|
|
13
28
|
},
|
|
14
29
|
{
|
|
15
30
|
"name": "anti-slop",
|
|
16
|
-
"specifier": "@kamaal111/
|
|
31
|
+
"specifier": "@kamaal111/kamaal-quality-config/plugins/anti-slop"
|
|
17
32
|
},
|
|
18
33
|
{
|
|
19
34
|
"name": "import-js",
|
|
20
|
-
"specifier": "
|
|
35
|
+
"specifier": "@kamaal111/kamaal-quality-config/plugins/import"
|
|
21
36
|
},
|
|
22
37
|
{
|
|
23
38
|
"name": "kamaal-imports",
|
|
@@ -58,7 +73,11 @@
|
|
|
58
73
|
"anti-slop/no-widen-then-assert": "error",
|
|
59
74
|
"anti-slop/require-readable-spacing": "error",
|
|
60
75
|
"anti-slop/require-safety-comment-for-type-assertion": "error",
|
|
76
|
+
"kamaal-errors/no-nested-try": "error",
|
|
77
|
+
"kamaal-zod/prefer-nonempty": "error",
|
|
61
78
|
"kamaal-zod/prefer-nullish": "error",
|
|
79
|
+
"kamaal-loops/prefer-while-true": "error",
|
|
80
|
+
"kamaal-arrows/require-multiline-arrow-braces": "error",
|
|
62
81
|
"@stylistic/lines-between-class-members": [
|
|
63
82
|
"error",
|
|
64
83
|
{
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anti-slop.d.ts","sourceRoot":"","sources":["../../src/plugins/anti-slop.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oCAAoC,CAAC;eAEzC,MAAM"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anti-slop.js","sourceRoot":"","sources":["../../src/plugins/anti-slop.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oCAAoC,CAAC;AAExD,eAAe,MAAM,CAAC"}
|
|
@@ -31,9 +31,11 @@ export default {
|
|
|
31
31
|
node,
|
|
32
32
|
message: 'Use a top-level `import type` instead of marking every named specifier with an inline `type` modifier.',
|
|
33
33
|
fix(fixer) {
|
|
34
|
-
const names = namedSpecifiers.map(specifier =>
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
const names = namedSpecifiers.map(specifier => {
|
|
35
|
+
return specifier.imported.name === specifier.local.name
|
|
36
|
+
? specifier.imported.name
|
|
37
|
+
: `${specifier.imported.name} as ${specifier.local.name}`;
|
|
38
|
+
});
|
|
37
39
|
const sourceText = context.sourceCode.getText(node.source);
|
|
38
40
|
return fixer.replaceText(node, `import type { ${names.join(', ')} } from ${sourceText};`);
|
|
39
41
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consistent-inline-type-imports.js","sourceRoot":"","sources":["../../src/plugins/consistent-inline-type-imports.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,2FAA2F;AAC3F,iEAAiE;AAkBjE,SAAS,iBAAiB,CAAC,SAAsD;IAC/E,OAAO,SAAS,CAAC,IAAI,KAAK,iBAAiB,CAAC;AAC9C,CAAC;AAED,eAAe;IACb,IAAI,EAAE,EAAE,IAAI,EAAE,gBAAgB,EAAE;IAChC,KAAK,EAAE;QACL,4BAA4B,EAAE;YAC5B,IAAI,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE;YACzB,MAAM,CAAC,OAAoB;gBACzB,OAAO;oBACL,iBAAiB,CAAC,IAA2B;wBAC3C,IAAI,IAAI,CAAC,UAAU,KAAK,MAAM,EAAE,CAAC;4BAC/B,OAAO;wBACT,CAAC;wBAED,MAAM,eAAe,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC;wBAElE,IAAI,eAAe,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;4BACjC,OAAO;wBACT,CAAC;wBAED,MAAM,qBAAqB,GAAG,eAAe,CAAC,MAAM,KAAK,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC;wBAEhF,IAAI,qBAAqB,EAAE,CAAC;4BAC1B,OAAO;wBACT,CAAC;wBAED,MAAM,aAAa,GAAG,eAAe,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,CAAC,SAAS,CAAC,UAAU,KAAK,MAAM,CAAC,CAAC;wBAE1F,IAAI,CAAC,aAAa,EAAE,CAAC;4BACnB,OAAO;wBACT,CAAC;wBAED,OAAO,CAAC,MAAM,CAAC;4BACb,IAAI;4BACJ,OAAO,EACL,wGAAwG;4BAC1G,GAAG,CAAC,KAAK;gCACP,MAAM,KAAK,GAAG,eAAe,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,
|
|
1
|
+
{"version":3,"file":"consistent-inline-type-imports.js","sourceRoot":"","sources":["../../src/plugins/consistent-inline-type-imports.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,2FAA2F;AAC3F,iEAAiE;AAkBjE,SAAS,iBAAiB,CAAC,SAAsD;IAC/E,OAAO,SAAS,CAAC,IAAI,KAAK,iBAAiB,CAAC;AAC9C,CAAC;AAED,eAAe;IACb,IAAI,EAAE,EAAE,IAAI,EAAE,gBAAgB,EAAE;IAChC,KAAK,EAAE;QACL,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AAK,CAAC,WAAW,CAAC,IAAI,EAAE,iBAAiB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,UAAU,GAAG,CAAC,CAAC;4BAC5F,CAAC;yBACF,CAAC,CAAC;oBACL,CAAC;iBACF,CAAC;YACJ,CAAC;SACF;KACF;CACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"import.d.ts","sourceRoot":"","sources":["../../src/plugins/import.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,sBAAsB,CAAC;eAE3B,MAAM"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"import.js","sourceRoot":"","sources":["../../src/plugins/import.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,sBAAsB,CAAC;AAE1C,eAAe,MAAM,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { AstNode, RuleContext } from './rule-context.ts';
|
|
2
|
+
declare const _default: {
|
|
3
|
+
meta: {
|
|
4
|
+
name: string;
|
|
5
|
+
};
|
|
6
|
+
rules: {
|
|
7
|
+
'no-nested-try': {
|
|
8
|
+
meta: {
|
|
9
|
+
type: string;
|
|
10
|
+
};
|
|
11
|
+
create(context: RuleContext): {
|
|
12
|
+
FunctionDeclaration: () => void;
|
|
13
|
+
'FunctionDeclaration:exit': () => void;
|
|
14
|
+
FunctionExpression: () => void;
|
|
15
|
+
'FunctionExpression:exit': () => void;
|
|
16
|
+
ArrowFunctionExpression: () => void;
|
|
17
|
+
'ArrowFunctionExpression:exit': () => void;
|
|
18
|
+
ClassBody: () => void;
|
|
19
|
+
'ClassBody:exit': () => void;
|
|
20
|
+
TryStatement(node: AstNode): void;
|
|
21
|
+
'TryStatement:exit'(): void;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
export default _default;
|
|
27
|
+
//# sourceMappingURL=no-nested-try.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-nested-try.d.ts","sourceRoot":"","sources":["../../src/plugins/no-nested-try.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;;IAQ5D,IAAI;QAAI,IAAI;;IACZ,KAAK;QACH,eAAe;YACb,IAAI;gBAAI,IAAI;;YACZ,MAAM,UAAU,WAAW;gBAcvB,mBAAmB;gBACnB,0BAA0B;gBAC1B,kBAAkB;gBAClB,yBAAyB;gBACzB,uBAAuB;gBACvB,8BAA8B;gBAC9B,SAAS;gBACT,gBAAgB;gBAChB,YAAY,OAAO,OAAO;gBAW1B,mBAAmB"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
meta: { name: 'kamaal-errors' },
|
|
3
|
+
rules: {
|
|
4
|
+
'no-nested-try': {
|
|
5
|
+
meta: { type: 'suggestion' },
|
|
6
|
+
create(context) {
|
|
7
|
+
let scope = { depth: 0 };
|
|
8
|
+
function enterScope() {
|
|
9
|
+
scope = { depth: 0, parent: scope };
|
|
10
|
+
}
|
|
11
|
+
function exitScope() {
|
|
12
|
+
if (scope.parent !== undefined) {
|
|
13
|
+
scope = scope.parent;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
FunctionDeclaration: enterScope,
|
|
18
|
+
'FunctionDeclaration:exit': exitScope,
|
|
19
|
+
FunctionExpression: enterScope,
|
|
20
|
+
'FunctionExpression:exit': exitScope,
|
|
21
|
+
ArrowFunctionExpression: enterScope,
|
|
22
|
+
'ArrowFunctionExpression:exit': exitScope,
|
|
23
|
+
ClassBody: enterScope,
|
|
24
|
+
'ClassBody:exit': exitScope,
|
|
25
|
+
TryStatement(node) {
|
|
26
|
+
if (scope.depth > 0) {
|
|
27
|
+
context.report({
|
|
28
|
+
node,
|
|
29
|
+
message: 'Avoid nested try statements. Extract error handling into a helper or use sequential try blocks.',
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
scope.depth++;
|
|
33
|
+
},
|
|
34
|
+
'TryStatement:exit'() {
|
|
35
|
+
scope.depth--;
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=no-nested-try.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-nested-try.js","sourceRoot":"","sources":["../../src/plugins/no-nested-try.ts"],"names":[],"mappings":"AAOA,eAAe;IACb,IAAI,EAAE,EAAE,IAAI,EAAE,eAAe,EAAE;IAC/B,KAAK,EAAE;QACL,eAAe,EAAE;YACf,IAAI,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE;YAC5B,MAAM,CAAC,OAAoB;gBACzB,IAAI,KAAK,GAAa,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;gBAEnC,SAAS,UAAU;oBACjB,KAAK,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;gBACtC,CAAC;gBAED,SAAS,SAAS;oBAChB,IAAI,KAAK,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;wBAC/B,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC;oBACvB,CAAC;gBACH,CAAC;gBAED,OAAO;oBACL,mBAAmB,EAAE,UAAU;oBAC/B,0BAA0B,EAAE,SAAS;oBACrC,kBAAkB,EAAE,UAAU;oBAC9B,yBAAyB,EAAE,SAAS;oBACpC,uBAAuB,EAAE,UAAU;oBACnC,8BAA8B,EAAE,SAAS;oBACzC,SAAS,EAAE,UAAU;oBACrB,gBAAgB,EAAE,SAAS;oBAC3B,YAAY,CAAC,IAAa;wBACxB,IAAI,KAAK,CAAC,KAAK,GAAG,CAAC,EAAE,CAAC;4BACpB,OAAO,CAAC,MAAM,CAAC;gCACb,IAAI;gCACJ,OAAO,EACL,iGAAiG;6BACpG,CAAC,CAAC;wBACL,CAAC;wBAED,KAAK,CAAC,KAAK,EAAE,CAAC;oBAChB,CAAC;oBACD,mBAAmB;wBACjB,KAAK,CAAC,KAAK,EAAE,CAAC;oBAChB,CAAC;iBACF,CAAC;YACJ,CAAC;SACF;KACF;CACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prefer-nonempty.d.ts","sourceRoot":"","sources":["../../src/plugins/prefer-nonempty.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAmB,IAAI,EAAS,MAAM,iBAAiB,CAAC;AA+HpE,QAAA,MAAM,cAAc,EAAE,IAoDrB,CAAC;eAEa,cAAc"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
const CHAIN_METHODS = {
|
|
2
|
+
string: new Set([
|
|
3
|
+
'trim',
|
|
4
|
+
'toLowerCase',
|
|
5
|
+
'toUpperCase',
|
|
6
|
+
'normalize',
|
|
7
|
+
'min',
|
|
8
|
+
'max',
|
|
9
|
+
'length',
|
|
10
|
+
'regex',
|
|
11
|
+
'includes',
|
|
12
|
+
'startsWith',
|
|
13
|
+
'endsWith',
|
|
14
|
+
'nonempty',
|
|
15
|
+
]),
|
|
16
|
+
array: new Set(['min', 'max', 'length', 'nonempty']),
|
|
17
|
+
set: new Set(['min', 'max', 'size', 'nonempty']),
|
|
18
|
+
};
|
|
19
|
+
function schemaKind(name) {
|
|
20
|
+
if (name === 'string' || name === 'array' || name === 'set') {
|
|
21
|
+
return name;
|
|
22
|
+
}
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
function importedName(node, context) {
|
|
26
|
+
let scope = context.sourceCode.getScope(node);
|
|
27
|
+
while (scope) {
|
|
28
|
+
const variable = scope.set.get(node.name);
|
|
29
|
+
if (variable) {
|
|
30
|
+
const definition = variable.defs[0];
|
|
31
|
+
if (!definition || definition.type !== 'ImportBinding') {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
const declaration = definition.parent;
|
|
35
|
+
const specifier = definition.node;
|
|
36
|
+
if (declaration?.type !== 'ImportDeclaration' ||
|
|
37
|
+
declaration.importKind === 'type' ||
|
|
38
|
+
(declaration.source.value !== 'zod' && declaration.source.value !== 'zod/v4')) {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
if (specifier.type === 'ImportDefaultSpecifier' || specifier.type === 'ImportNamespaceSpecifier') {
|
|
42
|
+
return 'z';
|
|
43
|
+
}
|
|
44
|
+
if (specifier.type === 'ImportSpecifier' && specifier.importKind !== 'type') {
|
|
45
|
+
return specifier.imported.type === 'Identifier' ? specifier.imported.name : specifier.imported.value;
|
|
46
|
+
}
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
scope = scope.upper;
|
|
50
|
+
}
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
function isNamedMember(node) {
|
|
54
|
+
return node.type === 'MemberExpression' && !node.computed && !node.optional && node.property.type === 'Identifier';
|
|
55
|
+
}
|
|
56
|
+
function isZodNamespace(node, context) {
|
|
57
|
+
return node.type === 'Identifier' && importedName(node, context) === 'z';
|
|
58
|
+
}
|
|
59
|
+
function inlineSchemaKind(node, context) {
|
|
60
|
+
if (node.type !== 'CallExpression' || node.optional) {
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
const callee = node.callee;
|
|
64
|
+
if (callee.type === 'Identifier') {
|
|
65
|
+
const name = importedName(callee, context);
|
|
66
|
+
return name !== undefined ? schemaKind(name) : undefined;
|
|
67
|
+
}
|
|
68
|
+
if (!isNamedMember(callee)) {
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
const name = callee.property.name;
|
|
72
|
+
if (isZodNamespace(callee.object, context)) {
|
|
73
|
+
return schemaKind(name);
|
|
74
|
+
}
|
|
75
|
+
if (name === 'string' &&
|
|
76
|
+
isNamedMember(callee.object) &&
|
|
77
|
+
callee.object.property.name === 'coerce' &&
|
|
78
|
+
isZodNamespace(callee.object.object, context)) {
|
|
79
|
+
return 'string';
|
|
80
|
+
}
|
|
81
|
+
const receiverKind = inlineSchemaKind(callee.object, context);
|
|
82
|
+
if (receiverKind === undefined) {
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
if (name === 'array') {
|
|
86
|
+
return 'array';
|
|
87
|
+
}
|
|
88
|
+
return CHAIN_METHODS[receiverKind].has(name) ? receiverKind : undefined;
|
|
89
|
+
}
|
|
90
|
+
const preferNonempty = {
|
|
91
|
+
meta: { type: 'suggestion', fixable: 'code', schema: [] },
|
|
92
|
+
create(context) {
|
|
93
|
+
return {
|
|
94
|
+
CallExpression(node) {
|
|
95
|
+
const member = node.callee;
|
|
96
|
+
const [bound, error] = node.arguments;
|
|
97
|
+
if (node.optional ||
|
|
98
|
+
!isNamedMember(member) ||
|
|
99
|
+
member.property.name !== 'min' ||
|
|
100
|
+
bound?.type !== 'Literal' ||
|
|
101
|
+
bound.value !== 1 ||
|
|
102
|
+
node.arguments.length > 2 ||
|
|
103
|
+
error?.type === 'SpreadElement' ||
|
|
104
|
+
inlineSchemaKind(member.object, context) === undefined) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
context.report({
|
|
108
|
+
node: member.property,
|
|
109
|
+
message: 'Use .nonempty() instead of .min(1).',
|
|
110
|
+
fix(fixer) {
|
|
111
|
+
const opening = context.sourceCode.getTokenAfter(member.property);
|
|
112
|
+
const closing = context.sourceCode.getLastToken(node);
|
|
113
|
+
if (!opening || !closing) {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
const tokens = context.sourceCode.getTokensBetween(opening, error ?? closing);
|
|
117
|
+
const commaIndex = tokens.findIndex(token => token.value === ',');
|
|
118
|
+
const removedTokens = error ? tokens.slice(0, commaIndex + 1) : tokens;
|
|
119
|
+
const lastRemoved = removedTokens.at(-1);
|
|
120
|
+
const next = lastRemoved ? context.sourceCode.getTokenAfter(lastRemoved) : closing;
|
|
121
|
+
if (!next) {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
const removals = context.sourceCode.commentsExistBetween(opening, next)
|
|
125
|
+
? removedTokens.map(token => fixer.remove(token))
|
|
126
|
+
: [fixer.removeRange([opening.range[1], next.range[0]])];
|
|
127
|
+
return [fixer.replaceText(member.property, 'nonempty'), ...removals];
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
export default preferNonempty;
|
|
135
|
+
//# sourceMappingURL=prefer-nonempty.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prefer-nonempty.js","sourceRoot":"","sources":["../../src/plugins/prefer-nonempty.ts"],"names":[],"mappings":"AAMA,MAAM,aAAa,GAA4C;IAC7D,MAAM,EAAE,IAAI,GAAG,CAAC;QACd,MAAM;QACN,aAAa;QACb,aAAa;QACb,WAAW;QACX,KAAK;QACL,KAAK;QACL,QAAQ;QACR,OAAO;QACP,UAAU;QACV,YAAY;QACZ,UAAU;QACV,UAAU;KACX,CAAC;IACF,KAAK,EAAE,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC;IACpD,GAAG,EAAE,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC;CACjD,CAAC;AAEF,SAAS,UAAU,CAAC,IAAY;IAC9B,IAAI,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,OAAO,IAAI,IAAI,KAAK,KAAK,EAAE,CAAC;QAC5D,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAS,YAAY,CAAC,IAAoB,EAAE,OAAgB;IAC1D,IAAI,KAAK,GAAiB,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAE5D,OAAO,KAAK,EAAE,CAAC;QACb,MAAM,QAAQ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