@sun-asterisk/sunlint 1.1.7 → 1.2.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.
- package/.sunlint.json +1 -1
- package/CHANGELOG.md +83 -0
- package/README.md +66 -4
- package/config/presets/all.json +125 -0
- package/config/presets/beginner.json +16 -8
- package/config/presets/ci.json +12 -4
- package/config/presets/maintainability.json +38 -0
- package/config/presets/performance.json +32 -0
- package/config/presets/quality.json +103 -0
- package/config/presets/recommended.json +36 -12
- package/config/presets/security.json +88 -0
- package/config/presets/strict.json +15 -5
- package/config/rules/rules-registry-generated.json +6312 -0
- package/config/rules-summary.json +1941 -0
- package/core/adapters/sunlint-rule-adapter.js +452 -0
- package/core/analysis-orchestrator.js +4 -4
- package/core/config-manager.js +28 -5
- package/core/rule-selection-service.js +52 -55
- package/docs/CONFIGURATION.md +111 -3
- package/docs/LANGUAGE-SPECIFIC-RULES.md +308 -0
- package/docs/README.md +3 -0
- package/docs/STANDARDIZED-CATEGORY-FILTERING.md +156 -0
- package/engines/eslint-engine.js +92 -2
- package/engines/heuristic-engine.js +8 -31
- package/origin-rules/common-en.md +1320 -0
- package/origin-rules/dart-en.md +289 -0
- package/origin-rules/java-en.md +60 -0
- package/origin-rules/kotlin-mobile-en.md +453 -0
- package/origin-rules/reactjs-en.md +102 -0
- package/origin-rules/security-en.md +1055 -0
- package/origin-rules/swift-en.md +449 -0
- package/origin-rules/typescript-en.md +136 -0
- package/package.json +6 -5
- package/scripts/copy-rules.js +86 -0
- package/rules/README.md +0 -252
- package/rules/common/C002_no_duplicate_code/analyzer.js +0 -65
- package/rules/common/C002_no_duplicate_code/config.json +0 -23
- package/rules/common/C003_no_vague_abbreviations/analyzer.js +0 -418
- package/rules/common/C003_no_vague_abbreviations/config.json +0 -35
- package/rules/common/C006_function_naming/analyzer.js +0 -349
- package/rules/common/C006_function_naming/config.json +0 -86
- package/rules/common/C010_limit_block_nesting/analyzer.js +0 -389
- package/rules/common/C013_no_dead_code/analyzer.js +0 -206
- package/rules/common/C014_dependency_injection/analyzer.js +0 -338
- package/rules/common/C017_constructor_logic/analyzer.js +0 -314
- package/rules/common/C019_log_level_usage/analyzer.js +0 -362
- package/rules/common/C019_log_level_usage/config.json +0 -121
- package/rules/common/C029_catch_block_logging/analyzer.js +0 -373
- package/rules/common/C029_catch_block_logging/config.json +0 -59
- package/rules/common/C031_validation_separation/analyzer.js +0 -186
- package/rules/common/C041_no_sensitive_hardcode/analyzer.js +0 -292
- package/rules/common/C042_boolean_name_prefix/analyzer.js +0 -300
- package/rules/common/C043_no_console_or_print/analyzer.js +0 -304
- package/rules/common/C047_no_duplicate_retry_logic/analyzer.js +0 -351
- package/rules/common/C075_explicit_return_types/analyzer.js +0 -103
- package/rules/common/C076_single_test_behavior/analyzer.js +0 -121
- package/rules/docs/C002_no_duplicate_code.md +0 -57
- package/rules/docs/C031_validation_separation.md +0 -72
- package/rules/index.js +0 -149
- package/rules/migration/converter.js +0 -385
- package/rules/migration/mapping.json +0 -164
- package/rules/security/S026_json_schema_validation/analyzer.js +0 -251
- package/rules/security/S026_json_schema_validation/config.json +0 -27
- package/rules/security/S027_no_hardcoded_secrets/analyzer.js +0 -263
- package/rules/security/S027_no_hardcoded_secrets/config.json +0 -29
- package/rules/security/S029_csrf_protection/analyzer.js +0 -264
- package/rules/tests/C002_no_duplicate_code.test.js +0 -50
- package/rules/universal/C010/generic.js +0 -0
- package/rules/universal/C010/tree-sitter-analyzer.js +0 -0
- package/rules/utils/ast-utils.js +0 -191
- package/rules/utils/base-analyzer.js +0 -98
- package/rules/utils/pattern-matchers.js +0 -239
- package/rules/utils/rule-helpers.js +0 -264
- package/rules/utils/severity-constants.js +0 -93
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Copy all rules files for packaging
|
|
8
|
+
* This script copies all .md rules from ../sunlint/rules/ to ./origin-rules/ for production builds
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const sourceRulesDir = path.join(__dirname, '..', '..', '..', 'rules');
|
|
12
|
+
const targetRulesDir = path.join(__dirname, '..', 'origin-rules');
|
|
13
|
+
|
|
14
|
+
console.log('📋 Copying all rules for packaging...');
|
|
15
|
+
console.log(`Source: ${sourceRulesDir}`);
|
|
16
|
+
console.log(`Target: ${targetRulesDir}`);
|
|
17
|
+
|
|
18
|
+
try {
|
|
19
|
+
// Check if source directory exists
|
|
20
|
+
if (!fs.existsSync(sourceRulesDir)) {
|
|
21
|
+
console.error('❌ Source rules directory not found:', sourceRulesDir);
|
|
22
|
+
console.log('⚠️ Skipping rules copy - will use existing local rules if available');
|
|
23
|
+
process.exit(0); // Don't fail build, just warn
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Create target directory if it doesn't exist
|
|
27
|
+
if (!fs.existsSync(targetRulesDir)) {
|
|
28
|
+
fs.mkdirSync(targetRulesDir, { recursive: true });
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Copy only English rule files (*-en.md) - skip empty base files and catalogs
|
|
32
|
+
const allFiles = fs.readdirSync(sourceRulesDir);
|
|
33
|
+
|
|
34
|
+
const ruleFiles = allFiles.filter(file => {
|
|
35
|
+
// Only include English versions of rule files
|
|
36
|
+
return file.endsWith('-en.md');
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
let copiedCount = 0;
|
|
40
|
+
|
|
41
|
+
console.log(`📁 Found ${ruleFiles.length} English rule files to copy (ignoring empty base files and catalogs)...`);
|
|
42
|
+
|
|
43
|
+
ruleFiles.forEach(fileName => {
|
|
44
|
+
const sourcePath = path.join(sourceRulesDir, fileName);
|
|
45
|
+
const targetPath = path.join(targetRulesDir, fileName);
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
fs.copyFileSync(sourcePath, targetPath);
|
|
49
|
+
console.log(`✅ Copied: ${fileName}`);
|
|
50
|
+
copiedCount++;
|
|
51
|
+
} catch (error) {
|
|
52
|
+
console.error(`❌ Failed to copy ${fileName}:`, error.message);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
// Also copy any CSV or other rule-related files (if they have content)
|
|
57
|
+
const csvFiles = allFiles.filter(file => file.endsWith('.csv'));
|
|
58
|
+
csvFiles.forEach(fileName => {
|
|
59
|
+
const sourcePath = path.join(sourceRulesDir, fileName);
|
|
60
|
+
const targetPath = path.join(targetRulesDir, fileName);
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
// Check if file has content
|
|
64
|
+
const stats = fs.statSync(sourcePath);
|
|
65
|
+
if (stats.size > 0) {
|
|
66
|
+
fs.copyFileSync(sourcePath, targetPath);
|
|
67
|
+
console.log(`✅ Copied CSV: ${fileName}`);
|
|
68
|
+
copiedCount++;
|
|
69
|
+
} else {
|
|
70
|
+
console.log(`⚠️ Skipped empty CSV: ${fileName}`);
|
|
71
|
+
}
|
|
72
|
+
} catch (error) {
|
|
73
|
+
console.log(`⚠️ Could not copy ${fileName}: ${error.message}`);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
if (copiedCount > 0) {
|
|
78
|
+
console.log(`✅ Successfully copied ${copiedCount} rule files to ${targetRulesDir}`);
|
|
79
|
+
} else {
|
|
80
|
+
console.log('⚠️ No files were copied');
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
} catch (error) {
|
|
84
|
+
console.error('❌ Error during rules copy:', error.message);
|
|
85
|
+
process.exit(1);
|
|
86
|
+
}
|
package/rules/README.md
DELETED
|
@@ -1,252 +0,0 @@
|
|
|
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
|
|
@@ -1,65 +0,0 @@
|
|
|
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;
|
|
@@ -1,23 +0,0 @@
|
|
|
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
|
-
}
|