ts-analyzer 1.3.2 → 1.3.7

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.
Files changed (2) hide show
  1. package/README.md +124 -33
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -4,55 +4,146 @@
4
4
  ![coverage](https://img.shields.io/badge/coverage-88%25-brightgreen)
5
5
  ![license](https://img.shields.io/npm/l/ts-analyzer)
6
6
 
7
- `ts-analyzer` is a comprehensive static analysis tool for checking TypeScript and JavaScript code quality, focusing on type safety, structural complexity, and identifying potential anti-patterns.
7
+ `ts-analyzer` is a code analysis tool that checks your TypeScript and JavaScript projects. It looks at how safe your types are, how complex your code is, and finds common mistakes.
8
+
9
+ ---
10
+
11
+ ## Features
12
+
13
+ - **Type Safety Checks**: It calculates your real type coverage. It tracks things like `any` usage, generics, and assertions.
14
+ - **Code Complexity**: It checks how hard your code is to read by measuring cyclomatic complexity and nested blocks.
15
+ - **Anti-patterns**: It spots bad practices like Magic Numbers, Callback Hell, huge files, and functions with too many parameters.
16
+ - **Reports**: You can view the results as a nice HTML page, JSON, or just plain text in your terminal.
17
+ - **Tested**: The project has around 88% test coverage using Vitest.
18
+
19
+ ---
20
+
21
+ ## How It Works
22
+
23
+ ### Type Safety
24
+ The tool looks at your code to see if your variables and parameters actually have types, or if they are just left as `any`.
25
+
26
+ ```text
27
+ ┌─────────────────────┐
28
+ │ TypeScript Files │
29
+ └─────────┬───────────┘
30
+
31
+
32
+ ┌─────────────────────┐ ┌─────────────────────┐
33
+ │ AST Analysis │───>│ Node Classification │
34
+ └─────────┬───────────┘ └─────────┬───────────┘
35
+ │ │
36
+ ▼ ▼
37
+ ┌─────────────────────┐ ┌─────────────────────┐
38
+ │ Explicitly Typed │ │ Implicitly Typed │
39
+ │ Nodes │ │ Nodes │
40
+ └─────────┬───────────┘ └─────────┬───────────┘
41
+ │ │
42
+ └──────────┬──────────────┘
43
+
44
+
45
+ ┌─────────────────────┐ ┌─────────────────────┐
46
+ │ Type Coverage │<───│ tsconfig.json │
47
+ │ Calculation │ │ Analysis │
48
+ └─────────┬───────────┘ └─────────────────────┘
49
+
50
+
51
+ ┌─────────────────────┐
52
+ │ "any" & Assertion │
53
+ │ Penalty Calculation │
54
+ └─────────┬───────────┘
55
+
56
+
57
+ ┌─────────────────────┐
58
+ │ Final Type Safety │
59
+ │ Score & Rating │
60
+ └─────────────────────┘
61
+ ```
8
62
 
9
- ## Features
63
+ * **Score**: It calculates a score based on your type coverage percentage, minus a penalty if you use `any` or type assertions too much.
64
+ * **tsconfig**: You get extra bonus points if your `tsconfig.json` has strict settings enabled.
10
65
 
11
- - **TypeScript Safety Metrics**: Calculates your project's true type coverage by tracking `any` usage, explicit generics, optional properties, type assertions, and non-null assertions.
12
- - **Code Complexity Analysis**: Measures Cyclomatic Complexity and Nesting Depth to ensure your code remains readable and maintainable.
13
- - **Anti-Pattern & Code Smell Detection**: Highlights potential red flags such as "Magic Numbers", "Callback Hell", "God Files" (>500 lines), and overly complex functions (excessive parameters).
14
- - **Flexible Reporting**: Generate beautiful HTML dashboards, parsable JSON payloads, or read insights directly in your terminal.
15
- - **High Reliability**: The tool is extensively tested with a robust **~88% test coverage** powered by Vitest, ensuring calculations remain accurate.
66
+ ### Code Complexity
67
+ It looks at your functions to see how complicated they are:
68
+ 1. **Cyclomatic Complexity**: How many different paths your code can take.
69
+ 2. **Nesting Depth**: How many blocks are inside each other (to avoid Callback Hell).
70
+ 3. **Size**: How many lines and parameters your functions have.
16
71
 
17
- ## 🚀 Quick Start
72
+ Based on this, it gives a rating: <30 is simple, 30-60 is moderate, and >60 means it's too complex.
18
73
 
19
- Run it directly on any project using `npx`:
74
+ ### Why switch to `ts-analyzer`?
75
+ This tool is an upgrade from `react-loc-analyzer`. Instead of just counting lines, it actually understands your TypeScript code and gives you useful feedback to improve it.
20
76
 
21
- ```bash
22
- npx ts-analyzer
23
- ```
77
+ ---
78
+
79
+ ## Quick Start
24
80
 
25
- ## 📦 Usage
81
+ You can run it directly using npx:
26
82
 
27
- Analyze a specific directory:
28
83
  ```bash
29
- ts-analyzer /path/to/project
84
+ npx ts-analyzer /path/to/project
30
85
  ```
31
86
 
32
- Available options:
33
- - `-f, --format <type>`: Select report format (`text`, `json`, or `html`).
34
- - `-e, --exclude <patterns>`: Comma-separated ignore patterns (e.g. `node_modules,dist`).
35
- - `--no-safety`: Skip type-safety analysis to speed up processing.
36
- - `--no-complexity`: Skip structural complexity analysis.
37
-
38
- ## 🛠 Development
39
-
40
- The repository uses modern open-source tooling, and features comprehensive test suites.
41
-
42
- Install dependencies:
43
- ```bash
44
- npm install
87
+ Some options you can use:
88
+ - `-f, --format <type>`: Choose between `text`, `json`, or `html`
89
+ - `-e, --exclude <patterns>`: Folders to ignore, separated by commas
90
+ - `--no-safety` / `--no-complexity`: Skip specific checks to run faster
91
+
92
+ ## Example Reports
93
+
94
+ ### JSON Output
95
+ When you run `npx ts-analyzer /path -f json`, it generates structured data you can use in your CI/CD pipelines:
96
+
97
+ ```json
98
+ {
99
+ "files": 156,
100
+ "totalLines": 15234,
101
+ "codeLines": 12845,
102
+ "typescriptSafety": {
103
+ "tsPercentage": "84.6",
104
+ "avgTypeCoverage": "92.3",
105
+ "totalAnyCount": 12,
106
+ "avgTypeSafetyScore": 85,
107
+ "overallComplexity": "Low"
108
+ },
109
+ "codeComplexity": {
110
+ "avgComplexity": "3.2",
111
+ "maxComplexity": 12,
112
+ "overallComplexity": "Low",
113
+ "codeSmells": {
114
+ "magicNumbers": 0,
115
+ "callbackHell": 0,
116
+ "godFiles": 0
117
+ }
118
+ }
119
+ }
45
120
  ```
46
121
 
47
- Run tests (powered by Vitest):
48
- ```bash
49
- npm test
122
+ ### HTML Output
123
+ When you run `npx ts-analyzer /path -f html`, it creates a `ts-analyzer-report.html` file. This acts as a beautiful visual dashboard with:
124
+ - **Project Summary Cards**: Big, clear numbers for your total lines and code lines.
125
+ - **Color-coded Progress Bars**: Visual bars for Type Coverage percentages (turns red if too low).
126
+ - **Red/Green Indicators**: Fast visual checks for code smells like Callback Hell and God Files.
127
+
128
+ ## Config File
129
+ You don't have to type arguments every time. Just create a `ts-analyzer.config.json` in your project folder:
130
+ ```json
131
+ {
132
+ "safety": true,
133
+ "complexity": true,
134
+ "format": "text",
135
+ "exclude": ["node_modules", "dist", ".next"],
136
+ "include": [".js", ".ts", ".tsx"]
137
+ }
50
138
  ```
51
139
 
52
- Generate coverage reports:
140
+ ## Development
141
+ To work on this project, install the dependencies and run the tests:
53
142
  ```bash
143
+ npm install
144
+ npm test
54
145
  npm run test:coverage
55
146
  ```
56
147
 
57
- ## 📝 License
148
+ ## License
58
149
  MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-analyzer",
3
- "version": "1.3.2",
3
+ "version": "1.3.7",
4
4
  "repository": "github:amir-valizadeh/ts-analyzer",
5
5
  "description": "Comprehensive TypeScript code analyzer with type safety and complexity metrics",
6
6
  "main": "dist/src/index.js",