@kamaal111/kamaal-quality-config 0.9.0 → 0.11.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 +20 -4
- package/dist/oxlint.d.ts.map +1 -1
- package/dist/oxlint.js +16 -2
- package/dist/oxlint.js.map +1 -1
- package/dist/oxlintrc.json +12 -2
- package/dist/plugins/no-middle-spread.d.ts +22 -0
- package/dist/plugins/no-middle-spread.d.ts.map +1 -0
- package/dist/plugins/no-middle-spread.js +36 -0
- package/dist/plugins/no-middle-spread.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/package.json +3 -1
- package/swift/SwiftLintChecks/Sources/SwiftLintChecks/LintViolation.swift +3 -0
- package/swift/SwiftLintChecks/Sources/SwiftLintChecks/NoNestedDoCatchVisitor.swift +29 -0
- package/swift/SwiftLintChecks/Sources/SwiftLintChecks/SwiftLint.swift +3 -1
- package/swift/SwiftLintChecks/Tests/SwiftLintChecksTests/NoNestedDoCatchTests.swift +138 -0
- package/swift/SwiftLintChecks/Tests/SwiftLintChecksTests/SingleTryPerDoCatchTests.swift +3 -7
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ 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 eight 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'`.
|
|
@@ -24,6 +24,17 @@ rules from oxlint's built-in `typescript`, `unicorn`, `oxc`, and `vitest` plugin
|
|
|
24
24
|
- `kamaal-loops/prefer-while-true` — requires `while (true)` instead of `for (;;)` when all three
|
|
25
25
|
header parts are empty. Autofix replaces comment-free headers; headers containing comments are
|
|
26
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
|
+
- `kamaal-objects/no-middle-spread` — rejects object spreads between explicit properties.
|
|
33
|
+
Spread groups may appear at either end of the same object. The rule reports each middle spread
|
|
34
|
+
and leaves property order intact when running with `--fix`.
|
|
35
|
+
|
|
36
|
+
The error-handling plugin is exported at
|
|
37
|
+
`@kamaal111/kamaal-quality-config/plugins/no-nested-try`.
|
|
27
38
|
|
|
28
39
|
The Zod plugin is exported at `@kamaal111/kamaal-quality-config/plugins/zod`.
|
|
29
40
|
|
|
@@ -199,15 +210,20 @@ Without paths, the command checks the current directory recursively. Explicit fi
|
|
|
199
210
|
paths are relative to your working directory. Recursive scanning skips hidden paths (including
|
|
200
211
|
`.build`), `node_modules`, symlinks, and non-Swift files. Use `--` before paths starting with a dash.
|
|
201
212
|
|
|
202
|
-
All
|
|
213
|
+
All five checks are enabled:
|
|
203
214
|
|
|
204
215
|
- `member_spacing`: separate methods and initializers from adjacent members with a blank line.
|
|
205
216
|
- `multiline_chain_spacing`: put each chained call on its own line in multiline expressions.
|
|
206
217
|
- `view_body_declarations`: move local `let` and `var` declarations out of SwiftUI
|
|
207
218
|
`var body: some View`, including nested builder closures. Conditional bindings remain allowed.
|
|
219
|
+
- `no_nested_do_catch`: reject a `do/catch` nested anywhere in another `do/catch`,
|
|
220
|
+
including its catch clauses. Plain `do` blocks do not count, but do not hide nesting.
|
|
221
|
+
Functions, closures, initializers, accessors, and nested types start independent scopes;
|
|
222
|
+
their own handlers are still checked. Use sequential handlers or extract a helper.
|
|
208
223
|
- `single_try_per_do_catch`: allow at most one plain `try` expression per `do/catch` body.
|
|
209
|
-
Count across branches and loops; `try?` and `try!` do not count.
|
|
210
|
-
|
|
224
|
+
Count across branches and loops; `try?` and `try!` do not count. Each `do/catch` body
|
|
225
|
+
is counted independently, while catchless `do` blocks contribute to the enclosing count.
|
|
226
|
+
Nesting handlers is rejected separately by `no_nested_do_catch`.
|
|
211
227
|
Closures, local functions, and nested types have separate scopes; their own `do/catch` blocks
|
|
212
228
|
are still checked. A `try` in a nested catch contributes to an enclosing handler, if present.
|
|
213
229
|
All conditional-compilation branches count, including inactive branches.
|
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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gBAqKuB,KAAK;gBAAS,eAAe"}
|
package/dist/oxlint.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
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 noMiddleSpreadPlugin from './plugins/no-middle-spread.js';
|
|
5
|
+
import noNestedTryPlugin from './plugins/no-nested-try.js';
|
|
4
6
|
import noNullishCheckFirstTernaryPlugin from './plugins/no-nullish-check-first-ternary.js';
|
|
5
7
|
import preferWhileTruePlugin from './plugins/prefer-while-true.js';
|
|
6
8
|
import requireMultilineArrowBracesPlugin from './plugins/require-multiline-arrow-braces.js';
|
|
@@ -11,12 +13,22 @@ function pluginRules(namespace, ruleNames) {
|
|
|
11
13
|
const antiSlopRules = pluginRules('anti-slop', Object.keys(antiSlopPlugin.rules));
|
|
12
14
|
const consistentInlineTypeImportsRules = pluginRules(consistentInlineTypeImportsPlugin.meta.name, Object.keys(consistentInlineTypeImportsPlugin.rules));
|
|
13
15
|
const noNullishCheckFirstTernaryRules = pluginRules(noNullishCheckFirstTernaryPlugin.meta.name, Object.keys(noNullishCheckFirstTernaryPlugin.rules));
|
|
16
|
+
const noMiddleSpreadRules = pluginRules(noMiddleSpreadPlugin.meta.name, Object.keys(noMiddleSpreadPlugin.rules));
|
|
17
|
+
const noNestedTryRules = pluginRules(noNestedTryPlugin.meta.name, Object.keys(noNestedTryPlugin.rules));
|
|
14
18
|
const zodRules = pluginRules(zodPlugin.meta.name, Object.keys(zodPlugin.rules));
|
|
15
19
|
const preferWhileTrueRules = pluginRules(preferWhileTruePlugin.meta.name, Object.keys(preferWhileTruePlugin.rules));
|
|
16
20
|
const requireMultilineArrowBracesRules = pluginRules(requireMultilineArrowBracesPlugin.meta.name, Object.keys(requireMultilineArrowBracesPlugin.rules));
|
|
17
21
|
export default defineConfig({
|
|
18
22
|
plugins: ['typescript', 'unicorn', 'oxc', 'vitest'],
|
|
19
23
|
jsPlugins: [
|
|
24
|
+
{
|
|
25
|
+
name: noMiddleSpreadPlugin.meta.name,
|
|
26
|
+
specifier: '@kamaal111/kamaal-quality-config/plugins/no-middle-spread',
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
name: noNestedTryPlugin.meta.name,
|
|
30
|
+
specifier: '@kamaal111/kamaal-quality-config/plugins/no-nested-try',
|
|
31
|
+
},
|
|
20
32
|
{ name: '@stylistic', specifier: '@kamaal111/kamaal-quality-config/plugins/stylistic' },
|
|
21
33
|
{
|
|
22
34
|
name: requireMultilineArrowBracesPlugin.meta.name,
|
|
@@ -45,9 +57,13 @@ export default defineConfig({
|
|
|
45
57
|
categories: { correctness: 'error' },
|
|
46
58
|
rules: {
|
|
47
59
|
...antiSlopRules,
|
|
60
|
+
...noNestedTryRules,
|
|
48
61
|
...zodRules,
|
|
49
62
|
...preferWhileTrueRules,
|
|
50
63
|
...requireMultilineArrowBracesRules,
|
|
64
|
+
...consistentInlineTypeImportsRules,
|
|
65
|
+
...noNullishCheckFirstTernaryRules,
|
|
66
|
+
...noMiddleSpreadRules,
|
|
51
67
|
'@stylistic/lines-between-class-members': [
|
|
52
68
|
'error',
|
|
53
69
|
{
|
|
@@ -77,8 +93,6 @@ export default defineConfig({
|
|
|
77
93
|
message: 'Use explicit typed assignments or object spread instead of Object.assign.',
|
|
78
94
|
},
|
|
79
95
|
],
|
|
80
|
-
...consistentInlineTypeImportsRules,
|
|
81
|
-
...noNullishCheckFirstTernaryRules,
|
|
82
96
|
curly: 'error',
|
|
83
97
|
'typescript/no-deprecated': 'error',
|
|
84
98
|
'typescript/consistent-type-imports': 'error',
|
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,qBAAqB,MAAM,gCAAgC,CAAC;AACn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C,EAAE,OAAO;QAC5C,mBAAmB,EAAE,OAAO;QAC5B,iBAAiB,EAAE;YACjB,OAAO;YACP;gBACE,MAAM,EAAE,CAAC,SAAS,EAAE,UAAU,EAAE,CAAC,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;gBAC3E,kBAAkB,EAAE,QAAQ;gBAC5B,WAAW,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,eAAe,EAAE,IAAI,EAAE;aACrD;SACF;KACF;IACD,GAAG,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE;CACvB,CAAC,CAAC"}
|
package/dist/oxlintrc.json
CHANGED
|
@@ -6,6 +6,14 @@
|
|
|
6
6
|
"vitest"
|
|
7
7
|
],
|
|
8
8
|
"jsPlugins": [
|
|
9
|
+
{
|
|
10
|
+
"name": "kamaal-objects",
|
|
11
|
+
"specifier": "@kamaal111/kamaal-quality-config/plugins/no-middle-spread"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"name": "kamaal-errors",
|
|
15
|
+
"specifier": "@kamaal111/kamaal-quality-config/plugins/no-nested-try"
|
|
16
|
+
},
|
|
9
17
|
{
|
|
10
18
|
"name": "@stylistic",
|
|
11
19
|
"specifier": "@kamaal111/kamaal-quality-config/plugins/stylistic"
|
|
@@ -69,10 +77,14 @@
|
|
|
69
77
|
"anti-slop/no-widen-then-assert": "error",
|
|
70
78
|
"anti-slop/require-readable-spacing": "error",
|
|
71
79
|
"anti-slop/require-safety-comment-for-type-assertion": "error",
|
|
80
|
+
"kamaal-errors/no-nested-try": "error",
|
|
72
81
|
"kamaal-zod/prefer-nonempty": "error",
|
|
73
82
|
"kamaal-zod/prefer-nullish": "error",
|
|
74
83
|
"kamaal-loops/prefer-while-true": "error",
|
|
75
84
|
"kamaal-arrows/require-multiline-arrow-braces": "error",
|
|
85
|
+
"kamaal-imports/no-all-inline-type-imports": "error",
|
|
86
|
+
"kamaal-ternary/no-nullish-check-first-ternary": "error",
|
|
87
|
+
"kamaal-objects/no-middle-spread": "error",
|
|
76
88
|
"@stylistic/lines-between-class-members": [
|
|
77
89
|
"error",
|
|
78
90
|
{
|
|
@@ -112,8 +124,6 @@
|
|
|
112
124
|
"message": "Use explicit typed assignments or object spread instead of Object.assign."
|
|
113
125
|
}
|
|
114
126
|
],
|
|
115
|
-
"kamaal-imports/no-all-inline-type-imports": "error",
|
|
116
|
-
"kamaal-ternary/no-nullish-check-first-ternary": "error",
|
|
117
127
|
"curly": "error",
|
|
118
128
|
"typescript/no-deprecated": "error",
|
|
119
129
|
"typescript/consistent-type-imports": "error",
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { AstNode, RuleContext } from './rule-context.ts';
|
|
2
|
+
interface ObjectExpressionNode extends AstNode {
|
|
3
|
+
type: 'ObjectExpression';
|
|
4
|
+
readonly properties: readonly AstNode[];
|
|
5
|
+
}
|
|
6
|
+
declare const _default: {
|
|
7
|
+
meta: {
|
|
8
|
+
name: string;
|
|
9
|
+
};
|
|
10
|
+
rules: {
|
|
11
|
+
'no-middle-spread': {
|
|
12
|
+
meta: {
|
|
13
|
+
type: string;
|
|
14
|
+
};
|
|
15
|
+
create(context: RuleContext): {
|
|
16
|
+
ObjectExpression(node: ObjectExpressionNode): void;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
export default _default;
|
|
22
|
+
//# sourceMappingURL=no-middle-spread.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-middle-spread.d.ts","sourceRoot":"","sources":["../../src/plugins/no-middle-spread.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAE9D,UAAU,oBAAqB,SAAQ,OAAO;IAC5C,IAAI,EAAE,kBAAkB,CAAC;IACzB,QAAQ,CAAC,UAAU,EAAE,SAAS,OAAO,EAAE,CAAC;CACzC;;IAGC,IAAI;QAAI,IAAI;;IACZ,KAAK;QACH,kBAAkB;YAChB,IAAI;gBAAI,IAAI;;YACZ,MAAM,UAAU,WAAW;gBAEvB,gBAAgB,OAAO,oBAAoB"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
meta: { name: 'kamaal-objects' },
|
|
3
|
+
rules: {
|
|
4
|
+
'no-middle-spread': {
|
|
5
|
+
meta: { type: 'suggestion' },
|
|
6
|
+
create(context) {
|
|
7
|
+
return {
|
|
8
|
+
ObjectExpression(node) {
|
|
9
|
+
let lastPropertyIndex = -1;
|
|
10
|
+
for (const [index, property] of node.properties.entries()) {
|
|
11
|
+
if (property.type === 'Property') {
|
|
12
|
+
lastPropertyIndex = index;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
let hasPrecedingProperty = false;
|
|
16
|
+
for (const [index, property] of node.properties.entries()) {
|
|
17
|
+
if (index >= lastPropertyIndex) {
|
|
18
|
+
break;
|
|
19
|
+
}
|
|
20
|
+
if (property.type === 'Property') {
|
|
21
|
+
hasPrecedingProperty = true;
|
|
22
|
+
}
|
|
23
|
+
else if (hasPrecedingProperty && property.type === 'SpreadElement') {
|
|
24
|
+
context.report({
|
|
25
|
+
node: property,
|
|
26
|
+
message: 'Keep object spreads at the beginning or end of the object literal.',
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=no-middle-spread.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-middle-spread.js","sourceRoot":"","sources":["../../src/plugins/no-middle-spread.ts"],"names":[],"mappings":"AAOA,eAAe;IACb,IAAI,EAAE,EAAE,IAAI,EAAE,gBAAgB,EAAE;IAChC,KAAK,EAAE;QACL,kBAAkB,EAAE;YAClB,IAAI,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE;YAC5B,MAAM,CAAC,OAAoB;gBACzB,OAAO;oBACL,gBAAgB,CAAC,IAA0B;wBACzC,IAAI,iBAAiB,GAAG,CAAC,CAAC,CAAC;wBAE3B,KAAK,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC;4BAC1D,IAAI,QAAQ,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;gCACjC,iBAAiB,GAAG,KAAK,CAAC;4BAC5B,CAAC;wBACH,CAAC;wBAED,IAAI,oBAAoB,GAAG,KAAK,CAAC;wBAEjC,KAAK,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC;4BAC1D,IAAI,KAAK,IAAI,iBAAiB,EAAE,CAAC;gCAC/B,MAAM;4BACR,CAAC;4BAED,IAAI,QAAQ,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;gCACjC,oBAAoB,GAAG,IAAI,CAAC;4BAC9B,CAAC;iCAAM,IAAI,oBAAoB,IAAI,QAAQ,CAAC,IAAI,KAAK,eAAe,EAAE,CAAC;gCACrE,OAAO,CAAC,MAAM,CAAC;oCACb,IAAI,EAAE,QAAQ;oCACd,OAAO,EAAE,oEAAoE;iCAC9E,CAAC,CAAC;4BACL,CAAC;wBACH,CAAC;oBACH,CAAC;iBACF,CAAC;YACJ,CAAC;SACF;KACF;CACF,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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kamaal111/kamaal-quality-config",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "Kamaal Farah's shared quality configurations.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lint",
|
|
@@ -44,6 +44,8 @@
|
|
|
44
44
|
"./plugins/consistent-inline-type-imports": "./dist/plugins/consistent-inline-type-imports.js",
|
|
45
45
|
"./plugins/no-nullish-check-first-ternary": "./dist/plugins/no-nullish-check-first-ternary.js",
|
|
46
46
|
"./plugins/zod": "./dist/plugins/zod.js",
|
|
47
|
+
"./plugins/no-middle-spread": "./dist/plugins/no-middle-spread.js",
|
|
48
|
+
"./plugins/no-nested-try": "./dist/plugins/no-nested-try.js",
|
|
47
49
|
"./plugins/prefer-while-true": "./dist/plugins/prefer-while-true.js",
|
|
48
50
|
"./swift-format": {
|
|
49
51
|
"types": "./dist/swift-format.d.ts",
|
|
@@ -8,6 +8,7 @@ struct LintViolation {
|
|
|
8
8
|
enum LintRule: String {
|
|
9
9
|
case memberSpacing = "member_spacing"
|
|
10
10
|
case multilineChainSpacing = "multiline_chain_spacing"
|
|
11
|
+
case noNestedDoCatch = "no_nested_do_catch"
|
|
11
12
|
case singleTryPerDoCatch = "single_try_per_do_catch"
|
|
12
13
|
case viewBodyDeclarations = "view_body_declarations"
|
|
13
14
|
|
|
@@ -17,6 +18,8 @@ enum LintRule: String {
|
|
|
17
18
|
"Separate initializers and methods from adjacent members with a blank line."
|
|
18
19
|
case .multilineChainSpacing:
|
|
19
20
|
"Place each chained call on its own line in a multiline expression."
|
|
21
|
+
case .noNestedDoCatch:
|
|
22
|
+
"Avoid nested do/catch statements. Extract error handling into a helper or use sequential do/catch blocks."
|
|
20
23
|
case .singleTryPerDoCatch:
|
|
21
24
|
"""
|
|
22
25
|
Keep at most one plain try expression in each do/catch body. \
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import SwiftSyntax
|
|
2
|
+
|
|
3
|
+
final class NoNestedDoCatchVisitor: SyntaxVisitor {
|
|
4
|
+
private(set) var violations: [LintViolation] = []
|
|
5
|
+
|
|
6
|
+
override func visit(_ node: DoStmtSyntax) -> SyntaxVisitorContinueKind {
|
|
7
|
+
guard !node.catchClauses.isEmpty else { return .visitChildren }
|
|
8
|
+
var ancestor = node.parent
|
|
9
|
+
while let current = ancestor {
|
|
10
|
+
if current.is(ClosureExprSyntax.self) || current.is(FunctionDeclSyntax.self)
|
|
11
|
+
|| current.is(InitializerDeclSyntax.self) || current.is(DeinitializerDeclSyntax.self)
|
|
12
|
+
|| current.is(MemberBlockSyntax.self) || current.is(AccessorBlockSyntax.self)
|
|
13
|
+
{
|
|
14
|
+
return .visitChildren
|
|
15
|
+
}
|
|
16
|
+
if let statement = current.as(DoStmtSyntax.self), !statement.catchClauses.isEmpty {
|
|
17
|
+
violations.append(
|
|
18
|
+
LintViolation(
|
|
19
|
+
position: node.doKeyword.positionAfterSkippingLeadingTrivia,
|
|
20
|
+
rule: .noNestedDoCatch
|
|
21
|
+
)
|
|
22
|
+
)
|
|
23
|
+
return .visitChildren
|
|
24
|
+
}
|
|
25
|
+
ancestor = current.parent
|
|
26
|
+
}
|
|
27
|
+
return .visitChildren
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -16,7 +16,9 @@ enum SwiftLint {
|
|
|
16
16
|
bodies.walk(tree)
|
|
17
17
|
let tries = SingleTryPerDoCatchVisitor(viewMode: .sourceAccurate)
|
|
18
18
|
tries.walk(tree)
|
|
19
|
-
|
|
19
|
+
let handlers = NoNestedDoCatchVisitor(viewMode: .sourceAccurate)
|
|
20
|
+
handlers.walk(tree)
|
|
21
|
+
return (visitor.violations + chains.violations + bodies.violations + tries.violations + handlers.violations)
|
|
20
22
|
.sorted { $0.position < $1.position }
|
|
21
23
|
.map { violation in
|
|
22
24
|
let location = converter.location(for: violation.position)
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import Testing
|
|
2
|
+
|
|
3
|
+
@testable import SwiftLintChecks
|
|
4
|
+
|
|
5
|
+
struct NoNestedDoCatchTests {
|
|
6
|
+
private static let message =
|
|
7
|
+
"Avoid nested do/catch statements. Extract error handling into a helper or use sequential do/catch blocks."
|
|
8
|
+
|
|
9
|
+
@Test(arguments: [
|
|
10
|
+
"do { do { try load() } catch { report(error) } } catch { report(error) }",
|
|
11
|
+
"do { try load() } catch { do { try recover() } catch { report(error) } }",
|
|
12
|
+
"do { if ready { do { try load() } catch {} } } catch {}",
|
|
13
|
+
"do { for item in items { do { try load(item) } catch {} } } catch {}",
|
|
14
|
+
"do { do { do { try load() } catch {} } } catch {}",
|
|
15
|
+
"""
|
|
16
|
+
do {
|
|
17
|
+
#if os(macOS)
|
|
18
|
+
do { try load() } catch {}
|
|
19
|
+
#else
|
|
20
|
+
load()
|
|
21
|
+
#endif
|
|
22
|
+
} catch {}
|
|
23
|
+
""",
|
|
24
|
+
"""
|
|
25
|
+
do {
|
|
26
|
+
#if os(macOS)
|
|
27
|
+
load()
|
|
28
|
+
#else
|
|
29
|
+
do { try load() } catch {}
|
|
30
|
+
#endif
|
|
31
|
+
} catch {}
|
|
32
|
+
""",
|
|
33
|
+
])
|
|
34
|
+
func `Rejects nesting across handler regions and control flow`(source: String) {
|
|
35
|
+
let diagnostics = SwiftLint.diagnostics(source: source, path: "Example.swift")
|
|
36
|
+
#expect(diagnostics.count == 1)
|
|
37
|
+
#expect(diagnostics.first?.hasSuffix("\(Self.message) [no_nested_do_catch]") == true)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@Test
|
|
41
|
+
func `Reports every nested handler once at its do keyword`() {
|
|
42
|
+
let source = """
|
|
43
|
+
do {
|
|
44
|
+
do {
|
|
45
|
+
do { try load() } catch {}
|
|
46
|
+
} catch {}
|
|
47
|
+
} catch {}
|
|
48
|
+
"""
|
|
49
|
+
#expect(
|
|
50
|
+
SwiftLint.diagnostics(source: source, path: "Example.swift") == [
|
|
51
|
+
"Example.swift:2:5: error: \(Self.message) [no_nested_do_catch]",
|
|
52
|
+
"Example.swift:3:9: error: \(Self.message) [no_nested_do_catch]",
|
|
53
|
+
]
|
|
54
|
+
)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@Test(arguments: [
|
|
58
|
+
"do { try load() } catch { report(error) }",
|
|
59
|
+
"do { try load() } catch {}\ndo { try save() } catch {}",
|
|
60
|
+
"do { do { try load() } catch {} }",
|
|
61
|
+
"do { do { try load() } } catch {}",
|
|
62
|
+
"do { func work() { do { try load() } catch {} } } catch {}",
|
|
63
|
+
"do { let work = { do { try load() } catch {} } } catch {}",
|
|
64
|
+
"do { var value: Int { do { return try load() } catch { return 0 } } } catch {}",
|
|
65
|
+
"do { struct Worker { func work() { do { try load() } catch {} } } } catch {}",
|
|
66
|
+
"do { struct Worker { init() { do { try load() } catch {} } } } catch {}",
|
|
67
|
+
"do { class Worker { deinit { do { try load() } catch {} } } } catch {}",
|
|
68
|
+
"do { struct Worker { var value: Int { do { return try load() } catch { return 0 } } } } catch {}",
|
|
69
|
+
"do { let text = \"do { do {} catch {} } catch {}\"; /* do {} catch {} */ try load() } catch {}",
|
|
70
|
+
])
|
|
71
|
+
func `Accepts independent handlers and execution scopes`(source: String) {
|
|
72
|
+
#expect(SwiftLint.diagnostics(source: source, path: "Example.swift").isEmpty)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
@Test(arguments: [
|
|
76
|
+
"do { func work() { do { do { try load() } catch {} } catch {} } } catch {}",
|
|
77
|
+
"do { let work = { do { do { try load() } catch {} } catch {} } } catch {}",
|
|
78
|
+
"do { var value: Int { do { do { return try load() } catch {} } catch {} } } catch {}",
|
|
79
|
+
"do { struct Worker { init() { do { do { try load() } catch {} } catch {} } } } catch {}",
|
|
80
|
+
"do { struct Worker { var value: Int { do { do { return try load() } catch {} } catch {} } } } catch {}",
|
|
81
|
+
])
|
|
82
|
+
func `Still checks handlers within independent scopes`(source: String) {
|
|
83
|
+
let diagnostics = SwiftLint.diagnostics(source: source, path: "Example.swift")
|
|
84
|
+
#expect(diagnostics.count == 1)
|
|
85
|
+
#expect(diagnostics.first?.hasSuffix("[no_nested_do_catch]") == true)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
@Test
|
|
89
|
+
func `Restores the outer scope after a local function`() {
|
|
90
|
+
let source = """
|
|
91
|
+
do {
|
|
92
|
+
func work() { do { try load() } catch {} }
|
|
93
|
+
do { try save() } catch {}
|
|
94
|
+
} catch {}
|
|
95
|
+
"""
|
|
96
|
+
#expect(
|
|
97
|
+
SwiftLint.diagnostics(source: source, path: "Example.swift") == [
|
|
98
|
+
"Example.swift:3:5: error: \(Self.message) [no_nested_do_catch]"
|
|
99
|
+
]
|
|
100
|
+
)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
@Test
|
|
104
|
+
func `Preserves source order alongside single try diagnostics`() {
|
|
105
|
+
let source = """
|
|
106
|
+
do {
|
|
107
|
+
do {
|
|
108
|
+
try load()
|
|
109
|
+
try save()
|
|
110
|
+
} catch {}
|
|
111
|
+
} catch {}
|
|
112
|
+
"""
|
|
113
|
+
let diagnostics = SwiftLint.diagnostics(source: source, path: "Example.swift")
|
|
114
|
+
#expect(diagnostics.count == 2)
|
|
115
|
+
#expect(diagnostics[0] == "Example.swift:2:5: error: \(Self.message) [no_nested_do_catch]")
|
|
116
|
+
#expect(diagnostics[1].hasPrefix("Example.swift:4:9: error:"))
|
|
117
|
+
#expect(diagnostics[1].hasSuffix("[single_try_per_do_catch]"))
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
@Test
|
|
121
|
+
func `Reports keyword positions with Windows line endings`() {
|
|
122
|
+
let source = "do {\r\n do { try load() } catch {}\r\n} catch {}"
|
|
123
|
+
#expect(
|
|
124
|
+
SwiftLint.diagnostics(source: source, path: "Example.swift") == [
|
|
125
|
+
"Example.swift:2:5: error: \(Self.message) [no_nested_do_catch]"
|
|
126
|
+
]
|
|
127
|
+
)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
@Test
|
|
131
|
+
func `Preserves invalid syntax errors`() {
|
|
132
|
+
#expect(
|
|
133
|
+
SwiftLint.diagnostics(source: "do { do {", path: "Broken.swift") == [
|
|
134
|
+
"Broken.swift:1:1: error: Cannot lint Swift source because Swift syntax is invalid."
|
|
135
|
+
]
|
|
136
|
+
)
|
|
137
|
+
}
|
|
138
|
+
}
|
|
@@ -42,12 +42,6 @@ struct SingleTryPerDoCatchTests {
|
|
|
42
42
|
"do { try load(); try save() }",
|
|
43
43
|
"do { try load() } catch { try save(); try refresh() }",
|
|
44
44
|
"""
|
|
45
|
-
do {
|
|
46
|
-
try load()
|
|
47
|
-
do { try save() } catch { reportSave(error) }
|
|
48
|
-
} catch { reportLoad(error) }
|
|
49
|
-
""",
|
|
50
|
-
"""
|
|
51
45
|
do { try load() } catch { reportLoad(error); return }
|
|
52
46
|
do { try save() } catch { reportSave(error) }
|
|
53
47
|
""",
|
|
@@ -175,6 +169,7 @@ struct SingleTryPerDoCatchTests {
|
|
|
175
169
|
"""
|
|
176
170
|
#expect(
|
|
177
171
|
SwiftLint.diagnostics(source: source, path: "Example.swift") == [
|
|
172
|
+
"Example.swift:3:5: error: Avoid nested do/catch statements. Extract error handling into a helper or use sequential do/catch blocks. [no_nested_do_catch]",
|
|
178
173
|
"Example.swift:5:9: error: \(Self.message) [single_try_per_do_catch]",
|
|
179
174
|
"Example.swift:9:5: error: \(Self.message) [single_try_per_do_catch]",
|
|
180
175
|
]
|
|
@@ -197,7 +192,8 @@ struct SingleTryPerDoCatchTests {
|
|
|
197
192
|
"""
|
|
198
193
|
#expect(
|
|
199
194
|
SwiftLint.diagnostics(source: source, path: "Example.swift") == [
|
|
200
|
-
"Example.swift:
|
|
195
|
+
"Example.swift:3:5: error: Avoid nested do/catch statements. Extract error handling into a helper or use sequential do/catch blocks. [no_nested_do_catch]",
|
|
196
|
+
"Example.swift:6:9: error: \(Self.message) [single_try_per_do_catch]",
|
|
201
197
|
]
|
|
202
198
|
)
|
|
203
199
|
}
|