energy-state-analyzer 0.23.1 → 0.23.2

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.
@@ -4,11 +4,15 @@ Energy State Analyzer is implemented in F# and compiled with Fable 5 to JavaScri
4
4
  VS Code extension share one host-independent detector pipeline, then webpack packages generated
5
5
  ESM into the CommonJS artifacts exposed by `package.json`.
6
6
 
7
- ## Coherence rules
7
+ ## Reading path
8
8
 
9
- Each F# file stays at **≤12 functions** and **≤10 import sources**. The analyzer enforces the
10
- same rule when `just analyze` dogfoods the project. Split a module by domain rather than growing
11
- one past its responsibility.
9
+ Start with [Analyze](../src/Core/Analyze.fs) and
10
+ [DetectorPipeline](../src/Core/DetectorPipeline.fs) for the shared transformation. Read
11
+ [LanguageAdapter](../src/Core/LanguageAdapter.fs) with one adapter in `src/Languages/` to see how
12
+ grammar facts enter detectors. Then follow [Cli](../src/Cli.fs) → [CliModes](../src/CliModes.fs) →
13
+ [CliRuntime](../src/CliRuntime.fs), or [Extension](../src/Extension/Extension.fs) →
14
+ [Grammar](../src/Extension/Grammar.fs) → [Analysis](../src/Extension/Analysis.fs) for the two host
15
+ flows. The analyzer itself determines code-quality thresholds; this guide sets none.
12
16
 
13
17
  ## Module map
14
18
 
@@ -16,10 +20,10 @@ one past its responsibility.
16
20
  | --- | --- | --- |
17
21
  | `src/Core/` | Violation model, parser facade, detector pipeline, suppressions, scanning and reports | No host state |
18
22
  | `src/Languages/` | Grammar-specific `LanguageAdapter` records for the supported languages | Static registry |
19
- | `src/Extension/Vscode*.fs` | Narrow Fable facade over VS Code | No |
23
+ | `src/Extension/Vscode/` | Narrow Fable facade over VS Code | No |
20
24
  | `src/Extension/Configuration*.fs` | VS Code settings and pure settings-to-threshold mapping | No |
21
25
  | `src/Extension/Grammar.fs` | Parser initialization, loaded grammar cache, in-flight load cache | Cache supplied by root |
22
- | `src/Extension/Analysis.fs` | Document analysis, `.esaignore`, `includeFixtures`, Python type-info logging | No |
26
+ | `src/Extension/Analysis.fs` | Document analysis, `.esaignore`, and `includeFixtures` | No |
23
27
  | `src/Extension/DecorationModel.fs` / `Decorations.fs` | Pure decoration range/heatmap calculations and VS Code rendering | No |
24
28
  | `src/Extension/DiagnosticModel.fs` / `Diagnostics.fs` | Pure Problems mapping and VS Code diagnostic rendering | No |
25
29
  | `src/Extension/Extension.fs` | Activation, deactivation, lifecycle state, commands, events | Yes |
@@ -28,21 +32,30 @@ one past its responsibility.
28
32
 
29
33
  ## Analysis pipeline
30
34
 
31
- `src/Core/Analyze.fs` builds one ordered detector list over an immutable `AnalysisContext`.
32
- Detectors remain synchronous once the source has been parsed; `Task` is confined to async edges
33
- such as grammar loading. Suppressions run last over the combined result, so an `esa-ignore`
34
- directive can name any detector category.
35
+ `src/Core/DetectorPipeline.fs` orders detectors over an immutable `AnalysisContext`;
36
+ `src/Core/Analyze.fs` creates the context and applies suppressions after detection. The shared
37
+ `src/Core/ParsedAnalysis.fs` owns the parsed tree's lifetime and converts parse or detector
38
+ exceptions into typed errors. Detection stays synchronous; grammar loading is asynchronous.
39
+ Applying suppressions last lets an `esa-ignore` directive name any detector category.
35
40
 
36
41
  `EnergyViolation` uses F# discriminated unions for severity/type plus a record payload. The CLI
37
42
  maps those values to the established JSON strings (`low`, `medium`, `high`, etc.), keeping its
38
43
  public contract unchanged.
39
44
 
45
+ `src/Core/Config.fs` resolves a project's optional `.esaconfig.json` before analysis. Missing
46
+ discovered config uses built-in defaults; a selected file that cannot be read or parsed is an
47
+ error. The CLI applies only supplied flag overrides to those resolved options. CLI paths are
48
+ checked before scanning, while host-specific source, grammar, parse, and report-write failures
49
+ leave the analysis path as explicit errors.
50
+
40
51
  ## Extension presentation
41
52
 
42
53
  The composition root owns per-activation grammar caches, decoration types, diagnostic collection,
43
54
  and subscriptions. It refreshes the active editor after editor/document/configuration events,
44
55
  recreates decoration types when colors change, clears ignored/unsupported documents, and verifies
45
56
  the active document again after an async grammar load.
57
+ Concurrent requests share an in-flight grammar load; completion removes that task so a failed
58
+ load can be retried by the next request.
46
59
 
47
60
  `DecorationModel.fs` keeps category-specific range selection and per-violation normalized
48
61
  complexity heatmaps testable outside VS Code. `DiagnosticModel.fs` groups same-line findings into
package/docs/cli.md CHANGED
@@ -21,7 +21,8 @@ npx energy-state-analyzer path/to/file.py \
21
21
  --medium-cognitive 12 --high-cognitive 20
22
22
  ```
23
23
 
24
- All threshold flags are optional: `--medium-nesting`, `--high-nesting`, `--medium-cyclomatic`, `--high-cyclomatic`, `--medium-cognitive`, `--high-cognitive`.
24
+ All threshold flags are optional: `--medium-nesting`, `--high-nesting`, `--medium-cyclomatic`, `--high-cyclomatic`, `--medium-cognitive`, `--high-cognitive`, `--medium-parameter-count`, and `--high-parameter-count`.
25
+ Unknown flags, invalid flag values, missing explicit paths, and unsupported explicit files exit `2`. An existing directory or supported glob that matches no files still produces a zero-file report. A malformed `.esaconfig.json` or missing explicit `--config` file also exits `2`.
25
26
 
26
27
  ## Supported file suffixes
27
28
 
@@ -6,7 +6,7 @@ Detector detail is configured at two levels, resolved in this order of increasin
6
6
  built-in defaults < .esaconfig.json
7
7
  ```
8
8
 
9
- The built-in defaults are the single source of truth for every threshold (see `src/Core/Config.fs`). A project's `.esaconfig.json` layers its values on top for both the editor and CLI/CI. Anything not set in the file falls back to the built-in default.
9
+ The built-in defaults are the single source of truth for every threshold (see `src/Core/Config.fs`). A project's `.esaconfig.json` layers its values on top for both the editor and CLI/CI. Anything not set in the file falls back to the built-in default. A selected file with malformed JSON or a read error fails configuration instead of silently using defaults; an explicit `--config` path must exist.
10
10
 
11
11
  ## Choosing thresholds
12
12
 
@@ -13,6 +13,8 @@ separate scopes; trait relationships and methods produced by macros are not reso
13
13
 
14
14
  **Function-count sprawl.** A file with more than 12 functions is flagged (medium; high past 15). The threshold drops to 8 if the filename itself contains `util`, `helper`, or `common`, treating the name as a proxy for "already known to be a grab-bag." These three bars (`genericFunctionCount`/`highFunctionCount`/`utilsFileFunctionCount`) are all configurable — see [Configuration](#configuration). The violation message deliberately steers away from "just split this file" — since the detector only sees one file, it can't tell whether a split would land the code in an existing cohesive module or just distribute the same coupling across new files with more imports wiring them back together.
15
15
 
16
+ Rust test functions do not contribute to this count or its naming/type-cohesion signals. This includes functions in test files, inline test modules, and functions marked `#[test]` or `#[cfg(test)]`. They still receive individual analysis and participate in the large-function check.
17
+
16
18
  A file is exempted from this check regardless of count if either of two independent cohesion signals says otherwise (unless the filename already admits to being utils/helper/common, which overrides both):
17
19
 
18
20
  - *Naming cohesion*: most of its functions share a leading name word (e.g. `extractFoo`/`extractBar`/`extractBaz`, at least a 70% share by default) — one coherent domain broken into small steps, not a grab-bag.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "energy-state-analyzer",
3
3
  "displayName": "Energy State Analyzer",
4
4
  "description": "Visualize code energy states in real-time (Python, F#, TypeScript, Kotlin, C++, C#, Erlang, Rust)",
5
- "version": "0.23.1",
5
+ "version": "0.23.2",
6
6
  "publisher": "cardamom-code",
7
7
  "license": "MIT",
8
8
  "icon": "images/icon.png",
@@ -216,7 +216,7 @@
216
216
  "@vscode/vsce": "^4.0.0",
217
217
  "copy-webpack-plugin": "^14.0.0",
218
218
  "license-checker": "^25.0.1",
219
- "markdownlint-cli": "^0.49.1",
219
+ "markdownlint-cli": "^0.50.0",
220
220
  "webpack": "^5.75.0",
221
221
  "webpack-cli": "^7.2.2"
222
222
  },