react-code-smell-detector 1.5.1 → 1.5.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.
- package/README.md +221 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ A CLI tool that analyzes React projects and detects common code smells, providin
|
|
|
7
7
|
- 🔍 **Detect Code Smells**: Identifies common React anti-patterns (70+ smell types)
|
|
8
8
|
- 📊 **Technical Debt Score**: Grades your codebase from A to F
|
|
9
9
|
- 💡 **Refactoring Suggestions**: Actionable recommendations for each issue
|
|
10
|
-
- 📝 **Multiple Output Formats**: Console (colored), JSON, Markdown, and
|
|
10
|
+
- 📝 **Multiple Output Formats**: Console (colored), JSON, Markdown, HTML, and PDF
|
|
11
11
|
- 🔒 **Security Scanning**: Detects XSS vulnerabilities, eval usage, exposed secrets
|
|
12
12
|
- ♿ **Accessibility Checks**: Missing alt text, labels, ARIA attributes
|
|
13
13
|
- 🐛 **Debug Cleanup**: console.log, debugger, TODO/FIXME detection
|
|
@@ -19,7 +19,7 @@ A CLI tool that analyzes React projects and detects common code smells, providin
|
|
|
19
19
|
- 💧 **Memory Leak Detection**: Find missing cleanup in useEffect
|
|
20
20
|
- 🔄 **Import Analysis**: Detect circular dependencies and barrel file issues
|
|
21
21
|
- 🗑️ **Unused Code Detection**: Find unused exports and dead imports
|
|
22
|
-
- 📈 **
|
|
22
|
+
- 📈 **Advanced Trend Analytics**: ML-powered trend analysis with predictions and health scores
|
|
23
23
|
- 💬 **Chat Notifications**: Send analysis results to Slack, Discord, or custom webhooks
|
|
24
24
|
- 🔗 **Dependency Graph Visualization**: Visual SVG/HTML of component and import relationships
|
|
25
25
|
- 📦 **Bundle Size Impact**: Per-component bundle size estimates and optimization suggestions
|
|
@@ -27,6 +27,8 @@ A CLI tool that analyzes React projects and detects common code smells, providin
|
|
|
27
27
|
- 🔧 **Interactive Fix Mode**: Review and apply fixes one by one with diff preview
|
|
28
28
|
- 💬 **GitHub PR Comments**: Auto-comment analysis results on pull requests
|
|
29
29
|
- 📊 **Performance Budget**: Set thresholds and enforce limits in CI/CD
|
|
30
|
+
- 📄 **PDF Report Generation**: Professional, printable reports with visual analytics
|
|
31
|
+
- 🎯 **ESLint Plugin Integration**: Run detectors directly as ESLint rules
|
|
30
32
|
- 📚 **Component Documentation**: Auto-generate docs from component analysis
|
|
31
33
|
- ⚛️ **React 19 Server Components**: Detect Server/Client boundary issues
|
|
32
34
|
- 🔮 **Context API Analysis**: Detect context overuse, missing memoization, re-render issues
|
|
@@ -121,8 +123,154 @@ react-smell ./src -f markdown -o report.md
|
|
|
121
123
|
|
|
122
124
|
# HTML (beautiful visual report)
|
|
123
125
|
react-smell ./src -f html -o report.html
|
|
126
|
+
|
|
127
|
+
# PDF (professional formatted report with charts)
|
|
128
|
+
react-smell ./src -f pdf -o report.pdf
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### ESLint Plugin Integration
|
|
132
|
+
|
|
133
|
+
Run code smell detection directly integrated with ESLint:
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
# Install ESLint if not already installed
|
|
137
|
+
npm install -D eslint
|
|
138
|
+
|
|
139
|
+
# Add to .eslintrc.json
|
|
140
|
+
{
|
|
141
|
+
"plugins": ["react-code-smell-detector"],
|
|
142
|
+
"extends": ["plugin:react-code-smell-detector/recommended"]
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
# Or use strict mode for more comprehensive checks
|
|
146
|
+
{
|
|
147
|
+
"plugins": ["react-code-smell-detector"],
|
|
148
|
+
"extends": ["plugin:react-code-smell-detector/strict"]
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
**Benefits:**
|
|
153
|
+
- Real-time feedback in your editor
|
|
154
|
+
- Integrates with existing ESLint workflow
|
|
155
|
+
- Runs on file save or pre-commit
|
|
156
|
+
- Works with git hooks and CI/CD pipelines
|
|
157
|
+
|
|
158
|
+
**Available ESLint Rules:**
|
|
159
|
+
- `no-excessive-use-effect`: Detect overuse of useEffect
|
|
160
|
+
- `no-prop-drilling`: Detect prop drilling patterns
|
|
161
|
+
- `no-large-components`: Warn on component size
|
|
162
|
+
- `no-unmemoized-calculations`: Flag unmemoized expensive operations
|
|
163
|
+
- `no-security-issues`: Detect security vulnerabilities
|
|
164
|
+
- `accessibility-checked`: Accessibility violations
|
|
165
|
+
- `no-memory-leaks`: Potential memory leaks
|
|
166
|
+
- `no-circular-dependencies`: Circular import detection
|
|
167
|
+
- `state-management-smell`: State management anti-patterns
|
|
168
|
+
- And 9 more rules for comprehensive coverage
|
|
169
|
+
|
|
170
|
+
### Advanced Trend Analytics
|
|
171
|
+
|
|
172
|
+
Track code quality trends over time with intelligent predictions and insights:
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
# Enable trend analysis in baseline tracking
|
|
176
|
+
react-smell ./src --baseline --trend-analysis
|
|
177
|
+
|
|
178
|
+
# View detailed trend insights
|
|
179
|
+
react-smell ./src --baseline --trend-report
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
**Features:**
|
|
183
|
+
- **Trend Direction**: Automatic detection of improving, worsening, or stable trends
|
|
184
|
+
- **Growth Metrics**: Daily velocity, change rate, consistency scoring
|
|
185
|
+
- **Predictive Analytics**: Machine learning-based predictions for next 30 days
|
|
186
|
+
- **Health Score**: Overall codebase health indicator (0-100)
|
|
187
|
+
- **Zero Smell Timeline**: Estimated days to reach zero code smells
|
|
188
|
+
- **Seasonality Detection**: Identify patterns in code quality changes
|
|
189
|
+
- **Smart Recommendations**: AI-powered suggestions based on trend analysis
|
|
190
|
+
|
|
191
|
+
**Trend Analysis Output:**
|
|
192
|
+
```
|
|
193
|
+
📈 Trend Analysis
|
|
194
|
+
──────────────────────────────────────────────────
|
|
195
|
+
Current: 42 smells
|
|
196
|
+
Previous: 48 smells
|
|
197
|
+
Change: -12.5%
|
|
198
|
+
Trend: IMPROVING
|
|
199
|
+
|
|
200
|
+
✅ Health Score: 72/100 (good)
|
|
201
|
+
|
|
202
|
+
📊 Metrics
|
|
203
|
+
• Daily Velocity: 0.75 smells/day (improving)
|
|
204
|
+
• Consistency: 85%
|
|
205
|
+
• Volatility: 2.1
|
|
206
|
+
|
|
207
|
+
🔮 Predictions
|
|
208
|
+
• Next Month: ~35 smells
|
|
209
|
+
• Trajectory: DOWNWARD
|
|
210
|
+
• Confidence: 92%
|
|
211
|
+
• Days to Zero Smells: 56
|
|
212
|
+
|
|
213
|
+
✨ Improvements
|
|
214
|
+
• useEffect-overuse (3 fewer)
|
|
215
|
+
• prop-drilling (2 fewer)
|
|
216
|
+
|
|
217
|
+
💡 Recommendations
|
|
218
|
+
🟢 Path to Code Smell-Free Codebase
|
|
219
|
+
At the current improvement rate, your codebase could be
|
|
220
|
+
smell-free in approximately 56 days. Focus on maintaining
|
|
221
|
+
this momentum.
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
**Configuration:**
|
|
225
|
+
```json
|
|
226
|
+
{
|
|
227
|
+
"baselineEnabled": true,
|
|
228
|
+
"trendAnalysisEnabled": true,
|
|
229
|
+
"trendReportFrequency": "weekly",
|
|
230
|
+
"predictiveDaysLookahead": 30
|
|
231
|
+
}
|
|
124
232
|
```
|
|
125
233
|
|
|
234
|
+
### PDF Report Generation
|
|
235
|
+
|
|
236
|
+
Generate professional, printable PDF reports with visual analytics:
|
|
237
|
+
|
|
238
|
+
```bash
|
|
239
|
+
# Generate PDF report
|
|
240
|
+
react-smell ./src -f pdf -o smell-report.pdf
|
|
241
|
+
|
|
242
|
+
# Include code snippets in PDF
|
|
243
|
+
react-smell ./src -f pdf -o report.pdf --snippets
|
|
244
|
+
|
|
245
|
+
# Generate PDF with trend analysis
|
|
246
|
+
react-smell ./src -f pdf -o report.pdf --baseline --trend-analysis
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
**PDF Report Contents:**
|
|
250
|
+
- Executive Summary with key metrics
|
|
251
|
+
- Technical Debt Grade with visual indicators
|
|
252
|
+
- Smell breakdown by type and severity
|
|
253
|
+
- Top affected files with risk levels
|
|
254
|
+
- Detailed smell analysis with code snippets
|
|
255
|
+
- Actionable recommendations prioritized by impact
|
|
256
|
+
- Trend analysis and predictions
|
|
257
|
+
- Estimated refactoring timeline
|
|
258
|
+
|
|
259
|
+
**Visual Elements:**
|
|
260
|
+
- Color-coded severity levels (error/warning/info)
|
|
261
|
+
- Grade badges with color gradients
|
|
262
|
+
- Data visualizations and charts
|
|
263
|
+
- Summary metrics in card layout
|
|
264
|
+
- Code snippets with syntax highlighting
|
|
265
|
+
- Professional typography and layout
|
|
266
|
+
|
|
267
|
+
**Use Cases:**
|
|
268
|
+
- Share reports with stakeholders
|
|
269
|
+
- Archive analysis history
|
|
270
|
+
- Print for code review meetings
|
|
271
|
+
- Executive dashboards
|
|
272
|
+
- Compliance documentation
|
|
273
|
+
|
|
126
274
|
### Configuration
|
|
127
275
|
|
|
128
276
|
Create a `.smellrc.json` file:
|
|
@@ -142,11 +290,28 @@ Or create manually:
|
|
|
142
290
|
}
|
|
143
291
|
```
|
|
144
292
|
|
|
293
|
+
Create a `.smellrc.json` file:
|
|
294
|
+
|
|
295
|
+
```bash
|
|
296
|
+
react-smell init
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
Or create manually:
|
|
300
|
+
|
|
301
|
+
```json
|
|
302
|
+
{
|
|
303
|
+
"maxUseEffectsPerComponent": 3,
|
|
304
|
+
"maxPropDrillingDepth": 3,
|
|
305
|
+
"maxComponentLines": 300,
|
|
306
|
+
"maxPropsCount": 7
|
|
307
|
+
}
|
|
308
|
+
```
|
|
309
|
+
|
|
145
310
|
### CLI Options
|
|
146
311
|
|
|
147
312
|
| Option | Description | Default |
|
|
148
313
|
|--------|-------------|---------|
|
|
149
|
-
| `-f, --format <format>` | Output format: console, json, markdown, html | `console` |
|
|
314
|
+
| `-f, --format <format>` | Output format: console, json, markdown, html, pdf | `console` |
|
|
150
315
|
| `-s, --snippets` | Show code snippets in output | `false` |
|
|
151
316
|
| `-c, --config <file>` | Path to config file | `.smellrc.json` |
|
|
152
317
|
| `--ci` | CI mode: exit with code 1 if any issues | `false` |
|
|
@@ -161,6 +326,8 @@ Or create manually:
|
|
|
161
326
|
| `--exclude <patterns>` | Glob patterns to exclude | `node_modules,dist` |
|
|
162
327
|
| `-o, --output <file>` | Write output to file | - |
|
|
163
328
|
| `--baseline` | Enable baseline tracking and trend analysis | `false` |
|
|
329
|
+
| `--trend-analysis` | Show detailed trend analysis and predictions | `false` |
|
|
330
|
+
| `--trend-report` | Generate comprehensive trend report | `false` |
|
|
164
331
|
| `--slack <url>` | Slack webhook URL for notifications | - |
|
|
165
332
|
| `--discord <url>` | Discord webhook URL for notifications | - |
|
|
166
333
|
| `--webhook <url>` | Generic webhook URL for notifications | - |
|
|
@@ -618,6 +785,11 @@ react-smell ./src
|
|
|
618
785
|
import {
|
|
619
786
|
analyzeProject,
|
|
620
787
|
reportResults,
|
|
788
|
+
// PDF Reporting
|
|
789
|
+
generatePDFReport,
|
|
790
|
+
// Trend Analytics
|
|
791
|
+
analyzeTrends,
|
|
792
|
+
formatTrendAnalysis,
|
|
621
793
|
// Interactive fixing
|
|
622
794
|
runInteractiveFix,
|
|
623
795
|
previewFixes,
|
|
@@ -631,6 +803,9 @@ import {
|
|
|
631
803
|
// Documentation
|
|
632
804
|
generateComponentDocs,
|
|
633
805
|
writeComponentDocs,
|
|
806
|
+
// Baseline & Trends
|
|
807
|
+
recordBaseline,
|
|
808
|
+
initializeBaseline,
|
|
634
809
|
} from 'react-code-smell-detector';
|
|
635
810
|
|
|
636
811
|
const result = await analyzeProject({
|
|
@@ -646,6 +821,28 @@ const result = await analyzeProject({
|
|
|
646
821
|
console.log(`Grade: ${result.debtScore.grade}`);
|
|
647
822
|
console.log(`Total issues: ${result.summary.totalSmells}`);
|
|
648
823
|
|
|
824
|
+
// Generate PDF report
|
|
825
|
+
await generatePDFReport(result, {
|
|
826
|
+
outputPath: './report.pdf',
|
|
827
|
+
rootDir: './src',
|
|
828
|
+
includeCharts: true,
|
|
829
|
+
includeCodeSnippets: true,
|
|
830
|
+
title: 'Code Quality Report',
|
|
831
|
+
});
|
|
832
|
+
|
|
833
|
+
// Record baseline for trend tracking
|
|
834
|
+
initializeBaseline('./');
|
|
835
|
+
const baselineRecord = recordBaseline('./', result.smells);
|
|
836
|
+
|
|
837
|
+
// Analyze trends from baseline history
|
|
838
|
+
// (requires multiple baseline recordings over time)
|
|
839
|
+
import { BaselineData } from 'react-code-smell-detector';
|
|
840
|
+
const baselineData: BaselineData = JSON.parse(
|
|
841
|
+
fs.readFileSync('.smellrc-baseline.json', 'utf-8')
|
|
842
|
+
);
|
|
843
|
+
const trendAnalysis = analyzeTrends(baselineData);
|
|
844
|
+
console.log(formatTrendAnalysis(trendAnalysis));
|
|
845
|
+
|
|
649
846
|
// Check against performance budget
|
|
650
847
|
const budget = await loadBudget();
|
|
651
848
|
const budgetResult = checkBudget(result, budget);
|
|
@@ -662,7 +859,7 @@ const docsPath = await writeComponentDocs(result, './src', {
|
|
|
662
859
|
// Generate PR comment
|
|
663
860
|
const prComment = generatePRComment(result, './src');
|
|
664
861
|
|
|
665
|
-
// Or use the reporter
|
|
862
|
+
// Or use the reporter for any format
|
|
666
863
|
const report = reportResults(result, {
|
|
667
864
|
format: 'markdown',
|
|
668
865
|
showCodeSnippets: true,
|
|
@@ -670,6 +867,26 @@ const report = reportResults(result, {
|
|
|
670
867
|
});
|
|
671
868
|
```
|
|
672
869
|
|
|
870
|
+
**Trend Analytics API:**
|
|
871
|
+
```typescript
|
|
872
|
+
import { TrendAnalysis, TrendPrediction } from 'react-code-smell-detector';
|
|
873
|
+
|
|
874
|
+
// Access trend data
|
|
875
|
+
const currentHealth = trendAnalysis.healthScore; // HealthScore
|
|
876
|
+
const predictions = trendAnalysis.predictions; // TrendPrediction
|
|
877
|
+
const metrics = trendAnalysis.metrics; // TrendMetrics
|
|
878
|
+
const recommendations = trendAnalysis.recommendations; // TrendRecommendation[]
|
|
879
|
+
|
|
880
|
+
// Timeline to zero smells
|
|
881
|
+
if (predictions.daysToZeroSmells) {
|
|
882
|
+
console.log(`Projected zero smells in ${predictions.daysToZeroSmells} days`);
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
// Access velocity and consistency metrics
|
|
886
|
+
console.log(`Daily Velocity: ${metrics.velocityPerDay} smells/day`);
|
|
887
|
+
console.log(`Consistency: ${metrics.consistency}%`);
|
|
888
|
+
```
|
|
889
|
+
|
|
673
890
|
## CI/CD Integration
|
|
674
891
|
|
|
675
892
|
The tool provides flexible exit codes and notification capabilities for CI/CD pipelines:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-code-smell-detector",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.2",
|
|
4
4
|
"description": "Detect code smells in React projects - useEffect overuse, prop drilling, large components, security issues, accessibility, memory leaks, React 19 Server Components, and more",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|