@sun-asterisk/sunlint 1.0.7 → 1.1.3
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 +35 -0
- package/CHANGELOG.md +30 -3
- package/CONTRIBUTING.md +235 -0
- package/PROJECT_STRUCTURE.md +60 -0
- package/README.md +73 -52
- package/cli.js +1 -0
- package/config/README.md +88 -0
- package/config/defaults/ai-rules-context.json +231 -0
- package/config/engines/engines.json +49 -0
- package/config/engines/eslint-rule-mapping.json +74 -0
- package/config/eslint-rule-mapping.json +126 -0
- package/config/integrations/eslint/base.config.js +125 -0
- package/config/integrations/eslint/simple.config.js +24 -0
- package/config/presets/strict.json +0 -1
- package/config/rule-analysis-strategies.js +74 -0
- package/config/{rules-registry.json → rules/rules-registry.json} +22 -0
- package/core/analysis-orchestrator.js +383 -591
- package/core/ast-modules/README.md +103 -0
- package/core/ast-modules/base-parser.js +90 -0
- package/core/ast-modules/index.js +97 -0
- package/core/ast-modules/package.json +37 -0
- package/core/ast-modules/parsers/eslint-js-parser.js +147 -0
- package/core/ast-modules/parsers/eslint-ts-parser.js +106 -0
- package/core/ast-modules/parsers/javascript-parser.js +187 -0
- package/core/ast-modules/parsers/typescript-parser.js +187 -0
- package/core/cli-action-handler.js +271 -255
- package/core/cli-program.js +18 -4
- package/core/config-manager.js +9 -3
- package/core/config-merger.js +40 -1
- package/core/config-validator.js +2 -2
- package/core/enhanced-rules-registry.js +331 -0
- package/core/file-targeting-service.js +92 -23
- package/core/interfaces/analysis-engine.interface.js +100 -0
- package/core/multi-rule-runner.js +0 -221
- package/core/output-service.js +1 -1
- package/core/rule-mapping-service.js +1 -1
- package/core/rule-selection-service.js +10 -2
- package/docs/AI.md +163 -0
- package/docs/ARCHITECTURE.md +78 -0
- package/docs/CI-CD-GUIDE.md +315 -0
- package/docs/COMMAND-EXAMPLES.md +256 -0
- package/docs/CONFIGURATION.md +414 -0
- package/docs/DEBUG.md +86 -0
- package/docs/DEPLOYMENT-STRATEGIES.md +270 -0
- package/docs/DISTRIBUTION.md +153 -0
- package/docs/ESLINT-INTEGRATION-STRATEGY.md +392 -0
- package/docs/ESLINT_INTEGRATION.md +238 -0
- package/docs/FOLDER_STRUCTURE.md +59 -0
- package/docs/HEURISTIC_VS_AI.md +113 -0
- package/docs/README.md +32 -0
- package/docs/RELEASE_GUIDE.md +230 -0
- package/engines/eslint-engine.js +601 -0
- package/engines/heuristic-engine.js +860 -0
- package/engines/openai-engine.js +374 -0
- package/engines/tree-sitter-parser.js +0 -0
- package/engines/universal-ast-engine.js +0 -0
- package/integrations/eslint/README.md +99 -0
- package/integrations/eslint/configs/.eslintrc.js +98 -0
- package/integrations/eslint/configs/eslint.config.js +133 -0
- package/integrations/eslint/configs/eslint.config.simple.js +24 -0
- package/integrations/eslint/package.json +23 -0
- package/integrations/eslint/plugin/index.js +164 -0
- package/integrations/eslint/plugin/package.json +13 -0
- package/integrations/eslint/plugin/rules/common/c002-no-duplicate-code.js +204 -0
- package/integrations/eslint/plugin/rules/common/c003-no-vague-abbreviations.js +246 -0
- package/integrations/eslint/plugin/rules/common/c006-function-name-verb-noun.js +216 -0
- package/integrations/eslint/plugin/rules/common/c010-limit-block-nesting.js +90 -0
- package/integrations/eslint/plugin/rules/common/c013-no-dead-code.js +78 -0
- package/integrations/eslint/plugin/rules/common/c014-abstract-dependency-preferred.js +38 -0
- package/integrations/eslint/plugin/rules/common/c017-limit-constructor-logic.js +146 -0
- package/integrations/eslint/plugin/rules/common/c018-no-generic-throw.js +335 -0
- package/integrations/eslint/plugin/rules/common/c023-no-duplicate-variable-name-in-scope.js +142 -0
- package/integrations/eslint/plugin/rules/common/c029-catch-block-logging.js +115 -0
- package/integrations/eslint/plugin/rules/common/c030-use-custom-error-classes.js +294 -0
- package/integrations/eslint/plugin/rules/common/c035-no-empty-catch.js +162 -0
- package/integrations/eslint/plugin/rules/common/c041-no-config-inline.js +122 -0
- package/integrations/eslint/plugin/rules/common/c042-boolean-name-prefix.js +406 -0
- package/integrations/eslint/plugin/rules/common/c043-no-console-or-print.js +300 -0
- package/integrations/eslint/plugin/rules/common/c047-no-duplicate-retry-logic.js +239 -0
- package/integrations/eslint/plugin/rules/common/c072-one-assert-per-test.js +184 -0
- package/integrations/eslint/plugin/rules/common/c075-explicit-function-return-types.js +168 -0
- package/integrations/eslint/plugin/rules/common/c076-single-behavior-per-test.js +254 -0
- package/integrations/eslint/plugin/rules/security/s001-fail-securely.js +381 -0
- package/integrations/eslint/plugin/rules/security/s002-idor-check.js +945 -0
- package/integrations/eslint/plugin/rules/security/s003-no-unvalidated-redirect.js +86 -0
- package/integrations/eslint/plugin/rules/security/s007-no-plaintext-otp.js +74 -0
- package/integrations/eslint/plugin/rules/security/s013-verify-tls-connection.js +47 -0
- package/integrations/eslint/plugin/rules/security/s047-secure-random-passwords.js +108 -0
- package/integrations/eslint/plugin/rules/security/s055-verification-rest-check-the-incoming-content-type.js +143 -0
- package/integrations/eslint/plugin/rules/typescript/t002-interface-prefix-i.js +42 -0
- package/integrations/eslint/plugin/rules/typescript/t003-ts-ignore-reason.js +48 -0
- package/integrations/eslint/plugin/rules/typescript/t004-no-empty-type.js +95 -0
- package/integrations/eslint/plugin/rules/typescript/t007-no-fn-in-constructor.js +52 -0
- package/integrations/eslint/plugin/rules/typescript/t010-no-nested-union-tuple.js +48 -0
- package/integrations/eslint/plugin/rules/typescript/t019-no-this-assign.js +81 -0
- package/integrations/eslint/plugin/rules/typescript/t020-no-default-multi-export.js +127 -0
- package/integrations/eslint/plugin/rules/typescript/t021-limit-nested-generics.js +150 -0
- package/integrations/eslint/test-c041-rule.js +87 -0
- package/integrations/eslint/tsconfig.json +27 -0
- package/package.json +29 -16
- package/rules/README.md +252 -0
- package/rules/common/C002_no_duplicate_code/analyzer.js +65 -0
- package/rules/common/C002_no_duplicate_code/config.json +23 -0
- package/rules/common/C003_no_vague_abbreviations/analyzer.js +418 -0
- package/rules/common/C003_no_vague_abbreviations/config.json +35 -0
- package/rules/{C006_function_naming → common/C006_function_naming}/analyzer.js +13 -2
- package/rules/common/C010_limit_block_nesting/analyzer.js +389 -0
- package/rules/common/C013_no_dead_code/analyzer.js +206 -0
- package/rules/common/C014_dependency_injection/analyzer.js +338 -0
- package/rules/common/C017_constructor_logic/analyzer.js +314 -0
- package/rules/{C019_log_level_usage → common/C019_log_level_usage}/analyzer.js +5 -2
- package/rules/{C029_catch_block_logging → common/C029_catch_block_logging}/analyzer.js +49 -15
- package/rules/common/C041_no_sensitive_hardcode/analyzer.js +292 -0
- package/rules/common/C042_boolean_name_prefix/analyzer.js +300 -0
- package/rules/common/C043_no_console_or_print/analyzer.js +304 -0
- package/rules/common/C047_no_duplicate_retry_logic/analyzer.js +351 -0
- package/rules/common/C075_explicit_return_types/analyzer.js +103 -0
- package/rules/common/C076_single_test_behavior/analyzer.js +121 -0
- package/rules/docs/C002_no_duplicate_code.md +57 -0
- package/rules/index.js +149 -0
- package/rules/migration/converter.js +385 -0
- package/rules/migration/mapping.json +164 -0
- package/rules/security/S026_json_schema_validation/analyzer.js +251 -0
- package/rules/security/S026_json_schema_validation/config.json +27 -0
- package/rules/security/S027_no_hardcoded_secrets/analyzer.js +263 -0
- package/rules/security/S027_no_hardcoded_secrets/config.json +29 -0
- package/rules/security/S029_csrf_protection/analyzer.js +264 -0
- package/rules/tests/C002_no_duplicate_code.test.js +50 -0
- package/rules/universal/C010/generic.js +0 -0
- package/rules/universal/C010/tree-sitter-analyzer.js +0 -0
- package/rules/utils/ast-utils.js +191 -0
- package/rules/utils/base-analyzer.js +98 -0
- package/rules/utils/pattern-matchers.js +239 -0
- package/rules/utils/rule-helpers.js +264 -0
- package/rules/utils/severity-constants.js +93 -0
- package/scripts/build-release.sh +117 -0
- package/scripts/ci-report.js +179 -0
- package/scripts/install.sh +196 -0
- package/scripts/manual-release.sh +338 -0
- package/scripts/merge-reports.js +424 -0
- package/scripts/pre-release-test.sh +175 -0
- package/scripts/prepare-release.sh +202 -0
- package/scripts/setup-github-registry.sh +42 -0
- package/scripts/test-scripts/README.md +22 -0
- package/scripts/test-scripts/test-c041-comparison.js +114 -0
- package/scripts/test-scripts/test-c041-eslint.js +67 -0
- package/scripts/test-scripts/test-eslint-rules.js +146 -0
- package/scripts/test-scripts/test-real-world.js +44 -0
- package/scripts/test-scripts/test-rules-on-real-projects.js +86 -0
- package/scripts/trigger-release.sh +285 -0
- package/scripts/validate-rule-structure.js +148 -0
- package/scripts/verify-install.sh +82 -0
- package/config/sunlint-schema.json +0 -159
- package/config/typescript/custom-rules.js +0 -9
- package/config/typescript/package-lock.json +0 -1585
- package/config/typescript/package.json +0 -13
- package/config/typescript/security-rules/index.js +0 -90
- package/config/typescript/tsconfig.json +0 -29
- package/core/ai-analyzer.js +0 -169
- package/core/eslint-engine-service.js +0 -312
- package/core/eslint-instance-manager.js +0 -104
- package/core/eslint-integration-service.js +0 -363
- package/core/sunlint-engine-service.js +0 -23
- package/core/typescript-analyzer.js +0 -262
- package/core/typescript-engine.js +0 -313
- /package/config/{default.json → defaults/default.json} +0 -0
- /package/config/{typescript/eslint.config.js → integrations/eslint/typescript.config.js} +0 -0
- /package/config/{typescript/custom-rules-new.js → schemas/sunlint-schema.json} +0 -0
- /package/config/{typescript → testing}/test-s005-working.ts +0 -0
- /package/{config/typescript/security-rules → integrations/eslint/plugin/rules/security}/s005-no-origin-auth.js +0 -0
- /package/{config/typescript/security-rules → integrations/eslint/plugin/rules/security}/s006-activation-recovery-secret-not-plaintext.js +0 -0
- /package/{config/typescript/security-rules → integrations/eslint/plugin/rules/security}/s008-crypto-agility.js +0 -0
- /package/{config/typescript/security-rules → integrations/eslint/plugin/rules/security}/s009-no-insecure-crypto.js +0 -0
- /package/{config/typescript/security-rules → integrations/eslint/plugin/rules/security}/s010-no-insecure-random-in-sensitive-context.js +0 -0
- /package/{config/typescript/security-rules → integrations/eslint/plugin/rules/security}/s011-no-insecure-uuid.js +0 -0
- /package/{config/typescript/security-rules → integrations/eslint/plugin/rules/security}/s012-hardcode-secret.js +0 -0
- /package/{config/typescript/security-rules → integrations/eslint/plugin/rules/security}/s014-insecure-tls-version.js +0 -0
- /package/{config/typescript/security-rules → integrations/eslint/plugin/rules/security}/s015-insecure-tls-certificate.js +0 -0
- /package/{config/typescript/security-rules → integrations/eslint/plugin/rules/security}/s016-sensitive-query-parameter.js +0 -0
- /package/{config/typescript/security-rules → integrations/eslint/plugin/rules/security}/s017-no-sql-injection.js +0 -0
- /package/{config/typescript/security-rules → integrations/eslint/plugin/rules/security}/s018-positive-input-validation.js +0 -0
- /package/{config/typescript/security-rules → integrations/eslint/plugin/rules/security}/s019-no-raw-user-input-in-email.js +0 -0
- /package/{config/typescript/security-rules → integrations/eslint/plugin/rules/security}/s020-no-eval-dynamic-execution.js +0 -0
- /package/{config/typescript/security-rules → integrations/eslint/plugin/rules/security}/s022-output-encoding.js +0 -0
- /package/{config/typescript/security-rules → integrations/eslint/plugin/rules/security}/s023-no-json-injection.js +0 -0
- /package/{config/typescript/security-rules → integrations/eslint/plugin/rules/security}/s025-server-side-input-validation.js +0 -0
- /package/{config/typescript/security-rules → integrations/eslint/plugin/rules/security}/s026-json-schema-validation.js +0 -0
- /package/{config/typescript/security-rules → integrations/eslint/plugin/rules/security}/s027-no-hardcoded-secrets.js +0 -0
- /package/{config/typescript/security-rules → integrations/eslint/plugin/rules/security}/s029-require-csrf-protection.js +0 -0
- /package/{config/typescript/security-rules → integrations/eslint/plugin/rules/security}/s030-no-directory-browsing.js +0 -0
- /package/{config/typescript/security-rules → integrations/eslint/plugin/rules/security}/s033-require-samesite-cookie.js +0 -0
- /package/{config/typescript/security-rules → integrations/eslint/plugin/rules/security}/s034-require-host-cookie-prefix.js +0 -0
- /package/{config/typescript/security-rules → integrations/eslint/plugin/rules/security}/s035-cookie-specific-path.js +0 -0
- /package/{config/typescript/security-rules → integrations/eslint/plugin/rules/security}/s036-no-unsafe-file-include.js +0 -0
- /package/{config/typescript/security-rules → integrations/eslint/plugin/rules/security}/s037-require-anti-cache-headers.js +0 -0
- /package/{config/typescript/security-rules → integrations/eslint/plugin/rules/security}/s038-no-version-disclosure.js +0 -0
- /package/{config/typescript/security-rules → integrations/eslint/plugin/rules/security}/s039-no-session-token-in-url.js +0 -0
- /package/{config/typescript/security-rules → integrations/eslint/plugin/rules/security}/s041-require-session-invalidate-on-logout.js +0 -0
- /package/{config/typescript/security-rules → integrations/eslint/plugin/rules/security}/s042-require-periodic-reauthentication.js +0 -0
- /package/{config/typescript/security-rules → integrations/eslint/plugin/rules/security}/s043-terminate-sessions-on-password-change.js +0 -0
- /package/{config/typescript/security-rules → integrations/eslint/plugin/rules/security}/s044-require-full-session-for-sensitive-operations.js +0 -0
- /package/{config/typescript/security-rules → integrations/eslint/plugin/rules/security}/s045-anti-automation-controls.js +0 -0
- /package/{config/typescript/security-rules → integrations/eslint/plugin/rules/security}/s046-secure-notification-on-auth-change.js +0 -0
- /package/{config/typescript/security-rules → integrations/eslint/plugin/rules/security}/s048-password-credential-recovery.js +0 -0
- /package/{config/typescript/security-rules → integrations/eslint/plugin/rules/security}/s050-session-token-weak-hash.js +0 -0
- /package/{config/typescript/security-rules → integrations/eslint/plugin/rules/security}/s052-secure-random-authentication-code.js +0 -0
- /package/{config/typescript/security-rules → integrations/eslint/plugin/rules/security}/s054-verification-default-account.js +0 -0
- /package/{config/typescript/security-rules → integrations/eslint/plugin/rules/security}/s057-utc-logging.js +0 -0
- /package/{config/typescript/security-rules → integrations/eslint/plugin/rules/security}/s058-no-ssrf.js +0 -0
- /package/rules/{C006_function_naming → common/C006_function_naming}/config.json +0 -0
- /package/rules/{C019_log_level_usage → common/C019_log_level_usage}/config.json +0 -0
- /package/rules/{C029_catch_block_logging → common/C029_catch_block_logging}/config.json +0 -0
- /package/rules/{C031_validation_separation → common/C031_validation_separation}/analyzer.js +0 -0
- /package/rules/{C031_validation_separation/README.md → docs/C031_validation_separation.md} +0 -0
package/docs/AI.md
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# 🤖 AI-Powered Analysis
|
|
2
|
+
|
|
3
|
+
Sunlint supports AI-powered code analysis alongside traditional pattern-based analysis for more intelligent and context-aware rule checking.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
- **🎯 Smart Analysis**: Uses AI to understand code context and intent
|
|
8
|
+
- **🔄 Fallback Strategy**: Automatically falls back to pattern analysis if AI fails
|
|
9
|
+
- **⚡ Performance**: AI analysis runs per-file with caching support
|
|
10
|
+
- **🔧 Configurable**: Multiple AI providers and models supported
|
|
11
|
+
|
|
12
|
+
## Configuration
|
|
13
|
+
|
|
14
|
+
### In `.sunlint.json`:
|
|
15
|
+
|
|
16
|
+
```json
|
|
17
|
+
{
|
|
18
|
+
"ai": {
|
|
19
|
+
"enabled": true,
|
|
20
|
+
"provider": "openai",
|
|
21
|
+
"model": "gpt-4o-mini",
|
|
22
|
+
"apiKey": "${OPENAI_API_KEY}",
|
|
23
|
+
"fallbackToPattern": true
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Environment Variables:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
export OPENAI_API_KEY="your-openai-api-key"
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Supported Providers
|
|
35
|
+
|
|
36
|
+
### OpenAI
|
|
37
|
+
- **Models**: `gpt-4`, `gpt-4o-mini`, `gpt-3.5-turbo`
|
|
38
|
+
- **API Key**: Required via `OPENAI_API_KEY` environment variable
|
|
39
|
+
- **Cost**: Pay-per-use based on OpenAI pricing
|
|
40
|
+
|
|
41
|
+
### GitHub Copilot (Planned)
|
|
42
|
+
- **Integration**: VS Code extension integration
|
|
43
|
+
- **Models**: GitHub Copilot models
|
|
44
|
+
- **Authentication**: VS Code Copilot session
|
|
45
|
+
|
|
46
|
+
## AI-Enhanced Rules
|
|
47
|
+
|
|
48
|
+
### C019 - Log Level Usage
|
|
49
|
+
✅ **AI-Enabled**: Understands code context to determine appropriate log levels
|
|
50
|
+
|
|
51
|
+
**AI Analysis Features:**
|
|
52
|
+
- **Context Understanding**: Analyzes surrounding code to determine error criticality
|
|
53
|
+
- **Intent Recognition**: Understands whether errors are expected or exceptional
|
|
54
|
+
- **Semantic Analysis**: Goes beyond pattern matching to understand meaning
|
|
55
|
+
|
|
56
|
+
**Example:**
|
|
57
|
+
```typescript
|
|
58
|
+
// AI understands this is a validation error, suggests warn level
|
|
59
|
+
if (!user.email) {
|
|
60
|
+
console.error('Missing email'); // AI: Should use console.warn()
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// AI understands this is a critical system error, keeps error level
|
|
64
|
+
try {
|
|
65
|
+
await database.connect();
|
|
66
|
+
} catch (error) {
|
|
67
|
+
console.error('Database connection failed:', error); // AI: Appropriate error level
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Usage
|
|
72
|
+
|
|
73
|
+
### CLI Commands
|
|
74
|
+
|
|
75
|
+
**Enable AI for specific rule:**
|
|
76
|
+
```bash
|
|
77
|
+
sunlint --rule=C019 --input=src --ai
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
**Enable AI for all rules:**
|
|
81
|
+
```bash
|
|
82
|
+
sunlint --quality --input=src --ai
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
**Debug AI analysis:**
|
|
86
|
+
```bash
|
|
87
|
+
sunlint --rule=C019 --input=src --ai --verbose
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### VS Code Integration
|
|
91
|
+
|
|
92
|
+
1. **Debug Configuration**: Use "Debug Sunlint - AI Analysis"
|
|
93
|
+
2. **Task**: Run "Sunlint: AI Analysis Test"
|
|
94
|
+
3. **Set API Key**: Configure `OPENAI_API_KEY` in environment
|
|
95
|
+
|
|
96
|
+
## Output Differences
|
|
97
|
+
|
|
98
|
+
### Pattern Analysis Output:
|
|
99
|
+
```
|
|
100
|
+
WARNING: Error log level used for non-critical issue - should use warn/info level
|
|
101
|
+
at src/user.ts:15:5 (C019)
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### AI Analysis Output:
|
|
105
|
+
```
|
|
106
|
+
WARNING: Email validation error should use console.warn() - this is user input validation, not a system error
|
|
107
|
+
at src/user.ts:15:5 (C019)
|
|
108
|
+
Suggestion: Change to console.warn('User email validation failed:', email)
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Performance Considerations
|
|
112
|
+
|
|
113
|
+
- **Caching**: AI responses are cached per file content hash
|
|
114
|
+
- **Concurrency**: AI calls are made concurrently with rate limiting
|
|
115
|
+
- **Timeout**: 30-second timeout per AI request
|
|
116
|
+
- **Cost**: Monitor API usage in OpenAI dashboard
|
|
117
|
+
|
|
118
|
+
## Troubleshooting
|
|
119
|
+
|
|
120
|
+
### Common Issues
|
|
121
|
+
|
|
122
|
+
**API Key Not Found:**
|
|
123
|
+
```bash
|
|
124
|
+
⚠️ AI API key not found, falling back to pattern analysis
|
|
125
|
+
```
|
|
126
|
+
Solution: Set `OPENAI_API_KEY` environment variable
|
|
127
|
+
|
|
128
|
+
**API Rate Limit:**
|
|
129
|
+
```bash
|
|
130
|
+
AI Analysis failed: OpenAI API error: 429 Too Many Requests
|
|
131
|
+
```
|
|
132
|
+
Solution: Reduce `maxConcurrentRules` in config or wait
|
|
133
|
+
|
|
134
|
+
**Network Issues:**
|
|
135
|
+
```bash
|
|
136
|
+
AI Analysis failed: OpenAI API error: Network timeout
|
|
137
|
+
```
|
|
138
|
+
Solution: Check internet connection, increase `timeoutMs`
|
|
139
|
+
|
|
140
|
+
### Debug AI Issues
|
|
141
|
+
|
|
142
|
+
1. **Enable verbose mode**: `--verbose`
|
|
143
|
+
2. **Check API key**: `echo $OPENAI_API_KEY`
|
|
144
|
+
3. **Test connection**: Use debug configuration
|
|
145
|
+
4. **Check API quota**: Visit OpenAI dashboard
|
|
146
|
+
|
|
147
|
+
## Future Enhancements
|
|
148
|
+
|
|
149
|
+
- **🔄 GitHub Copilot Integration**: Direct integration with VS Code Copilot
|
|
150
|
+
- **📊 Custom Models**: Support for fine-tuned models
|
|
151
|
+
- **🎯 Rule-Specific Prompts**: Specialized prompts per rule type
|
|
152
|
+
- **💾 Smart Caching**: Semantic caching across similar code patterns
|
|
153
|
+
- **📈 Analytics**: AI vs Pattern analysis effectiveness metrics
|
|
154
|
+
|
|
155
|
+
## Cost Estimation
|
|
156
|
+
|
|
157
|
+
**OpenAI API Costs** (approximate):
|
|
158
|
+
- **gpt-4o-mini**: ~$0.001 per 1K tokens
|
|
159
|
+
- **gpt-4**: ~$0.03 per 1K tokens
|
|
160
|
+
- **Average file**: ~500 tokens
|
|
161
|
+
- **1000 files with gpt-4o-mini**: ~$0.50
|
|
162
|
+
|
|
163
|
+
**Recommendation**: Start with `gpt-4o-mini` for cost-effectiveness.
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# SunLint Modular Architecture
|
|
2
|
+
|
|
3
|
+
## Phase 1: TypeScript Focus với Kiến trúc Modular
|
|
4
|
+
|
|
5
|
+
### Cấu trúc mới:
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
cli.js # CLI entry point (simplified)
|
|
9
|
+
core/
|
|
10
|
+
├── cli-program.js # CLI options definition (Rule C005)
|
|
11
|
+
├── cli-action-handler.js # Main execution flow (Rule C005)
|
|
12
|
+
├── rule-selection-service.js # Rule selection logic (Rule C005)
|
|
13
|
+
├── analysis-orchestrator.js # Analysis coordination (Rule C005)
|
|
14
|
+
├── output-service.js # Output formatting (Rule C005)
|
|
15
|
+
├── eslint-engine-service.js # ESLint integration (future)
|
|
16
|
+
└── sunlint-engine-service.js # Native SunLint engine
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### Nguyên tắc thiết kế:
|
|
20
|
+
|
|
21
|
+
1. **Rule C005**: Mỗi class/file chỉ làm một việc
|
|
22
|
+
2. **Rule C014**: Dependency injection thay vì new trực tiếp
|
|
23
|
+
3. **Rule C012**: Tách rõ Command và Query
|
|
24
|
+
4. **Modular**: Dễ mở rộng cho Phase 2
|
|
25
|
+
|
|
26
|
+
### Luồng hoạt động:
|
|
27
|
+
|
|
28
|
+
1. `cli.js` → `CliActionHandler`
|
|
29
|
+
2. `CliActionHandler` → Load config, validate input
|
|
30
|
+
3. `RuleSelectionService` → Select rules based on options
|
|
31
|
+
4. `AnalysisOrchestrator` → Run analysis (SunLint or ESLint)
|
|
32
|
+
5. `OutputService` → Format and display results
|
|
33
|
+
|
|
34
|
+
### Các tính năng hiện tại:
|
|
35
|
+
|
|
36
|
+
- ✅ Modular CLI với dependency injection
|
|
37
|
+
- ✅ Rule selection (single, multiple, all, category)
|
|
38
|
+
- ✅ Dry run mode
|
|
39
|
+
- ✅ TypeScript-specific options (chuẩn bị cho Phase 1)
|
|
40
|
+
- ✅ Graceful fallback khi không tìm thấy dependencies
|
|
41
|
+
- ✅ Clean error handling và logging
|
|
42
|
+
|
|
43
|
+
### Phase 1 roadmap:
|
|
44
|
+
|
|
45
|
+
1. **✅ Done**: Modular CLI architecture
|
|
46
|
+
2. **✅ Done**: ESLint integration cho TypeScript
|
|
47
|
+
3. **Next**: TypeScript custom rules thông qua ESLint
|
|
48
|
+
4. **✅ Done**: Hybrid engine (ESLint + SunLint)
|
|
49
|
+
|
|
50
|
+
### Phase 2 roadmap:
|
|
51
|
+
|
|
52
|
+
1. Native SunLint engine cho tất cả ngôn ngữ
|
|
53
|
+
2. Mở rộng Dart, Kotlin rules
|
|
54
|
+
3. AI-powered analysis
|
|
55
|
+
4. VS Code extension integration
|
|
56
|
+
|
|
57
|
+
### Usage Examples:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
# Basic usage
|
|
61
|
+
sunlint --rule=C006 --input=src
|
|
62
|
+
|
|
63
|
+
# Category-based
|
|
64
|
+
sunlint --quality --input=src
|
|
65
|
+
|
|
66
|
+
# TypeScript-specific (Phase 1)
|
|
67
|
+
sunlint --typescript --input=src
|
|
68
|
+
sunlint --typescript-engine=eslint --input=src
|
|
69
|
+
|
|
70
|
+
# Dry run
|
|
71
|
+
sunlint --dry-run --all --input=src
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Dependencies:
|
|
75
|
+
|
|
76
|
+
- Minimal core dependencies
|
|
77
|
+
- ESLint integration sẽ được thêm trong Phase 1
|
|
78
|
+
- Graceful fallback khi dependencies không có sẵn
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
# 🚀 SunLint CI/CD Integration Guide
|
|
2
|
+
|
|
3
|
+
## 📋 **Tổng quan các chức năng CLI**
|
|
4
|
+
|
|
5
|
+
### ✅ **Phạm vi kiểm tra**
|
|
6
|
+
- ✅ Kiểm tra 1 file: `node cli.js --all --input=file.js`
|
|
7
|
+
- ✅ Kiểm tra 1 folder: `node cli.js --all --input=src`
|
|
8
|
+
- ✅ Kiểm tra toàn project: `node cli.js --all --input=.`
|
|
9
|
+
- ✅ Kiểm tra changed files: `node cli.js --all --changed-files`
|
|
10
|
+
- ✅ Kiểm tra staged files: `node cli.js --all --staged-files`
|
|
11
|
+
|
|
12
|
+
### ✅ **Lựa chọn rules**
|
|
13
|
+
- ✅ 1 rule: `node cli.js --rule=C019 --input=src`
|
|
14
|
+
- ✅ Nhiều rules: `node cli.js --rules=C019,C006 --input=src`
|
|
15
|
+
- ✅ Tất cả rules: `node cli.js --all --input=src`
|
|
16
|
+
- ✅ Theo category: `node cli.js --quality --input=src`
|
|
17
|
+
|
|
18
|
+
### ✅ **Phương pháp phân tích**
|
|
19
|
+
- ✅ Pattern-based (free): `node cli.js --all --input=src --no-ai`
|
|
20
|
+
- ✅ AI-powered (cost): `node cli.js --all --input=src --ai`
|
|
21
|
+
|
|
22
|
+
### ✅ **CI/CD Features**
|
|
23
|
+
- ✅ Git integration: `--changed-files`, `--staged-files`, `--diff-base`
|
|
24
|
+
- ✅ Baseline comparison: `--baseline`, `--save-baseline`
|
|
25
|
+
- ✅ New violations only: `--fail-on-new-violations`
|
|
26
|
+
- ✅ Multiple output formats: `--format=json|eslint|github|summary`
|
|
27
|
+
|
|
28
|
+
## 🎯 **CI/CD Strategies**
|
|
29
|
+
|
|
30
|
+
### **Strategy 1: Full Coverage (Traditional)**
|
|
31
|
+
```bash
|
|
32
|
+
# Advantages: Complete analysis, no missed issues
|
|
33
|
+
# Disadvantages: Slow, expensive, noisy for large projects
|
|
34
|
+
|
|
35
|
+
# Usage:
|
|
36
|
+
node cli.js --all --input=. --format=json --output=report.json
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### **Strategy 2: Incremental (Recommended)**
|
|
40
|
+
```bash
|
|
41
|
+
# PR Check: Only changed files
|
|
42
|
+
node cli.js --all --changed-files --diff-base=origin/main --fail-on-new-violations
|
|
43
|
+
|
|
44
|
+
# Main Branch: Full scan + baseline
|
|
45
|
+
node cli.js --all --input=. --save-baseline=baseline.json --format=json
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### **Strategy 3: Risk-Based**
|
|
49
|
+
```bash
|
|
50
|
+
# High-risk areas only
|
|
51
|
+
node cli.js --security --input=src/auth,src/payment --format=summary
|
|
52
|
+
|
|
53
|
+
# Critical rules only
|
|
54
|
+
node cli.js --rules=C019,S001,S003 --changed-files --format=github
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## 📊 **Performance Comparison**
|
|
58
|
+
|
|
59
|
+
| Scope | Files | Time | Use Case |
|
|
60
|
+
|-------|-------|------|----------|
|
|
61
|
+
| Single file | 1 | ~1-3s | IDE integration, pre-commit |
|
|
62
|
+
| Changed files (PR) | 5-20 | ~10-30s | PR checks, fast feedback |
|
|
63
|
+
| Module/folder | 50-200 | ~1-2min | Feature development |
|
|
64
|
+
| Full project | 500+ | ~3-10min | Nightly builds, releases |
|
|
65
|
+
|
|
66
|
+
## 🔄 **Workflow Examples**
|
|
67
|
+
|
|
68
|
+
### **GitHub Actions - Complete Setup**
|
|
69
|
+
|
|
70
|
+
```yaml
|
|
71
|
+
name: SunLint Quality Gates
|
|
72
|
+
on:
|
|
73
|
+
push:
|
|
74
|
+
branches: [main]
|
|
75
|
+
pull_request:
|
|
76
|
+
branches: [main]
|
|
77
|
+
|
|
78
|
+
env:
|
|
79
|
+
NODE_VERSION: '18'
|
|
80
|
+
|
|
81
|
+
jobs:
|
|
82
|
+
# Job 1: PR Quality Check (fast)
|
|
83
|
+
pr-check:
|
|
84
|
+
if: github.event_name == 'pull_request'
|
|
85
|
+
runs-on: ubuntu-latest
|
|
86
|
+
steps:
|
|
87
|
+
- uses: actions/checkout@v3
|
|
88
|
+
with:
|
|
89
|
+
fetch-depth: 0
|
|
90
|
+
|
|
91
|
+
- name: Setup Node.js
|
|
92
|
+
uses: actions/setup-node@v3
|
|
93
|
+
with:
|
|
94
|
+
node-version: ${{ env.NODE_VERSION }}
|
|
95
|
+
|
|
96
|
+
- name: Install SunLint
|
|
97
|
+
run: |
|
|
98
|
+
cd coding-quality/extensions/sunlint
|
|
99
|
+
npm install
|
|
100
|
+
|
|
101
|
+
- name: Download Baseline
|
|
102
|
+
uses: actions/download-artifact@v3
|
|
103
|
+
with:
|
|
104
|
+
name: sunlint-baseline
|
|
105
|
+
path: coding-quality/extensions/sunlint/
|
|
106
|
+
continue-on-error: true
|
|
107
|
+
|
|
108
|
+
- name: Run SunLint on Changed Files
|
|
109
|
+
run: |
|
|
110
|
+
cd coding-quality/extensions/sunlint
|
|
111
|
+
node cli.js --all --changed-files \
|
|
112
|
+
--diff-base=origin/${{ github.base_ref }} \
|
|
113
|
+
--baseline=baseline.json \
|
|
114
|
+
--fail-on-new-violations \
|
|
115
|
+
--format=github \
|
|
116
|
+
--no-ai
|
|
117
|
+
|
|
118
|
+
- name: Comment PR
|
|
119
|
+
if: failure()
|
|
120
|
+
uses: actions/github-script@v6
|
|
121
|
+
with:
|
|
122
|
+
script: |
|
|
123
|
+
github.rest.issues.createComment({
|
|
124
|
+
issue_number: context.issue.number,
|
|
125
|
+
owner: context.repo.owner,
|
|
126
|
+
repo: context.repo.repo,
|
|
127
|
+
body: '❌ SunLint found code quality issues. Please check the Actions log for details.'
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
# Job 2: Full Scan + Baseline (comprehensive)
|
|
131
|
+
full-scan:
|
|
132
|
+
if: github.ref == 'refs/heads/main'
|
|
133
|
+
runs-on: ubuntu-latest
|
|
134
|
+
steps:
|
|
135
|
+
- uses: actions/checkout@v3
|
|
136
|
+
|
|
137
|
+
- name: Setup Node.js
|
|
138
|
+
uses: actions/setup-node@v3
|
|
139
|
+
with:
|
|
140
|
+
node-version: ${{ env.NODE_VERSION }}
|
|
141
|
+
|
|
142
|
+
- name: Install SunLint
|
|
143
|
+
run: |
|
|
144
|
+
cd coding-quality/extensions/sunlint
|
|
145
|
+
npm install
|
|
146
|
+
|
|
147
|
+
- name: Run Full SunLint Scan
|
|
148
|
+
run: |
|
|
149
|
+
cd coding-quality/extensions/sunlint
|
|
150
|
+
node cli.js --all --input=. \
|
|
151
|
+
--save-baseline=baseline.json \
|
|
152
|
+
--format=json \
|
|
153
|
+
--output=sunlint-report.json \
|
|
154
|
+
--no-ai
|
|
155
|
+
|
|
156
|
+
- name: Upload Baseline
|
|
157
|
+
uses: actions/upload-artifact@v3
|
|
158
|
+
with:
|
|
159
|
+
name: sunlint-baseline
|
|
160
|
+
path: coding-quality/extensions/sunlint/baseline.json
|
|
161
|
+
retention-days: 30
|
|
162
|
+
|
|
163
|
+
- name: Upload Report
|
|
164
|
+
uses: actions/upload-artifact@v3
|
|
165
|
+
with:
|
|
166
|
+
name: sunlint-report
|
|
167
|
+
path: coding-quality/extensions/sunlint/sunlint-report.json
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### **GitLab CI - Complete Setup**
|
|
171
|
+
|
|
172
|
+
```yaml
|
|
173
|
+
stages:
|
|
174
|
+
- quality-check
|
|
175
|
+
- quality-baseline
|
|
176
|
+
|
|
177
|
+
variables:
|
|
178
|
+
SUNLINT_PATH: "coding-quality/extensions/sunlint"
|
|
179
|
+
|
|
180
|
+
# Fast PR check
|
|
181
|
+
sunlint:pr:
|
|
182
|
+
stage: quality-check
|
|
183
|
+
image: node:18
|
|
184
|
+
rules:
|
|
185
|
+
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
|
|
186
|
+
before_script:
|
|
187
|
+
- cd $SUNLINT_PATH
|
|
188
|
+
- npm install
|
|
189
|
+
script:
|
|
190
|
+
- |
|
|
191
|
+
if [ -f baseline.json ]; then
|
|
192
|
+
echo "Using existing baseline"
|
|
193
|
+
node cli.js --all --changed-files \
|
|
194
|
+
--diff-base=origin/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME \
|
|
195
|
+
--baseline=baseline.json \
|
|
196
|
+
--fail-on-new-violations \
|
|
197
|
+
--format=summary \
|
|
198
|
+
--no-ai
|
|
199
|
+
else
|
|
200
|
+
echo "No baseline found, running on changed files only"
|
|
201
|
+
node cli.js --all --changed-files \
|
|
202
|
+
--diff-base=origin/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME \
|
|
203
|
+
--format=summary \
|
|
204
|
+
--no-ai
|
|
205
|
+
fi
|
|
206
|
+
artifacts:
|
|
207
|
+
reports:
|
|
208
|
+
junit: $SUNLINT_PATH/sunlint-report.xml
|
|
209
|
+
when: always
|
|
210
|
+
expire_in: 1 week
|
|
211
|
+
|
|
212
|
+
# Full scan for main branch
|
|
213
|
+
sunlint:baseline:
|
|
214
|
+
stage: quality-baseline
|
|
215
|
+
image: node:18
|
|
216
|
+
rules:
|
|
217
|
+
- if: $CI_COMMIT_BRANCH == "main"
|
|
218
|
+
before_script:
|
|
219
|
+
- cd $SUNLINT_PATH
|
|
220
|
+
- npm install
|
|
221
|
+
script:
|
|
222
|
+
- |
|
|
223
|
+
node cli.js --all --input=. \
|
|
224
|
+
--save-baseline=baseline.json \
|
|
225
|
+
--format=json \
|
|
226
|
+
--output=sunlint-report.json \
|
|
227
|
+
--no-ai
|
|
228
|
+
artifacts:
|
|
229
|
+
paths:
|
|
230
|
+
- $SUNLINT_PATH/baseline.json
|
|
231
|
+
- $SUNLINT_PATH/sunlint-report.json
|
|
232
|
+
expire_in: 1 month
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
## 🎲 **Pre-commit Hook**
|
|
236
|
+
|
|
237
|
+
```bash
|
|
238
|
+
#!/bin/sh
|
|
239
|
+
# .git/hooks/pre-commit
|
|
240
|
+
|
|
241
|
+
cd coding-quality/extensions/sunlint
|
|
242
|
+
|
|
243
|
+
echo "🔍 Running SunLint on staged files..."
|
|
244
|
+
node cli.js --all --staged-files --format=summary --no-ai
|
|
245
|
+
|
|
246
|
+
if [ $? -ne 0 ]; then
|
|
247
|
+
echo "❌ SunLint found issues. Commit aborted."
|
|
248
|
+
echo "💡 Fix the issues or use 'git commit --no-verify' to bypass."
|
|
249
|
+
exit 1
|
|
250
|
+
fi
|
|
251
|
+
|
|
252
|
+
echo "✅ SunLint passed!"
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
## 📈 **Monitoring & Metrics**
|
|
256
|
+
|
|
257
|
+
### **Track Quality Trends**
|
|
258
|
+
```bash
|
|
259
|
+
# Generate trend report
|
|
260
|
+
node cli.js --all --input=. --format=json --output=reports/$(date +%Y-%m-%d).json
|
|
261
|
+
|
|
262
|
+
# Compare with previous scan
|
|
263
|
+
node cli.js --all --input=. --baseline=reports/baseline.json --format=trend
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
### **Quality Gates**
|
|
267
|
+
```bash
|
|
268
|
+
# Fail if more than 10 new violations
|
|
269
|
+
node cli.js --all --changed-files --max-new-violations=10
|
|
270
|
+
|
|
271
|
+
# Fail on any security issues
|
|
272
|
+
node cli.js --security --changed-files --severity=error
|
|
273
|
+
|
|
274
|
+
# Allow warnings but fail on errors
|
|
275
|
+
node cli.js --all --changed-files --severity=error
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
## 🚨 **Troubleshooting**
|
|
279
|
+
|
|
280
|
+
### **Common Issues**
|
|
281
|
+
|
|
282
|
+
1. **"No changed files detected"**
|
|
283
|
+
```bash
|
|
284
|
+
# Check git status
|
|
285
|
+
git status
|
|
286
|
+
git diff --name-only origin/main
|
|
287
|
+
|
|
288
|
+
# Force include specific files
|
|
289
|
+
node cli.js --all --input=src/specific-file.ts
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
2. **"Baseline not found"**
|
|
293
|
+
```bash
|
|
294
|
+
# Create initial baseline
|
|
295
|
+
node cli.js --all --input=. --save-baseline=baseline.json --no-ai
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
3. **"Too many violations"**
|
|
299
|
+
```bash
|
|
300
|
+
# Focus on high-priority rules first
|
|
301
|
+
node cli.js --rules=C019,S001 --changed-files
|
|
302
|
+
|
|
303
|
+
# Use severity filtering
|
|
304
|
+
node cli.js --all --changed-files --severity=error
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
## 🎯 **Best Practices Summary**
|
|
308
|
+
|
|
309
|
+
1. **Start Small**: Begin with changed files only
|
|
310
|
+
2. **Incremental Adoption**: Add rules gradually
|
|
311
|
+
3. **Use Baselines**: For large existing projects
|
|
312
|
+
4. **Monitor Performance**: Track CI execution time
|
|
313
|
+
5. **Focus on New Code**: Don't overwhelm with legacy issues
|
|
314
|
+
6. **Automate Everything**: Pre-commit + PR checks + nightly scans
|
|
315
|
+
7. **Cost Optimization**: Use `--no-ai` for CI to avoid API costs
|