@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
package/README.md
CHANGED
|
@@ -14,17 +14,19 @@ rill enables platform builders to make their apps scriptable without exposing ar
|
|
|
14
14
|
rill solves for AI platforms what Lua solves for game engines and Liquid solves for e-commerce: safe, user-authored logic.
|
|
15
15
|
|
|
16
16
|
- **Embeddable.** Zero dependencies. Runs in browser or backend. [Integration](docs/14_host-integration.md) only requires a few lines of code.
|
|
17
|
-
- **Sandboxed.**
|
|
17
|
+
- **Sandboxed.** No filesystem, no network, no `eval()`. Host controls all side effects via function bindings.
|
|
18
18
|
- **Bounded execution.** Retry limits prevent exhausting LLM usage limits because of runaway loops.
|
|
19
19
|
- **Consistent, clean syntax.** Ships with [EBNF grammar](docs/15_grammar.ebnf). LLMs can write rill scripts for your users.
|
|
20
|
-
- **Built-in LLM output parsing.** [Auto-detect](docs/10_parsing.md) JSON, XML, YAML, checklists.
|
|
20
|
+
- **Built-in LLM output parsing.** [Auto-detect](docs/10_parsing.md) and parse JSON, XML, YAML, checklists.
|
|
21
21
|
|
|
22
22
|
## Who is this for?
|
|
23
23
|
|
|
24
|
-
**Platform builders** who want power users to define custom
|
|
24
|
+
**Application and Platform builders** who want to enable their power users to define custom automation workflows and logic.
|
|
25
25
|
|
|
26
26
|
rill is not a general-purpose language and it's intentionally constrained. For general application development, you'll want TypeScript, Python, or Go.
|
|
27
27
|
|
|
28
|
+
rill powers [Claude Code Runner](https://github.com/rcrsr/claude-code-runner), a rich automation tool for Claude Code.
|
|
29
|
+
|
|
28
30
|
## Quick Start
|
|
29
31
|
|
|
30
32
|
```typescript
|
|
@@ -37,8 +39,14 @@ const script = `
|
|
|
37
39
|
|
|
38
40
|
const ctx = createRuntimeContext({
|
|
39
41
|
functions: {
|
|
40
|
-
prompt:
|
|
41
|
-
|
|
42
|
+
prompt: {
|
|
43
|
+
params: [{ name: 'message', type: 'string' }],
|
|
44
|
+
fn: async (args) => await callYourLLM(args[0]),
|
|
45
|
+
},
|
|
46
|
+
error: {
|
|
47
|
+
params: [{ name: 'message', type: 'string' }],
|
|
48
|
+
fn: (args) => { throw new Error(String(args[0])); },
|
|
49
|
+
},
|
|
42
50
|
},
|
|
43
51
|
});
|
|
44
52
|
|
|
@@ -125,7 +133,7 @@ Built-in functions for extracting structured data from LLM responses.
|
|
|
125
133
|
|
|
126
134
|
### String Interpolation
|
|
127
135
|
|
|
128
|
-
Embed expressions in strings.
|
|
136
|
+
Embed expressions in strings. Triple-quotes for multi-line.
|
|
129
137
|
|
|
130
138
|
```rill
|
|
131
139
|
"world" -> "Hello, {$}!" -> log # Hello, world!
|
|
@@ -133,10 +141,10 @@ Embed expressions in strings. Heredoc for multi-line.
|
|
|
133
141
|
|
|
134
142
|
```rill
|
|
135
143
|
"x + 1" :> $code
|
|
136
|
-
|
|
144
|
+
"""
|
|
137
145
|
Analyze: {$code}
|
|
138
146
|
Return: PASS or FAIL
|
|
139
|
-
|
|
147
|
+
"""
|
|
140
148
|
```
|
|
141
149
|
|
|
142
150
|
## Core Syntax
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration Loader for rill-check
|
|
3
|
+
* Loads and validates .rill-check.json configuration files.
|
|
4
|
+
*/
|
|
5
|
+
import type { CheckConfig } from './types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Create default configuration with all rules enabled.
|
|
8
|
+
* Returns configuration where all known rules are set to 'on'.
|
|
9
|
+
*/
|
|
10
|
+
export declare function createDefaultConfig(): CheckConfig;
|
|
11
|
+
/**
|
|
12
|
+
* Load configuration from .rill-check.json in the specified directory.
|
|
13
|
+
*
|
|
14
|
+
* @param cwd - Directory to search for configuration file
|
|
15
|
+
* @returns CheckConfig object, or null if file not found
|
|
16
|
+
* @throws Error with "Invalid configuration: {reason}" if JSON is invalid [EC-3]
|
|
17
|
+
* @throws Error with "Invalid configuration: unknown rule {code}" if unknown rule [EC-4]
|
|
18
|
+
*/
|
|
19
|
+
export declare function loadConfig(cwd: string): CheckConfig | null;
|
|
20
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/check/config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,KAAK,EAAE,WAAW,EAAuB,MAAM,YAAY,CAAC;AAcnE;;;GAGG;AACH,wBAAgB,mBAAmB,IAAI,WAAW,CAUjD;AAqGD;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI,CAiD1D"}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration Loader for rill-check
|
|
3
|
+
* Loads and validates .rill-check.json configuration files.
|
|
4
|
+
*/
|
|
5
|
+
import { readFileSync, existsSync } from 'node:fs';
|
|
6
|
+
import { join } from 'node:path';
|
|
7
|
+
import { VALIDATION_RULES } from './rules/index.js';
|
|
8
|
+
// ============================================================
|
|
9
|
+
// CONSTANTS
|
|
10
|
+
// ============================================================
|
|
11
|
+
/** Configuration file name */
|
|
12
|
+
const CONFIG_FILE_NAME = '.rill-check.json';
|
|
13
|
+
// ============================================================
|
|
14
|
+
// DEFAULT CONFIGURATION
|
|
15
|
+
// ============================================================
|
|
16
|
+
/**
|
|
17
|
+
* Create default configuration with all rules enabled.
|
|
18
|
+
* Returns configuration where all known rules are set to 'on'.
|
|
19
|
+
*/
|
|
20
|
+
export function createDefaultConfig() {
|
|
21
|
+
const rules = {};
|
|
22
|
+
const severity = {};
|
|
23
|
+
for (const rule of VALIDATION_RULES) {
|
|
24
|
+
rules[rule.code] = 'on';
|
|
25
|
+
severity[rule.code] = rule.severity;
|
|
26
|
+
}
|
|
27
|
+
return { rules, severity };
|
|
28
|
+
}
|
|
29
|
+
// ============================================================
|
|
30
|
+
// VALIDATION
|
|
31
|
+
// ============================================================
|
|
32
|
+
/**
|
|
33
|
+
* Validate that a value is a valid RuleState.
|
|
34
|
+
*/
|
|
35
|
+
function isRuleState(value) {
|
|
36
|
+
return value === 'on' || value === 'off' || value === 'warn';
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Validate that a value is a valid Severity.
|
|
40
|
+
*/
|
|
41
|
+
function isSeverity(value) {
|
|
42
|
+
return value === 'error' || value === 'warning' || value === 'info';
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Validate configuration structure and values.
|
|
46
|
+
* Throws Error if configuration is invalid.
|
|
47
|
+
*/
|
|
48
|
+
function validateConfig(data) {
|
|
49
|
+
if (typeof data !== 'object' || data === null || Array.isArray(data)) {
|
|
50
|
+
throw new Error('Invalid configuration: must be an object');
|
|
51
|
+
}
|
|
52
|
+
const config = data;
|
|
53
|
+
// Validate rules field if present
|
|
54
|
+
if ('rules' in config) {
|
|
55
|
+
if (typeof config['rules'] !== 'object' ||
|
|
56
|
+
config['rules'] === null ||
|
|
57
|
+
Array.isArray(config['rules'])) {
|
|
58
|
+
throw new Error('Invalid configuration: rules must be an object');
|
|
59
|
+
}
|
|
60
|
+
const rules = config['rules'];
|
|
61
|
+
for (const [code, state] of Object.entries(rules)) {
|
|
62
|
+
if (!isRuleState(state)) {
|
|
63
|
+
throw new Error(`Invalid configuration: rule ${code} has invalid state "${state}" (must be 'on', 'off', or 'warn')`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
// Validate severity field if present
|
|
68
|
+
if ('severity' in config) {
|
|
69
|
+
if (typeof config['severity'] !== 'object' ||
|
|
70
|
+
config['severity'] === null ||
|
|
71
|
+
Array.isArray(config['severity'])) {
|
|
72
|
+
throw new Error('Invalid configuration: severity must be an object');
|
|
73
|
+
}
|
|
74
|
+
const severity = config['severity'];
|
|
75
|
+
for (const [code, sev] of Object.entries(severity)) {
|
|
76
|
+
if (!isSeverity(sev)) {
|
|
77
|
+
throw new Error(`Invalid configuration: rule ${code} has invalid severity "${sev}" (must be 'error', 'warning', or 'info')`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Validate that all rule codes in config are known rules.
|
|
84
|
+
* Throws Error if unknown rule code found.
|
|
85
|
+
*/
|
|
86
|
+
function validateRuleCodes(config) {
|
|
87
|
+
const knownRules = new Set(VALIDATION_RULES.map((r) => r.code));
|
|
88
|
+
// Check rules field
|
|
89
|
+
for (const code of Object.keys(config.rules)) {
|
|
90
|
+
if (!knownRules.has(code)) {
|
|
91
|
+
throw new Error(`Invalid configuration: unknown rule ${code}`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
// Check severity field
|
|
95
|
+
for (const code of Object.keys(config.severity)) {
|
|
96
|
+
if (!knownRules.has(code)) {
|
|
97
|
+
throw new Error(`Invalid configuration: unknown rule ${code}`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
// ============================================================
|
|
102
|
+
// CONFIGURATION LOADING
|
|
103
|
+
// ============================================================
|
|
104
|
+
/**
|
|
105
|
+
* Load configuration from .rill-check.json in the specified directory.
|
|
106
|
+
*
|
|
107
|
+
* @param cwd - Directory to search for configuration file
|
|
108
|
+
* @returns CheckConfig object, or null if file not found
|
|
109
|
+
* @throws Error with "Invalid configuration: {reason}" if JSON is invalid [EC-3]
|
|
110
|
+
* @throws Error with "Invalid configuration: unknown rule {code}" if unknown rule [EC-4]
|
|
111
|
+
*/
|
|
112
|
+
export function loadConfig(cwd) {
|
|
113
|
+
const configPath = join(cwd, CONFIG_FILE_NAME);
|
|
114
|
+
// Return null if file not found (not an error)
|
|
115
|
+
if (!existsSync(configPath)) {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
let fileContent;
|
|
119
|
+
try {
|
|
120
|
+
fileContent = readFileSync(configPath, 'utf-8');
|
|
121
|
+
}
|
|
122
|
+
catch (err) {
|
|
123
|
+
throw new Error(`Invalid configuration: failed to read file (${err instanceof Error ? err.message : String(err)})`);
|
|
124
|
+
}
|
|
125
|
+
// Parse JSON
|
|
126
|
+
let parsedData;
|
|
127
|
+
try {
|
|
128
|
+
parsedData = JSON.parse(fileContent);
|
|
129
|
+
}
|
|
130
|
+
catch (err) {
|
|
131
|
+
throw new Error(`Invalid configuration: invalid JSON (${err instanceof Error ? err.message : String(err)})`);
|
|
132
|
+
}
|
|
133
|
+
// Validate structure
|
|
134
|
+
validateConfig(parsedData);
|
|
135
|
+
// Get defaults
|
|
136
|
+
const defaults = createDefaultConfig();
|
|
137
|
+
// Merge with defaults (parsedData is validated, so we can safely cast)
|
|
138
|
+
const rules = {
|
|
139
|
+
...defaults.rules,
|
|
140
|
+
...parsedData.rules,
|
|
141
|
+
};
|
|
142
|
+
const severity = {
|
|
143
|
+
...defaults.severity,
|
|
144
|
+
...parsedData.severity,
|
|
145
|
+
};
|
|
146
|
+
const config = { rules, severity };
|
|
147
|
+
// Validate rule codes
|
|
148
|
+
validateRuleCodes(config);
|
|
149
|
+
return config;
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/check/config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEpD,+DAA+D;AAC/D,YAAY;AACZ,+DAA+D;AAE/D,8BAA8B;AAC9B,MAAM,gBAAgB,GAAG,kBAAkB,CAAC;AAE5C,+DAA+D;AAC/D,wBAAwB;AACxB,+DAA+D;AAE/D;;;GAGG;AACH,MAAM,UAAU,mBAAmB;IACjC,MAAM,KAAK,GAA8B,EAAE,CAAC;IAC5C,MAAM,QAAQ,GAA6B,EAAE,CAAC;IAE9C,KAAK,MAAM,IAAI,IAAI,gBAAgB,EAAE,CAAC;QACpC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;QACxB,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC;IACtC,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC;AAC7B,CAAC;AAED,+DAA+D;AAC/D,aAAa;AACb,+DAA+D;AAE/D;;GAEG;AACH,SAAS,WAAW,CA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AE,KAAK,EAAE,QAAQ,EAAE,CAAC;IAEhD,sBAAsB;IACtB,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAE1B,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fix Applier
|
|
3
|
+
* Apply automatic fixes to source code with collision detection.
|
|
4
|
+
*/
|
|
5
|
+
import type { Diagnostic, ValidationContext } from './types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Result of applying fixes to source code.
|
|
8
|
+
*/
|
|
9
|
+
export interface ApplyResult {
|
|
10
|
+
/** Modified source code with fixes applied */
|
|
11
|
+
readonly modified: string;
|
|
12
|
+
/** Number of fixes successfully applied */
|
|
13
|
+
readonly applied: number;
|
|
14
|
+
/** Number of fixes skipped */
|
|
15
|
+
readonly skipped: number;
|
|
16
|
+
/** Reasons for skipped fixes */
|
|
17
|
+
readonly skippedReasons: Array<{
|
|
18
|
+
code: string;
|
|
19
|
+
reason: string;
|
|
20
|
+
}>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Apply automatic fixes to source code.
|
|
24
|
+
*
|
|
25
|
+
* Constraints:
|
|
26
|
+
* - Applies fixes in reverse position order (end to start) to avoid offset shifts
|
|
27
|
+
* - Skips fixes where applicable === false
|
|
28
|
+
* - Detects collisions (overlapping ranges) and skips with reason
|
|
29
|
+
* - Verifies modified source parses successfully
|
|
30
|
+
* - Throws if any applied fix creates invalid syntax
|
|
31
|
+
*
|
|
32
|
+
* @param source - Original source code
|
|
33
|
+
* @param diagnostics - Diagnostics with potential fixes
|
|
34
|
+
* @param context - Validation context (unused but required by spec)
|
|
35
|
+
* @returns ApplyResult with modified source and counts
|
|
36
|
+
* @throws Error if applied fixes create invalid syntax [EC-6]
|
|
37
|
+
*/
|
|
38
|
+
export declare function applyFixes(source: string, diagnostics: Diagnostic[], _context: ValidationContext): ApplyResult;
|
|
39
|
+
//# sourceMappingURL=fixer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fixer.d.ts","sourceRoot":"","sources":["../../src/check/fixer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAMhE;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,8CAA8C;IAC9C,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,2CAA2C;IAC3C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,8BAA8B;IAC9B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,gCAAgC;IAChC,QAAQ,CAAC,cAAc,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAClE;AAgBD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,UAAU,EAAE,EACzB,QAAQ,EAAE,iBAAiB,GAC1B,WAAW,CAuDb"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fix Applier
|
|
3
|
+
* Apply automatic fixes to source code with collision detection.
|
|
4
|
+
*/
|
|
5
|
+
import { parse } from '../parser/index.js';
|
|
6
|
+
// ============================================================
|
|
7
|
+
// FIX APPLICATION
|
|
8
|
+
// ============================================================
|
|
9
|
+
/**
|
|
10
|
+
* Apply automatic fixes to source code.
|
|
11
|
+
*
|
|
12
|
+
* Constraints:
|
|
13
|
+
* - Applies fixes in reverse position order (end to start) to avoid offset shifts
|
|
14
|
+
* - Skips fixes where applicable === false
|
|
15
|
+
* - Detects collisions (overlapping ranges) and skips with reason
|
|
16
|
+
* - Verifies modified source parses successfully
|
|
17
|
+
* - Throws if any applied fix creates invalid syntax
|
|
18
|
+
*
|
|
19
|
+
* @param source - Original source code
|
|
20
|
+
* @param diagnostics - Diagnostics with potential fixes
|
|
21
|
+
* @param context - Validation context (unused but required by spec)
|
|
22
|
+
* @returns ApplyResult with modified source and counts
|
|
23
|
+
* @throws Error if applied fixes create invalid syntax [EC-6]
|
|
24
|
+
*/
|
|
25
|
+
export function applyFixes(source, diagnostics, _context) {
|
|
26
|
+
// Filter to diagnostics with fixes
|
|
27
|
+
const fixableDiagnostics = diagnostics.filter((d) => d.fix !== null && d.fix.applicable);
|
|
28
|
+
// If no applicable fixes, return original
|
|
29
|
+
if (fixableDiagnostics.length === 0) {
|
|
30
|
+
return {
|
|
31
|
+
modified: source,
|
|
32
|
+
applied: 0,
|
|
33
|
+
skipped: 0,
|
|
34
|
+
skippedReasons: [],
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
// Convert to ApplicableFix with positions
|
|
38
|
+
const fixes = fixableDiagnostics.map((d) => ({
|
|
39
|
+
code: d.code,
|
|
40
|
+
start: d.fix.range.start.offset,
|
|
41
|
+
end: d.fix.range.end.offset,
|
|
42
|
+
replacement: d.fix.replacement,
|
|
43
|
+
}));
|
|
44
|
+
// Sort fixes by end position (descending) to apply from end to start
|
|
45
|
+
// This avoids offset shifts when applying multiple fixes
|
|
46
|
+
const sortedFixes = fixes.slice().sort((a, b) => b.end - a.end);
|
|
47
|
+
// Detect collisions and filter to non-overlapping fixes
|
|
48
|
+
const { validFixes, skippedReasons } = filterCollisions(sortedFixes);
|
|
49
|
+
// Apply fixes to source
|
|
50
|
+
let modified = source;
|
|
51
|
+
for (const fix of validFixes) {
|
|
52
|
+
const before = modified.slice(0, fix.start);
|
|
53
|
+
const after = modified.slice(fix.end);
|
|
54
|
+
modified = before + fix.replacement + after;
|
|
55
|
+
}
|
|
56
|
+
// Verify modified source parses successfully [EC-6]
|
|
57
|
+
try {
|
|
58
|
+
parse(modified);
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
throw new Error('Fix would create invalid syntax');
|
|
62
|
+
}
|
|
63
|
+
const applied = validFixes.length;
|
|
64
|
+
const skipped = sortedFixes.length - applied;
|
|
65
|
+
return {
|
|
66
|
+
modified,
|
|
67
|
+
applied,
|
|
68
|
+
skipped,
|
|
69
|
+
skippedReasons,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
// ============================================================
|
|
73
|
+
// COLLISION DETECTION
|
|
74
|
+
// ============================================================
|
|
75
|
+
/**
|
|
76
|
+
* Filter fixes to remove overlapping ranges.
|
|
77
|
+
* Detects collisions where fix ranges overlap [EC-5].
|
|
78
|
+
*
|
|
79
|
+
* Strategy: Keep first fix in sorted order (end to start),
|
|
80
|
+
* skip subsequent fixes that overlap with any kept fix.
|
|
81
|
+
*
|
|
82
|
+
* @param sortedFixes - Fixes sorted by end position (descending)
|
|
83
|
+
* @returns Valid fixes and reasons for skipped fixes
|
|
84
|
+
*/
|
|
85
|
+
function filterCollisions(sortedFixes) {
|
|
86
|
+
const validFixes = [];
|
|
87
|
+
const skippedReasons = [];
|
|
88
|
+
for (const fix of sortedFixes) {
|
|
89
|
+
// Check if this fix overlaps with any already-kept fix
|
|
90
|
+
const hasCollision = validFixes.some((kept) => rangesOverlap(fix, kept));
|
|
91
|
+
if (hasCollision) {
|
|
92
|
+
// Skip this fix due to collision [EC-5]
|
|
93
|
+
skippedReasons.push({
|
|
94
|
+
code: fix.code,
|
|
95
|
+
reason: 'Fix range overlaps with another fix',
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
// No collision, keep this fix
|
|
100
|
+
validFixes.push(fix);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return { validFixes, skippedReasons };
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Check if two fix ranges overlap.
|
|
107
|
+
*
|
|
108
|
+
* Ranges overlap if:
|
|
109
|
+
* - One starts before the other ends, AND
|
|
110
|
+
* - One ends after the other starts
|
|
111
|
+
*
|
|
112
|
+
* @param a - First fix range
|
|
113
|
+
* @param b - Second fix range
|
|
114
|
+
* @returns true if ranges overlap
|
|
115
|
+
*/
|
|
116
|
+
function rangesOverlap(a, b) {
|
|
117
|
+
return a.start < b.end && a.end > b.start;
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=fixer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fixer.js","sourceRoot":"","sources":["../../src/check/fixer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AA+B3C,+DAA+D;AAC/D,kBAAkB;AAClB,+DAA+D;AAE/D;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,UAAU,CACxB,MAAc,EACd,WAAyB,EACzB,QAA2B;IAE3B,mCAAmC;IACnC,MAAM,kBAAkB,GAAG,WAAW,CAAC,MAAM,CAC3C,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,IAAI,IAAI,CAAC,CAAC,GAAG,CAAC,UAAU,CAC1C,CAAC;IAEF,0CAA0C;IAC1C,IAAI,kBAAkB,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACpC,OAAO;YACL,QAAQ,EAAE,MAAM;YAChB,OAAO,EAAE,CAAC;YACV,OAAO,EAAE,CAAC;YACV,cAAc,EAAE,EAAE;SACnB,CAAC;IACJ,CAAC;IAED,0CAA0C;IAC1C,MAAM,KAAK,GAAoB,kBAAkB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAC5D,IAAI,EAAE,CAAC,CAAC,IAAI;QACZ,KAAK,EAAE,CAAC,CAAC,GAAI,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM;QAChC,GAAG,EAAE,CAAC,CAAC,GAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM;QAC5B,WAAW,EAAE,CAAC,CAAC,GAAI,CAAC,WAAW;KAChC,CAAC,CAAC,CAAC;IAEJ,qEAAqE;IACrE,yDAAyD;IACzD,MAAM,W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CAAC,IAAI,EAAE,EAAE,CAAC,aAAa,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC;QAEzE,IAAI,YAAY,EAAE,CAAC;YACjB,wCAAwC;YACxC,cAAc,CAAC,IAAI,CAAC;gBAClB,IAAI,EAAE,GAAG,CAAC,IAAI;gBACd,MAAM,EAAE,qCAAqC;aAC9C,CAAC,CAAC;QACL,CAAC;aAAM,CAAC;YACN,8BAA8B;YAC9B,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACvB,CAAC;IACH,CAAC;IAED,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,CAAC;AACxC,CAAC;AAED;;;;;;;;;;GAUG;AACH,SAAS,aAAa,CACpB,CAAiC,EACjC,CAAiC;IAEjC,OAAO,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,KAAK,CAAC;AAC5C,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check Module - Static Analysis for rill
|
|
3
|
+
* Public API for rill-check tool.
|
|
4
|
+
*/
|
|
5
|
+
export type { ValidationRule, RuleCategory, Severity, RuleState, Diagnostic, Fix, CheckConfig, ValidationContext, FixContext, } from './types.js';
|
|
6
|
+
export { VALIDATION_RULES } from './rules/index.js';
|
|
7
|
+
export { loadConfig, createDefaultConfig } from './config.js';
|
|
8
|
+
export { validateScript } from './validator.js';
|
|
9
|
+
export { applyFixes, type ApplyResult } from './fixer.js';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/check/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,YAAY,EACV,cAAc,EACd,YAAY,EACZ,QAAQ,EACR,SAAS,EACT,UAAU,EACV,GAAG,EACH,WAAW,EACX,iBAAiB,EACjB,UAAU,GACX,MAAM,YAAY,CAAC;AAKpB,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAKpD,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAK9D,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAKhD,OAAO,EAAE,UAAU,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check Module - Static Analysis for rill
|
|
3
|
+
* Public API for rill-check tool.
|
|
4
|
+
*/
|
|
5
|
+
// ============================================================
|
|
6
|
+
// RULE REGISTRY
|
|
7
|
+
// ============================================================
|
|
8
|
+
export { VALIDATION_RULES } from './rules/index.js';
|
|
9
|
+
// ============================================================
|
|
10
|
+
// CONFIGURATION
|
|
11
|
+
// ============================================================
|
|
12
|
+
export { loadConfig, createDefaultConfig } from './config.js';
|
|
13
|
+
// ============================================================
|
|
14
|
+
// VALIDATION
|
|
15
|
+
// ============================================================
|
|
16
|
+
export { validateScript } from './validator.js';
|
|
17
|
+
// ============================================================
|
|
18
|
+
// FIX APPLICATION
|
|
19
|
+
// ============================================================
|
|
20
|
+
export { applyFixes } from './fixer.js';
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/check/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAiBH,+DAA+D;AAC/D,gBAAgB;AAChB,+DAA+D;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEpD,+DAA+D;AAC/D,gBAAgB;AAChB,+DAA+D;AAC/D,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAE9D,+DAA+D;AAC/D,aAAa;AACb,+DAA+D;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhD,+DAA+D;AAC/D,kBAAkB;AAClB,+DAA+D;AAC/D,OAAO,EAAE,UAAU,EAAoB,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anti-Pattern Rules
|
|
3
|
+
* Enforces best practices from docs/16_conventions.md:411-462.
|
|
4
|
+
*/
|
|
5
|
+
import type { ValidationRule } from '../types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Warns on variable reassignment patterns.
|
|
8
|
+
* Variables lock to their first type, and reassignment suggests confusing
|
|
9
|
+
* flow control. Prefer functional style or new variables.
|
|
10
|
+
*
|
|
11
|
+
* Detection:
|
|
12
|
+
* - Capture node (:> $var) where $var already exists in validation context
|
|
13
|
+
* - Tracks variables seen during validation pass
|
|
14
|
+
*
|
|
15
|
+
* Valid alternatives:
|
|
16
|
+
* - Use new variable: $result1, $result2
|
|
17
|
+
* - Functional chains: value -> op1 -> op2
|
|
18
|
+
*
|
|
19
|
+
* References:
|
|
20
|
+
* - docs/16_conventions.md:413-424
|
|
21
|
+
*/
|
|
22
|
+
export declare const AVOID_REASSIGNMENT: ValidationRule;
|
|
23
|
+
/**
|
|
24
|
+
* Warns on complex nested boolean conditions.
|
|
25
|
+
* Complex conditions with multiple nested operators are hard to read.
|
|
26
|
+
* Extract to named variables for clarity.
|
|
27
|
+
*
|
|
28
|
+
* Detection:
|
|
29
|
+
* - Conditional nodes with conditions containing 3+ boolean operators (&&, ||)
|
|
30
|
+
* - Nesting depth > 2 for boolean expressions
|
|
31
|
+
*
|
|
32
|
+
* Valid alternatives:
|
|
33
|
+
* - Extract sub-conditions to named variables
|
|
34
|
+
* - Split complex checks into multiple smaller checks
|
|
35
|
+
*
|
|
36
|
+
* References:
|
|
37
|
+
* - docs/16_conventions.md:451-461
|
|
38
|
+
*/
|
|
39
|
+
export declare const COMPLEX_CONDITION: ValidationRule;
|
|
40
|
+
/**
|
|
41
|
+
* Detects attempts to modify outer-scope variables from inside loops.
|
|
42
|
+
* This is a common LLM-generated anti-pattern that never works in Rill.
|
|
43
|
+
*
|
|
44
|
+
* Rill's scoping rules mean that captures inside loop bodies create LOCAL
|
|
45
|
+
* variables that don't affect outer scope. This is a fundamental language
|
|
46
|
+
* constraint, not a style preference.
|
|
47
|
+
*
|
|
48
|
+
* WRONG - this pattern NEVER works:
|
|
49
|
+
* 0 :> $count
|
|
50
|
+
* [1, 2, 3] -> each { $count + 1 :> $count } # creates LOCAL $count
|
|
51
|
+
* $count # still 0!
|
|
52
|
+
*
|
|
53
|
+
* RIGHT - use accumulators:
|
|
54
|
+
* [1, 2, 3] -> fold(0) { $@ + 1 } # returns 3
|
|
55
|
+
* [1, 2, 3] -> each(0) { $@ + 1 } # returns [1, 2, 3]
|
|
56
|
+
*
|
|
57
|
+
* This rule catches captures inside loop/collection bodies where the
|
|
58
|
+
* variable name matches an outer-scope variable.
|
|
59
|
+
*
|
|
60
|
+
* References:
|
|
61
|
+
* - docs/99_llm-reference.txt (LOOP STATE PATTERNS)
|
|
62
|
+
* - docs/03_variables.md (Scope Rules)
|
|
63
|
+
*/
|
|
64
|
+
export declare const LOOP_OUTER_CAPTURE: ValidationRule;
|
|
65
|
+
//# sourceMappingURL=anti-patterns.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anti-patterns.d.ts","sourceRoot":"","sources":["../../../src/check/rules/anti-patterns.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACV,cAAc,EAGf,MAAM,aAAa,CAAC;AAmBrB;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,kBAAkB,EAAE,cA+BhC,CAAC;AAMF;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,iBAAiB,EAAE,cA6C/B,CAAC;AAmIF;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,kBAAkB,EAAE,cAiEhC,CAAC"}
|