dittory 0.0.3 → 0.0.5

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 CHANGED
@@ -3,9 +3,7 @@
3
3
  [![npm version](https://img.shields.io/npm/v/dittory.svg)](https://www.npmjs.com/package/dittory)
4
4
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
5
 
6
- A static analysis CLI that detects **parameters always receiving the same value** in React components and functions.
7
-
8
- > **dittory** = "ditto" (same) + "-ory" — finds repetitive patterns in your code
6
+ A static analysis CLI that detects **parameters that always receive the same value** in React components and functions.
9
7
 
10
8
  ## Why?
11
9
 
@@ -47,8 +45,8 @@ dittory --target=functions # Functions and class methods only
47
45
  dittory --target=all # Both (default)
48
46
 
49
47
  # Output mode
50
- dittory --output=simple # Show only constants (default)
51
- dittory --output=verbose # Show all exported functions and details
48
+ dittory --output=simple # Show only constant parameters (default)
49
+ dittory --output=verbose # Also show all analyzed functions
52
50
  ```
53
51
 
54
52
  ## Example Output
@@ -84,7 +82,7 @@ Found 2 function(s) with constant arguments out of 24 function(s).
84
82
  | Target | Description |
85
83
  |--------|-------------|
86
84
  | **React Components** | Props passed to JSX elements (`<Button variant="primary" />`) |
87
- | **Functions** | Arguments passed to exported function calls |
85
+ | **Functions** | Arguments passed to exported functions |
88
86
  | **Class Methods** | Arguments passed to methods of exported classes |
89
87
 
90
88
  ## Supported Detection Patterns
@@ -101,9 +99,11 @@ Found 2 function(s) with constant arguments out of 24 function(s).
101
99
  | Variable references | `const x = 3; fn(x)` | ✅ |
102
100
  | Variable chains | `const a = 1; const b = a; fn(b)` → resolves to `1` | ✅ |
103
101
  | Object literals | `{ nested: { value: 1 } }` | ✅ |
104
- | Function references | `onClick={handleClick}` | (by location) |
102
+ | Function references | `onClick={handleClick}` | ⚠️ (tracked per call site) |
105
103
  | `undefined` | `fn(undefined)` | ✅ |
106
104
 
105
+ > **Note on Function references:** Function values are identified by their usage location (file + line), not by identity. Even if the same function is passed from multiple locations, each usage is treated as a different value. This is by design, as the analysis takes a conservative approach regarding runtime behavior.
106
+
107
107
  ### Parameter Propagation (Call Graph Analysis)
108
108
 
109
109
  dittory can track values through component/function chains:
@@ -152,7 +152,7 @@ const Parent = ({ num, ...others }) => <Child {...others} />;
152
152
 
153
153
  ### Conditional Branches
154
154
 
155
- When different code paths pass different values, dittory correctly identifies them as different values (not constant):
155
+ When different code paths pass different values, dittory correctly identifies them as different values (not constants):
156
156
 
157
157
  ```tsx
158
158
  // Different values in branches → correctly NOT reported as constant
@@ -189,14 +189,27 @@ const Enhanced = withAuth(Component);
189
189
  <Enhanced role="admin" />
190
190
  ```
191
191
 
192
+ ### Function Overloads
193
+
194
+ ```ts
195
+ // ❌ Overloaded functions may not correctly map arguments
196
+ function process(a: string): void;
197
+ function process(a: string, b: number): void;
198
+ function process(a: string, b?: number): void { ... }
199
+
200
+ // Only parameters from the first overload signature are recognized
201
+ process("hello", 42); // "b" argument is not tracked
202
+ ```
203
+
192
204
  ## CLI Options
193
205
 
194
206
  | Option | Description | Default |
195
207
  |--------|-------------|---------|
196
- | `--min=<n>` | Minimum number of usages to consider | `2` |
208
+ | `--min=<n>` | Minimum number of usages required to report | `2` |
197
209
  | `--target=<mode>` | What to analyze: `all`, `components`, `functions` | `all` |
198
210
  | `--output=<mode>` | Output verbosity: `simple`, `verbose` | `simple` |
199
211
  | `--tsconfig=<path>` | Path to tsconfig.json | `./tsconfig.json` |
212
+ | `--value-types=<types>` | Value types to detect (comma-separated): `boolean`, `number`, `string`, `enum`, `undefined`, `all` | `all` |
200
213
  | `--help` | Show help message | — |
201
214
 
202
215
  ## Configuration File
@@ -215,6 +228,7 @@ export default {
215
228
  output: "verbose",
216
229
  tsconfig: "./tsconfig.app.json",
217
230
  targetDir: "./src",
231
+ valueTypes: ["boolean", "string"], // or "all"
218
232
  };
219
233
  ```
220
234
 
@@ -247,7 +261,7 @@ Works alongside other directives like `eslint-disable-line` or `@ts-ignore`.
247
261
  <Button onClick={handleClick}>Submit</Button>
248
262
  ```
249
263
 
250
- ### Remove Unused Flexibility
264
+ ### Remove Unnecessary Flexibility
251
265
 
252
266
  ```ts
253
267
  // Before: cache is always false in all 15 call sites