@sun-asterisk/sunlint 1.3.0 → 1.3.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.
Files changed (124) hide show
  1. package/CHANGELOG.md +115 -1
  2. package/CONTRIBUTING.md +249 -605
  3. package/README.md +3 -4
  4. package/config/ci-cd.json +54 -0
  5. package/config/development.json +56 -0
  6. package/config/large-project.json +143 -0
  7. package/config/presets/all.json +0 -1
  8. package/config/release.json +70 -0
  9. package/config/rule-analysis-strategies.js +38 -3
  10. package/config/rules/enhanced-rules-registry.json +474 -1179
  11. package/config/rules/rules-registry-generated.json +3 -3
  12. package/core/cli-action-handler.js +24 -30
  13. package/core/cli-program.js +11 -3
  14. package/core/config-merger.js +29 -2
  15. package/core/enhanced-rules-registry.js +3 -2
  16. package/core/semantic-engine.js +129 -19
  17. package/core/semantic-rule-base.js +4 -2
  18. package/core/unified-rule-registry.js +1 -1
  19. package/docs/COMMAND-EXAMPLES.md +134 -0
  20. package/docs/LARGE-PROJECT-GUIDE.md +324 -0
  21. package/engines/heuristic-engine.js +135 -16
  22. package/integrations/eslint/plugin/index.js +0 -2
  23. package/integrations/eslint/plugin/rules/common/c003-no-vague-abbreviations.js +59 -1
  24. package/integrations/eslint/plugin/rules/common/c006-function-name-verb-noun.js +26 -1
  25. package/integrations/eslint/plugin/rules/common/c030-use-custom-error-classes.js +54 -19
  26. package/origin-rules/common-en.md +19 -15
  27. package/package.json +1 -1
  28. package/rules/common/C002_no_duplicate_code/analyzer.js +334 -36
  29. package/rules/common/C003_no_vague_abbreviations/analyzer.js +220 -35
  30. package/rules/common/C006_function_naming/analyzer.js +29 -3
  31. package/rules/common/C010_limit_block_nesting/analyzer.js +181 -337
  32. package/rules/common/C010_limit_block_nesting/config.json +64 -0
  33. package/rules/common/C010_limit_block_nesting/regex-based-analyzer.js +379 -0
  34. package/rules/common/C010_limit_block_nesting/symbol-based-analyzer.js +231 -0
  35. package/rules/common/C013_no_dead_code/analyzer.js +75 -177
  36. package/rules/common/C013_no_dead_code/config.json +61 -0
  37. package/rules/common/C013_no_dead_code/regex-based-analyzer.js +345 -0
  38. package/rules/common/C013_no_dead_code/symbol-based-analyzer.js +640 -0
  39. package/rules/common/C014_dependency_injection/analyzer.js +48 -313
  40. package/rules/common/C014_dependency_injection/config.json +26 -0
  41. package/rules/common/C014_dependency_injection/symbol-based-analyzer.js +751 -0
  42. package/rules/common/C017_constructor_logic/analyzer.js +254 -17
  43. package/rules/common/C017_constructor_logic/semantic-analyzer.js +340 -0
  44. package/rules/common/C018_no_throw_generic_error/analyzer.js +232 -0
  45. package/rules/common/C018_no_throw_generic_error/config.json +50 -0
  46. package/rules/common/C018_no_throw_generic_error/regex-based-analyzer.js +387 -0
  47. package/rules/common/C018_no_throw_generic_error/symbol-based-analyzer.js +314 -0
  48. package/rules/common/C019_log_level_usage/analyzer.js +110 -317
  49. package/rules/common/C019_log_level_usage/pattern-analyzer.js +88 -0
  50. package/rules/common/C019_log_level_usage/system-log-analyzer.js +1267 -0
  51. package/rules/common/C023_no_duplicate_variable/analyzer.js +180 -0
  52. package/rules/common/C023_no_duplicate_variable/config.json +50 -0
  53. package/rules/common/C023_no_duplicate_variable/symbol-based-analyzer.js +158 -0
  54. package/rules/common/C024_no_scatter_hardcoded_constants/analyzer.js +180 -0
  55. package/rules/common/C024_no_scatter_hardcoded_constants/config.json +50 -0
  56. package/rules/common/C024_no_scatter_hardcoded_constants/symbol-based-analyzer.js +181 -0
  57. package/rules/common/C030_use_custom_error_classes/analyzer.js +200 -0
  58. package/rules/common/C033_separate_service_repository/README.md +78 -0
  59. package/rules/common/C033_separate_service_repository/analyzer.js +160 -0
  60. package/rules/common/C033_separate_service_repository/config.json +50 -0
  61. package/rules/common/C033_separate_service_repository/regex-based-analyzer.js +585 -0
  62. package/rules/common/C033_separate_service_repository/symbol-based-analyzer.js +368 -0
  63. package/rules/common/C035_error_logging_context/STRATEGY.md +99 -0
  64. package/rules/common/C035_error_logging_context/analyzer.js +232 -0
  65. package/rules/common/C035_error_logging_context/config.json +54 -0
  66. package/rules/common/C035_error_logging_context/regex-based-analyzer.js +299 -0
  67. package/rules/common/C035_error_logging_context/symbol-based-analyzer.js +454 -0
  68. package/rules/common/C040_centralized_validation/analyzer.js +165 -0
  69. package/rules/common/C040_centralized_validation/config.json +46 -0
  70. package/rules/common/C040_centralized_validation/regex-based-analyzer.js +243 -0
  71. package/rules/common/C040_centralized_validation/symbol-based-analyzer.js +416 -0
  72. package/rules/common/{C076_single_test_behavior → C072_single_test_behavior}/analyzer.js +6 -6
  73. package/rules/common/C076_explicit_function_types/README.md +30 -0
  74. package/rules/common/C076_explicit_function_types/analyzer.js +172 -0
  75. package/rules/common/C076_explicit_function_types/config.json +15 -0
  76. package/rules/common/C076_explicit_function_types/semantic-analyzer.js +341 -0
  77. package/rules/index.js +6 -1
  78. package/rules/parser/rule-parser.js +13 -2
  79. package/rules/security/S005_no_origin_auth/README.md +226 -0
  80. package/rules/security/S005_no_origin_auth/analyzer.js +184 -0
  81. package/rules/security/S005_no_origin_auth/ast-analyzer.js +406 -0
  82. package/rules/security/S005_no_origin_auth/config.json +85 -0
  83. package/rules/security/S006_no_plaintext_recovery_codes/README.md +139 -0
  84. package/rules/security/S006_no_plaintext_recovery_codes/analyzer.js +306 -0
  85. package/rules/security/S006_no_plaintext_recovery_codes/config.json +48 -0
  86. package/rules/security/S007_no_plaintext_otp/README.md +198 -0
  87. package/rules/security/S007_no_plaintext_otp/analyzer.js +406 -0
  88. package/rules/security/S007_no_plaintext_otp/config.json +79 -0
  89. package/rules/security/S007_no_plaintext_otp/semantic-analyzer.js +609 -0
  90. package/rules/security/S007_no_plaintext_otp/semantic-config.json +195 -0
  91. package/rules/security/S007_no_plaintext_otp/semantic-wrapper.js +280 -0
  92. package/rules/security/S009_no_insecure_encryption/README.md +158 -0
  93. package/rules/security/S009_no_insecure_encryption/analyzer.js +319 -0
  94. package/rules/security/S009_no_insecure_encryption/config.json +55 -0
  95. package/rules/security/S010_no_insecure_encryption/README.md +224 -0
  96. package/rules/security/S010_no_insecure_encryption/analyzer.js +493 -0
  97. package/rules/security/S010_no_insecure_encryption/config.json +48 -0
  98. package/rules/security/S016_no_sensitive_querystring/STRATEGY.md +149 -0
  99. package/rules/security/S016_no_sensitive_querystring/analyzer.js +276 -0
  100. package/rules/security/S016_no_sensitive_querystring/config.json +127 -0
  101. package/rules/security/S016_no_sensitive_querystring/regex-based-analyzer.js +258 -0
  102. package/rules/security/S016_no_sensitive_querystring/symbol-based-analyzer.js +495 -0
  103. package/rules/security/S027_no_hardcoded_secrets/analyzer.js +180 -366
  104. package/rules/security/S027_no_hardcoded_secrets/categories.json +153 -0
  105. package/rules/security/S027_no_hardcoded_secrets/categorized-analyzer.js +250 -0
  106. package/rules/security/S048_no_current_password_in_reset/README.md +222 -0
  107. package/rules/security/S048_no_current_password_in_reset/analyzer.js +366 -0
  108. package/rules/security/S048_no_current_password_in_reset/config.json +48 -0
  109. package/rules/security/S055_content_type_validation/README.md +176 -0
  110. package/rules/security/S055_content_type_validation/analyzer.js +312 -0
  111. package/rules/security/S055_content_type_validation/config.json +48 -0
  112. package/rules/utils/rule-helpers.js +140 -1
  113. package/scripts/consolidate-config.js +116 -0
  114. package/scripts/prepare-release.sh +1 -1
  115. package/config/rules/rules-registry.json +0 -765
  116. package/docs/ESLINT-INTEGRATION-STRATEGY.md +0 -392
  117. package/docs/FUTURE_PACKAGES.md +0 -83
  118. package/docs/HEURISTIC_VS_AI.md +0 -113
  119. package/docs/PRODUCTION_DEPLOYMENT_ANALYSIS.md +0 -112
  120. package/docs/PRODUCTION_SIZE_IMPACT.md +0 -183
  121. package/docs/RELEASE_GUIDE.md +0 -230
  122. package/docs/STANDARDIZED-CATEGORY-FILTERING.md +0 -156
  123. package/integrations/eslint/plugin/rules/common/c076-single-behavior-per-test.js +0 -254
  124. package/rules/common/C006_function_naming/smart-analyzer.js +0 -503
@@ -1,183 +0,0 @@
1
- # 📦 SunLint Production Size Impact Analysis
2
-
3
- ## Tóm tắt cho Leadership
4
-
5
- **KẾT LUẬN: SunLint KHÔNG làm tăng size production khi sử dụng đúng cách.**
6
-
7
- ## Chi tiết phân tích
8
-
9
- ### 1. Package Size của SunLint
10
-
11
- ```bash
12
- SunLint package size: 241.6 kB
13
- SunLint unpacked size: 1.1 MB
14
- Total files: 214
15
- ```
16
-
17
- ### 2. Test Production Impact
18
-
19
- Chúng tôi đã tạo một project test để kiểm tra impact thực tế:
20
-
21
- | Giai đoạn | Size | Ghi chú |
22
- |-----------|------|---------|
23
- | Project ban đầu | 8.0K | Chỉ có package.json và .gitignore |
24
- | Sau khi cài SunLint (devDependency) | 88M | Bao gồm tất cả devDependencies |
25
- | Production bundle (dist/) | 4.0K | Code production thực tế |
26
- | Sau npm prune --production | 156K | Đã xóa tất cả devDependencies |
27
-
28
- ### 3. Khuyến nghị sử dụng trong Production
29
-
30
- #### ✅ ĐÚNG CÁCH (Production-friendly):
31
-
32
- ```json
33
- {
34
- "devDependencies": {
35
- "@sun-asterisk/sunlint": "^1.1.4"
36
- }
37
- }
38
- ```
39
-
40
- **Lợi ích:**
41
- - ✅ Không ảnh hưởng size production bundle
42
- - ✅ Chỉ cài khi development (`npm install`)
43
- - ✅ Tự động loại trừ khỏi production (`npm prune --production`)
44
- - ✅ CI/CD có thể dùng để check code quality
45
-
46
- #### ❌ SAI CÁCH (Không khuyến nghị):
47
-
48
- ```json
49
- {
50
- "dependencies": {
51
- "@sun-asterisk/sunlint": "^1.1.4"
52
- }
53
- }
54
- ```
55
-
56
- **Vấn đề:**
57
- - ❌ Tăng 1.1MB cho production bundle
58
- - ❌ Không cần thiết cho runtime
59
- - ❌ Làm chậm deployment
60
-
61
- ### 4. Deployment Strategies
62
-
63
- #### Option 1: Development Only (Khuyến nghị)
64
- ```bash
65
- # Development
66
- npm install
67
-
68
- # Production build
69
- npm run build
70
- npm prune --production
71
- # → SunLint sẽ bị xóa hoàn toàn
72
- ```
73
-
74
- #### Option 2: CI/CD Pipeline
75
- ```yaml
76
- # .github/workflows/ci.yml
77
- - name: Install deps
78
- run: npm ci
79
- - name: Run SunLint
80
- run: npx sunlint --quality --input=src
81
- - name: Build production
82
- run: npm run build
83
- - name: Remove dev deps
84
- run: npm prune --production
85
- ```
86
-
87
- #### Option 3: Docker Multi-stage
88
- ```dockerfile
89
- # Development stage với SunLint
90
- FROM node:18 as dev
91
- COPY package*.json ./
92
- RUN npm ci
93
- COPY . .
94
- RUN npx sunlint --all --input=src
95
-
96
- # Production stage KHÔNG có SunLint
97
- FROM node:18-alpine as prod
98
- COPY package*.json ./
99
- RUN npm ci --only=production
100
- COPY dist/ ./dist/
101
- ```
102
-
103
- ### 5. So sánh với các tools khác
104
-
105
- | Tool | Package Size | Production Impact | Use Case |
106
- |------|-------------|-------------------|-----------|
107
- | ESLint | ~500KB | ❌ Nếu để dependencies | Development only |
108
- | Prettier | ~200KB | ❌ Nếu để dependencies | Development only |
109
- | **SunLint** | **241KB** | **✅ KHÔNG (devDep)** | **Development + CI/CD** |
110
- | TypeScript | ~60MB | ❌ Nếu để dependencies | Development only |
111
-
112
- ### 6. Best Practices cho Teams
113
-
114
- #### Developers:
115
- ```bash
116
- # Local development
117
- npm install # Cài tất cả deps (bao gồm SunLint)
118
- npx sunlint --quality --input=src
119
-
120
- # Pre-commit hook
121
- npx sunlint --changed-files
122
- ```
123
-
124
- #### CI/CD:
125
- ```bash
126
- # Build pipeline
127
- npm ci # Cài tất cả deps
128
- npx sunlint --all --input=src # Quality check
129
- npm run build # Build production
130
- npm prune --production # Xóa devDeps
131
- ```
132
-
133
- #### Production:
134
- ```bash
135
- # Server deployment
136
- npm ci --only=production # Chỉ cài production deps
137
- # → SunLint sẽ KHÔNG được cài
138
- ```
139
-
140
- ### 7. Monitoring & Verification
141
-
142
- #### Verify production size:
143
- ```bash
144
- # Trước deploy
145
- du -sh node_modules
146
- du -sh dist/
147
-
148
- # Kiểm tra không có SunLint
149
- ls node_modules | grep sunlint # Không có kết quả = OK
150
- ```
151
-
152
- #### Bundle size monitoring:
153
- ```bash
154
- # Add to package.json
155
- {
156
- "scripts": {
157
- "analyze-bundle": "du -sh dist/ && echo 'Production bundle size'",
158
- "verify-prod": "npm ls --production --depth=0"
159
- }
160
- }
161
- ```
162
-
163
- ## Kết luận
164
-
165
- ### ✅ AN TOÀN cho Production:
166
- - SunLint được thiết kế như devDependency
167
- - Không ảnh hưởng size production bundle khi sử dụng đúng
168
- - Có thể tích hợp vào CI/CD mà không ảnh hưởng deployment
169
-
170
- ### 📊 Số liệu cụ thể:
171
- - **Development**: +88MB (chỉ khi dev)
172
- - **Production**: +0KB (khi dùng đúng cách)
173
- - **CI/CD**: Impact chỉ ở build time, không ở runtime
174
-
175
- ### 🚀 Khuyến nghị:
176
- 1. **Luôn cài như devDependency**
177
- 2. **Sử dụng trong CI/CD pipeline**
178
- 3. **npm prune --production trước deploy**
179
- 4. **Monitor bundle size định kỳ**
180
-
181
- ---
182
-
183
- *Tài liệu này được cập nhật cho SunLint v1.1.4 - July 2025*
@@ -1,230 +0,0 @@
1
- # 🚀 SunLint v1.0.5 Release Guide
2
-
3
- ## 📦 **Dual Release Strategy**
4
-
5
- SunLint v1.0.5 supports **two deployment methods** to meet different enterprise needs:
6
-
7
- ### **1. GitHub Package Registry (Private/Enterprise)**
8
- - **Purpose**: Private enterprise distribution
9
- - **Benefits**: Free private packages, organization control
10
- - **Target**: Internal teams, enterprise customers
11
-
12
- ### **2. Global Tarball Release (Public)**
13
- - **Purpose**: Public distribution via GitHub Releases
14
- - **Benefits**: No NPM Registry fees, direct download
15
- - **Target**: Open source community, public usage
16
-
17
- ## 🔧 **Release Process**
18
-
19
- ### **Automated Release (Recommended)**
20
-
21
- 1. **Trigger GitHub Action**:
22
- - Go to GitHub Actions → "Release SunLint" workflow
23
- - Click "Run workflow"
24
- - Select parameters:
25
- - **Version**: `1.0.5`
26
- - **Release Type**: `both` (GitHub Package + Tarball)
27
-
28
- 2. **Automated Steps**:
29
- - ✅ Run tests
30
- - ✅ Update version numbers
31
- - ✅ Build package tarball
32
- - ✅ Publish to GitHub Package Registry
33
- - ✅ Create GitHub Release with tarball
34
- - ✅ Generate installation documentation
35
-
36
- ### **Manual Release (Alternative)**
37
-
38
- ```bash
39
- # 1. Prepare release
40
- cd coding-quality/extensions/sunlint
41
- npm test
42
- npm run clean
43
-
44
- # 2. Update version
45
- npm version 1.0.5 --no-git-tag-version
46
-
47
- # 3. GitHub Package Registry
48
- cp package-github.json package.json
49
- npm publish --registry=https://npm.pkg.github.com
50
-
51
- # 4. Global tarball
52
- npm pack
53
- mv *.tgz sunlint-1.0.5.tgz
54
-
55
- # 5. Create GitHub release (manual upload)
56
- ```
57
-
58
- ## 📖 **Installation Methods**
59
-
60
- ### **Method 1: GitHub Package Registry**
61
-
62
- **Setup (one-time)**:
63
- ```bash
64
- # Configure GitHub Package Registry
65
- echo "@sun-asterisk:registry=https://npm.pkg.github.com" >> ~/.npmrc
66
- echo "//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}" >> ~/.npmrc
67
- ```
68
-
69
- **Install**:
70
- ```bash
71
- # Global installation
72
- npm install -g @sun-asterisk/sunlint
73
-
74
- # Project installation
75
- npm install --save-dev @sun-asterisk/sunlint
76
- ```
77
-
78
- ### **Method 2: Direct Tarball**
79
-
80
- ```bash
81
- # Global installation from release
82
- npm install -g https://github.com/sun-asterisk/engineer-excellence/releases/download/sunlint-v1.0.5/sunlint-1.0.5.tgz
83
-
84
- # Project installation
85
- npm install --save-dev https://github.com/sun-asterisk/engineer-excellence/releases/download/sunlint-v1.0.5/sunlint-1.0.5.tgz
86
- ```
87
-
88
- ### **Method 3: Setup Script**
89
-
90
- ```bash
91
- # One-line setup for GitHub Package Registry
92
- curl -fsSL https://raw.githubusercontent.com/sun-asterisk/engineer-excellence/main/coding-quality/extensions/sunlint/scripts/setup-github-registry.sh | GITHUB_TOKEN=your_token bash
93
- ```
94
-
95
- ## 🎯 **Team Integration Examples**
96
-
97
- ### **Enterprise Team (GitHub Package Registry)**
98
-
99
- ```json
100
- {
101
- "name": "my-enterprise-project",
102
- "scripts": {
103
- "lint": "sunlint --all --input=src",
104
- "lint:changed": "sunlint --all --changed-files",
105
- "lint:eslint": "sunlint --all --eslint-integration --input=src",
106
- "ci:lint": "sunlint --all --changed-files --fail-on-new-violations"
107
- },
108
- "devDependencies": {
109
- "@sun-asterisk/sunlint": "^1.0.5"
110
- }
111
- }
112
- ```
113
-
114
- **.npmrc** (project-level):
115
- ```
116
- @sun-asterisk:registry=https://npm.pkg.github.com
117
- //npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}
118
- ```
119
-
120
- ### **Open Source Project (Direct Tarball)**
121
-
122
- ```json
123
- {
124
- "name": "my-open-source-project",
125
- "scripts": {
126
- "lint": "sunlint --all --input=src",
127
- "lint:eslint": "sunlint --all --eslint-integration --input=src"
128
- },
129
- "devDependencies": {
130
- "@sun-asterisk/sunlint": "https://github.com/sun-asterisk/engineer-excellence/releases/download/sunlint-v1.0.5/sunlint-1.0.5.tgz"
131
- }
132
- }
133
- ```
134
-
135
- ## 🚢 **CI/CD Integration**
136
-
137
- ### **GitHub Actions with GitHub Package Registry**
138
-
139
- ```yaml
140
- name: Code Quality
141
- on: [pull_request]
142
-
143
- jobs:
144
- lint:
145
- runs-on: ubuntu-latest
146
- steps:
147
- - uses: actions/checkout@v4
148
- - uses: actions/setup-node@v4
149
- with:
150
- node-version: '18'
151
- registry-url: 'https://npm.pkg.github.com'
152
-
153
- - name: Configure GitHub Package Registry
154
- run: |
155
- echo "@sun-asterisk:registry=https://npm.pkg.github.com" >> ~/.npmrc
156
- echo "//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}" >> ~/.npmrc
157
-
158
- - run: npm ci
159
- - name: Run SunLint
160
- run: |
161
- npx @sun-asterisk/sunlint --all --eslint-integration --changed-files \
162
- --diff-base=origin/main --fail-on-new-violations --format=summary
163
- ```
164
-
165
- ### **GitHub Actions with Direct Tarball**
166
-
167
- ```yaml
168
- name: Code Quality
169
- on: [pull_request]
170
-
171
- jobs:
172
- lint:
173
- runs-on: ubuntu-latest
174
- steps:
175
- - uses: actions/checkout@v4
176
- - uses: actions/setup-node@v4
177
-
178
- - name: Install SunLint
179
- run: |
180
- npm install -g https://github.com/sun-asterisk/engineer-excellence/releases/download/sunlint-v1.0.5/sunlint-1.0.5.tgz
181
-
182
- - name: Run SunLint
183
- run: |
184
- sunlint --all --eslint-integration --changed-files \
185
- --diff-base=origin/main --fail-on-new-violations --format=summary
186
- ```
187
-
188
- ## 🔍 **Verification**
189
-
190
- After installation, verify SunLint is working:
191
-
192
- ```bash
193
- # Check version
194
- sunlint --version
195
-
196
- # Test basic functionality
197
- sunlint --rule=C006 --input=src
198
-
199
- # Test ESLint integration
200
- sunlint --all --eslint-integration --input=src
201
-
202
- # Test Git integration
203
- sunlint --all --changed-files
204
- ```
205
-
206
- ## 📊 **Release Metrics**
207
-
208
- Track adoption through:
209
- - GitHub Package downloads
210
- - GitHub Release download statistics
211
- - GitHub stars/forks
212
- - Issue reports and feature requests
213
-
214
- ## 🎉 **Benefits Summary**
215
-
216
- ### **For Teams**
217
- - ✅ **Zero-disruption**: Works with existing ESLint
218
- - ✅ **Flexible deployment**: GitHub Package or direct download
219
- - ✅ **Enterprise-ready**: Private package distribution
220
- - ✅ **CI/CD optimized**: Git integration for performance
221
-
222
- ### **For Maintainers**
223
- - ✅ **Cost-effective**: No NPM Registry fees
224
- - ✅ **Control**: Private distribution via GitHub
225
- - ✅ **Automation**: GitHub Actions release pipeline
226
- - ✅ **Monitoring**: Built-in download analytics
227
-
228
- ---
229
-
230
- **🚀 Ready to deploy SunLint v1.0.5 with dual release strategy!**
@@ -1,156 +0,0 @@
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