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

Commit 217e40e

Browse files
committed
fix: filter Sonar config "sources" list to only include directories that exist
1 parent 855d597 commit 217e40e

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

packages/ember-cli-sonarqube/lib/report-metrics.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,15 @@ const logProgress = require('./utils/log-progress');
1010
function getSonarConfiguration(config) {
1111
const pkgJson = JSON.parse(fs.readFileSync(path.join(config.projectRoot, 'package.json'), 'utf8'));
1212

13-
const sources = (Array.isArray(pkgJson.keywords) && pkgJson.keywords.includes('ember-addon'))
13+
let sources = (Array.isArray(pkgJson.keywords) && pkgJson.keywords.includes('ember-addon'))
1414
? 'addon,addon-test-support,public'
1515
: 'app,public';
1616

17+
sources = sources
18+
.split(',')
19+
.filter((src) => fs.existsSync(path.join(config.projectRoot, src)))
20+
.join(',');
21+
1722
const executionReport = fs.existsSync(config.reporterOut) ? config.reporterOut : undefined;
1823

1924
const eslintReports = [config.codeLintOut, config.tmplLintOut]
@@ -83,3 +88,5 @@ module.exports = function reportSonarMetrics(config) {
8388
sonarqubeScanner(sonarConfig, resolve);
8489
});
8590
}
91+
92+
module.exports.getSonarConfiguration = getSonarConfiguration;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const { getConfiguration } = require('@nsf-open/ember-cli-sonarqube/lib/configuration');
2+
const { getSonarConfiguration } = require('@nsf-open/ember-cli-sonarqube/lib/report-metrics');
3+
const { getTestPackage } = require('./test-helpers');
4+
5+
6+
describe('getSonarConfiguration', function () {
7+
const testPackage = getTestPackage('my-addon');
8+
9+
afterEach(function () {
10+
jest.resetModules();
11+
return testPackage.reset();
12+
});
13+
14+
it('filters the sources list to only directories that exist', function () {
15+
const cliConfig = getConfiguration(testPackage.toPath(), { 'dry-run': true });
16+
const sonarConfig = getSonarConfiguration(cliConfig);
17+
18+
expect(sonarConfig.options['sonar.sources']).toEqual('addon');
19+
});
20+
});

0 commit comments

Comments
 (0)