@rcrsr/rill 0.1.0 → 0.2.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 +16 -8
- package/dist/check/config.d.ts +20 -0
- package/dist/check/config.d.ts.map +1 -0
- package/dist/check/config.js +151 -0
- package/dist/check/config.js.map +1 -0
- package/dist/check/fixer.d.ts +39 -0
- package/dist/check/fixer.d.ts.map +1 -0
- package/dist/check/fixer.js +119 -0
- package/dist/check/fixer.js.map +1 -0
- package/dist/check/index.d.ts +10 -0
- package/dist/check/index.d.ts.map +1 -0
- package/dist/check/index.js +21 -0
- package/dist/check/index.js.map +1 -0
- package/dist/check/rules/anti-patterns.d.ts +65 -0
- package/dist/check/rules/anti-patterns.d.ts.map +1 -0
- package/dist/check/rules/anti-patterns.js +427 -0
- package/dist/check/rules/anti-patterns.js.map +1 -0
- package/dist/check/rules/closures.d.ts +66 -0
- package/dist/check/rules/closures.d.ts.map +1 -0
- package/dist/check/rules/closures.js +373 -0
- package/dist/check/rules/closures.js.map +1 -0
- package/dist/check/rules/collections.d.ts +90 -0
- package/dist/check/rules/collections.d.ts.map +1 -0
- package/dist/check/rules/collections.js +373 -0
- package/dist/check/rules/collections.js.map +1 -0
- package/dist/check/rules/conditionals.d.ts +41 -0
- package/dist/check/rules/conditionals.d.ts.map +1 -0
- package/dist/check/rules/conditionals.js +106 -0
- package/dist/check/rules/conditionals.js.map +1 -0
- package/dist/check/rules/flow.d.ts +46 -0
- package/dist/check/rules/flow.d.ts.map +1 -0
- package/dist/check/rules/flow.js +206 -0
- package/dist/check/rules/flow.js.map +1 -0
- package/dist/check/rules/formatting.d.ts +133 -0
- package/dist/check/rules/formatting.d.ts.map +1 -0
- package/dist/check/rules/formatting.js +639 -0
- package/dist/check/rules/formatting.js.map +1 -0
- package/dist/check/rules/helpers.d.ts +26 -0
- package/dist/check/rules/helpers.d.ts.map +1 -0
- package/dist/check/rules/helpers.js +66 -0
- package/dist/check/rules/helpers.js.map +1 -0
- package/dist/check/rules/index.d.ts +21 -0
- package/dist/check/rules/index.d.ts.map +1 -0
- package/dist/check/rules/index.js +78 -0
- package/dist/check/rules/index.js.map +1 -0
- package/dist/check/rules/loops.d.ts +70 -0
- package/dist/check/rules/loops.d.ts.map +1 -0
- package/dist/check/rules/loops.js +227 -0
- package/dist/check/rules/loops.js.map +1 -0
- package/dist/check/rules/naming.d.ts +21 -0
- package/dist/check/rules/naming.d.ts.map +1 -0
- package/dist/check/rules/naming.js +167 -0
- package/dist/check/rules/naming.js.map +1 -0
- package/dist/check/rules/strings.d.ts +28 -0
- package/dist/check/rules/strings.d.ts.map +1 -0
- package/dist/check/rules/strings.js +80 -0
- package/dist/check/rules/strings.js.map +1 -0
- package/dist/check/rules/types.d.ts +41 -0
- package/dist/check/rules/types.d.ts.map +1 -0
- package/dist/check/rules/types.js +162 -0
- package/dist/check/rules/types.js.map +1 -0
- package/dist/check/types.d.ts +106 -0
- package/dist/check/types.d.ts.map +1 -0
- package/dist/check/types.js +6 -0
- package/dist/check/types.js.map +1 -0
- package/dist/check/validator.d.ts +18 -0
- package/dist/check/validator.d.ts.map +1 -0
- package/dist/check/validator.js +88 -0
- package/dist/check/validator.js.map +1 -0
- package/dist/check/visitor.d.ts +33 -0
- package/dist/check/visitor.d.ts.map +1 -0
- package/dist/check/visitor.js +243 -0
- package/dist/check/visitor.js.map +1 -0
- package/dist/cli-check.d.ts +43 -0
- package/dist/cli-check.d.ts.map +1 -0
- package/dist/cli-check.js +356 -0
- package/dist/cli-check.js.map +1 -0
- package/dist/cli-eval.d.ts +15 -0
- package/dist/cli-eval.d.ts.map +1 -0
- package/dist/cli-eval.js +120 -0
- package/dist/cli-eval.js.map +1 -0
- package/dist/cli-exec.d.ts +49 -0
- package/dist/cli-exec.d.ts.map +1 -0
- package/dist/cli-exec.js +191 -0
- package/dist/cli-exec.js.map +1 -0
- package/dist/cli-module-loader.d.ts +19 -0
- package/dist/cli-module-loader.d.ts.map +1 -0
- package/dist/cli-module-loader.js +83 -0
- package/dist/cli-module-loader.js.map +1 -0
- package/dist/cli-shared.d.ts +36 -0
- package/dist/cli-shared.d.ts.map +1 -0
- package/dist/cli-shared.js +101 -0
- package/dist/cli-shared.js.map +1 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +4 -11
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lexer/readers.d.ts +1 -1
- package/dist/lexer/readers.d.ts.map +1 -1
- package/dist/lexer/readers.js +62 -32
- package/dist/lexer/readers.js.map +1 -1
- package/dist/lexer/tokenizer.d.ts.map +1 -1
- package/dist/lexer/tokenizer.js +5 -6
- package/dist/lexer/tokenizer.js.map +1 -1
- package/dist/parser/index.js +1 -1
- package/dist/parser/index.js.map +1 -1
- package/dist/parser/parser-expr.js +23 -5
- package/dist/parser/parser-expr.js.map +1 -1
- package/dist/parser/parser-functions.d.ts +2 -2
- package/dist/parser/parser-functions.d.ts.map +1 -1
- package/dist/parser/parser-functions.js +2 -1
- package/dist/parser/parser-functions.js.map +1 -1
- package/dist/parser/parser-literals.js +2 -2
- package/dist/parser/parser-literals.js.map +1 -1
- package/dist/parser/parser-script.js +9 -7
- package/dist/parser/parser-script.js.map +1 -1
- package/dist/parser/parser-variables.js +4 -3
- package/dist/parser/parser-variables.js.map +1 -1
- package/dist/runtime/core/callable.d.ts +5 -6
- package/dist/runtime/core/callable.d.ts.map +1 -1
- package/dist/runtime/core/callable.js.map +1 -1
- package/dist/runtime/core/context.d.ts.map +1 -1
- package/dist/runtime/core/context.js +19 -32
- package/dist/runtime/core/context.js.map +1 -1
- package/dist/runtime/core/equals.js +1 -1
- package/dist/runtime/core/equals.js.map +1 -1
- package/dist/runtime/core/eval/evaluator.d.ts +78 -0
- package/dist/runtime/core/eval/evaluator.d.ts.map +1 -1
- package/dist/runtime/core/eval/evaluator.js +78 -0
- package/dist/runtime/core/eval/evaluator.js.map +1 -1
- package/dist/runtime/core/eval/mixins/closures.d.ts.map +1 -1
- package/dist/runtime/core/eval/mixins/closures.js +9 -1
- package/dist/runtime/core/eval/mixins/closures.js.map +1 -1
- package/dist/runtime/core/eval/mixins/variables.d.ts.map +1 -1
- package/dist/runtime/core/eval/mixins/variables.js +143 -2
- package/dist/runtime/core/eval/mixins/variables.js.map +1 -1
- package/dist/runtime/core/types.d.ts +15 -2
- package/dist/runtime/core/types.d.ts.map +1 -1
- package/dist/runtime/core/types.js.map +1 -1
- package/dist/runtime/ext/extensions.d.ts +51 -0
- package/dist/runtime/ext/extensions.d.ts.map +1 -0
- package/dist/runtime/ext/extensions.js +67 -0
- package/dist/runtime/ext/extensions.js.map +1 -0
- package/dist/runtime/index.d.ts +3 -0
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +1 -0
- package/dist/runtime/index.js.map +1 -1
- package/dist/types.d.ts +8 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +5 -4
- package/dist/types.js.map +1 -1
- package/docs/00_INDEX.md +1 -0
- package/docs/01_guide.md +3 -3
- package/docs/02_types.md +8 -10
- package/docs/03_variables.md +10 -0
- package/docs/04_operators.md +3 -3
- package/docs/05_control-flow.md +21 -0
- package/docs/07_collections.md +2 -0
- package/docs/10_parsing.md +9 -9
- package/docs/11_reference.md +1 -1
- package/docs/12_examples.md +36 -62
- package/docs/14_host-integration.md +116 -111
- package/docs/15_grammar.ebnf +1 -5
- package/docs/16_conventions.md +3 -4
- package/docs/17_cli-tools.md +184 -0
- package/docs/99_llm-reference.txt +46 -5
- package/package.json +13 -4
- package/dist/demo.d.ts +0 -6
- package/dist/demo.d.ts.map +0 -1
- package/dist/demo.js +0 -121
- package/dist/demo.js.map +0 -1
- package/dist/lexer.d.ts +0 -19
- package/dist/lexer.d.ts.map +0 -1
- package/dist/lexer.js +0 -344
- package/dist/lexer.js.map +0 -1
- package/dist/parser/arithmetic.d.ts +0 -16
- package/dist/parser/arithmetic.d.ts.map +0 -1
- package/dist/parser/arithmetic.js +0 -128
- package/dist/parser/arithmetic.js.map +0 -1
- package/dist/parser/boolean.d.ts +0 -15
- package/dist/parser/boolean.d.ts.map +0 -1
- package/dist/parser/boolean.js +0 -20
- package/dist/parser/boolean.js.map +0 -1
- package/dist/parser/control-flow.d.ts +0 -56
- package/dist/parser/control-flow.d.ts.map +0 -1
- package/dist/parser/control-flow.js +0 -167
- package/dist/parser/control-flow.js.map +0 -1
- package/dist/parser/expressions.d.ts +0 -23
- package/dist/parser/expressions.d.ts.map +0 -1
- package/dist/parser/expressions.js +0 -950
- package/dist/parser/expressions.js.map +0 -1
- package/dist/parser/extraction.d.ts +0 -48
- package/dist/parser/extraction.d.ts.map +0 -1
- package/dist/parser/extraction.js +0 -279
- package/dist/parser/extraction.js.map +0 -1
- package/dist/parser/functions.d.ts +0 -20
- package/dist/parser/functions.d.ts.map +0 -1
- package/dist/parser/functions.js +0 -96
- package/dist/parser/functions.js.map +0 -1
- package/dist/parser/literals.d.ts +0 -37
- package/dist/parser/literals.d.ts.map +0 -1
- package/dist/parser/literals.js +0 -373
- package/dist/parser/literals.js.map +0 -1
- package/dist/parser/script.d.ts +0 -14
- package/dist/parser/script.d.ts.map +0 -1
- package/dist/parser/script.js +0 -196
- package/dist/parser/script.js.map +0 -1
- package/dist/parser/variables.d.ts +0 -10
- package/dist/parser/variables.d.ts.map +0 -1
- package/dist/parser/variables.js +0 -215
- package/dist/parser/variables.js.map +0 -1
- package/dist/runtime/ast-equals.d.ts +0 -13
- package/dist/runtime/ast-equals.d.ts.map +0 -1
- package/dist/runtime/ast-equals.js +0 -447
- package/dist/runtime/ast-equals.js.map +0 -1
- package/dist/runtime/builtins.d.ts +0 -13
- package/dist/runtime/builtins.d.ts.map +0 -1
- package/dist/runtime/builtins.js +0 -180
- package/dist/runtime/builtins.js.map +0 -1
- package/dist/runtime/callable.d.ts +0 -88
- package/dist/runtime/callable.d.ts.map +0 -1
- package/dist/runtime/callable.js +0 -98
- package/dist/runtime/callable.js.map +0 -1
- package/dist/runtime/context.d.ts +0 -13
- package/dist/runtime/context.d.ts.map +0 -1
- package/dist/runtime/context.js +0 -73
- package/dist/runtime/context.js.map +0 -1
- package/dist/runtime/core/evaluate.d.ts +0 -42
- package/dist/runtime/core/evaluate.d.ts.map +0 -1
- package/dist/runtime/core/evaluate.debug.js +0 -1251
- package/dist/runtime/core/evaluate.js +0 -1913
- package/dist/runtime/core/evaluate.js.map +0 -1
- package/dist/runtime/evaluate.d.ts +0 -32
- package/dist/runtime/evaluate.d.ts.map +0 -1
- package/dist/runtime/evaluate.js +0 -1111
- package/dist/runtime/evaluate.js.map +0 -1
- package/dist/runtime/execute.d.ts +0 -26
- package/dist/runtime/execute.d.ts.map +0 -1
- package/dist/runtime/execute.js +0 -121
- package/dist/runtime/execute.js.map +0 -1
- package/dist/runtime/signals.d.ts +0 -19
- package/dist/runtime/signals.d.ts.map +0 -1
- package/dist/runtime/signals.js +0 -26
- package/dist/runtime/signals.js.map +0 -1
- package/dist/runtime/types.d.ts +0 -169
- package/dist/runtime/types.d.ts.map +0 -1
- package/dist/runtime/types.js +0 -50
- package/dist/runtime/types.js.map +0 -1
- package/dist/runtime/values.d.ts +0 -50
- package/dist/runtime/values.d.ts.map +0 -1
- package/dist/runtime/values.js +0 -209
- package/dist/runtime/values.js.map +0 -1
- package/dist/runtime.d.ts +0 -254
- package/dist/runtime.d.ts.map +0 -1
- package/dist/runtime.js +0 -2014
- package/dist/runtime.js.map +0 -1
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared Helper Functions
|
|
3
|
+
* Common utilities used across validation rules.
|
|
4
|
+
*/
|
|
5
|
+
import type { ExpressionNode } from '../../types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Extract source line at location for context display.
|
|
8
|
+
* Splits source by newlines, retrieves the specified line (1-indexed), and trims it.
|
|
9
|
+
*/
|
|
10
|
+
export declare function extractContextLine(line: number, source: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* Detect if expression is a bare $ (pipe variable) reference.
|
|
13
|
+
* Used by IMPLICIT_DOLLAR_* rules to detect replaceable patterns.
|
|
14
|
+
*
|
|
15
|
+
* Returns true only for single bare $, not $var or $.field or $[0].
|
|
16
|
+
* O(1) depth traversal (max 3 node levels): PipeChain -> ArithHead -> PostfixExpr -> Variable.
|
|
17
|
+
*
|
|
18
|
+
* Distinct from containsBareReference() in closures.ts:
|
|
19
|
+
* - isBareReference(): O(1) single-node check, answers "is this exact node a bare $?"
|
|
20
|
+
* - containsBareReference(): Recursive AST walker, answers "does this subtree contain any bare $?"
|
|
21
|
+
*
|
|
22
|
+
* @param expr - Expression node to check
|
|
23
|
+
* @returns true if expr is a bare $ reference, false otherwise
|
|
24
|
+
*/
|
|
25
|
+
export declare function isBareReference(expr: ExpressionNode | null | undefined): boolean;
|
|
26
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/check/rules/helpers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACV,cAAc,EAIf,MAAM,gBAAgB,CAAC;AAExB;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAIvE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,cAAc,GAAG,IAAI,GAAG,SAAS,GACtC,OAAO,CAkDT"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared Helper Functions
|
|
3
|
+
* Common utilities used across validation rules.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Extract source line at location for context display.
|
|
7
|
+
* Splits source by newlines, retrieves the specified line (1-indexed), and trims it.
|
|
8
|
+
*/
|
|
9
|
+
export function extractContextLine(line, source) {
|
|
10
|
+
const lines = source.split('\n');
|
|
11
|
+
const sourceLine = lines[line - 1];
|
|
12
|
+
return sourceLine ? sourceLine.trim() : '';
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Detect if expression is a bare $ (pipe variable) reference.
|
|
16
|
+
* Used by IMPLICIT_DOLLAR_* rules to detect replaceable patterns.
|
|
17
|
+
*
|
|
18
|
+
* Returns true only for single bare $, not $var or $.field or $[0].
|
|
19
|
+
* O(1) depth traversal (max 3 node levels): PipeChain -> ArithHead -> PostfixExpr -> Variable.
|
|
20
|
+
*
|
|
21
|
+
* Distinct from containsBareReference() in closures.ts:
|
|
22
|
+
* - isBareReference(): O(1) single-node check, answers "is this exact node a bare $?"
|
|
23
|
+
* - containsBareReference(): Recursive AST walker, answers "does this subtree contain any bare $?"
|
|
24
|
+
*
|
|
25
|
+
* @param expr - Expression node to check
|
|
26
|
+
* @returns true if expr is a bare $ reference, false otherwise
|
|
27
|
+
*/
|
|
28
|
+
export function isBareReference(expr) {
|
|
29
|
+
// Defensive: handle null/undefined input
|
|
30
|
+
if (!expr) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
// Expression is PipeChain
|
|
34
|
+
if (expr.type !== 'PipeChain') {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
const pipeChain = expr;
|
|
38
|
+
// Must have no pipe targets (just the head)
|
|
39
|
+
if (pipeChain.pipes.length > 0 || pipeChain.terminator !== null) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
const head = pipeChain.head;
|
|
43
|
+
// ArithHead can be BinaryExpr, UnaryExpr, or PostfixExpr
|
|
44
|
+
// For bare $, we need PostfixExpr
|
|
45
|
+
if (head.type !== 'PostfixExpr') {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
const postfix = head;
|
|
49
|
+
// Must have no method calls (just the primary)
|
|
50
|
+
if (postfix.methods.length > 0) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
const primary = postfix.primary;
|
|
54
|
+
// Primary must be a Variable
|
|
55
|
+
if (primary.type !== 'Variable') {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
const variable = primary;
|
|
59
|
+
// Must be pipe variable ($) with no access chain, default value, or existence check
|
|
60
|
+
return (variable.isPipeVar &&
|
|
61
|
+
variable.name === null &&
|
|
62
|
+
variable.accessChain.length === 0 &&
|
|
63
|
+
variable.defaultValue === null &&
|
|
64
|
+
variable.existenceCheck === null);
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/check/rules/helpers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AASH;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAAY,EAAE,MAAc;IAC7D,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACjC,MAAM,UAAU,GAAG,KAAK,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC;IACnC,OAAO,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;AAC7C,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,eAAe,CAC7B,IAAuC;IAEvC,yCAAyC;IACzC,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,OAAO,KAAK,CAAC;IACf,CAAC;IAED,0BAA0B;IAC1B,IAAI,IAAI,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,SAAS,GAAG,IAAqB,CAAC;IAExC,4CAA4C;IAC5C,IAAI,SAAS,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,SAAS,CAAC,UAAU,KAAK,IAAI,EAAE,CAAC;QAChE,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC;IAE5B,yDAAyD;IACzD,kCAAkC;IAClC,IAAI,IAAI,CAAC,IAAI,KAAK,aAAa,EAAE,CAAC;QAChC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,OAAO,GAAG,IAAuB,CAAC;IAExC,+CAA+C;IAC/C,IAAI,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC/B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAEhC,6BAA6B;IAC7B,IAAI,OAAO,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;QAChC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,QAAQ,GAAG,OAAuB,CAAC;IAEzC,oFAAoF;IACpF,OAAO,CACL,QAAQ,CAAC,SAAS;QAClB,QAAQ,CAAC,IAAI,KAAK,IAAI;QACtB,QAAQ,CAAC,WAAW,CAAC,MAAM,KAAK,CAAC;QACjC,QAAQ,CAAC,YAAY,KAAK,IAAI;QAC9B,QAAQ,CAAC,cAAc,KAAK,IAAI,CACjC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validation Rules Registry
|
|
3
|
+
* Barrel export for all validation rules.
|
|
4
|
+
*/
|
|
5
|
+
import type { ValidationRule } from '../types.js';
|
|
6
|
+
export { NAMING_SNAKE_CASE } from './naming.js';
|
|
7
|
+
export { CAPTURE_INLINE_CHAIN, CAPTURE_BEFORE_BRANCH } from './flow.js';
|
|
8
|
+
export { BREAK_IN_PARALLEL, PREFER_MAP, FOLD_INTERMEDIATES, FILTER_NEGATION, METHOD_SHORTHAND, } from './collections.js';
|
|
9
|
+
export { LOOP_ACCUMULATOR, PREFER_DO_WHILE, USE_EACH } from './loops.js';
|
|
10
|
+
export { USE_DEFAULT_OPERATOR, CONDITION_TYPE } from './conditionals.js';
|
|
11
|
+
export { CLOSURE_BARE_DOLLAR, CLOSURE_BRACES, CLOSURE_LATE_BINDING, } from './closures.js';
|
|
12
|
+
export { UNNECESSARY_ASSERTION, VALIDATE_EXTERNAL } from './types.js';
|
|
13
|
+
export { USE_EMPTY_METHOD } from './strings.js';
|
|
14
|
+
export { AVOID_REASSIGNMENT, COMPLEX_CONDITION, LOOP_OUTER_CAPTURE, } from './anti-patterns.js';
|
|
15
|
+
export { SPACING_OPERATOR, SPACING_BRACES, SPACING_BRACKETS, SPACING_CLOSURE, INDENT_CONTINUATION, IMPLICIT_DOLLAR_METHOD, IMPLICIT_DOLLAR_FUNCTION, IMPLICIT_DOLLAR_CLOSURE, THROWAWAY_CAPTURE, } from './formatting.js';
|
|
16
|
+
/**
|
|
17
|
+
* All registered validation rules.
|
|
18
|
+
* Rules are applied during AST traversal via the validator.
|
|
19
|
+
*/
|
|
20
|
+
export declare const VALIDATION_RULES: ValidationRule[];
|
|
21
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/check/rules/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAwClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AACxE,OAAO,EACL,iBAAiB,EACjB,UAAU,EACV,kBAAkB,EAClB,eAAe,EACf,gBAAgB,GACjB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACzE,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,EACL,mBAAmB,EACnB,cAAc,EACd,oBAAoB,GACrB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACnB,sBAAsB,EACtB,wBAAwB,EACxB,uBAAuB,EACvB,iBAAiB,GAClB,MAAM,iBAAiB,CAAC;AAMzB;;;GAGG;AACH,eAAO,MAAM,gBAAgB,EAAE,cAAc,EAmD5C,CAAC"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validation Rules Registry
|
|
3
|
+
* Barrel export for all validation rules.
|
|
4
|
+
*/
|
|
5
|
+
import { NAMING_SNAKE_CASE } from './naming.js';
|
|
6
|
+
import { CAPTURE_INLINE_CHAIN, CAPTURE_BEFORE_BRANCH } from './flow.js';
|
|
7
|
+
import { BREAK_IN_PARALLEL, PREFER_MAP, FOLD_INTERMEDIATES, FILTER_NEGATION, METHOD_SHORTHAND, } from './collections.js';
|
|
8
|
+
import { LOOP_ACCUMULATOR, PREFER_DO_WHILE, USE_EACH } from './loops.js';
|
|
9
|
+
import { USE_DEFAULT_OPERATOR, CONDITION_TYPE } from './conditionals.js';
|
|
10
|
+
import { CLOSURE_BARE_DOLLAR, CLOSURE_BRACES, CLOSURE_LATE_BINDING, } from './closures.js';
|
|
11
|
+
import { UNNECESSARY_ASSERTION, VALIDATE_EXTERNAL } from './types.js';
|
|
12
|
+
import { USE_EMPTY_METHOD } from './strings.js';
|
|
13
|
+
import { AVOID_REASSIGNMENT, COMPLEX_CONDITION, LOOP_OUTER_CAPTURE, } from './anti-patterns.js';
|
|
14
|
+
import { SPACING_OPERATOR, SPACING_BRACES, SPACING_BRACKETS, SPACING_CLOSURE, INDENT_CONTINUATION, IMPLICIT_DOLLAR_METHOD, IMPLICIT_DOLLAR_FUNCTION, IMPLICIT_DOLLAR_CLOSURE, THROWAWAY_CAPTURE, } from './formatting.js';
|
|
15
|
+
// ============================================================
|
|
16
|
+
// RE-EXPORT INDIVIDUAL RULES
|
|
17
|
+
// ============================================================
|
|
18
|
+
export { NAMING_SNAKE_CASE } from './naming.js';
|
|
19
|
+
export { CAPTURE_INLINE_CHAIN, CAPTURE_BEFORE_BRANCH } from './flow.js';
|
|
20
|
+
export { BREAK_IN_PARALLEL, PREFER_MAP, FOLD_INTERMEDIATES, FILTER_NEGATION, METHOD_SHORTHAND, } from './collections.js';
|
|
21
|
+
export { LOOP_ACCUMULATOR, PREFER_DO_WHILE, USE_EACH } from './loops.js';
|
|
22
|
+
export { USE_DEFAULT_OPERATOR, CONDITION_TYPE } from './conditionals.js';
|
|
23
|
+
export { CLOSURE_BARE_DOLLAR, CLOSURE_BRACES, CLOSURE_LATE_BINDING, } from './closures.js';
|
|
24
|
+
export { UNNECESSARY_ASSERTION, VALIDATE_EXTERNAL } from './types.js';
|
|
25
|
+
export { USE_EMPTY_METHOD } from './strings.js';
|
|
26
|
+
export { AVOID_REASSIGNMENT, COMPLEX_CONDITION, LOOP_OUTER_CAPTURE, } from './anti-patterns.js';
|
|
27
|
+
export { SPACING_OPERATOR, SPACING_BRACES, SPACING_BRACKETS, SPACING_CLOSURE, INDENT_CONTINUATION, IMPLICIT_DOLLAR_METHOD, IMPLICIT_DOLLAR_FUNCTION, IMPLICIT_DOLLAR_CLOSURE, THROWAWAY_CAPTURE, } from './formatting.js';
|
|
28
|
+
// ============================================================
|
|
29
|
+
// RULE REGISTRY
|
|
30
|
+
// ============================================================
|
|
31
|
+
/**
|
|
32
|
+
* All registered validation rules.
|
|
33
|
+
* Rules are applied during AST traversal via the validator.
|
|
34
|
+
*/
|
|
35
|
+
export const VALIDATION_RULES = [
|
|
36
|
+
// Naming conventions
|
|
37
|
+
NAMING_SNAKE_CASE,
|
|
38
|
+
// Flow and capture
|
|
39
|
+
CAPTURE_INLINE_CHAIN,
|
|
40
|
+
CAPTURE_BEFORE_BRANCH,
|
|
41
|
+
// Collection operators
|
|
42
|
+
BREAK_IN_PARALLEL,
|
|
43
|
+
PREFER_MAP,
|
|
44
|
+
FOLD_INTERMEDIATES,
|
|
45
|
+
FILTER_NEGATION,
|
|
46
|
+
METHOD_SHORTHAND,
|
|
47
|
+
// Loop conventions
|
|
48
|
+
LOOP_ACCUMULATOR,
|
|
49
|
+
PREFER_DO_WHILE,
|
|
50
|
+
USE_EACH,
|
|
51
|
+
// Conditional conventions
|
|
52
|
+
USE_DEFAULT_OPERATOR,
|
|
53
|
+
CONDITION_TYPE,
|
|
54
|
+
// Closure conventions
|
|
55
|
+
CLOSURE_BARE_DOLLAR,
|
|
56
|
+
CLOSURE_BRACES,
|
|
57
|
+
CLOSURE_LATE_BINDING,
|
|
58
|
+
// Type safety
|
|
59
|
+
UNNECESSARY_ASSERTION,
|
|
60
|
+
VALIDATE_EXTERNAL,
|
|
61
|
+
// String handling
|
|
62
|
+
USE_EMPTY_METHOD,
|
|
63
|
+
// Anti-patterns
|
|
64
|
+
AVOID_REASSIGNMENT,
|
|
65
|
+
COMPLEX_CONDITION,
|
|
66
|
+
LOOP_OUTER_CAPTURE,
|
|
67
|
+
// Formatting
|
|
68
|
+
SPACING_OPERATOR,
|
|
69
|
+
SPACING_BRACES,
|
|
70
|
+
SPACING_BRACKETS,
|
|
71
|
+
SPACING_CLOSURE,
|
|
72
|
+
INDENT_CONTINUATION,
|
|
73
|
+
IMPLICIT_DOLLAR_METHOD,
|
|
74
|
+
IMPLICIT_DOLLAR_FUNCTION,
|
|
75
|
+
IMPLICIT_DOLLAR_CLOSURE,
|
|
76
|
+
THROWAWAY_CAPTURE,
|
|
77
|
+
];
|
|
78
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sour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do-while, and loop control flow.
|
|
4
|
+
*/
|
|
5
|
+
import type { ValidationRule } from '../types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Validates that $ is used as accumulator in while/do-while loops.
|
|
8
|
+
*
|
|
9
|
+
* In while and do-while loops, $ serves as the accumulator across iterations.
|
|
10
|
+
* Variables captured inside the loop body exist only within that iteration.
|
|
11
|
+
*
|
|
12
|
+
* Good pattern ($ accumulates):
|
|
13
|
+
* 0 -> ($ < 5) @ { $ + 1 }
|
|
14
|
+
*
|
|
15
|
+
* Avoid pattern (named variables don't persist):
|
|
16
|
+
* 0 -> ($ < 5) @ {
|
|
17
|
+
* $ :> $x # $x exists only in this iteration
|
|
18
|
+
* $x + 1
|
|
19
|
+
* }
|
|
20
|
+
*
|
|
21
|
+
* This is stylistic - both work, but $ is clearer for accumulation.
|
|
22
|
+
*
|
|
23
|
+
* References:
|
|
24
|
+
* - docs/16_conventions.md:151-171
|
|
25
|
+
*/
|
|
26
|
+
export declare const LOOP_ACCUMULATOR: ValidationRule;
|
|
27
|
+
/**
|
|
28
|
+
* Suggests using do-while for retry patterns.
|
|
29
|
+
*
|
|
30
|
+
* Do-while is clearer for retry patterns where the body must run at least once:
|
|
31
|
+
*
|
|
32
|
+
* Good (do-while for retry):
|
|
33
|
+
* @ {
|
|
34
|
+
* attemptOperation()
|
|
35
|
+
* } ? (.contains("RETRY"))
|
|
36
|
+
*
|
|
37
|
+
* Less clear (while with separate first attempt):
|
|
38
|
+
* attemptOperation() :> $result
|
|
39
|
+
* $result -> .contains("RETRY") @ {
|
|
40
|
+
* attemptOperation()
|
|
41
|
+
* }
|
|
42
|
+
*
|
|
43
|
+
* This is informational - helps guide users to the clearer pattern.
|
|
44
|
+
*
|
|
45
|
+
* References:
|
|
46
|
+
* - docs/16_conventions.md:173-186
|
|
47
|
+
*/
|
|
48
|
+
export declare const PREFER_DO_WHILE: ValidationRule;
|
|
49
|
+
/**
|
|
50
|
+
* Suggests using each for collection iteration instead of while loops.
|
|
51
|
+
*
|
|
52
|
+
* When iterating over a collection, each is clearer and more idiomatic:
|
|
53
|
+
*
|
|
54
|
+
* Good (each for collection):
|
|
55
|
+
* $items -> each { process($) }
|
|
56
|
+
*
|
|
57
|
+
* Less clear (while loop):
|
|
58
|
+
* 0 :> $i
|
|
59
|
+
* ($i < $items.len) @ {
|
|
60
|
+
* $items[$i] -> process()
|
|
61
|
+
* $i + 1
|
|
62
|
+
* }
|
|
63
|
+
*
|
|
64
|
+
* This is informational - while loops work, but each is clearer for collections.
|
|
65
|
+
*
|
|
66
|
+
* References:
|
|
67
|
+
* - docs/16_conventions.md:188-196
|
|
68
|
+
*/
|
|
69
|
+
export declare const USE_EACH: ValidationRule;
|
|
70
|
+
//# sourceMappingURL=loops.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loops.d.ts","sourceRoot":"","sources":["../../../src/check/rules/loops.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACV,cAAc,EAGf,MAAM,aAAa,CAAC;AAmGrB;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,gBAAgB,EAAE,cA0B9B,CAAC;AAMF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,eAAe,EAAE,cA2B7B,CAAC;AAMF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,QAAQ,EAAE,cAmCtB,CAAC"}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Loop Convention Rules
|
|
3
|
+
* Enforces conventions for while, do-while, and loop control flow.
|
|
4
|
+
*/
|
|
5
|
+
import { extractContextLine } from './helpers.js';
|
|
6
|
+
// ============================================================
|
|
7
|
+
// HELPER FUNCTIONS
|
|
8
|
+
// ============================================================
|
|
9
|
+
/**
|
|
10
|
+
* Check if a loop body contains variable captures.
|
|
11
|
+
* Returns true if any captures are found in the body.
|
|
12
|
+
*/
|
|
13
|
+
function containsCaptures(node) {
|
|
14
|
+
switch (node.type) {
|
|
15
|
+
case 'Capture':
|
|
16
|
+
return true;
|
|
17
|
+
case 'Block':
|
|
18
|
+
return node.statements.some((stmt) => containsCaptures(stmt));
|
|
19
|
+
case 'Statement':
|
|
20
|
+
return containsCaptures(node.expression);
|
|
21
|
+
case 'AnnotatedStatement':
|
|
22
|
+
return containsCaptures(node.statement);
|
|
23
|
+
case 'PipeChain':
|
|
24
|
+
if (node.pipes.some((pipe) => containsCaptures(pipe)))
|
|
25
|
+
return true;
|
|
26
|
+
if (node.terminator && node.terminator.type === 'Capture')
|
|
27
|
+
return true;
|
|
28
|
+
return false;
|
|
29
|
+
case 'PostfixExpr':
|
|
30
|
+
if (containsCaptures(node.primary))
|
|
31
|
+
return true;
|
|
32
|
+
return node.methods.some((method) => containsCaptures(method));
|
|
33
|
+
case 'BinaryExpr':
|
|
34
|
+
return containsCaptures(node.left) || containsCaptures(node.right);
|
|
35
|
+
case 'UnaryExpr':
|
|
36
|
+
return containsCaptures(node.operand);
|
|
37
|
+
case 'GroupedExpr':
|
|
38
|
+
return containsCaptures(node.expression);
|
|
39
|
+
case 'Conditional':
|
|
40
|
+
if (node.input && containsCaptures(node.input))
|
|
41
|
+
return true;
|
|
42
|
+
if (node.condition && containsCaptures(node.condition))
|
|
43
|
+
return true;
|
|
44
|
+
if (containsCaptures(node.thenBranch))
|
|
45
|
+
return true;
|
|
46
|
+
if (node.elseBranch && containsCaptures(node.elseBranch))
|
|
47
|
+
return true;
|
|
48
|
+
return false;
|
|
49
|
+
case 'WhileLoop':
|
|
50
|
+
case 'DoWhileLoop':
|
|
51
|
+
return containsCaptures(node.body);
|
|
52
|
+
default:
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Check if a loop body appears to be calling a retry function.
|
|
58
|
+
* Simple heuristic: looks for function calls like attemptOperation() or retry().
|
|
59
|
+
*/
|
|
60
|
+
function callsRetryFunction(node) {
|
|
61
|
+
if (node.type === 'Block') {
|
|
62
|
+
return node.statements.some((stmt) => callsRetryFunction(stmt));
|
|
63
|
+
}
|
|
64
|
+
if (node.type === 'Statement') {
|
|
65
|
+
return callsRetryFunction(node.expression);
|
|
66
|
+
}
|
|
67
|
+
if (node.type === 'PipeChain') {
|
|
68
|
+
const chain = node;
|
|
69
|
+
const head = chain.head;
|
|
70
|
+
// Check if head is a function call
|
|
71
|
+
if (head.type === 'PostfixExpr') {
|
|
72
|
+
const primary = head.primary;
|
|
73
|
+
if (primary.type === 'HostCall' || primary.type === 'ClosureCall') {
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
// ============================================================
|
|
81
|
+
// LOOP_ACCUMULATOR RULE
|
|
82
|
+
// ============================================================
|
|
83
|
+
/**
|
|
84
|
+
* Validates that $ is used as accumulator in while/do-while loops.
|
|
85
|
+
*
|
|
86
|
+
* In while and do-while loops, $ serves as the accumulator across iterations.
|
|
87
|
+
* Variables captured inside the loop body exist only within that iteration.
|
|
88
|
+
*
|
|
89
|
+
* Good pattern ($ accumulates):
|
|
90
|
+
* 0 -> ($ < 5) @ { $ + 1 }
|
|
91
|
+
*
|
|
92
|
+
* Avoid pattern (named variables don't persist):
|
|
93
|
+
* 0 -> ($ < 5) @ {
|
|
94
|
+
* $ :> $x # $x exists only in this iteration
|
|
95
|
+
* $x + 1
|
|
96
|
+
* }
|
|
97
|
+
*
|
|
98
|
+
* This is stylistic - both work, but $ is clearer for accumulation.
|
|
99
|
+
*
|
|
100
|
+
* References:
|
|
101
|
+
* - docs/16_conventions.md:151-171
|
|
102
|
+
*/
|
|
103
|
+
export const LOOP_ACCUMULATOR = {
|
|
104
|
+
code: 'LOOP_ACCUMULATOR',
|
|
105
|
+
category: 'loops',
|
|
106
|
+
severity: 'info',
|
|
107
|
+
nodeTypes: ['WhileLoop', 'DoWhileLoop'],
|
|
108
|
+
validate(node, context) {
|
|
109
|
+
const loop = node;
|
|
110
|
+
// Check if loop body contains captures
|
|
111
|
+
if (containsCaptures(loop.body)) {
|
|
112
|
+
return [
|
|
113
|
+
{
|
|
114
|
+
location: node.span.start,
|
|
115
|
+
severity: 'info',
|
|
116
|
+
code: 'LOOP_ACCUMULATOR',
|
|
117
|
+
message: 'Use $ as accumulator in while/do-while. Variables captured inside loop body exist only within that iteration.',
|
|
118
|
+
context: extractContextLine(node.span.start.line, context.source),
|
|
119
|
+
fix: null, // Complex fix - requires refactoring loop body
|
|
120
|
+
},
|
|
121
|
+
];
|
|
122
|
+
}
|
|
123
|
+
return [];
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
// ============================================================
|
|
127
|
+
// PREFER_DO_WHILE RULE
|
|
128
|
+
// ============================================================
|
|
129
|
+
/**
|
|
130
|
+
* Suggests using do-while for retry patterns.
|
|
131
|
+
*
|
|
132
|
+
* Do-while is clearer for retry patterns where the body must run at least once:
|
|
133
|
+
*
|
|
134
|
+
* Good (do-while for retry):
|
|
135
|
+
* @ {
|
|
136
|
+
* attemptOperation()
|
|
137
|
+
* } ? (.contains("RETRY"))
|
|
138
|
+
*
|
|
139
|
+
* Less clear (while with separate first attempt):
|
|
140
|
+
* attemptOperation() :> $result
|
|
141
|
+
* $result -> .contains("RETRY") @ {
|
|
142
|
+
* attemptOperation()
|
|
143
|
+
* }
|
|
144
|
+
*
|
|
145
|
+
* This is informational - helps guide users to the clearer pattern.
|
|
146
|
+
*
|
|
147
|
+
* References:
|
|
148
|
+
* - docs/16_conventions.md:173-186
|
|
149
|
+
*/
|
|
150
|
+
export const PREFER_DO_WHILE = {
|
|
151
|
+
code: 'PREFER_DO_WHILE',
|
|
152
|
+
category: 'loops',
|
|
153
|
+
severity: 'info',
|
|
154
|
+
nodeTypes: ['WhileLoop'],
|
|
155
|
+
validate(node, context) {
|
|
156
|
+
const loop = node;
|
|
157
|
+
// Heuristic: if loop body appears to be calling a retry/attempt function,
|
|
158
|
+
// suggest do-while
|
|
159
|
+
if (callsRetryFunction(loop.body)) {
|
|
160
|
+
return [
|
|
161
|
+
{
|
|
162
|
+
location: node.span.start,
|
|
163
|
+
severity: 'info',
|
|
164
|
+
code: 'PREFER_DO_WHILE',
|
|
165
|
+
message: 'Consider do-while for retry patterns where body runs at least once: @ { body } ? (condition)',
|
|
166
|
+
context: extractContextLine(node.span.start.line, context.source),
|
|
167
|
+
fix: null, // Complex fix - requires restructuring to do-while
|
|
168
|
+
},
|
|
169
|
+
];
|
|
170
|
+
}
|
|
171
|
+
return [];
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
// ============================================================
|
|
175
|
+
// USE_EACH RULE
|
|
176
|
+
// ============================================================
|
|
177
|
+
/**
|
|
178
|
+
* Suggests using each for collection iteration instead of while loops.
|
|
179
|
+
*
|
|
180
|
+
* When iterating over a collection, each is clearer and more idiomatic:
|
|
181
|
+
*
|
|
182
|
+
* Good (each for collection):
|
|
183
|
+
* $items -> each { process($) }
|
|
184
|
+
*
|
|
185
|
+
* Less clear (while loop):
|
|
186
|
+
* 0 :> $i
|
|
187
|
+
* ($i < $items.len) @ {
|
|
188
|
+
* $items[$i] -> process()
|
|
189
|
+
* $i + 1
|
|
190
|
+
* }
|
|
191
|
+
*
|
|
192
|
+
* This is informational - while loops work, but each is clearer for collections.
|
|
193
|
+
*
|
|
194
|
+
* References:
|
|
195
|
+
* - docs/16_conventions.md:188-196
|
|
196
|
+
*/
|
|
197
|
+
export const USE_EACH = {
|
|
198
|
+
code: 'USE_EACH',
|
|
199
|
+
category: 'loops',
|
|
200
|
+
severity: 'info',
|
|
201
|
+
nodeTypes: ['WhileLoop'],
|
|
202
|
+
validate(node, context) {
|
|
203
|
+
const loop = node;
|
|
204
|
+
// Simple heuristic: if the condition or body appears to be doing array iteration
|
|
205
|
+
const conditionStr = JSON.stringify(loop.condition);
|
|
206
|
+
const bodyStr = JSON.stringify(loop.body);
|
|
207
|
+
// Look for patterns like:
|
|
208
|
+
// - field access to 'len' (array length checks)
|
|
209
|
+
// - bracket access patterns with BracketAccess nodes in body
|
|
210
|
+
const hasLenCheck = conditionStr.includes('"field":"len"');
|
|
211
|
+
const hasBracketAccess = bodyStr.includes('"accessKind":"bracket"');
|
|
212
|
+
if (hasLenCheck || hasBracketAccess) {
|
|
213
|
+
return [
|
|
214
|
+
{
|
|
215
|
+
location: node.span.start,
|
|
216
|
+
severity: 'info',
|
|
217
|
+
code: 'USE_EACH',
|
|
218
|
+
message: "Use 'each' for collection iteration instead of while loops: collection -> each { body }",
|
|
219
|
+
context: extractContextLine(node.span.start.line, context.source),
|
|
220
|
+
fix: null, // Complex fix - requires restructuring to each
|
|
221
|
+
},
|
|
222
|
+
];
|
|
223
|
+
}
|
|
224
|
+
return [];
|
|
225
|
+
},
|
|
226
|
+
};
|
|
227
|
+
//# sourceMappingURL=loops.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loops.js","sourceRoot":"","sources":["../../../src/check/rules/loops.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAaH,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAElD,+DAA+D;AAC/D,mBAAmB;AACnB,+DAA+D;AAE/D;;;GAGG;AACH,SAAS,gBAAgB,CAAC,IAAa;IACrC,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;QAClB,KAAK,SAAS;YACZ,OAAO,IAAI,CAAC;QAEd,KAAK,OAAO;YACV,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC;QAEhE,KAAK,WAAW;YACd,OAAO,gBAAgB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAE3C,KAAK,oBAAoB;YACvB,OAAO,gBAAgB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAE1C,KAAK,WAAW;YACd,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAA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MAAM,QAAQ,GAAmB;IACtC,IAAI,EAAE,UAAU;IAChB,QAAQ,EAAE,OAAO;IACjB,QAAQ,EAAE,MAAM;IAChB,SAAS,EAAE,CAAC,WAAW,CAAC;IAExB,QAAQ,CAAC,IAAa,EAAE,OAA0B;QAChD,MAAM,IAAI,GAAG,IAAqB,CAAC;QAEnC,iFAAiF;QACjF,MAAM,YAAY,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACpD,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAE1C,0BAA0B;QAC1B,gDAAgD;QAChD,6DAA6D;QAC7D,MAAM,WAAW,GAAG,YAAY,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC;QAC3D,MAAM,gBAAgB,GAAG,OAAO,CAAC,QAAQ,CAAC,wBAAwB,CAAC,CAAC;QAEpE,IAAI,WAAW,IAAI,gBAAgB,EAAE,CAAC;YACpC,OAAO;gBACL;oBACE,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAC,KAAK;oBACzB,QAAQ,EAAE,MAAM;oBAChB,IAAI,EAAE,UAAU;oBAChB,OAAO,EACL,yFAAyF;oBAC3F,OAAO,EAAE,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC;oBACjE,GAAG,EAAE,IAAI,EAAE,+CAA+C;iBAC3D;aACF,CAAC;QACJ,CAAC;QAED,OAAO,EAAE,CAAC;IACZ,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Naming Convention Rules
|
|
3
|
+
* Enforces snake_case naming for variables, parameters, and dict keys.
|
|
4
|
+
*/
|
|
5
|
+
import type { ValidationRule } from '../types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Validates that variable definitions, parameters, and dict keys use snake_case.
|
|
8
|
+
*
|
|
9
|
+
* Checks definition sites only (not variable usage):
|
|
10
|
+
* - Captures: :> $user_name, :> $item_list, :> $is_valid
|
|
11
|
+
* - Closure params: |user_name, count| { }
|
|
12
|
+
* - Dict keys: [user_name: "Alice", is_active: true]
|
|
13
|
+
*
|
|
14
|
+
* Exceptions:
|
|
15
|
+
* - Single-letter names are valid (common for loop variables)
|
|
16
|
+
*
|
|
17
|
+
* References:
|
|
18
|
+
* - docs/16_conventions.md:10-53
|
|
19
|
+
*/
|
|
20
|
+
export declare const NAMING_SNAKE_CASE: ValidationRule;
|
|
21
|
+
//# sourceMappingURL=naming.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"naming.d.ts","sourceRoot":"","sources":["../../../src/check/rules/naming.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACV,cAAc,EAKf,MAAM,aAAa,CAAC;AAsFrB;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,iBAAiB,EAAE,cA0H/B,CAAC"}
|