From d1a030cde2948416c7c6016850cc060aba7fc4ee Mon Sep 17 00:00:00 2001 From: Fabrice Bellingard Date: Tue, 28 May 2019 14:31:32 +0200 Subject: [PATCH] Validation of project fails for scoped module #48 Thanks to @raksit31667 and @Bangsadrengur for the solution available on #52. --- dist/sonarqube-scanner-params.js | 6 +++++- .../package.json | 7 +++++++ specs/sonarqube-scanner-params-test.js | 12 ++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 specs/resources/fake_project_with_scoped_package_name/package.json diff --git a/dist/sonarqube-scanner-params.js b/dist/sonarqube-scanner-params.js index a4b36ca2..1384341c 100644 --- a/dist/sonarqube-scanner-params.js +++ b/dist/sonarqube-scanner-params.js @@ -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'. @@ -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) { diff --git a/specs/resources/fake_project_with_scoped_package_name/package.json b/specs/resources/fake_project_with_scoped_package_name/package.json new file mode 100644 index 00000000..1c661f17 --- /dev/null +++ b/specs/resources/fake_project_with_scoped_package_name/package.json @@ -0,0 +1,7 @@ +{ + "name": "@my/fake-basic-project", + "version": "1.0.0", + "engines": { + "node": ">= 0.10" + } +} diff --git a/specs/sonarqube-scanner-params-test.js b/specs/sonarqube-scanner-params-test.js index 444d45ba..c1e7a6a1 100644 --- a/specs/sonarqube-scanner-params-test.js +++ b/specs/sonarqube-scanner-params-test.js @@ -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',