Skip to content
This repository has been archived by the owner on Mar 9, 2023. It is now read-only.

Commit

Permalink
Validation of project fails for scoped module #48
Browse files Browse the repository at this point in the history
Thanks to @raksit31667 and @Bangsadrengur for
the solution available on #52.
  • Loading branch information
bellingard committed May 28, 2019
1 parent 0b6fb55 commit d1a030c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
6 changes: 5 additions & 1 deletion dist/sonarqube-scanner-params.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ var uniq = require('lodash.uniq')

module.exports = defineSonarQubeScannerParams

var invalidCharacterRegex = /[?$*+~.()'"!:@/]/g

/*
* Try to be smart and guess most SQ parameters from JS files that
* might exist - like 'package.json'.
Expand Down Expand Up @@ -70,7 +72,9 @@ function extractInfoFromPackageFile(sonarqubeScannerParams, projectBaseDir) {
})
}
if (pkg) {
sonarqubeScannerParams['sonar.projectKey'] = slugify(pkg.name)
sonarqubeScannerParams['sonar.projectKey'] = slugify(pkg.name, {
remove: invalidCharacterRegex
})
sonarqubeScannerParams['sonar.projectName'] = pkg.name
sonarqubeScannerParams['sonar.projectVersion'] = pkg.version
if (pkg.description) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "@my/fake-basic-project",
"version": "1.0.0",
"engines": {
"node": ">= 0.10"
}
}
12 changes: 12 additions & 0 deletions specs/sonarqube-scanner-params-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@ describe('sqScannerParams', function() {
assert.deepEqual(sqScannerParams({}, pathForProject('fake_project_with_basic_package_file'), null), expectedResult)
})

it('should get mandatory information from scoped packages package.json file', function() {
var expectedResult = {
'sonar.projectKey': 'myfake-basic-project',
'sonar.projectName': '@my/fake-basic-project',
'sonar.projectDescription': 'No description.',
'sonar.projectVersion': '1.0.0',
'sonar.sources': '.',
'sonar.exclusions': 'node_modules/**,bower_components/**,jspm_packages/**,typings/**,lib-cov/**'
}
assert.deepEqual(sqScannerParams({}, pathForProject('fake_project_with_scoped_package_name'), null), expectedResult)
})

it('should get all information from package.json file', function() {
var expectedResult = {
'sonar.projectKey': 'fake-project',
Expand Down

0 comments on commit d1a030c

Please sign in to comment.