ts-analyzer 1.3.1 → 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 +126 -21
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,42 +1,147 @@
1
1
  # ts-analyzer
2
2
 
3
- ts-analyzer is a static analysis tool for checking TypeScript code quality, focusing on type safety and structural complexity.
3
+ ![npm](https://img.shields.io/npm/v/ts-analyzer)
4
+ ![coverage](https://img.shields.io/badge/coverage-88%25-brightgreen)
5
+ ![license](https://img.shields.io/npm/l/ts-analyzer)
6
+
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
+ ---
4
10
 
5
11
  ## Features
6
12
 
7
- - TypeScript safety metrics (type coverage, any usage, assertions).
8
- - Cyclomatic complexity and nesting depth analysis.
9
- - Detection of anti-patterns like magic numbers, callback hell, and god files.
10
- - Formatted output in Text, JSON, and HTML.
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.
11
18
 
12
- ## Quick Start
19
+ ---
13
20
 
14
- ```bash
15
- npx ts-analyzer
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
+ └─────────────────────┘
16
61
  ```
17
62
 
18
- ## Usage
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.
65
+
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.
71
+
72
+ Based on this, it gives a rating: <30 is simple, 30-60 is moderate, and >60 means it's too complex.
73
+
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.
76
+
77
+ ---
78
+
79
+ ## Quick Start
80
+
81
+ You can run it directly using npx:
19
82
 
20
- Analyze a specific directory:
21
83
  ```bash
22
- ts-analyzer /path/to/project
84
+ npx ts-analyzer /path/to/project
23
85
  ```
24
86
 
25
- Available options:
26
- - `-f, --format <type>`: `text`, `json`, or `html`.
27
- - `-e, --exclude <patterns>`: Comma-separated ignore patterns.
28
- - `--no-safety`: Skip type-safety analysis.
29
- - `--no-complexity`: Skip complexity analysis.
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
30
91
 
31
- ## Development
92
+ ## Example Reports
32
93
 
33
- Run tests:
34
- ```bash
35
- npm test
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
+ }
36
120
  ```
37
121
 
38
- Generate coverage:
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
+ }
138
+ ```
139
+
140
+ ## Development
141
+ To work on this project, install the dependencies and run the tests:
39
142
  ```bash
143
+ npm install
144
+ npm test
40
145
  npm run test:coverage
41
146
  ```
42
147
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-analyzer",
3
- "version": "1.3.1",
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",