SonarQube Properties Skill
Purpose
Generate SonarQube project configuration file for code quality analysis and coverage reporting with automatic detection of test framework and coverage paths.
🚨 MANDATORY FILE COUNT
Expected Output: 1 file
🔍 BEFORE GENERATING - CRITICAL RESEARCH REQUIRED
Perform these checks in order before generating the configuration:
Application Name Detection: Use application_name parameter
- Format: Use application_name as-is for projectKey and projectName
- Placeholder:
{application_name} will be replaced with actual value
- User Action Required: Inform user to review and update projectKey, projectName, and projectDescription after generation
Test Framework Detection: Determine which test framework is used
- Check
package.json dependencies:
- If
"vitest" found → Vitest (uses coverage/lcov.info, coverage provider: v8 or istanbul)
- If
"jest" found → Jest (uses coverage/lcov.info and coverage/clover.xml)
- If neither found → Default to Vitest (Vue 3 standard)
- Impact: Determines which coverage report paths to include
Coverage Report Path Detection: Verify coverage output location
- Default:
./coverage/lcov.info (both Jest and Vitest)
- Additional for Jest:
./coverage/clover.xml
- Vitest v8 provider: Only
lcov.info (no clover)
- Check: Verify coverage configuration in test framework config
- Fallback: Use standard paths if not specified
Source Directory Detection: Verify source code location
- Standard:
src directory
- Check: Verify
src/ exists in project structure
- Alternative: If different, detect from
package.json or tsconfig.json
Coverage Exclusion Patterns: Detect files to exclude from coverage
- Always Exclude:
- Test files:
src/**/*.spec.ts
- Entry point:
src/main.ts (if exists)
- Conditionally Exclude (check if exists):
- Services:
src/services/**/*.ts (API layer, tested with mocks)
- Router:
src/**/router/*.ts (configuration, tested E2E)
- Store index:
src/store/index.ts (setup file)
- Interfaces:
src/**/interfaces/*.ts (type definitions only)
- Constants:
src/**/shared/constants/**/*.ts (static data)
- Action: Build exclusion list based on detected files
Language Detection: Verify primary language
- Standard: TypeScript (
ts)
- Check: Look for
typescript in package.json dependencies
- Alternative: If no TypeScript, use
js
Git Provider Detection: Determine SCM provider
- Default:
git
- Check:
.git directory exists
- Note: SonarQube property is informational
Encoding Verification: Confirm source file encoding
- Standard:
UTF-8
- Note: Modern projects always use UTF-8
Execution Checklist
Execute in this order:
Output
Primary Format: sonar-project.properties
For Vitest Projects (recommended):
sonar.projectKey={application_name}
sonar.projectName={application_name}
sonar.projectDescription=Vue 3 application for {application_name}
sonar.sources=src
sonar.language=ts
sonar.sourceEncoding=UTF-8
sonar.scm.provider=git
sonar.qualitygate.wait=true
sonar.javascript.lcov.reportPaths=./coverage/lcov.info
sonar.tests=src
sonar.test.inclusions=src/**/*.spec.ts
sonar.exclusions=src/**/*.spec.ts
sonar.coverage.exclusions=src/main.ts,src/services/**/*.ts,src/**/router/*.ts
For Jest Projects:
sonar.projectKey={application_name}
sonar.projectName={application_name}
sonar.projectDescription=Vue 3 application for {application_name}
sonar.sources=src
sonar.language=ts
sonar.sourceEncoding=UTF-8
sonar.scm.provider=git
sonar.qualitygate.wait=true
sonar.javascript.lcov.reportPaths=./coverage/lcov.info
sonar.clover.reportPaths=./coverage/clover.xml
sonar.tests=src
sonar.test.inclusions=src/**/*.spec.ts
sonar.exclusions=src/**/*.spec.ts
sonar.coverage.exclusions=src/main.ts,src/services/**/*.ts,src/**/router/*.ts
Key Difference: Jest includes sonar.clover.reportPaths, Vitest does not.
🛑 BLOCKING VALIDATION CHECKPOINT
After generating the file, run this validation:
#!/bin/bash
# Validate sonar-project.properties exists
if [ ! -f "sonar-project.properties" ]; then
echo "✗ ERROR: sonar-project.properties not found"
exit 1
fi
echo "✓ Found: sonar-project.properties"
# Validate required properties exist
REQUIRED_PROPS=(
"sonar.projectKey"
"sonar.projectName"
"sonar.sources"
"sonar.language"
"sonar.sourceEncoding"
"sonar.qualitygate.wait"
"sonar.javascript.lcov.reportPaths"
"sonar.tests"
"sonar.test.inclusions"
"sonar.exclusions"
"sonar.coverage.exclusions"
)
MISSING_PROPS=()
for prop in "${REQUIRED_PROPS[@]}"; do
if ! grep -q "^$prop=" sonar-project.properties; then
MISSING_PROPS+=("$prop")
fi
done
if [ ${#MISSING_PROPS[@]} -gt 0 ]; then
echo "✗ ERROR: Missing required properties:"
printf ' - %s\n' "${MISSING_PROPS[@]}"
exit 1
fi
# Validate coverage report paths exist or are configured
LCOV_PATH=$(grep "^sonar.javascript.lcov.reportPaths=" sonar-project.properties | cut -d'=' -f2)
if [ -z "$LCOV_PATH" ]; then
echo "✗ ERROR: Missing LCOV report path"
exit 1
fi
# Check for test framework specific paths
if grep -q "vitest" package.json; then
echo "✓ Detected Vitest - LCOV only"
if grep -q "sonar.clover.reportPaths" sonar-project.properties; then
echo "⚠️ WARNING: Vitest detected but clover path included (Jest-specific)"
fi
elif grep -q "jest" package.json; then
echo "✓ Detected Jest - LCOV + Clover"
if ! grep -q "sonar.clover.reportPaths" sonar-project.properties; then
echo "⚠️ WARNING: Jest detected but clover path missing"
fi
fi
# Validate sources directory exists
SOURCES_DIR=$(grep "^sonar.sources=" sonar-project.properties | cut -d'=' -f2)
if [ ! -d "$SOURCES_DIR" ]; then
echo "✗ ERROR: Sources directory not found: $SOURCES_DIR"
exit 1
fi
echo "✓ Sources directory exists: $SOURCES_DIR"
# Validate language is set correctly
LANGUAGE=$(grep "^sonar.language=" sonar-project.properties | cut -d'=' -f2)
if [ "$LANGUAGE" != "ts" ] && [ "$LANGUAGE" != "js" ]; then
echo "✗ ERROR: Invalid language: $LANGUAGE (expected 'ts' or 'js')"
exit 1
fi
echo "✓ Language: $LANGUAGE"
# Validate encoding
ENCODING=$(grep "^sonar.sourceEncoding=" sonar-project.properties | cut -d'=' -f2)
if [ "$ENCODING" != "UTF-8" ]; then
echo "⚠️ WARNING: Non-standard encoding: $ENCODING (expected 'UTF-8')"
fi
# Validate exclusions are properly formatted (no spaces after commas in list)
EXCLUSIONS=$(grep "^sonar.coverage.exclusions=" sonar-project.properties | cut -d'=' -f2)
if [[ "$EXCLUSIONS" =~ ", " ]]; then
echo "⚠️ WARNING: Coverage exclusions contain spaces after commas (should be comma-separated without spaces)"
fi
echo ""
echo "✓ SonarQube configuration validation passed"
echo ""
echo "⚠️ IMPORTANT: Please review and update the following properties:"
echo " - sonar.projectKey (currently: $(grep '^sonar.projectKey=' sonar-project.properties | cut -d'=' -f2))"
echo " - sonar.projectName (currently: $(grep '^sonar.projectName=' sonar-project.properties | cut -d'=' -f2))"
echo " - sonar.projectDescription (currently: $(grep '^sonar.projectDescription=' sonar-project.properties | cut -d'=' -f2))"
Validation Requirements:
- ✅ File
sonar-project.properties exists
- ✅ All required properties present
- ✅ Coverage report paths configured based on test framework
- ✅ Sources directory exists
- ✅ Language is valid (
ts or js)
- ✅ Encoding is UTF-8
- ⚠️ Coverage exclusions properly formatted (no spaces)
- ⚠️ User notified to review projectKey, projectName, projectDescription
Template Reference
See: examples.md in this directory for:
- Complete
sonar-project.properties examples (Vitest and Jest variants)
- Detailed property explanations with why each is configured
- Test framework detection guide
- Coverage path verification commands
- Common issues and troubleshooting
- Property customization guide
Notes
Key Features
- Automatic Test Framework Detection: Vitest vs Jest from package.json
- Dynamic Coverage Paths: Adapts to test framework capabilities
- Smart Exclusions: Only excludes files that exist in project
- Application Name Integration: Uses configured application_name parameter
- User Review Required: Notifies user to update project metadata
Property Essentials
- projectKey/projectName: Uses application_name, user must review
- projectDescription: Generic description, user should customize
- sources: Always
src (standard Vue project structure)
- language:
ts for TypeScript projects
- sourceEncoding: Always
UTF-8 (modern standard)
- scm.provider:
git (standard version control)
- qualitygate.wait:
true (wait for quality gate results)
Coverage Configuration
- LCOV: Universal format supported by both Jest and Vitest
- Clover: Jest-specific XML format (not used by Vitest)
- Test Inclusions:
src/**/*.spec.ts (all test files)
- Source Exclusions: Test files excluded from analysis
- Coverage Exclusions: Entry points, services, routers, config files
Coverage Exclusion Philosophy
- Test Files: No runtime code, shouldn't count toward coverage
- Entry Point (main.ts): Application bootstrap, tested through E2E
- Services: API layer, tested with mocks, not unit testable
- Router: Configuration files, tested through E2E navigation
- Store Index: Setup/configuration, not meaningful to unit test
- Interfaces: TypeScript type definitions only, no runtime code
- Constants: Static data, no logic to test
Test Framework Differences
- Vitest: Modern, Vue 3 recommended, v8 or istanbul coverage, LCOV only
- Jest: Legacy but widely used, multiple coverage formats (LCOV + Clover)
- Detection: Check package.json dependencies for framework presence
- Default: Assume Vitest if neither found (Vue 3 standard)
Quality Gate Configuration
- qualitygate.wait=true: CI/CD pipeline waits for SonarQube analysis
- Purpose: Prevent merging code that fails quality standards
- Timeout: Controlled by SonarQube server configuration
- Impact: CI/CD build may fail if quality gate not passed
Maintenance Considerations
- SonarQube Version: Properties may change between SonarQube versions
- Coverage Formats: Verify test framework still generates expected formats
- Path Changes: Update if project structure changes
- New Exclusions: Add patterns as project grows
- Property Deprecation: Monitor SonarQube release notes
Common Customizations
- Organization Key: Add
sonar.organization for SonarCloud
- Branch Analysis: Add
sonar.branch.name for branch-specific analysis
- PR Analysis: Add PR-specific properties for pull request decoration
- Authentication: Add
sonar.login token (usually in CI/CD environment)
- Additional Exclusions: Extend based on project needs
1---2name: sonar-properties3description: Generates sonar-project.properties for SonarQube code quality analysis and coverage reporting. Auto-detects test framework (Jest/Vitest) and configures coverage paths.4---5
6# SonarQube Properties Skill
7
8## Purpose
9Generate SonarQube project configuration file for code quality analysis and coverage reporting with automatic detection of test framework and coverage paths.
10
11## 🚨 MANDATORY FILE COUNT
12**Expected Output**: **1 file**
13- `sonar-project.properties`
14
15## 🔍 BEFORE GENERATING - CRITICAL RESEARCH REQUIRED
16
17Perform these checks in order before generating the configuration:
18
191. **Application Name Detection**: Use `application_name` parameter
20 - **Format**: Use application_name as-is for projectKey and projectName
21 - **Placeholder**: `{application_name}` will be replaced with actual value
22 - **User Action Required**: Inform user to review and update projectKey, projectName, and projectDescription after generation
23
242. **Test Framework Detection**: Determine which test framework is used
25 - **Check `package.json` dependencies**:
26 - If `"vitest"` found → **Vitest** (uses `coverage/lcov.info`, coverage provider: v8 or istanbul)
27 - If `"jest"` found → **Jest** (uses `coverage/lcov.info` and `coverage/clover.xml`)
28 - If neither found → **Default to Vitest** (Vue 3 standard)
29 - **Impact**: Determines which coverage report paths to include
30
313. **Coverage Report Path Detection**: Verify coverage output location
32 - **Default**: `./coverage/lcov.info` (both Jest and Vitest)
33 - **Additional for Jest**: `./coverage/clover.xml`
34 - **Vitest v8 provider**: Only `lcov.info` (no clover)
35 - **Check**: Verify coverage configuration in test framework config
36 - **Fallback**: Use standard paths if not specified
37
384. **Source Directory Detection**: Verify source code location
39 - **Standard**: `src` directory
40 - **Check**: Verify `src/` exists in project structure
41 - **Alternative**: If different, detect from `package.json` or `tsconfig.json`
42
435. **Coverage Exclusion Patterns**: Detect files to exclude from coverage
44 - **Always Exclude**:
45 - Test files: `src/**/*.spec.ts`
46 - Entry point: `src/main.ts` (if exists)
47 - **Conditionally Exclude** (check if exists):
48 - Services: `src/services/**/*.ts` (API layer, tested with mocks)
49 - Router: `src/**/router/*.ts` (configuration, tested E2E)
50 - Store index: `src/store/index.ts` (setup file)
51 - Interfaces: `src/**/interfaces/*.ts` (type definitions only)
52 - Constants: `src/**/shared/constants/**/*.ts` (static data)
53 - **Action**: Build exclusion list based on detected files
54
556. **Language Detection**: Verify primary language
56 - **Standard**: TypeScript (`ts`)
57 - **Check**: Look for `typescript` in package.json dependencies
58 - **Alternative**: If no TypeScript, use `js`
59
607. **Git Provider Detection**: Determine SCM provider
61 - **Default**: `git`
62 - **Check**: `.git` directory exists
63 - **Note**: SonarQube property is informational
64
658. **Encoding Verification**: Confirm source file encoding
66 - **Standard**: `UTF-8`
67 - **Note**: Modern projects always use UTF-8
68
69## Execution Checklist
70
71Execute in this order:
72
73- [ ] 1. Get `application_name` from configuration parameters
74- [ ] 2. Detect test framework (Vitest vs Jest) from package.json
75- [ ] 3. Determine coverage report paths based on test framework
76- [ ] 4. Verify `src/` directory exists
77- [ ] 5. Detect which files/directories exist for coverage exclusions:
78 - [ ] `src/main.ts`
79 - [ ] `src/services/` directory
80 - [ ] `src/**/router/` directories
81 - [ ] `src/store/index.ts`
82 - [ ] `src/**/interfaces/` directories
83 - [ ] `src/**/shared/constants/` directories
84- [ ] 6. Build coverage.exclusions list from detected patterns
85- [ ] 7. Verify TypeScript is used (check package.json)
86- [ ] 8. Generate `sonar-project.properties` with detected configuration
87- [ ] 9. Run validation script to confirm file exists and properties are valid
88- [ ] 10. **IMPORTANT**: Notify user to review projectKey, projectName, and projectDescription
89
90## Output
91
92### Primary Format: `sonar-project.properties`
93
94**For Vitest Projects** (recommended):
95```properties
96sonar.projectKey={application_name}
97sonar.projectName={application_name}
98sonar.projectDescription=Vue 3 application for {application_name}
99sonar.sources=src
100sonar.language=ts
101sonar.sourceEncoding=UTF-8
102sonar.scm.provider=git
103sonar.qualitygate.wait=true
104sonar.javascript.lcov.reportPaths=./coverage/lcov.info
105sonar.tests=src
106sonar.test.inclusions=src/**/*.spec.ts
107sonar.exclusions=src/**/*.spec.ts
108sonar.coverage.exclusions=src/main.ts,src/services/**/*.ts,src/**/router/*.ts
109```
110
111**For Jest Projects**:
112```properties
113sonar.projectKey={application_name}
114sonar.projectName={application_name}
115sonar.projectDescription=Vue 3 application for {application_name}
116sonar.sources=src
117sonar.language=ts
118sonar.sourceEncoding=UTF-8
119sonar.scm.provider=git
120sonar.qualitygate.wait=true
121sonar.javascript.lcov.reportPaths=./coverage/lcov.info
122sonar.clover.reportPaths=./coverage/clover.xml
123sonar.tests=src
124sonar.test.inclusions=src/**/*.spec.ts
125sonar.exclusions=src/**/*.spec.ts
126sonar.coverage.exclusions=src/main.ts,src/services/**/*.ts,src/**/router/*.ts
127```
128
129**Key Difference**: Jest includes `sonar.clover.reportPaths`, Vitest does not.
130
131## 🛑 BLOCKING VALIDATION CHECKPOINT
132
133After generating the file, run this validation:
134
135```bash
136#!/bin/bash
137
138# Validate sonar-project.properties exists
139if [ ! -f "sonar-project.properties" ]; then
140 echo "✗ ERROR: sonar-project.properties not found"
141 exit 1
142fi
143
144echo "✓ Found: sonar-project.properties"
145
146# Validate required properties exist
147REQUIRED_PROPS=(
148 "sonar.projectKey"
149 "sonar.projectName"
150 "sonar.sources"
151 "sonar.language"
152 "sonar.sourceEncoding"
153 "sonar.qualitygate.wait"
154 "sonar.javascript.lcov.reportPaths"
155 "sonar.tests"
156 "sonar.test.inclusions"
157 "sonar.exclusions"
158 "sonar.coverage.exclusions"
159)
160
161MISSING_PROPS=()
162for prop in "${REQUIRED_PROPS[@]}"; do
163 if ! grep -q "^$prop=" sonar-project.properties; then
164 MISSING_PROPS+=("$prop")
165 fi
166done
167
168if [ ${#MISSING_PROPS[@]} -gt 0 ]; then
169 echo "✗ ERROR: Missing required properties:"
170 printf ' - %s\n' "${MISSING_PROPS[@]}"
171 exit 1
172fi
173
174# Validate coverage report paths exist or are configured
175LCOV_PATH=$(grep "^sonar.javascript.lcov.reportPaths=" sonar-project.properties | cut -d'=' -f2)
176if [ -z "$LCOV_PATH" ]; then
177 echo "✗ ERROR: Missing LCOV report path"
178 exit 1
179fi
180
181# Check for test framework specific paths
182if grep -q "vitest" package.json; then
183 echo "✓ Detected Vitest - LCOV only"
184 if grep -q "sonar.clover.reportPaths" sonar-project.properties; then
185 echo "⚠️ WARNING: Vitest detected but clover path included (Jest-specific)"
186 fi
187elif grep -q "jest" package.json; then
188 echo "✓ Detected Jest - LCOV + Clover"
189 if ! grep -q "sonar.clover.reportPaths" sonar-project.properties; then
190 echo "⚠️ WARNING: Jest detected but clover path missing"
191 fi
192fi
193
194# Validate sources directory exists
195SOURCES_DIR=$(grep "^sonar.sources=" sonar-project.properties | cut -d'=' -f2)
196if [ ! -d "$SOURCES_DIR" ]; then
197 echo "✗ ERROR: Sources directory not found: $SOURCES_DIR"
198 exit 1
199fi
200
201echo "✓ Sources directory exists: $SOURCES_DIR"
202
203# Validate language is set correctly
204LANGUAGE=$(grep "^sonar.language=" sonar-project.properties | cut -d'=' -f2)
205if [ "$LANGUAGE" != "ts" ] && [ "$LANGUAGE" != "js" ]; then
206 echo "✗ ERROR: Invalid language: $LANGUAGE (expected 'ts' or 'js')"
207 exit 1
208fi
209
210echo "✓ Language: $LANGUAGE"
211
212# Validate encoding
213ENCODING=$(grep "^sonar.sourceEncoding=" sonar-project.properties | cut -d'=' -f2)
214if [ "$ENCODING" != "UTF-8" ]; then
215 echo "⚠️ WARNING: Non-standard encoding: $ENCODING (expected 'UTF-8')"
216fi
217
218# Validate exclusions are properly formatted (no spaces after commas in list)
219EXCLUSIONS=$(grep "^sonar.coverage.exclusions=" sonar-project.properties | cut -d'=' -f2)
220if [[ "$EXCLUSIONS" =~ ", " ]]; then
221 echo "⚠️ WARNING: Coverage exclusions contain spaces after commas (should be comma-separated without spaces)"
222fi
223
224echo ""
225echo "✓ SonarQube configuration validation passed"
226echo ""
227echo "⚠️ IMPORTANT: Please review and update the following properties:"
228echo " - sonar.projectKey (currently: $(grep '^sonar.projectKey=' sonar-project.properties | cut -d'=' -f2))"
229echo " - sonar.projectName (currently: $(grep '^sonar.projectName=' sonar-project.properties | cut -d'=' -f2))"
230echo " - sonar.projectDescription (currently: $(grep '^sonar.projectDescription=' sonar-project.properties | cut -d'=' -f2))"
231```
232
233**Validation Requirements**:
2341. ✅ File `sonar-project.properties` exists
2352. ✅ All required properties present
2363. ✅ Coverage report paths configured based on test framework
2374. ✅ Sources directory exists
2385. ✅ Language is valid (`ts` or `js`)
2396. ✅ Encoding is UTF-8
2407. ⚠️ Coverage exclusions properly formatted (no spaces)
2418. ⚠️ User notified to review projectKey, projectName, projectDescription
242
243## Template Reference
244See: `examples.md` in this directory for:
245- Complete `sonar-project.properties` examples (Vitest and Jest variants)
246- Detailed property explanations with why each is configured
247- Test framework detection guide
248- Coverage path verification commands
249- Common issues and troubleshooting
250- Property customization guide
251
252## Notes
253
254### Key Features
255- **Automatic Test Framework Detection**: Vitest vs Jest from package.json
256- **Dynamic Coverage Paths**: Adapts to test framework capabilities
257- **Smart Exclusions**: Only excludes files that exist in project
258- **Application Name Integration**: Uses configured application_name parameter
259- **User Review Required**: Notifies user to update project metadata
260
261### Property Essentials
262- **projectKey/projectName**: Uses application_name, user must review
263- **projectDescription**: Generic description, user should customize
264- **sources**: Always `src` (standard Vue project structure)
265- **language**: `ts` for TypeScript projects
266- **sourceEncoding**: Always `UTF-8` (modern standard)
267- **scm.provider**: `git` (standard version control)
268- **qualitygate.wait**: `true` (wait for quality gate results)
269
270### Coverage Configuration
271- **LCOV**: Universal format supported by both Jest and Vitest
272- **Clover**: Jest-specific XML format (not used by Vitest)
273- **Test Inclusions**: `src/**/*.spec.ts` (all test files)
274- **Source Exclusions**: Test files excluded from analysis
275- **Coverage Exclusions**: Entry points, services, routers, config files
276
277### Coverage Exclusion Philosophy
278- **Test Files**: No runtime code, shouldn't count toward coverage
279- **Entry Point (main.ts)**: Application bootstrap, tested through E2E
280- **Services**: API layer, tested with mocks, not unit testable
281- **Router**: Configuration files, tested through E2E navigation
282- **Store Index**: Setup/configuration, not meaningful to unit test
283- **Interfaces**: TypeScript type definitions only, no runtime code
284- **Constants**: Static data, no logic to test
285
286### Test Framework Differences
287- **Vitest**: Modern, Vue 3 recommended, v8 or istanbul coverage, LCOV only
288- **Jest**: Legacy but widely used, multiple coverage formats (LCOV + Clover)
289- **Detection**: Check package.json dependencies for framework presence
290- **Default**: Assume Vitest if neither found (Vue 3 standard)
291
292### Quality Gate Configuration
293- **qualitygate.wait=true**: CI/CD pipeline waits for SonarQube analysis
294- **Purpose**: Prevent merging code that fails quality standards
295- **Timeout**: Controlled by SonarQube server configuration
296- **Impact**: CI/CD build may fail if quality gate not passed
297
298### Maintenance Considerations
299- **SonarQube Version**: Properties may change between SonarQube versions
300- **Coverage Formats**: Verify test framework still generates expected formats
301- **Path Changes**: Update if project structure changes
302- **New Exclusions**: Add patterns as project grows
303- **Property Deprecation**: Monitor SonarQube release notes
304
305### Common Customizations
306- **Organization Key**: Add `sonar.organization` for SonarCloud
307- **Branch Analysis**: Add `sonar.branch.name` for branch-specific analysis
308- **PR Analysis**: Add PR-specific properties for pull request decoration
309- **Authentication**: Add `sonar.login` token (usually in CI/CD environment)
310- **Additional Exclusions**: Extend based on project needs
311