react-code-smell-detector 1.4.1 → 1.5.0

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 (56) hide show
  1. package/README.md +347 -22
  2. package/dist/__tests__/parser.test.d.ts +2 -0
  3. package/dist/__tests__/parser.test.d.ts.map +1 -0
  4. package/dist/__tests__/parser.test.js +56 -0
  5. package/dist/__tests__/performanceBudget.test.d.ts +2 -0
  6. package/dist/__tests__/performanceBudget.test.d.ts.map +1 -0
  7. package/dist/__tests__/performanceBudget.test.js +91 -0
  8. package/dist/__tests__/prComments.test.d.ts +2 -0
  9. package/dist/__tests__/prComments.test.d.ts.map +1 -0
  10. package/dist/__tests__/prComments.test.js +118 -0
  11. package/dist/analyzer.d.ts.map +1 -1
  12. package/dist/analyzer.js +34 -1
  13. package/dist/bundleAnalyzer.d.ts +25 -0
  14. package/dist/bundleAnalyzer.d.ts.map +1 -0
  15. package/dist/bundleAnalyzer.js +375 -0
  16. package/dist/cli.js +148 -1
  17. package/dist/customRules.d.ts +31 -0
  18. package/dist/customRules.d.ts.map +1 -0
  19. package/dist/customRules.js +289 -0
  20. package/dist/detectors/complexity.d.ts +0 -4
  21. package/dist/detectors/complexity.d.ts.map +1 -1
  22. package/dist/detectors/complexity.js +1 -1
  23. package/dist/detectors/deadCode.d.ts +0 -7
  24. package/dist/detectors/deadCode.d.ts.map +1 -1
  25. package/dist/detectors/deadCode.js +0 -24
  26. package/dist/detectors/index.d.ts +3 -2
  27. package/dist/detectors/index.d.ts.map +1 -1
  28. package/dist/detectors/index.js +4 -2
  29. package/dist/detectors/serverComponents.d.ts +11 -0
  30. package/dist/detectors/serverComponents.d.ts.map +1 -0
  31. package/dist/detectors/serverComponents.js +222 -0
  32. package/dist/docGenerator.d.ts +37 -0
  33. package/dist/docGenerator.d.ts.map +1 -0
  34. package/dist/docGenerator.js +306 -0
  35. package/dist/git.d.ts.map +1 -1
  36. package/dist/git.js +0 -7
  37. package/dist/graphGenerator.d.ts +34 -0
  38. package/dist/graphGenerator.d.ts.map +1 -0
  39. package/dist/graphGenerator.js +320 -0
  40. package/dist/index.d.ts +4 -0
  41. package/dist/index.d.ts.map +1 -1
  42. package/dist/index.js +4 -0
  43. package/dist/interactiveFixer.d.ts +20 -0
  44. package/dist/interactiveFixer.d.ts.map +1 -0
  45. package/dist/interactiveFixer.js +178 -0
  46. package/dist/performanceBudget.d.ts +54 -0
  47. package/dist/performanceBudget.d.ts.map +1 -0
  48. package/dist/performanceBudget.js +218 -0
  49. package/dist/prComments.d.ts +47 -0
  50. package/dist/prComments.d.ts.map +1 -0
  51. package/dist/prComments.js +233 -0
  52. package/dist/reporter.js +2 -0
  53. package/dist/types/index.d.ts +7 -1
  54. package/dist/types/index.d.ts.map +1 -1
  55. package/dist/types/index.js +10 -0
  56. package/package.json +10 -4
package/dist/cli.js CHANGED
@@ -11,12 +11,18 @@ import { startWatch } from './watcher.js';
11
11
  import { getAllModifiedFiles, filterReactFiles, getGitInfo } from './git.js';
12
12
  import { initializeBaseline, recordBaseline, formatTrendReport } from './baseline.js';
13
13
  import { sendWebhookNotification, getWebhookConfig } from './webhooks.js';
14
+ import { generateDependencyGraphHTML } from './graphGenerator.js';
15
+ import { generateBundleReport } from './bundleAnalyzer.js';
16
+ import { runInteractiveFix, previewFixes } from './interactiveFixer.js';
17
+ import { generatePRComment, postPRComment, parseGitHubInfo, getPRNumber } from './prComments.js';
18
+ import { loadBudget, checkBudget, formatBudgetReport, createBudgetConfig } from './performanceBudget.js';
19
+ import { writeComponentDocs } from './docGenerator.js';
14
20
  import fs from 'fs/promises';
15
21
  const program = new Command();
16
22
  program
17
23
  .name('react-smell')
18
24
  .description('Detect code smells in React projects')
19
- .version('1.3.0')
25
+ .version('1.5.0')
20
26
  .argument('[directory]', 'Directory to analyze', '.')
21
27
  .option('-f, --format <format>', 'Output format: console, json, markdown, html', 'console')
22
28
  .option('-s, --snippets', 'Show code snippets in output', false)
@@ -37,6 +43,17 @@ program
37
43
  .option('--discord <url>', 'Discord webhook URL for notifications')
38
44
  .option('--webhook <url>', 'Generic webhook URL for notifications')
39
45
  .option('--webhook-threshold <number>', 'Only notify if smells exceed this threshold', parseInt)
46
+ .option('--graph', 'Generate dependency graph visualization', false)
47
+ .option('--graph-format <format>', 'Graph output format: svg, html', 'html')
48
+ .option('--bundle', 'Analyze bundle size impact per component', false)
49
+ .option('--rules <file>', 'Custom rules configuration file')
50
+ .option('--fix-interactive', 'Interactive fix mode: review and apply fixes one by one')
51
+ .option('--fix-preview', 'Preview fixable issues without applying')
52
+ .option('--pr-comment', 'Generate PR comment (for GitHub Actions)')
53
+ .option('--budget', 'Check against performance budget')
54
+ .option('--budget-config <file>', 'Path to budget config file')
55
+ .option('--docs', 'Generate component documentation')
56
+ .option('--docs-format <format>', 'Documentation format: markdown, html, json', 'markdown')
40
57
  .action(async (directory, options) => {
41
58
  const rootDir = path.resolve(process.cwd(), directory);
42
59
  // Check if directory exists
@@ -60,6 +77,18 @@ program
60
77
  process.exit(1);
61
78
  }
62
79
  }
80
+ // Load custom rules if specified
81
+ let customRules;
82
+ if (options.rules) {
83
+ try {
84
+ const rulesPath = path.resolve(process.cwd(), options.rules);
85
+ const rulesContent = await fs.readFile(rulesPath, 'utf-8');
86
+ customRules = JSON.parse(rulesContent);
87
+ }
88
+ catch (error) {
89
+ console.warn(chalk.yellow(`Warning: Could not load custom rules: ${error.message}`));
90
+ }
91
+ }
63
92
  // Build config from options
64
93
  const config = {
65
94
  ...DEFAULT_CONFIG,
@@ -67,6 +96,10 @@ program
67
96
  ...(options.maxEffects && { maxUseEffectsPerComponent: options.maxEffects }),
68
97
  ...(options.maxProps && { maxPropsCount: options.maxProps }),
69
98
  ...(options.maxLines && { maxComponentLines: options.maxLines }),
99
+ ...(options.graph && { generateDependencyGraph: true }),
100
+ ...(options.graphFormat && { graphOutputFormat: options.graphFormat }),
101
+ ...(options.bundle && { analyzeBundleSize: true }),
102
+ ...(customRules && { customRules }),
70
103
  };
71
104
  const include = options.include?.split(',').map((p) => p.trim()) || ['**/*.tsx', '**/*.jsx'];
72
105
  const exclude = options.exclude?.split(',').map((p) => p.trim()) || ['**/node_modules/**', '**/dist/**'];
@@ -144,6 +177,59 @@ program
144
177
  console.log(chalk.yellow('\nNo auto-fixable issues found\n'));
145
178
  }
146
179
  }
180
+ // Interactive fix mode
181
+ if (options.fixInteractive) {
182
+ const allSmells = result.files.flatMap(f => f.smells);
183
+ await runInteractiveFix({ smells: allSmells, rootDir, showDiff: true });
184
+ }
185
+ // Fix preview mode
186
+ if (options.fixPreview) {
187
+ const allSmells = result.files.flatMap(f => f.smells);
188
+ previewFixes(allSmells, rootDir);
189
+ }
190
+ // Performance budget check
191
+ if (options.budget) {
192
+ const budget = await loadBudget(options.budgetConfig);
193
+ const budgetResult = checkBudget(result, budget);
194
+ console.log(formatBudgetReport(budgetResult));
195
+ if (!budgetResult.passed && options.ci) {
196
+ process.exit(1);
197
+ }
198
+ }
199
+ // Generate documentation
200
+ if (options.docs) {
201
+ const docsPath = await writeComponentDocs(result, rootDir, {
202
+ format: options.docsFormat || 'markdown',
203
+ includeSmells: true,
204
+ includeMetrics: true,
205
+ groupByFolder: true,
206
+ });
207
+ console.log(chalk.green(`✓ Component documentation written to ${docsPath}`));
208
+ }
209
+ // PR comment generation (for GitHub Actions)
210
+ if (options.prComment) {
211
+ const comment = generatePRComment(result, rootDir);
212
+ // Try to post to GitHub if in Actions environment
213
+ const ghToken = process.env.GITHUB_TOKEN;
214
+ const ghInfo = parseGitHubInfo();
215
+ const prNumber = getPRNumber();
216
+ if (ghToken && ghInfo && prNumber) {
217
+ const posted = await postPRComment({
218
+ token: ghToken,
219
+ owner: ghInfo.owner,
220
+ repo: ghInfo.repo,
221
+ prNumber,
222
+ }, comment);
223
+ if (posted) {
224
+ console.log(chalk.green('✓ PR comment posted successfully'));
225
+ }
226
+ }
227
+ else {
228
+ // Output comment to console/file for manual use
229
+ console.log(chalk.cyan('\n📝 PR Comment (copy to GitHub):\n'));
230
+ console.log(comment);
231
+ }
232
+ }
147
233
  let output;
148
234
  if (options.format === 'html') {
149
235
  output = generateHTMLReport(result, rootDir);
@@ -188,6 +274,26 @@ program
188
274
  console.log(chalk.green('✓ Notification sent to webhook'));
189
275
  }
190
276
  }
277
+ // Generate dependency graph if requested
278
+ if (options.graph) {
279
+ const graph = global._dependencyGraph;
280
+ if (graph) {
281
+ const graphHTML = generateDependencyGraphHTML(graph, path.basename(rootDir), graph.circularDependencies.length);
282
+ const graphPath = path.resolve(process.cwd(), 'dependency-graph.html');
283
+ await fs.writeFile(graphPath, graphHTML, 'utf-8');
284
+ console.log(chalk.green(`✓ Dependency graph written to ${graphPath}`));
285
+ }
286
+ }
287
+ // Generate bundle analysis if requested
288
+ if (options.bundle) {
289
+ const bundleAnalysis = global._bundleAnalysis;
290
+ if (bundleAnalysis) {
291
+ const bundleHTML = generateBundleReport(bundleAnalysis, path.basename(rootDir));
292
+ const bundlePath = path.resolve(process.cwd(), 'bundle-analysis.html');
293
+ await fs.writeFile(bundlePath, bundleHTML, 'utf-8');
294
+ console.log(chalk.green(`✓ Bundle analysis written to ${bundlePath}`));
295
+ }
296
+ }
191
297
  // CI/CD exit code handling
192
298
  const { smellsBySeverity } = result.summary;
193
299
  let shouldFail = false;
@@ -243,4 +349,45 @@ program
243
349
  console.log(chalk.green('✓ Created .smellrc.json'));
244
350
  }
245
351
  });
352
+ // Init budget command
353
+ program
354
+ .command('init-budget')
355
+ .description('Create a performance budget configuration file')
356
+ .action(async () => {
357
+ try {
358
+ const budgetPath = await createBudgetConfig();
359
+ console.log(chalk.green(`✓ Created performance budget config at ${budgetPath}`));
360
+ }
361
+ catch (error) {
362
+ console.error(chalk.red(`Error: ${error.message}`));
363
+ process.exit(1);
364
+ }
365
+ });
366
+ // Generate docs command
367
+ program
368
+ .command('docs')
369
+ .description('Generate component documentation')
370
+ .argument('[directory]', 'Directory to analyze', '.')
371
+ .option('-f, --format <format>', 'Output format: markdown, html, json', 'markdown')
372
+ .option('-o, --output <dir>', 'Output directory')
373
+ .action(async (directory, options) => {
374
+ const rootDir = path.resolve(process.cwd(), directory);
375
+ const spinner = ora('Generating documentation...').start();
376
+ try {
377
+ const result = await analyzeProject({ rootDir });
378
+ spinner.stop();
379
+ const docsPath = await writeComponentDocs(result, rootDir, {
380
+ format: options.format,
381
+ outputDir: options.output,
382
+ includeSmells: true,
383
+ includeMetrics: true,
384
+ groupByFolder: true,
385
+ });
386
+ console.log(chalk.green(`✓ Documentation written to ${docsPath}`));
387
+ }
388
+ catch (error) {
389
+ spinner.fail(`Documentation generation failed: ${error.message}`);
390
+ process.exit(1);
391
+ }
392
+ });
246
393
  program.parse();
@@ -0,0 +1,31 @@
1
+ import { CodeSmell } from './types/index.js';
2
+ export interface CustomRule {
3
+ name: string;
4
+ description?: string;
5
+ severity: 'error' | 'warning' | 'info';
6
+ pattern: string | RegExp;
7
+ patternType: 'regex' | 'ast' | 'text';
8
+ message?: string;
9
+ enabled?: boolean;
10
+ }
11
+ export interface CustomRulesConfig {
12
+ rules: CustomRule[];
13
+ enabled?: boolean;
14
+ }
15
+ /**
16
+ * Parse custom rules from configuration
17
+ */
18
+ export declare function parseCustomRules(config: any): CustomRule[];
19
+ /**
20
+ * Detect violations of custom rules
21
+ */
22
+ export declare function detectCustomRuleViolations(component: any, filePath: string, sourceCode: string, customRules: CustomRule[]): CodeSmell[];
23
+ /**
24
+ * Example custom rules configuration
25
+ */
26
+ export declare const EXAMPLE_CUSTOM_RULES: CustomRulesConfig;
27
+ /**
28
+ * Generate custom rules documentation
29
+ */
30
+ export declare function generateRulesDocumentation(): string;
31
+ //# sourceMappingURL=customRules.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"customRules.d.ts","sourceRoot":"","sources":["../src/customRules.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAK7C,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,OAAO,GAAG,SAAS,GAAG,MAAM,CAAC;IACvC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,WAAW,EAAE,OAAO,GAAG,KAAK,GAAG,MAAM,CAAC;IACtC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,UAAU,EAAE,CAAC;IACpB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,GAAG,GAAG,UAAU,EAAE,CAY1D;AAsBD;;GAEG;AACH,wBAAgB,0BAA0B,CACxC,SAAS,EAAE,GAAG,EACd,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,UAAU,EAAE,GACxB,SAAS,EAAE,CA2Bb;AAuDD;;GAEG;AACH,eAAO,MAAM,oBAAoB,EAAE,iBAoClC,CAAC;AAEF;;GAEG;AACH,wBAAgB,0BAA0B,IAAI,MAAM,CA8InD"}
@@ -0,0 +1,289 @@
1
+ import _traverse from '@babel/traverse';
2
+ const traverse = typeof _traverse === 'function' ? _traverse : _traverse.default;
3
+ /**
4
+ * Parse custom rules from configuration
5
+ */
6
+ export function parseCustomRules(config) {
7
+ if (!config.customRules || typeof config.customRules !== 'object') {
8
+ return [];
9
+ }
10
+ const rulesArray = Array.isArray(config.customRules)
11
+ ? config.customRules
12
+ : [config.customRules];
13
+ return rulesArray
14
+ .map((rule) => normalizeRule(rule))
15
+ .filter((rule) => rule !== null);
16
+ }
17
+ /**
18
+ * Normalize and validate a custom rule
19
+ */
20
+ function normalizeRule(rule) {
21
+ if (!rule.name || !rule.pattern) {
22
+ console.warn('Invalid custom rule: missing name or pattern');
23
+ return null;
24
+ }
25
+ return {
26
+ name: rule.name,
27
+ description: rule.description || '',
28
+ severity: rule.severity || 'warning',
29
+ pattern: rule.pattern,
30
+ patternType: rule.patternType || 'text',
31
+ message: rule.message || `Custom rule violation: ${rule.name}`,
32
+ enabled: rule.enabled !== false,
33
+ };
34
+ }
35
+ /**
36
+ * Detect violations of custom rules
37
+ */
38
+ export function detectCustomRuleViolations(component, filePath, sourceCode, customRules) {
39
+ const smells = [];
40
+ for (const rule of customRules) {
41
+ if (!rule.enabled)
42
+ continue;
43
+ const violations = detectRuleViolation(component, sourceCode, rule);
44
+ violations.forEach(violation => {
45
+ smells.push({
46
+ type: 'custom-rule',
47
+ severity: rule.severity,
48
+ message: violation.message,
49
+ file: filePath,
50
+ line: violation.line,
51
+ column: violation.column,
52
+ suggestion: `Follow custom rule: ${rule.name}. ${rule.description || ''}`,
53
+ codeSnippet: violation.snippet,
54
+ });
55
+ });
56
+ }
57
+ return smells;
58
+ }
59
+ /**
60
+ * Detect a single rule violation
61
+ */
62
+ function detectRuleViolation(component, sourceCode, rule) {
63
+ const violations = [];
64
+ if (rule.patternType === 'regex' || rule.patternType === 'text') {
65
+ // Text/regex matching
66
+ const pattern = new RegExp(rule.pattern, 'gm');
67
+ const lines = sourceCode.split('\n');
68
+ for (let i = 0; i < lines.length; i++) {
69
+ const line = lines[i];
70
+ let match;
71
+ if (typeof rule.pattern === 'string') {
72
+ pattern.lastIndex = 0;
73
+ match = pattern.exec(line);
74
+ }
75
+ else {
76
+ match = rule.pattern.exec(line);
77
+ }
78
+ if (match) {
79
+ violations.push({
80
+ line: i + 1,
81
+ column: match.index,
82
+ message: rule.message || `Matches custom pattern: ${rule.pattern}`,
83
+ snippet: line,
84
+ });
85
+ }
86
+ }
87
+ }
88
+ else if (rule.patternType === 'ast') {
89
+ // AST-based matching
90
+ const patternStr = typeof rule.pattern === 'string' ? rule.pattern : String(rule.pattern);
91
+ const handlers = {};
92
+ handlers[patternStr] = (path) => {
93
+ violations.push({
94
+ line: path.node.loc?.start.line || 1,
95
+ column: path.node.loc?.start.column || 0,
96
+ message: rule.message || `Violates AST rule: ${patternStr}`,
97
+ snippet: sourceCode.split('\n')[path.node.loc?.start.line - 1] || '',
98
+ });
99
+ };
100
+ component.path.traverse(handlers);
101
+ }
102
+ return violations;
103
+ }
104
+ /**
105
+ * Example custom rules configuration
106
+ */
107
+ export const EXAMPLE_CUSTOM_RULES = {
108
+ enabled: true,
109
+ rules: [
110
+ {
111
+ name: 'no-hardcoded-strings',
112
+ description: 'Flags hardcoded strings in components (should use i18n)',
113
+ severity: 'warning',
114
+ pattern: '"(hello|world|test|demo|todo)"',
115
+ patternType: 'regex',
116
+ enabled: false,
117
+ },
118
+ {
119
+ name: 'no-px-margins',
120
+ description: 'Disallow px units for margins (use rem or em)',
121
+ severity: 'info',
122
+ pattern: 'margin[^:]*:\\s*\\d+px',
123
+ patternType: 'regex',
124
+ enabled: false,
125
+ },
126
+ {
127
+ name: 'max-inline-styles',
128
+ description: 'Disallow multiple inline style props in JSX',
129
+ severity: 'warning',
130
+ pattern: 'style={{[^}]*[,;][^}]*}}.*style={{',
131
+ patternType: 'regex',
132
+ enabled: false,
133
+ },
134
+ {
135
+ name: 'require-display-name',
136
+ description: 'All components must have a display name',
137
+ severity: 'info',
138
+ pattern: 'displayName',
139
+ patternType: 'text',
140
+ enabled: false,
141
+ },
142
+ ],
143
+ };
144
+ /**
145
+ * Generate custom rules documentation
146
+ */
147
+ export function generateRulesDocumentation() {
148
+ return `# Custom Rules Configuration
149
+
150
+ ## Overview
151
+ Custom rules allow you to define project-specific code quality standards. Add custom rules to your \`.smellrc.json\` configuration.
152
+
153
+ ## Configuration
154
+
155
+ ### Basic Example
156
+
157
+ \`\`\`json
158
+ {
159
+ "customRules": [
160
+ {
161
+ "name": "no-console-logs",
162
+ "description": "Disallow console.log in production code",
163
+ "severity": "warning",
164
+ "pattern": "console\\\\.(log|debug|info)",
165
+ "patternType": "regex",
166
+ "enabled": true
167
+ }
168
+ ]
169
+ }
170
+ \`\`\`
171
+
172
+ ## Rule Properties
173
+
174
+ | Property | Type | Required | Default | Description |
175
+ |----------|------|----------|---------|-------------|
176
+ | name | string | ✓ | - | Unique rule identifier |
177
+ | description | string | | "" | Human-readable description |
178
+ | severity | string | | "warning" | One of: error, warning, info |
179
+ | pattern | string | ✓ | - | Regex pattern or AST node type |
180
+ | patternType | string | | "text" | One of: regex, text, ast |
181
+ | message | string | | Rule pattern | Custom error message |
182
+ | enabled | boolean | | true | Enable/disable rule |
183
+
184
+ ## Pattern Types
185
+
186
+ ### 1. Regex Pattern
187
+ Match against source code using regular expressions.
188
+
189
+ \`\`\`json
190
+ {
191
+ "name": "no-hardcoded-urls",
192
+ "pattern": "https?://[^\\\"']+",
193
+ "patternType": "regex",
194
+ "severity": "warning"
195
+ }
196
+ \`\`\`
197
+
198
+ ### 2. Text Pattern
199
+ Simple string matching (case-sensitive).
200
+
201
+ \`\`\`json
202
+ {
203
+ "name": "no-debugger",
204
+ "pattern": "debugger",
205
+ "patternType": "text",
206
+ "severity": "error"
207
+ }
208
+ \`\`\`
209
+
210
+ ### 3. AST Pattern
211
+ Match against Babel AST node types.
212
+
213
+ \`\`\`json
214
+ {
215
+ "name": "no-nested-functions",
216
+ "pattern": "FunctionExpression",
217
+ "patternType": "ast",
218
+ "severity": "info"
219
+ }
220
+ \`\`\`
221
+
222
+ ## Real-World Examples
223
+
224
+ ### Prevent hardcoded strings for i18n
225
+ \`\`\`json
226
+ {
227
+ "name": "require-i18n",
228
+ "description": "All strings must be internationalized",
229
+ "pattern": "['\\\"]([A-Z][a-z]+\\\\s*){2,}['\\\"]",
230
+ "patternType": "regex",
231
+ "severity": "warning",
232
+ "message": "Hardcoded text found. Use i18n instead."
233
+ }
234
+ \`\`\`
235
+
236
+ ### Enforce accessibility attributes
237
+ \`\`\`json
238
+ {
239
+ "name": "missing-aria-label",
240
+ "description": "Interactive elements need aria-label",
241
+ "pattern": "<(button|input|select)(?!.*aria-label)",
242
+ "patternType": "regex",
243
+ "severity": "error"
244
+ }
245
+ \`\`\`
246
+
247
+ ### No logger calls without context
248
+ \`\`\`json
249
+ {
250
+ "name": "logger-needs-context",
251
+ "description": "Logger calls must include context",
252
+ "pattern": "logger\\\\.(log|warn)\\\\(['\\\"](?!\\\\[)",
253
+ "patternType": "regex",
254
+ "severity": "warning",
255
+ "message": "Logger call missing context. Use: logger.log('[Component]', ...)"
256
+ }
257
+ \`\`\`
258
+
259
+ ### Maximum nesting depth for JSX
260
+ \`\`\`json
261
+ {
262
+ "name": "jsx-nesting-limit",
263
+ "description": "Limit JSX nesting to improve readability",
264
+ "pattern": "<.*>.*<.*>.*<.*>.*<.*>.*<",
265
+ "patternType": "regex",
266
+ "severity": "info"
267
+ }
268
+ \`\`\`
269
+
270
+ ## Using Custom Rules in CLI
271
+
272
+ \`\`\`bash
273
+ # Custom rules are automatically applied with config file
274
+ react-smell ./src -c .smellrc.json
275
+
276
+ # Or create default config with examples
277
+ react-smell init
278
+ \`\`\`
279
+
280
+ ## Tips
281
+
282
+ 1. **Start simple** - Begin with basic regex patterns
283
+ 2. **Test patterns** - Use online regex testers before adding to config
284
+ 3. **Use specific patterns** - Avoid overly broad patterns that match unintended code
285
+ 4. **Document rules** - Always include clear descriptions
286
+ 5. **Set appropriate severity** - Use 'error' for critical rules, 'info' for suggestions
287
+ 6. **Enable progressively** - Start with disabled rules, enable after team agreement
288
+ `;
289
+ }
@@ -10,8 +10,4 @@ export interface ComplexityMetrics {
10
10
  * Detect code complexity issues in a component
11
11
  */
12
12
  export declare function detectComplexity(component: ParsedComponent, filePath: string, sourceCode: string, config: DetectorConfig): CodeSmell[];
13
- /**
14
- * Calculate complexity metrics for a component
15
- */
16
- export declare function calculateComplexityMetrics(component: ParsedComponent): ComplexityMetrics;
17
13
  //# sourceMappingURL=complexity.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"complexity.d.ts","sourceRoot":"","sources":["../../src/detectors/complexity.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAE9D,MAAM,WAAW,iBAAiB;IAChC,oBAAoB,EAAE,MAAM,CAAC;IAC7B,mBAAmB,EAAE,MAAM,CAAC;IAC5B,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,eAAe,EAC1B,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,cAAc,GACrB,SAAS,EAAE,CAqCb;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,SAAS,EAAE,eAAe,GAAG,iBAAiB,CA6BxF"}
1
+ {"version":3,"file":"complexity.d.ts","sourceRoot":"","sources":["../../src/detectors/complexity.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAE9D,MAAM,WAAW,iBAAiB;IAChC,oBAAoB,EAAE,MAAM,CAAC;IAC7B,mBAAmB,EAAE,MAAM,CAAC;IAC5B,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,eAAe,EAC1B,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,cAAc,GACrB,SAAS,EAAE,CAqCb"}
@@ -38,7 +38,7 @@ export function detectComplexity(component, filePath, sourceCode, config) {
38
38
  /**
39
39
  * Calculate complexity metrics for a component
40
40
  */
41
- export function calculateComplexityMetrics(component) {
41
+ function calculateComplexityMetrics(component) {
42
42
  let cyclomaticComplexity = 1;
43
43
  let cognitiveComplexity = 0;
44
44
  component.path.traverse({
@@ -4,11 +4,4 @@ import { CodeSmell, DetectorConfig } from '../types/index.js';
4
4
  * Detects potentially dead code: unused variables, imports, and functions
5
5
  */
6
6
  export declare function detectDeadCode(component: ParsedComponent, filePath: string, sourceCode: string, config?: DetectorConfig): CodeSmell[];
7
- /**
8
- * Detects unused imports at the file level
9
- */
10
- export declare function detectUnusedImports(imports: Map<string, {
11
- source: string;
12
- line: number;
13
- }>, usedInFile: Set<string>, filePath: string, sourceCode: string): CodeSmell[];
14
7
  //# sourceMappingURL=deadCode.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"deadCode.d.ts","sourceRoot":"","sources":["../../src/detectors/deadCode.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAkB,MAAM,oBAAoB,CAAC;AACrE,OAAO,EAAE,SAAS,EAAE,cAAc,EAAkB,MAAM,mBAAmB,CAAC;AAE9E;;GAEG;AACH,wBAAgB,cAAc,CAC5B,SAAS,EAAE,eAAe,EAC1B,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,MAAM,GAAE,cAA+B,GACtC,SAAS,EAAE,CAsHb;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,EACtD,UAAU,EAAE,GAAG,CAAC,MAAM,CAAC,EACvB,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,GACjB,SAAS,EAAE,CAsBb"}
1
+ {"version":3,"file":"deadCode.d.ts","sourceRoot":"","sources":["../../src/detectors/deadCode.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAkB,MAAM,oBAAoB,CAAC;AACrE,OAAO,EAAE,SAAS,EAAE,cAAc,EAAkB,MAAM,mBAAmB,CAAC;AAE9E;;GAEG;AACH,wBAAgB,cAAc,CAC5B,SAAS,EAAE,eAAe,EAC1B,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,MAAM,GAAE,cAA+B,GACtC,SAAS,EAAE,CAsHb"}
@@ -115,27 +115,3 @@ export function detectDeadCode(component, filePath, sourceCode, config = DEFAULT
115
115
  });
116
116
  return smells;
117
117
  }
118
- /**
119
- * Detects unused imports at the file level
120
- */
121
- export function detectUnusedImports(imports, usedInFile, filePath, sourceCode) {
122
- const smells = [];
123
- imports.forEach((info, name) => {
124
- // Skip React imports as they might be used implicitly
125
- if (name === 'React' || info.source === 'react')
126
- return;
127
- if (!usedInFile.has(name)) {
128
- smells.push({
129
- type: 'dead-code',
130
- severity: 'info',
131
- message: `Unused import "${name}" from "${info.source}"`,
132
- file: filePath,
133
- line: info.line,
134
- column: 0,
135
- suggestion: `Remove the unused import: import { ${name} } from '${info.source}'`,
136
- codeSnippet: getCodeSnippet(sourceCode, info.line),
137
- });
138
- }
139
- });
140
- return smells;
141
- }
@@ -6,7 +6,7 @@ export { detectMissingKeys } from './missingKey.js';
6
6
  export { detectHooksRulesViolations } from './hooksRules.js';
7
7
  export { detectDependencyArrayIssues } from './dependencyArray.js';
8
8
  export { detectNestedTernaries } from './nestedTernary.js';
9
- export { detectDeadCode, detectUnusedImports } from './deadCode.js';
9
+ export { detectDeadCode } from './deadCode.js';
10
10
  export { detectMagicValues } from './magicValues.js';
11
11
  export { detectNextjsIssues } from './nextjs.js';
12
12
  export { detectReactNativeIssues } from './reactNative.js';
@@ -16,8 +16,9 @@ export { detectTypescriptIssues } from './typescript.js';
16
16
  export { detectDebugStatements } from './debug.js';
17
17
  export { detectSecurityIssues } from './security.js';
18
18
  export { detectAccessibilityIssues } from './accessibility.js';
19
- export { detectComplexity, calculateComplexityMetrics } from './complexity.js';
19
+ export { detectComplexity } from './complexity.js';
20
20
  export { detectMemoryLeaks } from './memoryLeak.js';
21
21
  export { detectImportIssues, analyzeImports } from './imports.js';
22
22
  export { detectUnusedCode } from './unusedCode.js';
23
+ export { detectServerComponentIssues, detectAsyncComponentIssues } from './serverComponents.js';
23
24
  //# sourceMappingURL=index.d.ts.map
@@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,cAAc,EAAE,MAAM,cAAc,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEnD,OAAO,EAAE,2BAA2B,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAC"}
@@ -6,7 +6,7 @@ export { detectMissingKeys } from './missingKey.js';
6
6
  export { detectHooksRulesViolations } from './hooksRules.js';
7
7
  export { detectDependencyArrayIssues } from './dependencyArray.js';
8
8
  export { detectNestedTernaries } from './nestedTernary.js';
9
- export { detectDeadCode, detectUnusedImports } from './deadCode.js';
9
+ export { detectDeadCode } from './deadCode.js';
10
10
  export { detectMagicValues } from './magicValues.js';
11
11
  // Framework-specific detectors
12
12
  export { detectNextjsIssues } from './nextjs.js';
@@ -19,7 +19,9 @@ export { detectDebugStatements } from './debug.js';
19
19
  export { detectSecurityIssues } from './security.js';
20
20
  export { detectAccessibilityIssues } from './accessibility.js';
21
21
  // Complexity, Memory Leaks, Imports
22
- export { detectComplexity, calculateComplexityMetrics } from './complexity.js';
22
+ export { detectComplexity } from './complexity.js';
23
23
  export { detectMemoryLeaks } from './memoryLeak.js';
24
24
  export { detectImportIssues, analyzeImports } from './imports.js';
25
25
  export { detectUnusedCode } from './unusedCode.js';
26
+ // Server Components (React 19)
27
+ export { detectServerComponentIssues, detectAsyncComponentIssues } from './serverComponents.js';
@@ -0,0 +1,11 @@
1
+ import { ParsedComponent } from '../parser/index.js';
2
+ import { CodeSmell, DetectorConfig } from '../types/index.js';
3
+ /**
4
+ * Detect React 19 Server/Client component boundary issues
5
+ */
6
+ export declare function detectServerComponentIssues(component: ParsedComponent, filePath: string, sourceCode: string, config: DetectorConfig, imports?: string[]): CodeSmell[];
7
+ /**
8
+ * Detect proper async component patterns in React 19
9
+ */
10
+ export declare function detectAsyncComponentIssues(component: ParsedComponent, filePath: string, sourceCode: string, config: DetectorConfig): CodeSmell[];
11
+ //# sourceMappingURL=serverComponents.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serverComponents.d.ts","sourceRoot":"","sources":["../../src/detectors/serverComponents.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAqC9D;;GAEG;AACH,wBAAgB,2BAA2B,CACzC,SAAS,EAAE,eAAe,EAC1B,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,cAAc,EACtB,OAAO,GAAE,MAAM,EAAO,GACrB,SAAS,EAAE,CA+Jb;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CACxC,SAAS,EAAE,eAAe,EAC1B,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,cAAc,GACrB,SAAS,EAAE,CAmCb"}