@sun-asterisk/sunlint 1.1.8 → 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.
Files changed (73) hide show
  1. package/.sunlint.json +1 -1
  2. package/CHANGELOG.md +50 -1
  3. package/README.md +66 -4
  4. package/config/presets/all.json +125 -0
  5. package/config/presets/beginner.json +16 -8
  6. package/config/presets/ci.json +12 -4
  7. package/config/presets/maintainability.json +38 -0
  8. package/config/presets/performance.json +32 -0
  9. package/config/presets/quality.json +103 -0
  10. package/config/presets/recommended.json +36 -12
  11. package/config/presets/security.json +88 -0
  12. package/config/presets/strict.json +15 -5
  13. package/config/rules/rules-registry-generated.json +6312 -0
  14. package/config/rules-summary.json +1941 -0
  15. package/core/adapters/sunlint-rule-adapter.js +452 -0
  16. package/core/analysis-orchestrator.js +4 -4
  17. package/core/config-manager.js +28 -5
  18. package/core/rule-selection-service.js +52 -55
  19. package/docs/CONFIGURATION.md +111 -3
  20. package/docs/LANGUAGE-SPECIFIC-RULES.md +308 -0
  21. package/docs/README.md +3 -0
  22. package/docs/STANDARDIZED-CATEGORY-FILTERING.md +156 -0
  23. package/engines/heuristic-engine.js +8 -31
  24. package/origin-rules/common-en.md +1320 -0
  25. package/origin-rules/dart-en.md +289 -0
  26. package/origin-rules/java-en.md +60 -0
  27. package/origin-rules/kotlin-mobile-en.md +453 -0
  28. package/origin-rules/reactjs-en.md +102 -0
  29. package/origin-rules/security-en.md +1055 -0
  30. package/origin-rules/swift-en.md +449 -0
  31. package/origin-rules/typescript-en.md +136 -0
  32. package/package.json +6 -5
  33. package/scripts/copy-rules.js +86 -0
  34. package/rules/README.md +0 -252
  35. package/rules/common/C002_no_duplicate_code/analyzer.js +0 -65
  36. package/rules/common/C002_no_duplicate_code/config.json +0 -23
  37. package/rules/common/C003_no_vague_abbreviations/analyzer.js +0 -418
  38. package/rules/common/C003_no_vague_abbreviations/config.json +0 -35
  39. package/rules/common/C006_function_naming/analyzer.js +0 -349
  40. package/rules/common/C006_function_naming/config.json +0 -86
  41. package/rules/common/C010_limit_block_nesting/analyzer.js +0 -389
  42. package/rules/common/C013_no_dead_code/analyzer.js +0 -206
  43. package/rules/common/C014_dependency_injection/analyzer.js +0 -338
  44. package/rules/common/C017_constructor_logic/analyzer.js +0 -314
  45. package/rules/common/C019_log_level_usage/analyzer.js +0 -362
  46. package/rules/common/C019_log_level_usage/config.json +0 -121
  47. package/rules/common/C029_catch_block_logging/analyzer.js +0 -373
  48. package/rules/common/C029_catch_block_logging/config.json +0 -59
  49. package/rules/common/C031_validation_separation/analyzer.js +0 -186
  50. package/rules/common/C041_no_sensitive_hardcode/analyzer.js +0 -292
  51. package/rules/common/C042_boolean_name_prefix/analyzer.js +0 -300
  52. package/rules/common/C043_no_console_or_print/analyzer.js +0 -304
  53. package/rules/common/C047_no_duplicate_retry_logic/analyzer.js +0 -351
  54. package/rules/common/C075_explicit_return_types/analyzer.js +0 -103
  55. package/rules/common/C076_single_test_behavior/analyzer.js +0 -121
  56. package/rules/docs/C002_no_duplicate_code.md +0 -57
  57. package/rules/docs/C031_validation_separation.md +0 -72
  58. package/rules/index.js +0 -149
  59. package/rules/migration/converter.js +0 -385
  60. package/rules/migration/mapping.json +0 -164
  61. package/rules/security/S026_json_schema_validation/analyzer.js +0 -251
  62. package/rules/security/S026_json_schema_validation/config.json +0 -27
  63. package/rules/security/S027_no_hardcoded_secrets/analyzer.js +0 -263
  64. package/rules/security/S027_no_hardcoded_secrets/config.json +0 -29
  65. package/rules/security/S029_csrf_protection/analyzer.js +0 -264
  66. package/rules/tests/C002_no_duplicate_code.test.js +0 -50
  67. package/rules/universal/C010/generic.js +0 -0
  68. package/rules/universal/C010/tree-sitter-analyzer.js +0 -0
  69. package/rules/utils/ast-utils.js +0 -191
  70. package/rules/utils/base-analyzer.js +0 -98
  71. package/rules/utils/pattern-matchers.js +0 -239
  72. package/rules/utils/rule-helpers.js +0 -264
  73. package/rules/utils/severity-constants.js +0 -93
@@ -0,0 +1,156 @@
1
+ # Standardized Category Filtering
2
+
3
+ ## Overview
4
+ SunLint implements standardized category filtering to ensure consistent behavior between CLI and VSCode extension. Category commands (like `--security`, `--quality`) now use a unified approach that only includes rules from core files.
5
+
6
+ ## Core Principles
7
+
8
+ ### 1. Core Files Only
9
+ Category filtering exclusively uses rules from core files:
10
+ - `common-en.md` - Universal quality and security rules
11
+ - `security-en.md` - Specialized security rules
12
+ - Language-specific files (typescript-en.md, etc.) are **excluded** from category commands
13
+
14
+ ### 2. Language-Specific Rules are Opt-In
15
+ - Language-specific rules are not included in category commands by default
16
+ - Must be explicitly enabled via project configuration
17
+ - This ensures category commands remain language-agnostic
18
+
19
+ ### 3. Principle-Based Filtering
20
+ Rules are filtered by their `principle` field based on actual rule catalog:
21
+ - `--security` → includes rules with principle: "SECURITY"
22
+ - `--quality` → includes rules with principle: "CODE_QUALITY"
23
+
24
+ Available principles in rule catalog:
25
+ - **SECURITY** - Security-focused rules
26
+ - **CODE_QUALITY** - Code quality and maintainability
27
+ - **PERFORMANCE** - Performance optimization rules
28
+ - **MAINTAINABILITY** - Code maintainability rules
29
+ - **TESTABILITY** - Testing and testability rules
30
+ - **RELIABILITY** - System reliability rules
31
+ - **DESIGN_PATTERNS** - Design pattern compliance
32
+ - **INTEGRATION** - Integration best practices
33
+ - **USABILITY** - User experience and usability
34
+
35
+ ## Implementation
36
+
37
+ ### SunlintRuleAdapter Methods
38
+
39
+ ```javascript
40
+ // Get rules for standardized category filtering (core files only)
41
+ getStandardCategoryRules(category) {
42
+ const coreRules = this.getCoreRules();
43
+ return coreRules.filter(rule => rule.principle === category);
44
+ }
45
+
46
+ // Category mapping based on actual principles
47
+ const categoryPrincipleMap = {
48
+ 'security': ['SECURITY'],
49
+ 'quality': ['CODE_QUALITY'],
50
+ 'performance': ['PERFORMANCE'],
51
+ 'maintainability': ['MAINTAINABILITY'],
52
+ 'testability': ['TESTABILITY'],
53
+ 'reliability': ['RELIABILITY'],
54
+ 'design': ['DESIGN_PATTERNS'],
55
+ 'integration': ['INTEGRATION'],
56
+ 'usability': ['USABILITY']
57
+ };
58
+ ```
59
+
60
+ ### CLI Integration
61
+
62
+ The rule selection service now uses standardized category filtering:
63
+
64
+ ```javascript
65
+ // core/rule-selection-service.js
66
+ const rules = adapter.getStandardCategoryRules(category);
67
+ console.log(`📋 Selected ${rules.length} ${category} rules from core files`);
68
+ ```
69
+
70
+ ## Rule Counts
71
+
72
+ Based on current rule catalog:
73
+ - **Total rules**: 256
74
+ - **Core rules**: 135 (common-en.md + security-en.md)
75
+ - **Security rules (core only)**: 60 rules
76
+ - **Quality rules (core only)**: 112 rules
77
+ - **Language-specific rules**: 121 rules (excluded from categories)
78
+
79
+ ## Usage Examples
80
+
81
+ ### CLI Commands
82
+ ```bash
83
+ # Uses 60 security rules from core files only
84
+ sunlint --input=src --security
85
+
86
+ # Uses 112 quality rules from core files only
87
+ sunlint --input=src --quality
88
+
89
+ # Custom rule selection (can include language-specific)
90
+ sunlint --input=src --rules="TS001,TS002,S001"
91
+
92
+ # Future categories (when CLI support is added)
93
+ sunlint --input=src --performance
94
+ sunlint --input=src --maintainability
95
+ ```
96
+
97
+ ### Project Configuration
98
+ To include language-specific rules, use project config:
99
+
100
+ ```json
101
+ {
102
+ "rules": ["TS001", "TS002"],
103
+ "presets": ["typescript", "security"]
104
+ }
105
+ ```
106
+
107
+ ## Benefits
108
+
109
+ ### 1. Consistency
110
+ - CLI and VSCode extension use identical rule selection logic
111
+ - Predictable behavior across all interfaces
112
+
113
+ ### 2. Maintainability
114
+ - Single source of truth for category definitions
115
+ - Easy to add new categories or core rules
116
+
117
+ ### 3. Extensibility
118
+ - Clear separation between core and language-specific rules
119
+ - Framework for adding new languages without breaking existing categories
120
+
121
+ ### 4. Performance
122
+ - Reduced rule count for category commands
123
+ - Faster analysis for common security/quality checks
124
+
125
+ ## Migration from Legacy System
126
+
127
+ ### Before (Legacy)
128
+ - Category commands included all rules matching principle
129
+ - Language-specific rules were included by default
130
+ - Different behavior between CLI and VSCode extension
131
+
132
+ ### After (Standardized)
133
+ - Category commands use core files only
134
+ - Language-specific rules are opt-in via config
135
+ - Unified behavior across all interfaces
136
+
137
+ ## Validation
138
+
139
+ Use the test script to validate category filtering:
140
+
141
+ ```bash
142
+ node test-category-filtering.js
143
+ ```
144
+
145
+ Expected output:
146
+ - Core rules: 135
147
+ - Security rules (core): 60
148
+ - Quality rules (core): 112
149
+ - All tests pass ✅
150
+
151
+ ## Related Files
152
+
153
+ - `core/adapters/sunlint-rule-adapter.js` - Main implementation
154
+ - `core/rule-selection-service.js` - CLI integration
155
+ - `test-category-filtering.js` - Validation script
156
+ - `config/presets/recommended.json` - Updated preset config
@@ -8,6 +8,7 @@
8
8
  const AnalysisEngineInterface = require('../core/interfaces/analysis-engine.interface');
9
9
  const ASTModuleRegistry = require('../core/ast-modules/index');
10
10
  const dependencyChecker = require('../core/dependency-checker');
11
+ const SunlintRuleAdapter = require('../core/adapters/sunlint-rule-adapter');
11
12
  const fs = require('fs');
12
13
  const path = require('path');
13
14
 
@@ -17,7 +18,7 @@ class HeuristicEngine extends AnalysisEngineInterface {
17
18
 
18
19
  this.ruleAnalyzers = new Map();
19
20
  this.supportedRulesList = [];
20
- this.rulesRegistry = {};
21
+ this.ruleAdapter = SunlintRuleAdapter.getInstance();
21
22
  this.astRegistry = ASTModuleRegistry;
22
23
  }
23
24
 
@@ -34,8 +35,8 @@ class HeuristicEngine extends AnalysisEngineInterface {
34
35
  // Check for optional AST dependencies
35
36
  dependencyChecker.checkAndNotify('ast');
36
37
 
37
- // Load rules registry
38
- await this.loadRulesRegistry(config);
38
+ // Initialize rule adapter
39
+ await this.ruleAdapter.initialize();
39
40
 
40
41
  // Scan for available rule analyzers
41
42
  await this.scanRuleAnalyzers(config);
@@ -51,30 +52,6 @@ class HeuristicEngine extends AnalysisEngineInterface {
51
52
  }
52
53
  }
53
54
 
54
- /**
55
- * Load rules registry configuration
56
- * Following Rule C006: Verb-noun naming
57
- */
58
- async loadRulesRegistry(config = {}) {
59
- try {
60
- const registryPath = path.resolve(__dirname, '../config/rules/rules-registry.json');
61
- if (fs.existsSync(registryPath)) {
62
- this.rulesRegistry = require(registryPath);
63
- if (config.verbose) {
64
- if (this.verbose) {
65
- console.log('📋 Loaded rules registry');
66
- }
67
- }
68
- } else {
69
- console.warn('⚠️ Rules registry not found, using minimal support');
70
- this.rulesRegistry = { rules: {} };
71
- }
72
- } catch (error) {
73
- console.warn('⚠️ Failed to load rules registry:', error.message);
74
- this.rulesRegistry = { rules: {} };
75
- }
76
- }
77
-
78
55
  /**
79
56
  * Scan for available rule analyzers
80
57
  * Following Rule C006: Verb-noun naming
@@ -324,10 +301,10 @@ class HeuristicEngine extends AnalysisEngineInterface {
324
301
  * @returns {string[]} Supported languages
325
302
  */
326
303
  getRuleLanguages(rule) {
327
- // Get from rules registry
328
- const registryRule = this.rulesRegistry.rules?.[rule.id];
329
- if (registryRule?.languages) {
330
- return registryRule.languages;
304
+ // Get from rule adapter
305
+ const adapterRule = this.ruleAdapter.getRuleById(rule.id);
306
+ if (adapterRule?.languages) {
307
+ return adapterRule.languages;
331
308
  }
332
309
 
333
310
  // Fallback to rule object