@sun-asterisk/sunlint 1.2.1 → 1.3.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 (109) hide show
  1. package/CHANGELOG.md +40 -1
  2. package/CONTRIBUTING.md +533 -70
  3. package/README.md +16 -2
  4. package/config/engines/engines-enhanced.json +86 -0
  5. package/config/engines/semantic-config.json +114 -0
  6. package/config/eslint-rule-mapping.json +50 -38
  7. package/config/rule-analysis-strategies.js +18 -2
  8. package/config/rules/enhanced-rules-registry.json +2503 -0
  9. package/config/rules/rules-registry-generated.json +785 -837
  10. package/core/adapters/sunlint-rule-adapter.js +25 -30
  11. package/core/analysis-orchestrator.js +42 -2
  12. package/core/categories.js +52 -0
  13. package/core/category-constants.js +39 -0
  14. package/core/cli-action-handler.js +32 -5
  15. package/core/config-manager.js +111 -0
  16. package/core/config-merger.js +61 -0
  17. package/core/constants/categories.js +168 -0
  18. package/core/constants/defaults.js +165 -0
  19. package/core/constants/engines.js +185 -0
  20. package/core/constants/index.js +30 -0
  21. package/core/constants/rules.js +215 -0
  22. package/core/file-targeting-service.js +128 -7
  23. package/core/interfaces/rule-plugin.interface.js +207 -0
  24. package/core/plugin-manager.js +448 -0
  25. package/core/rule-selection-service.js +42 -15
  26. package/core/semantic-engine.js +560 -0
  27. package/core/semantic-rule-base.js +433 -0
  28. package/core/unified-rule-registry.js +484 -0
  29. package/docs/CONSTANTS-ARCHITECTURE.md +288 -0
  30. package/engines/core/base-engine.js +249 -0
  31. package/engines/engine-factory.js +275 -0
  32. package/engines/eslint-engine.js +180 -30
  33. package/engines/heuristic-engine.js +513 -56
  34. package/integrations/eslint/plugin/index.js +27 -27
  35. package/package.json +11 -6
  36. package/rules/README.md +252 -0
  37. package/rules/common/C002_no_duplicate_code/analyzer.js +65 -0
  38. package/rules/common/C002_no_duplicate_code/config.json +23 -0
  39. package/rules/common/C003_no_vague_abbreviations/analyzer.js +418 -0
  40. package/rules/common/C003_no_vague_abbreviations/config.json +35 -0
  41. package/rules/common/C006_function_naming/analyzer.js +504 -0
  42. package/rules/common/C006_function_naming/config.json +86 -0
  43. package/rules/common/C006_function_naming/smart-analyzer.js +503 -0
  44. package/rules/common/C010_limit_block_nesting/analyzer.js +389 -0
  45. package/rules/common/C012_command_query_separation/analyzer.js +481 -0
  46. package/rules/common/C012_command_query_separation/ast-analyzer.js +495 -0
  47. package/rules/common/C013_no_dead_code/analyzer.js +206 -0
  48. package/rules/common/C014_dependency_injection/analyzer.js +338 -0
  49. package/rules/common/C017_constructor_logic/analyzer.js +314 -0
  50. package/rules/common/C019_log_level_usage/analyzer.js +362 -0
  51. package/rules/common/C019_log_level_usage/config.json +121 -0
  52. package/rules/common/C029_catch_block_logging/analyzer-smart-pipeline.js +755 -0
  53. package/rules/common/C029_catch_block_logging/analyzer.js +141 -0
  54. package/rules/common/C029_catch_block_logging/config.json +59 -0
  55. package/rules/common/C031_validation_separation/analyzer.js +186 -0
  56. package/rules/common/C041_no_sensitive_hardcode/analyzer.js +292 -0
  57. package/rules/common/C041_no_sensitive_hardcode/ast-analyzer.js +296 -0
  58. package/rules/common/C042_boolean_name_prefix/analyzer.js +300 -0
  59. package/rules/common/C043_no_console_or_print/analyzer.js +431 -0
  60. package/rules/common/C047_no_duplicate_retry_logic/analyzer.js +590 -0
  61. package/rules/common/C047_no_duplicate_retry_logic/c047-semantic-rule.js +278 -0
  62. package/rules/common/C047_no_duplicate_retry_logic/symbol-analyzer-enhanced.js +968 -0
  63. package/rules/common/C047_no_duplicate_retry_logic/symbol-config.json +71 -0
  64. package/rules/common/C075_explicit_return_types/analyzer.js +103 -0
  65. package/rules/common/C076_single_test_behavior/analyzer.js +121 -0
  66. package/rules/docs/C002_no_duplicate_code.md +57 -0
  67. package/rules/docs/C031_validation_separation.md +72 -0
  68. package/rules/index.js +162 -0
  69. package/rules/migration/converter.js +385 -0
  70. package/rules/migration/mapping.json +164 -0
  71. package/rules/parser/constants.js +31 -0
  72. package/rules/parser/file-config.js +80 -0
  73. package/rules/parser/rule-parser-simple.js +305 -0
  74. package/rules/parser/rule-parser.js +527 -0
  75. package/rules/security/S015_insecure_tls_certificate/analyzer.js +150 -0
  76. package/rules/security/S015_insecure_tls_certificate/ast-analyzer.js +237 -0
  77. package/rules/security/S023_no_json_injection/analyzer.js +278 -0
  78. package/rules/security/S023_no_json_injection/ast-analyzer.js +359 -0
  79. package/rules/security/S026_json_schema_validation/analyzer.js +251 -0
  80. package/rules/security/S026_json_schema_validation/config.json +27 -0
  81. package/rules/security/S027_no_hardcoded_secrets/analyzer.js +436 -0
  82. package/rules/security/S027_no_hardcoded_secrets/config.json +29 -0
  83. package/rules/security/S029_csrf_protection/analyzer.js +330 -0
  84. package/rules/tests/C002_no_duplicate_code.test.js +50 -0
  85. package/rules/utils/ast-utils.js +191 -0
  86. package/rules/utils/base-analyzer.js +98 -0
  87. package/rules/utils/pattern-matchers.js +239 -0
  88. package/rules/utils/rule-helpers.js +264 -0
  89. package/rules/utils/severity-constants.js +93 -0
  90. package/scripts/category-manager.js +150 -0
  91. package/scripts/generate-rules-registry.js +88 -0
  92. package/scripts/generate_insights.js +188 -0
  93. package/scripts/migrate-rule-registry.js +157 -0
  94. package/scripts/validate-system.js +48 -0
  95. package/.sunlint.json +0 -35
  96. package/config/README.md +0 -88
  97. package/config/engines/eslint-rule-mapping.json +0 -74
  98. package/config/testing/test-s005-working.ts +0 -22
  99. package/engines/tree-sitter-parser.js +0 -0
  100. package/engines/universal-ast-engine.js +0 -0
  101. package/scripts/merge-reports.js +0 -424
  102. package/scripts/test-scripts/README.md +0 -22
  103. package/scripts/test-scripts/test-c041-comparison.js +0 -114
  104. package/scripts/test-scripts/test-c041-eslint.js +0 -67
  105. package/scripts/test-scripts/test-eslint-rules.js +0 -146
  106. package/scripts/test-scripts/test-real-world.js +0 -44
  107. package/scripts/test-scripts/test-rules-on-real-projects.js +0 -86
  108. /package/{config/schemas/sunlint-schema.json → rules/universal/C010/generic.js} +0 -0
  109. /package/{core/multi-rule-runner.js → rules/universal/C010/tree-sitter-analyzer.js} +0 -0
@@ -85,33 +85,33 @@ const s058 = require("./rules/security/s058-no-ssrf.js");
85
85
 
86
86
  module.exports = {
87
87
  rules: {
88
- "c002": c002,
89
- "c003": c003,
90
- "c006": c006,
91
- "c010": c010,
92
- "c013": c013,
93
- "c014": c014,
94
- "c017": c017,
95
- "c018": c018,
96
- "c030": c030,
97
- "c035": c035,
98
- "c023": c023,
99
- "c029": c029,
100
- "c041": c041,
101
- "c042": c042,
102
- "c043": c043,
103
- "c047": c047,
104
- "c072": c072,
105
- "c075": c075,
106
- "c076": c076,
107
- "t002": t002,
108
- "t003": t003,
109
- "t004": t004,
110
- "t007": t007,
111
- "t010": t010,
112
- "t019": t019,
113
- "t020": t020,
114
- "t021": t021,
88
+ "c002-no-duplicate-code": c002,
89
+ "c003-no-vague-abbreviations": c003,
90
+ "c006-function-name-verb-noun": c006,
91
+ "c010-limit-block-nesting": c010,
92
+ "c013-no-dead-code": c013,
93
+ "c014-abstract-dependency-preferred": c014,
94
+ "c017-limit-constructor-logic": c017,
95
+ "c018-no-generic-throw": c018,
96
+ "c030-use-custom-error-classes": c030,
97
+ "c035-no-empty-catch": c035,
98
+ "c023-no-duplicate-variable-name-in-scope": c023,
99
+ "c029-catch-block-logging": c029,
100
+ "c041-no-config-inline": c041,
101
+ "c042-boolean-name-prefix": c042,
102
+ "c043-no-console-or-print": c043,
103
+ "c047-no-duplicate-retry-logic": c047,
104
+ "c072-one-assert-per-test": c072,
105
+ "c075-explicit-function-return-types": c075,
106
+ "c076-single-behavior-per-test": c076,
107
+ "t002-interface-prefix-i": t002,
108
+ "t003-ts-ignore-reason": t003,
109
+ "t004-no-empty-type": t004,
110
+ "t007-no-fn-in-constructor": t007,
111
+ "t010-no-nested-union-tuple": t010,
112
+ "t019-no-this-assign": t019,
113
+ "t020-no-default-multi-export": t020,
114
+ "t021-limit-nested-generics": t021,
115
115
  // Security rules
116
116
  "typescript_s001": s001,
117
117
  "typescript_s002": s002,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sun-asterisk/sunlint",
3
- "version": "1.2.1",
3
+ "version": "1.3.0",
4
4
  "description": "☀️ SunLint - Multi-language static analysis tool for code quality and security | Sun* Engineering Standards",
5
5
  "main": "cli.js",
6
6
  "bin": {
@@ -40,17 +40,18 @@
40
40
  "demo:file-targeting": "./demo-file-targeting.sh",
41
41
  "lint": "node cli.js --config=.sunlint.json --input=.",
42
42
  "lint:eslint-integration": "node cli.js --all --eslint-integration --input=.",
43
- "build": "npm run copy-rules && echo 'Build completed with rules copy'",
43
+ "build": "npm run copy-rules && npm run generate-registry && echo 'Build completed with rules copy and registry generation'",
44
44
  "copy-rules": "node scripts/copy-rules.js",
45
+ "generate-registry": "node scripts/generate-rules-registry.js",
45
46
  "clean": "rm -rf coverage/ *.log reports/ *.tgz",
46
47
  "postpack": "echo '📦 Package created successfully! Size: ' && ls -lh *.tgz | awk '{print $5}'",
47
48
  "start": "node cli.js --help",
48
49
  "version": "node cli.js --version",
49
- "pack": "npm run copy-rules && npm pack",
50
+ "pack": "npm run copy-rules && npm run generate-registry && npm pack",
50
51
  "publish:github": "npm publish --registry=https://npm.pkg.github.com",
51
52
  "publish:npmjs": "npm publish --registry=https://registry.npmjs.org",
52
53
  "publish:test": "npm publish --dry-run --registry=https://registry.npmjs.org",
53
- "prepublishOnly": "npm run clean && npm run copy-rules"
54
+ "prepublishOnly": "npm run clean && npm run copy-rules && npm run generate-registry"
54
55
  },
55
56
  "keywords": [
56
57
  "linting",
@@ -74,6 +75,7 @@
74
75
  "config/",
75
76
  "engines/",
76
77
  "integrations/",
78
+ "rules/",
77
79
  "scripts/",
78
80
  "docs/",
79
81
  ".sunlint.json",
@@ -98,7 +100,8 @@
98
100
  "espree": "^10.3.0",
99
101
  "minimatch": "^10.0.3",
100
102
  "node-fetch": "^3.3.2",
101
- "table": "^6.8.2"
103
+ "table": "^6.8.2",
104
+ "ts-morph": "^26.0.0"
102
105
  },
103
106
  "peerDependencies": {
104
107
  "typescript": ">=4.0.0"
@@ -125,8 +128,10 @@
125
128
  },
126
129
  "devDependencies": {
127
130
  "@types/node": "^22.10.1",
131
+ "eslint-plugin-import": "^2.32.0",
128
132
  "glob": "^11.0.3",
129
- "jest": "^29.7.0"
133
+ "jest": "^29.7.0",
134
+ "typescript": "^5.8.3"
130
135
  },
131
136
  "bugs": {
132
137
  "url": "https://github.com/sun-asterisk/engineer-excellence/issues"
@@ -0,0 +1,252 @@
1
+ # SunLint Heuristic Rules System
2
+
3
+ Enhanced heuristic rules engine with organized rule categories and migration support.
4
+
5
+ ## 📁 Structure
6
+
7
+ ```
8
+ rules/
9
+ ├── # SunLint Heuristic Rules Structure
10
+
11
+ ## 📁 Clean Rule Organization
12
+
13
+ ```
14
+ rules/
15
+ ├── 📚 docs/ # Rule documentation
16
+ │ ├── C002_no_duplicate_code.md
17
+ │ └── C031_validation_separation.md
18
+ ├── 🧪 tests/ # Rule unit tests
19
+ │ └── C002_no_duplicate_code.test.js
20
+ ├── 🛠️ utils/ # Shared utilities
21
+ │ ├── ast-utils.js # AST parsing helpers
22
+ │ ├── pattern-matchers.js # Pattern matching utilities
23
+ │ └── rule-helpers.js # Rule helper functions
24
+ ├── 🔹 common/ # C-series rules (Common standards)
25
+ │ ├── C002_no_duplicate_code/
26
+ │ │ ├── analyzer.js # 🔍 Core analysis logic
27
+ │ │ └── config.json # ⚙️ Rule configuration
28
+ │ ├── C006_function_naming/
29
+ │ ├── C019_log_level_usage/
30
+ │ ├── C029_catch_block_logging/
31
+ │ └── C031_validation_separation/
32
+ ├── 🔒 security/ # S-series rules (Security standards)
33
+ └── 📘 typescript/ # T-series rules (TypeScript specific)
34
+ ```
35
+
36
+ ## ✅ Key Improvements
37
+
38
+ ### **1. Clean Rule Folders**
39
+ - **Before**: `README.md`, `test.js`, `analyzer.js`, `config.json` mixed together
40
+ - **After**: Only **core files** in rule folders (`analyzer.js`, `config.json`)
41
+
42
+ ### **2. Centralized Documentation**
43
+ - **Before**: README scattered in each rule folder
44
+ - **After**: All docs in `rules/docs/[RuleId].md`
45
+
46
+ ### **3. Centralized Testing**
47
+ - **Before**: `test.js` in each rule folder
48
+ - **After**: All tests in `rules/tests/[RuleId].test.js`
49
+
50
+ ### **4. Correct Categorization**
51
+ - **Before**: ❌ `rules/coding/` (incorrect - C ≠ Coding)
52
+ - **After**: ✅ `rules/common/` (correct - C = Common)
53
+
54
+ ## 🔍 Rule Analyzer Structure
55
+
56
+ Each rule analyzer follows a clean structure:
57
+
58
+ ```javascript
59
+ // rules/common/C019_log_level_usage/analyzer.js
60
+ class C019Analyzer {
61
+ constructor() {
62
+ this.ruleId = 'C019';
63
+ this.ruleName = 'Log Level Usage';
64
+ // ...
65
+ }
66
+
67
+ async analyze(files, language, config) {
68
+ // Core analysis logic only
69
+ }
70
+ }
71
+ ```
72
+
73
+ ```json
74
+ // rules/common/C019_log_level_usage/config.json
75
+ {
76
+ "ruleId": "C019",
77
+ "name": "Log Level Usage",
78
+ "description": "Don't use error level for non-critical issues",
79
+ "severity": "warning",
80
+ "languages": ["typescript", "javascript", "dart"]
81
+ }
82
+ ```
83
+
84
+ ## 🚀 Benefits
85
+
86
+ 1. **Clean Separation**: Core logic separated from docs/tests
87
+ 2. **Easy Maintenance**: Find docs/tests in centralized locations
88
+ 3. **Correct Semantics**: C = Common (not Coding)
89
+ 4. **Scalable**: Easy to add new rules/categories
90
+ 5. **Engine Compatible**: Heuristic engine auto-discovers all rules
91
+
92
+ ## 📊 Migration Summary
93
+
94
+ | **Aspect** | **Before** | **After** |
95
+ |------------|------------|-----------|
96
+ | **Rule Folders** | Mixed content | Core only (`analyzer.js`, `config.json`) |
97
+ | **Documentation** | Scattered | Centralized in `docs/` |
98
+ | **Tests** | Scattered | Centralized in `tests/` |
99
+ | **Categories** | ❌ `coding/` | ✅ `common/` |
100
+ | **Structure** | Flat | Nested by category |
101
+ | **Discoverable Rules** | 0 (broken) | 5 (working) |
102
+
103
+ ---
104
+ *Rules structure cleaned and optimized for maintainability! 🎉*
105
+ ├── index.js # Rule registry and loader
106
+ ├── common/ # 🛠️ Shared utilities
107
+ │ ├── ast-utils.js # AST parsing utilities
108
+ │ ├── pattern-matchers.js # Common pattern matching
109
+ │ └── rule-helpers.js # Rule development helpers
110
+ ├── coding/ # 🔹 C-series: Coding standards (4 → expanding)
111
+ │ ├── C006_function_naming/ # Function naming conventions
112
+ │ ├── C019_log_level_usage/ # Log level usage patterns
113
+ │ ├── C029_catch_block_logging/ # Exception logging standards
114
+ │ └── C031_validation_separation/ # Input validation separation
115
+ ├── security/ # 🔒 S-series: Security rules (0 → 49 planned)
116
+ │ └── (ready for migration from ESLint)
117
+ ├── typescript/ # 📘 T-series: TypeScript rules (0 → 10 planned)
118
+ │ └── (ready for migration from ESLint)
119
+ └── migration/ # 🔄 ESLint → Heuristic migration
120
+ ├── mapping.json # Rule mapping configuration
121
+ ├── converter.js # Auto-migration tool
122
+ └── compatibility.js # Compatibility layer
123
+ ```
124
+
125
+ ## 🎯 Current Status
126
+
127
+ ### ✅ **Active Heuristic Rules (4)**
128
+ | Rule ID | Name | Type | Status |
129
+ |---------|------|------|--------|
130
+ | **C006** | Function Naming | Coding | ✅ Production |
131
+ | **C019** | Log Level Usage | Coding | ✅ Production |
132
+ | **C029** | Catch Block Logging | Coding | ✅ Production |
133
+ | **C031** | Validation Separation | Coding | ✅ Production |
134
+
135
+ ### 🚀 **Migration Pipeline (77 rules)**
136
+ | Category | ESLint Rules | Heuristic Target | Status |
137
+ |----------|--------------|------------------|--------|
138
+ | **Coding** | 22 rules | rules/coding/ | 🔄 Ready for migration |
139
+ | **Security** | 49 rules | rules/security/ | 🔄 Ready for migration |
140
+ | **TypeScript** | 10 rules | rules/typescript/ | 🔄 Ready for migration |
141
+
142
+ ## 🛠️ Rule Development
143
+
144
+ ### **Heuristic Rule Structure**
145
+ Each rule follows this standard structure:
146
+ ```
147
+ rules/{category}/{RULE_ID}/
148
+ ├── analyzer.js # Core heuristic logic
149
+ ├── config.json # Rule configuration
150
+ ├── test.js # Rule-specific tests
151
+ └── README.md # Rule documentation
152
+ ```
153
+
154
+ ### **Rule Development Helpers**
155
+ Use shared utilities in `rules/common/`:
156
+ - `ast-utils.js` - AST traversal and analysis
157
+ - `pattern-matchers.js` - Common code pattern detection
158
+ - `rule-helpers.js` - Rule configuration and reporting
159
+
160
+ ### **Example: Adding New Rule**
161
+ ```bash
162
+ # Create new coding rule
163
+ mkdir rules/coding/C045_new_rule/
164
+ cd rules/coding/C045_new_rule/
165
+
166
+ # Create rule files
167
+ touch analyzer.js config.json test.js README.md
168
+ ```
169
+
170
+ ## 🔄 Migration Process
171
+
172
+ ### **ESLint → Heuristic Migration**
173
+
174
+ 1. **Mapping**: Define rule equivalencies in `migration/mapping.json`
175
+ ```json
176
+ {
177
+ "eslint": "c006-function-name-verb-noun",
178
+ "heuristic": "C006_function_naming",
179
+ "compatibility": "partial",
180
+ "migration_priority": "high"
181
+ }
182
+ ```
183
+
184
+ 2. **Conversion**: Use `migration/converter.js` for automated migration
185
+ ```bash
186
+ node rules/migration/converter.js --rule=C006 --target=heuristic
187
+ ```
188
+
189
+ 3. **Testing**: Validate against existing ESLint rule behavior
190
+ ```bash
191
+ node rules/migration/compatibility.js --test=C006
192
+ ```
193
+
194
+ ## 🚀 Future Expansion
195
+
196
+ ### **Phase 2A: Security Rules Migration**
197
+ Target: Migrate 49 security rules to heuristic engine
198
+ - Priority: S001, S003, S012 (critical security)
199
+ - Timeline: After ESLint deprecation decision
200
+
201
+ ### **Phase 2B: TypeScript Rules Migration**
202
+ Target: Migrate 10 TypeScript rules to heuristic engine
203
+ - Priority: T002, T003, T004 (interface standards)
204
+ - Timeline: Post security migration
205
+
206
+ ### **Phase 3: Advanced Heuristics**
207
+ - Multi-file analysis capabilities
208
+ - Cross-language rule support
209
+ - AI-assisted pattern detection
210
+
211
+ ## 📊 Engine Comparison
212
+
213
+ | Feature | ESLint Engine | Heuristic Engine | Status |
214
+ |---------|---------------|------------------|--------|
215
+ | **Rules Count** | 81 rules | 4 → 81 rules | 🔄 Migration |
216
+ | **Performance** | AST heavy | Pattern optimized | 🚀 Faster |
217
+ | **Languages** | JS/TS only | Multi-language | 🌟 Flexible |
218
+ | **Customization** | Limited | Full control | ✅ Better |
219
+ | **Maintenance** | ESLint dependent | Self-contained | 🛡️ Stable |
220
+
221
+ ## 🎯 Integration
222
+
223
+ ### **Engine Loading**
224
+ The heuristic engine automatically loads rules from this structure:
225
+ ```javascript
226
+ // core/analysis-orchestrator.js
227
+ const heuristicRules = require('../rules/index.js');
228
+ ```
229
+
230
+ ### **Rule Registry**
231
+ All rules are registered in `rules/index.js`:
232
+ ```javascript
233
+ module.exports = {
234
+ coding: {
235
+ C006: require('./coding/C006_function_naming/analyzer.js'),
236
+ C019: require('./coding/C019_log_level_usage/analyzer.js'),
237
+ // ...
238
+ },
239
+ security: {
240
+ // Ready for S-series rules
241
+ },
242
+ typescript: {
243
+ // Ready for T-series rules
244
+ }
245
+ };
246
+ ```
247
+
248
+ ---
249
+
250
+ **🏗️ Architecture**: Scalable, organized, migration-ready
251
+ **🎯 Goal**: 81 heuristic rules (ESLint independence)
252
+ **🚀 Status**: 4 active, 77 ready for migration
@@ -0,0 +1,65 @@
1
+ /**
2
+ * C002_no_duplicate_code - Heuristic Rule Analyzer
3
+ * Category: coding
4
+ *
5
+ * TODO: Migrate logic from ESLint rule
6
+ * ESLint rule: integrations/eslint/plugin/rules/coding/c002-no_duplicate_code.js
7
+ */
8
+
9
+ const ts = require('typescript');
10
+ const { PatternMatcher } = require('../../utils/pattern-matchers');
11
+ const { RuleHelper } = require('../../utils/rule-helpers');
12
+
13
+ class C002_no_duplicate_codeAnalyzer {
14
+ constructor(config = {}) {
15
+ this.config = config;
16
+ this.patternMatcher = new PatternMatcher();
17
+ this.helper = new RuleHelper();
18
+ }
19
+
20
+ /**
21
+ * Analyze code content for rule violations
22
+ * @param {string} content - File content
23
+ * @param {string} filePath - File path
24
+ * @param {Object} context - Analysis context
25
+ * @returns {Array} Array of violations
26
+ */
27
+ analyze(content, filePath, context = {}) {
28
+ const violations = [];
29
+
30
+ // TODO: Implement heuristic analysis logic
31
+ // This should replicate the ESLint rule behavior using pattern matching
32
+
33
+ try {
34
+ // Example pattern-based analysis
35
+ // const patterns = this.getViolationPatterns();
36
+ // const matches = this.patternMatcher.findMatches(content, patterns);
37
+ //
38
+ // matches.forEach(match => {
39
+ // violations.push(this.helper.createViolation({
40
+ // ruleId: 'C002_no_duplicate_code',
41
+ // message: 'Rule violation detected',
42
+ // line: match.line,
43
+ // column: match.column,
44
+ // severity: 'error'
45
+ // }));
46
+ // });
47
+
48
+ } catch (error) {
49
+ console.warn(`Error analyzing ${filePath} with C002_no_duplicate_code:`, error.message);
50
+ }
51
+
52
+ return violations;
53
+ }
54
+
55
+ /**
56
+ * Get violation patterns for this rule
57
+ * @returns {Array} Array of patterns to match
58
+ */
59
+ getViolationPatterns() {
60
+ // TODO: Define patterns based on ESLint rule logic
61
+ return [];
62
+ }
63
+ }
64
+
65
+ module.exports = C002_no_duplicate_codeAnalyzer;
@@ -0,0 +1,23 @@
1
+ {
2
+ "id": "C002_no_duplicate_code",
3
+ "name": "C002_no_duplicate_code",
4
+ "category": "coding",
5
+ "description": "C002_no_duplicate_code heuristic rule - migrated from ESLint",
6
+ "severity": "error",
7
+ "enabled": true,
8
+ "migration": {
9
+ "from_eslint": "c002-no-duplicate-code",
10
+ "compatibility": "partial",
11
+ "status": "pending"
12
+ },
13
+ "patterns": {
14
+ "include": [
15
+ "**/*.js",
16
+ "**/*.ts"
17
+ ],
18
+ "exclude": [
19
+ "**/*.test.*",
20
+ "**/*.spec.*"
21
+ ]
22
+ }
23
+ }