Skip to content

Commit cb165ce

Browse files
committedOct 13, 2017
Add eslint config files
1 parent 09a8426 commit cb165ce

12 files changed

+4986
-518
lines changed
 

‎.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
coverage

‎.eslintrc.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = {
2+
extends: 'standard',
3+
root: true,
4+
rules: {
5+
// allow paren-less arrow functions
6+
'arrow-parens': 0,
7+
'space-before-function-paren': ['error', 'never'],
8+
'indent': ['error', 2]
9+
}
10+
}

‎.vscode/settings.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"editor.tabSize": 2,
3+
"prettier.semi": false,
4+
"prettier.singleQuote": true,
5+
"prettier.printWidth": 120
6+
}

‎dist/index.js

+27-28
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,50 @@
1-
var exec = require('child_process').execFileSync;
2-
var log = require('fancy-log');
3-
var prepareExecEnvironment = require('./sonarqube-scanner-executable').prepareExecEnvironment;
4-
var sonarQubeExecutable = require('./sonarqube-scanner-executable').getSonarQubeScannerExecutable;
5-
var localSonarQubeExecutable = require('./sonarqube-scanner-executable').getLocalSonarQubeScannerExecutable;
1+
var exec = require('child_process').execFileSync
2+
var log = require('fancy-log')
3+
var prepareExecEnvironment = require('./sonarqube-scanner-executable').prepareExecEnvironment
4+
var sonarQubeExecutable = require('./sonarqube-scanner-executable').getSonarQubeScannerExecutable
5+
var localSonarQubeExecutable = require('./sonarqube-scanner-executable').getLocalSonarQubeScannerExecutable
66

7-
8-
module.exports = scan;
9-
module.exports.cli = scanCLI;
10-
module.exports.customScanner = scanUsingCustomSonarQubeScanner;
7+
module.exports = scan
8+
module.exports.cli = scanCLI
9+
module.exports.customScanner = scanUsingCustomSonarQubeScanner
1110

1211
/*
1312
* Function used programmatically to trigger an analysis.
1413
*/
1514
function scan(params, callback) {
16-
scanCLI([], params, callback);
15+
scanCLI([], params, callback)
1716
}
1817

1918
/*
2019
* Function used by the '/bin/sonar-scanner' executable that accepts command line arguments.
2120
*/
2221
function scanCLI(cliArgs, params, callback) {
23-
log("Starting SonarQube analysis...");
22+
log('Starting SonarQube analysis...')
2423

25-
// prepare the exec options, most notably with the SQ params
26-
var options_exec = prepareExecEnvironment(params, process);
24+
// prepare the exec options, most notably with the SQ params
25+
var optionsExec = prepareExecEnvironment(params, process)
2726

28-
// determine the command to run and execute it
29-
sonarQubeExecutable((sqScannerCommand) => {
30-
exec(sqScannerCommand, cliArgs, options_exec);
31-
log("SonarQube analysis finished.");
32-
callback();
33-
});
27+
// determine the command to run and execute it
28+
sonarQubeExecutable(sqScannerCommand => {
29+
exec(sqScannerCommand, cliArgs, optionsExec)
30+
log('SonarQube analysis finished.')
31+
callback()
32+
})
3433
}
3534

3635
/*
3736
* Alternatively, trigger an analysis with a local install of the SonarQube Scanner.
3837
*/
3938
function scanUsingCustomSonarQubeScanner(params, callback) {
40-
log("Starting SonarQube analysis (with local install of the SonarQube Scanner)...");
39+
log('Starting SonarQube analysis (with local install of the SonarQube Scanner)...')
4140

42-
// prepare the exec options, most notably with the SQ params
43-
var options_exec = prepareExecEnvironment(params, process);
41+
// prepare the exec options, most notably with the SQ params
42+
var optionsExec = prepareExecEnvironment(params, process)
4443

45-
// determine the command to run and execute it
46-
localSonarQubeExecutable((sqScannerCommand) => {
47-
exec(sqScannerCommand, [], options_exec);
48-
log("SonarQube analysis finished.");
49-
callback();
50-
});
44+
// determine the command to run and execute it
45+
localSonarQubeExecutable(sqScannerCommand => {
46+
exec(sqScannerCommand, [], optionsExec)
47+
log('SonarQube analysis finished.')
48+
callback()
49+
})
5150
}

‎dist/sonarqube-scanner-executable.js

+117-124
Original file line numberDiff line numberDiff line change
@@ -1,168 +1,161 @@
1-
var fs = require('fs');
2-
var path = require('path');
3-
var os = require('os');
4-
var exec = require('child_process').execSync;
5-
var mkdirs = require('mkdirp').sync;
6-
var extend = require('extend');
7-
var Download = require('download');
8-
var downloadStatus = require('download-status');
9-
var log = require('fancy-log');
10-
var logError = log.error;
11-
var sonarQubeParams = require('./sonarqube-scanner-params');
12-
13-
module.exports.prepareExecEnvironment = prepareExecEnvironment;
14-
module.exports.getSonarQubeScannerExecutable = getSonarQubeScannerExecutable;
15-
module.exports.getLocalSonarQubeScannerExecutable = getLocalSonarQubeScannerExecutable;
1+
var fs = require('fs')
2+
var path = require('path')
3+
var os = require('os')
4+
var exec = require('child_process').execSync
5+
var mkdirs = require('mkdirp').sync
6+
var extend = require('extend')
7+
var Download = require('download')
8+
var downloadStatus = require('download-status')
9+
var log = require('fancy-log')
10+
var logError = log.error
11+
var sonarQubeParams = require('./sonarqube-scanner-params')
1612

13+
module.exports.prepareExecEnvironment = prepareExecEnvironment
14+
module.exports.getSonarQubeScannerExecutable = getSonarQubeScannerExecutable
15+
module.exports.getLocalSonarQubeScannerExecutable = getLocalSonarQubeScannerExecutable
1716

1817
/*
1918
* Prepare the executable options (including env environments) required to run the
2019
* SQ executable.
2120
*/
2221
function prepareExecEnvironment(params, process) {
23-
// Define what the SQ Scanner params must be
24-
var processEnvParams = {};
25-
if (process.env.SONARQUBE_SCANNER_PARAMS) {
26-
processEnvParams = JSON.parse(process.env.SONARQUBE_SCANNER_PARAMS);
27-
}
28-
var sqScannerParams = sonarQubeParams(
29-
params,
30-
process.cwd(),
31-
processEnvParams
32-
);
22+
// Define what the SQ Scanner params must be
23+
var processEnvParams = {}
24+
if (process.env.SONARQUBE_SCANNER_PARAMS) {
25+
processEnvParams = JSON.parse(process.env.SONARQUBE_SCANNER_PARAMS)
26+
}
27+
var sqScannerParams = sonarQubeParams(params, process.cwd(), processEnvParams)
3328

34-
// We need to merge the existing env variables (process.env) with the SQ ones
35-
var mergedEnv = {};
36-
extend(mergedEnv, process.env, {
37-
SONARQUBE_SCANNER_PARAMS: JSON.stringify(sqScannerParams)
38-
});
29+
// We need to merge the existing env variables (process.env) with the SQ ones
30+
var mergedEnv = {}
31+
extend(mergedEnv, process.env, {
32+
SONARQUBE_SCANNER_PARAMS: JSON.stringify(sqScannerParams)
33+
})
3934

40-
// this is the actual object that the process.exec function is waiting for
41-
var options_exec = {
42-
env: mergedEnv,
43-
stdio: [0, 1, 2],
44-
// Increase the amount of data allowed on stdout or stderr
45-
// (if this value is exceeded then the child process is killed).
46-
// TODO: make this customizable
47-
maxBuffer: 1024 * 1024
48-
};
35+
// this is the actual object that the process.exec function is waiting for
36+
var optionsExec = {
37+
env: mergedEnv,
38+
stdio: [0, 1, 2],
39+
// Increase the amount of data allowed on stdout or stderr
40+
// (if this value is exceeded then the child process is killed).
41+
// TODO: make this customizable
42+
maxBuffer: 1024 * 1024
43+
}
4944

50-
return options_exec;
45+
return optionsExec
5146
}
5247

5348
/*
5449
* Returns the SQ Scanner executable for the current platform
5550
*/
5651
function getSonarQubeScannerExecutable(passExecutableCallback) {
57-
const platformBinariesVersion = "3.0.3.778";
58-
var targetOS = findTargetOS();
59-
var installFolder = path.join(os.homedir(), ".sonar", "native-sonar-scanner");
60-
var binaryExtension = "";
61-
if (isWindows()) {
62-
binaryExtension = ".bat";
63-
}
64-
var platformExecutable = path.join(installFolder,
65-
`sonar-scanner-${platformBinariesVersion}-${targetOS}`,
66-
"bin",
67-
`sonar-scanner${binaryExtension}`);
52+
const platformBinariesVersion = '3.0.3.778'
53+
var targetOS = findTargetOS()
54+
var installFolder = path.join(os.homedir(), '.sonar', 'native-sonar-scanner')
55+
var binaryExtension = ''
56+
if (isWindows()) {
57+
binaryExtension = '.bat'
58+
}
59+
var platformExecutable = path.join(
60+
installFolder,
61+
`sonar-scanner-${platformBinariesVersion}-${targetOS}`,
62+
'bin',
63+
`sonar-scanner${binaryExtension}`
64+
)
6865

69-
// #1 - Try to execute the scanner
70-
var executableFound = false;
71-
try {
72-
log("Checking if executable exists: " + platformExecutable);
73-
fs.accessSync(platformExecutable, fs.F_OK);
74-
// executable exists!
75-
log("Platform binaries for SonarQube scanner found. Using it.");
76-
executableFound = true;
77-
} catch (e) {
78-
log("Could not find executable in '" + installFolder + "'.");
79-
}
80-
if (executableFound) {
81-
passExecutableCallback(platformExecutable);
82-
return;
83-
}
66+
// #1 - Try to execute the scanner
67+
var executableFound = false
68+
try {
69+
log('Checking if executable exists: ' + platformExecutable)
70+
fs.accessSync(platformExecutable, fs.F_OK)
71+
// executable exists!
72+
log('Platform binaries for SonarQube scanner found. Using it.')
73+
executableFound = true
74+
} catch (e) {
75+
log('Could not find executable in "' + installFolder + '".')
76+
}
77+
if (executableFound) {
78+
passExecutableCallback(platformExecutable)
79+
return
80+
}
8481

85-
// #2 - Download the binaries and unzip them
86-
// They are located at https://sonarsource.bintray.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${version}-${os}.zip
87-
log("Proceed with download of the platform binaries for SonarQube Scanner...");
88-
log("Creating " + installFolder);
89-
mkdirs(installFolder);
90-
var baseUrl = process.env.SONAR_SCANNER_MIRROR || "https://sonarsource.bintray.com/Distribution/sonar-scanner-cli/";
91-
var fileName = "sonar-scanner-cli-"
92-
+ platformBinariesVersion
93-
+ "-"
94-
+ targetOS
95-
+ ".zip";
96-
var downloadUrl = baseUrl + fileName;
97-
log(`Downloading from ${downloadUrl}`);
98-
log(`(executable will be saved in cache folder: ${installFolder})`);
99-
new Download({extract: true})
100-
.get(downloadUrl)
101-
.dest(installFolder)
102-
.use(downloadStatus())
103-
.run((err) => {
104-
if (err) {
105-
logError(`Impossible to download and extract binary: ${err.message}`);
106-
logError(`SonarQube Scanner binaries probably don't exist for your OS (${targetOS}).`);
107-
logError("In such situation, the best solution is to install the standard SonarQube Scanner (requires a JVM).");
108-
logError("Check it out at https://redirect.sonarsource.com/doc/install-configure-scanner.html");
109-
throw err;
110-
}
111-
passExecutableCallback(platformExecutable);
112-
});
82+
// #2 - Download the binaries and unzip them
83+
// They are located at https://sonarsource.bintray.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${version}-${os}.zip
84+
log('Proceed with download of the platform binaries for SonarQube Scanner...')
85+
log('Creating ' + installFolder)
86+
mkdirs(installFolder)
87+
var baseUrl = process.env.SONAR_SCANNER_MIRROR || 'https://sonarsource.bintray.com/Distribution/sonar-scanner-cli/'
88+
var fileName = 'sonar-scanner-cli-' + platformBinariesVersion + '-' + targetOS + '.zip'
89+
var downloadUrl = baseUrl + fileName
90+
log(`Downloading from ${downloadUrl}`)
91+
log(`(executable will be saved in cache folder: ${installFolder})`)
92+
new Download({ extract: true })
93+
.get(downloadUrl)
94+
.dest(installFolder)
95+
.use(downloadStatus())
96+
.run(err => {
97+
if (err) {
98+
logError(`Impossible to download and extract binary: ${err.message}`)
99+
logError(`SonarQube Scanner binaries probably don't exist for your OS (${targetOS}).`)
100+
logError('In such situation, the best solution is to install the standard SonarQube Scanner (requires a JVM).')
101+
logError('Check it out at https://redirect.sonarsource.com/doc/install-configure-scanner.html')
102+
throw err
103+
}
104+
passExecutableCallback(platformExecutable)
105+
})
113106
}
114107

115108
/*
116109
* Returns the SQ Scanner executable if one available in the PATH (meaning user has also JAVA)
117110
*/
118111
function getLocalSonarQubeScannerExecutable(passExecutableCallback) {
119-
var command = "sonar-scanner";
120-
if (isWindows()) {
121-
command += ".bat";
122-
}
112+
var command = 'sonar-scanner'
113+
if (isWindows()) {
114+
command += '.bat'
115+
}
123116

124-
// Try to execute the "sonar-scanner" command to see if it's installed locally
125-
try {
126-
log("Trying to find a local install of the SonarQube Scanner");
127-
exec(command + " -v", {});
128-
// if we're here, this means that the SQ Scanner can be executed
129-
// TODO: we should check that it's at least v2.8+
130-
log("Local install of SonarQube scanner found. Using it.");
131-
passExecutableCallback(command);
132-
return;
133-
} catch (e) {
134-
// sonar-scanner is not in the PATH
135-
throw Error("Local install of SonarQube scanner not found.");
136-
}
117+
// Try to execute the 'sonar-scanner' command to see if it's installed locally
118+
try {
119+
log('Trying to find a local install of the SonarQube Scanner')
120+
exec(command + ' -v', {})
121+
// if we're here, this means that the SQ Scanner can be executed
122+
// TODO: we should check that it's at least v2.8+
123+
log('Local install of SonarQube scanner found. Using it.')
124+
passExecutableCallback(command)
125+
return
126+
} catch (e) {
127+
// sonar-scanner is not in the PATH
128+
throw Error('Local install of SonarQube scanner not found.')
129+
}
137130
}
138131

139132
/*
140133
* Get the target OS based on the platform name
141134
*/
142135
function findTargetOS() {
143-
if (isWindows()) {
144-
return "windows";
145-
}
146-
if (isLinux()) {
147-
return "linux";
148-
}
149-
if (isMac()) {
150-
return "macosx";
151-
}
152-
throw Error(`Your platform "${process.platform}" is currently not supported.`)
136+
if (isWindows()) {
137+
return 'windows'
138+
}
139+
if (isLinux()) {
140+
return 'linux'
141+
}
142+
if (isMac()) {
143+
return 'macosx'
144+
}
145+
throw Error(`Your platform '${process.platform}' is currently not supported.`)
153146
}
154147

155148
/*
156149
* Some util functions...
157150
*/
158151
function isWindows() {
159-
return /^win/.test(process.platform);
152+
return /^win/.test(process.platform)
160153
}
161154

162155
function isMac() {
163-
return /^darwin/.test(process.platform);
156+
return /^darwin/.test(process.platform)
164157
}
165158

166159
function isLinux() {
167-
return /^linux/.test(process.platform);
160+
return /^linux/.test(process.platform)
168161
}

0 commit comments

Comments
 (0)