@sun-asterisk/sunlint 1.3.17 → 1.3.18

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.
@@ -1,270 +0,0 @@
1
- # SunLint Deployment Strategies
2
-
3
- This document outlines different deployment strategies for SunLint, demonstrating the modular approach that allows selective inclusion/exclusion of features.
4
-
5
- ## Overview
6
-
7
- SunLint supports flexible deployment strategies through its modular architecture:
8
-
9
- - **Core Features**: Always included (heuristic regex, ESLint integration)
10
- - **AST Enhancement**: Optional Tree-sitter modules for improved accuracy
11
- - **Language-Specific**: Can include/exclude language-specific parsers
12
- - **AI Features**: Optional OpenAI integration
13
-
14
- ## Deployment Strategies
15
-
16
- ### 1. Full Distribution (Development/Enterprise)
17
-
18
- **Target**: Development teams, enterprise installations
19
- **Size**: Large (~50MB+ with all AST parsers)
20
- **Accuracy**: Highest
21
-
22
- ```bash
23
- # Include everything
24
- npm install sunlint
25
-
26
- # Available engines: eslint, heuristic (with AST), openai
27
- sunlint --rule=C010 --engine=heuristic src/
28
- # Uses AST when available, falls back to regex
29
- ```
30
-
31
- **Files Included**:
32
- ```
33
- sunlint/
34
- ├── engines/
35
- │ ├── eslint-engine.js ✅ ESLint integration
36
- │ ├── heuristic-engine.js ✅ Enhanced with AST
37
- │ └── openai-engine.js ✅ AI-powered analysis
38
- ├── core/ast-modules/ ✅ Full AST support
39
- │ ├── parsers/
40
- │ │ ├── javascript-parser.js ✅ JS AST
41
- │ │ ├── typescript-parser.js ✅ TS AST
42
- │ │ ├── dart-parser.js ✅ Dart AST
43
- │ │ ├── java-parser.js ✅ Java AST
44
- │ │ └── ... ✅ All languages
45
- │ └── package.json ✅ Tree-sitter deps
46
- └── ...
47
- ```
48
-
49
- ### 2. TypeScript-Only Distribution
50
-
51
- **Target**: TypeScript-only projects, Next.js, React
52
- **Size**: Medium (~15MB)
53
- **Accuracy**: High for TS/JS, regex for others
54
-
55
- ```bash
56
- # Build script for TypeScript distribution
57
- npm run build:typescript
58
-
59
- # Available engines: eslint, heuristic (TS/JS AST only)
60
- sunlint --rule=C010 --engine=heuristic src/
61
- # Uses AST for .ts/.js files, regex for others
62
- ```
63
-
64
- **Build Process**:
65
- ```bash
66
- #!/bin/bash
67
- # build-typescript.sh
68
-
69
- # Copy base files
70
- cp -r engines/ dist/
71
- cp -r rules/ dist/
72
- cp -r core/ dist/
73
-
74
- # Keep only TypeScript/JavaScript AST parsers
75
- mkdir -p dist/core/ast-modules/parsers/
76
- cp core/ast-modules/index.js dist/core/ast-modules/
77
- cp core/ast-modules/base-parser.js dist/core/ast-modules/
78
- cp core/ast-modules/parsers/javascript-parser.js dist/core/ast-modules/parsers/
79
- cp core/ast-modules/parsers/typescript-parser.js dist/core/ast-modules/parsers/
80
-
81
- # Update package.json to include only JS/TS Tree-sitter deps
82
- cat > dist/core/ast-modules/package.json << 'EOF'
83
- {
84
- "name": "@sunlint/ast-typescript",
85
- "dependencies": {
86
- "tree-sitter": "^0.20.0",
87
- "tree-sitter-javascript": "^0.20.0",
88
- "tree-sitter-typescript": "^0.20.0"
89
- }
90
- }
91
- EOF
92
-
93
- # Remove OpenAI engine for smaller bundle
94
- rm dist/engines/openai-engine.js
95
-
96
- npm pack dist/
97
- ```
98
-
99
- ### 3. Minimal Distribution (Regex-Only)
100
-
101
- **Target**: CI/CD, embedded systems, minimal installs
102
- **Size**: Small (~2MB)
103
- **Accuracy**: Basic regex patterns only
104
-
105
- ```bash
106
- # Build script for minimal distribution
107
- npm run build:minimal
108
-
109
- # Available engines: eslint, heuristic (regex-only)
110
- sunlint --rule=C010 --engine=heuristic src/
111
- # Uses only regex patterns, no AST enhancement
112
- ```
113
-
114
- **Build Process**:
115
- ```bash
116
- #!/bin/bash
117
- # build-minimal.sh
118
-
119
- # Copy only essential files
120
- cp -r engines/ dist/
121
- cp -r rules/ dist/
122
- cp -r core/ dist/
123
-
124
- # Remove entire AST modules directory
125
- rm -rf dist/core/ast-modules/
126
-
127
- # Remove OpenAI engine
128
- rm dist/engines/openai-engine.js
129
-
130
- # Update heuristic engine to not reference AST modules
131
- sed -i 's/const ASTModuleRegistry = require.*//g' dist/engines/heuristic-engine.js
132
- sed -i 's/this.astRegistry = ASTModuleRegistry;//g' dist/engines/heuristic-engine.js
133
-
134
- npm pack dist/
135
- ```
136
-
137
- ### 4. Language-Specific Distributions
138
-
139
- **Example: Java-Only Distribution**
140
-
141
- ```bash
142
- #!/bin/bash
143
- # build-java.sh
144
-
145
- # Base files
146
- cp -r engines/ dist/
147
- cp -r rules/ dist/
148
- cp -r core/ dist/
149
-
150
- # Keep only Java AST parser
151
- mkdir -p dist/core/ast-modules/parsers/
152
- cp core/ast-modules/index.js dist/core/ast-modules/
153
- cp core/ast-modules/base-parser.js dist/core/ast-modules/
154
- cp core/ast-modules/parsers/java-parser.js dist/core/ast-modules/parsers/
155
-
156
- # Java-specific package.json
157
- cat > dist/core/ast-modules/package.json << 'EOF'
158
- {
159
- "name": "@sunlint/ast-java",
160
- "dependencies": {
161
- "tree-sitter": "^0.20.0",
162
- "tree-sitter-java": "^0.20.0"
163
- }
164
- }
165
- EOF
166
-
167
- # Remove ESLint engine (Java doesn't need it)
168
- rm dist/engines/eslint-engine.js
169
-
170
- # Update engine registry
171
- cat > dist/config/engines/engines.json << 'EOF'
172
- {
173
- "engines": {
174
- "heuristic": {
175
- "enabled": true,
176
- "path": "./engines/heuristic-engine.js",
177
- "version": "2.0",
178
- "supportedLanguages": ["java"],
179
- "priority": 1,
180
- "description": "Enhanced Java analyzer with AST support"
181
- }
182
- },
183
- "defaultEngines": ["heuristic"],
184
- "fallbackEngine": "heuristic"
185
- }
186
- EOF
187
-
188
- npm pack dist/
189
- ```
190
-
191
- ## Runtime Behavior
192
-
193
- ### With AST Support Available
194
- ```bash
195
- $ sunlint --rule=C010 --engine=heuristic --debug src/
196
- 🌳 [AST-Enhanced] Analyzing C010 for typescript with AST support
197
- 🌳 [AST-Enhanced] Found 12 violations via AST, 3 via regex
198
- ✅ heuristic: 15 violations found
199
- ```
200
-
201
- ### AST Support Not Available (Fallback)
202
- ```bash
203
- $ sunlint --rule=C010 --engine=heuristic --debug src/
204
- ⚠️ Tree-sitter TypeScript parser not available, falling back to regex
205
- ✅ heuristic: 8 violations found
206
- ```
207
-
208
- ### Minimal Installation
209
- ```bash
210
- $ sunlint --rule=C010 --engine=heuristic --debug src/
211
- # No AST warnings - AST modules not included
212
- ✅ heuristic: 8 violations found
213
- ```
214
-
215
- ## Package.json Configurations
216
-
217
- ### Full Distribution
218
- ```json
219
- {
220
- "name": "sunlint",
221
- "dependencies": {
222
- "minimatch": "^9.0.0",
223
- "eslint": "^8.0.0"
224
- },
225
- "optionalDependencies": {
226
- "tree-sitter": "^0.20.0",
227
- "tree-sitter-javascript": "^0.20.0",
228
- "tree-sitter-typescript": "^0.20.0",
229
- "tree-sitter-dart": "^0.1.0",
230
- "tree-sitter-java": "^0.20.0",
231
- "tree-sitter-kotlin": "^0.3.0",
232
- "tree-sitter-swift": "^0.4.0",
233
- "tree-sitter-python": "^0.20.0",
234
- "tree-sitter-go": "^0.20.0",
235
- "tree-sitter-rust": "^0.20.0"
236
- }
237
- }
238
- ```
239
-
240
- ### TypeScript-Only Distribution
241
- ```json
242
- {
243
- "name": "@sunlint/typescript",
244
- "dependencies": {
245
- "minimatch": "^9.0.0",
246
- "eslint": "^8.0.0",
247
- "tree-sitter": "^0.20.0",
248
- "tree-sitter-javascript": "^0.20.0",
249
- "tree-sitter-typescript": "^0.20.0"
250
- }
251
- }
252
- ```
253
-
254
- ### Minimal Distribution
255
- ```json
256
- {
257
- "name": "@sunlint/minimal",
258
- "dependencies": {
259
- "minimatch": "^9.0.0"
260
- }
261
- }
262
- ```
263
-
264
- ## Benefits
265
-
266
- 1. **Flexibility**: Choose the right distribution for your needs
267
- 2. **Performance**: Smaller bundles load faster, fewer dependencies to install
268
- 3. **Compatibility**: Minimal distribution works everywhere, enhanced versions provide better accuracy
269
- 4. **Gradual Adoption**: Start with minimal, upgrade to AST-enhanced when needed
270
- 5. **Deployment Options**: Different distributions for different environments (CI vs development)
@@ -1,238 +0,0 @@
1
- # ESLint Integration Feature
2
-
3
- ## 🎯 **Overview**
4
-
5
- SunLint ESLint Integration cho phép teams **merge** existing ESLint configuration với SunLint rules trong **single execution pipeline**. Thay vì chạy parallel, SunLint sẽ **orchestrate** và **combine** cả 2 rule sets.
6
-
7
- ### **Problem Solved**
8
- - ✅ Teams có existing ESLint (20 rules) + muốn add SunLint (93 rules) = **113 rules total**
9
- - ✅ Single command execution thay vì multiple tool chains
10
- - ✅ No degradation của existing ESLint workflow
11
- - ✅ Combined reporting cho easier debugging
12
-
13
- ## 📖 **Configuration**
14
-
15
- ### **Method 1: package.json Configuration**
16
- ```json
17
- {
18
- "scripts": {
19
- "lint:integrated": "sunlint --all --eslint-integration --input=src"
20
- },
21
- "sunlint": {
22
- "eslintIntegration": {
23
- "enabled": true,
24
- "mergeRules": true,
25
- "preserveUserConfig": true
26
- },
27
- "rules": {
28
- "C006": "warn",
29
- "C019": "error"
30
- }
31
- }
32
- }
33
- ```
34
-
35
- ### **Method 2: .sunlint.json Configuration**
36
- ```json
37
- {
38
- "eslintIntegration": {
39
- "enabled": true,
40
- "mergeRules": true,
41
- "preserveUserConfig": true,
42
- "runAfterSunLint": false
43
- },
44
- "rules": {
45
- "C006": "warn",
46
- "C019": "error",
47
- "S047": "warn"
48
- }
49
- }
50
- ```
51
-
52
- ### **Method 3: CLI Flags**
53
- ```bash
54
- # Enable integration
55
- sunlint --all --eslint-integration --input=src
56
-
57
- # Merge rules (default: true)
58
- sunlint --all --eslint-integration --eslint-merge-rules --input=src
59
-
60
- # Preserve user config (default: true)
61
- sunlint --all --eslint-integration --eslint-preserve-config --input=src
62
-
63
- # Run ESLint after SunLint (alternative to merge)
64
- sunlint --all --eslint-integration --eslint-run-after --input=src
65
- ```
66
-
67
- ## 🔧 **Integration Modes**
68
-
69
- ### **Mode 1: Merged Execution (Default)**
70
- ```bash
71
- sunlint --all --eslint-integration --input=src
72
- ```
73
-
74
- **How it works:**
75
- 1. SunLint discovers existing `.eslintrc.json`
76
- 2. Merges SunLint rules + User ESLint rules
77
- 3. Creates combined ESLint configuration
78
- 4. Runs single ESLint execution with **merged ruleset**
79
- 5. Categorizes results by rule source (SunLint vs User)
80
-
81
- **Output:**
82
- ```
83
- 🔗 ESLint Integration Summary:
84
- 📋 SunLint violations: 4
85
- 🔧 User ESLint violations: 6
86
- 📊 Total combined violations: 10
87
- ```
88
-
89
- ### **Mode 2: Sequential Execution**
90
- ```bash
91
- sunlint --all --eslint-integration --eslint-run-after --input=src
92
- ```
93
-
94
- **How it works:**
95
- 1. Run SunLint rules first
96
- 2. Run user ESLint rules after
97
- 3. Combine results for reporting
98
- 4. Maintain separation of concerns
99
-
100
- ## 🚀 **Usage Examples**
101
-
102
- ### **Basic Integration**
103
- ```bash
104
- # Analyze with both SunLint + existing ESLint rules
105
- sunlint --typescript --eslint-integration --input=src
106
-
107
- # Git integration + ESLint integration
108
- sunlint --all --eslint-integration --changed-files
109
-
110
- # CI pipeline
111
- sunlint --all --eslint-integration --changed-files --format=summary --fail-on-new-violations
112
- ```
113
-
114
- ### **Team Migration Scripts**
115
- ```json
116
- {
117
- "scripts": {
118
- "lint": "npm run lint:integrated",
119
- "lint:integrated": "sunlint --all --eslint-integration --input=src",
120
- "lint:changed": "sunlint --all --eslint-integration --changed-files",
121
- "lint:staged": "sunlint --all --eslint-integration --staged-files",
122
- "ci:lint": "sunlint --all --eslint-integration --changed-files --format=summary"
123
- }
124
- }
125
- ```
126
-
127
- ### **GitHub Actions Integration**
128
- ```yaml
129
- name: Code Quality Check
130
- on: [pull_request]
131
-
132
- jobs:
133
- lint:
134
- runs-on: ubuntu-latest
135
- steps:
136
- - uses: actions/checkout@v3
137
- - uses: actions/setup-node@v3
138
- - run: npm ci
139
- - name: Run Integrated Linting
140
- run: |
141
- sunlint --all --eslint-integration --changed-files \
142
- --diff-base=origin/main \
143
- --format=summary \
144
- --fail-on-new-violations
145
- ```
146
-
147
- ## 🏗️ **Architecture**
148
-
149
- ### **ESLintIntegrationService**
150
- - **Responsibility**: Detect, load, and merge ESLint configurations
151
- - **Methods**:
152
- - `hasExistingESLintConfig()`: Auto-detect existing ESLint setup
153
- - `loadExistingESLintConfig()`: Load user's ESLint configuration
154
- - `createMergedConfig()`: Merge SunLint + User rules
155
- - `runIntegratedAnalysis()`: Execute combined analysis
156
-
157
- ### **Configuration Merging Strategy**
158
- ```javascript
159
- mergedConfig = {
160
- extends: [...sunlintExtends, ...userExtends],
161
- plugins: [...sunlintPlugins, ...userPlugins],
162
- rules: {
163
- ...sunlintRules,
164
- ...userRules // User rules override SunLint in case of conflicts
165
- }
166
- }
167
- ```
168
-
169
- ### **Result Categorization**
170
- ```javascript
171
- {
172
- results: [...],
173
- categorized: {
174
- sunlint: [/* SunLint violations */],
175
- user: [/* User ESLint violations */],
176
- combined: [/* All violations */]
177
- },
178
- integration: {
179
- totalRules: 113,
180
- sunlintRules: 93,
181
- userRules: 20
182
- }
183
- }
184
- ```
185
-
186
- ## 🎯 **Benefits**
187
-
188
- ### **For Development Teams**
189
- - ✅ **No workflow disruption**: Existing ESLint continues working
190
- - ✅ **Single command**: One execution for all quality checks
191
- - ✅ **Incremental adoption**: Can enable/disable integration easily
192
- - ✅ **Conflict resolution**: User rules take precedence over SunLint
193
-
194
- ### **For CI/CD Pipelines**
195
- - ✅ **Faster execution**: Single tool execution vs multiple tools
196
- - ✅ **Unified reporting**: Combined results, easier to track
197
- - ✅ **Git integration**: Works with `--changed-files`, `--staged-files`
198
- - ✅ **Baseline comparison**: `--fail-on-new-violations`
199
-
200
- ### **For Enterprise Adoption**
201
- - ✅ **Backward compatibility**: No existing config changes required
202
- - ✅ **Gradual migration**: Teams can test integration without commitment
203
- - ✅ **Centralized enforcement**: SunLint rules + team-specific ESLint rules
204
- - ✅ **Compliance reporting**: Combined violation tracking
205
-
206
- ## 📊 **Example Scenario**
207
-
208
- **Before Integration:**
209
- ```bash
210
- # Team workflow (2 separate commands)
211
- npm run lint:eslint # 20 rules, 6 violations
212
- npm run lint:sunlint # 93 rules, 4 violations
213
- # Total: 10 violations, 2 command executions
214
- ```
215
-
216
- **After Integration:**
217
- ```bash
218
- # Single integrated command
219
- npm run lint:integrated # 113 rules, 10 violations
220
- # Total: 10 violations, 1 command execution
221
- ```
222
-
223
- ## 🔍 **Demo**
224
-
225
- Run the integration demo:
226
- ```bash
227
- ./demo-eslint-integration.sh
228
- ```
229
-
230
- This demonstrates:
231
- 1. Existing ESLint workflow (20 rules)
232
- 2. SunLint-only analysis (93 rules)
233
- 3. **Integrated analysis (113 rules total)**
234
- 4. Available npm scripts for team adoption
235
-
236
- ---
237
-
238
- **🎉 Result**: Teams can now run **113 total rules** (93 SunLint + 20 existing ESLint) in **single command execution** without disrupting existing workflows!