Skip to content

Commit

Permalink
Apply Eslint automatic fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gabssnake committed Dec 4, 2022
1 parent ea0356d commit b5406fc
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ module.exports = {
// allow paren-less arrow functions
'arrow-parens': 0,
'space-before-function-paren': ['error', 'never'],
'indent': ['error', 2]
indent: ['error', 2]
}
}
8 changes: 4 additions & 4 deletions specs/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
'env': {
mocha: true,
},
}
env: {
mocha: true
}
}
4 changes: 2 additions & 2 deletions specs/index-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var assert = require('assert')
var index = require('../src/index')
const assert = require('assert')
const index = require('../src/index')

describe('fromParam', function() {
it('should provide the correct identity', function() {
Expand Down
16 changes: 8 additions & 8 deletions specs/sonar-scanner-executable-test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
var assert = require('assert')
var path = require('path')
var index = require('../src/sonar-scanner-executable')
const assert = require('assert')
const path = require('path')
const index = require('../src/sonar-scanner-executable')

describe('sqScannerExecutable', function() {
var exclusions = 'node_modules/**,bower_components/**,jspm_packages/**,typings/**,lib-cov/**'
const exclusions = 'node_modules/**,bower_components/**,jspm_packages/**,typings/**,lib-cov/**'

it('should provide default values', function() {
var expectedResult = {
const expectedResult = {
maxBuffer: 1024 * 1024,
stdio: [0, 1, 2],
env: {
Expand All @@ -18,7 +18,7 @@ describe('sqScannerExecutable', function() {
}
}

var fakeProcess = {
const fakeProcess = {
env: {},
cwd: function() {
return pathForProject('fake_project_with_no_package_file')
Expand All @@ -29,7 +29,7 @@ describe('sqScannerExecutable', function() {
})

it('should read SONARQUBE_SCANNER_PARAMS provided by environment if it exists', function() {
var expectedResult = {
const expectedResult = {
maxBuffer: 1024 * 1024,
stdio: [0, 1, 2],
env: {
Expand All @@ -43,7 +43,7 @@ describe('sqScannerExecutable', function() {
}
}

var fakeProcess = {
const fakeProcess = {
env: {
SONARQUBE_SCANNER_PARAMS: JSON.stringify({
'sonar.host.url': 'https://sonarcloud.io',
Expand Down
30 changes: 15 additions & 15 deletions specs/sonar-scanner-params-test.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
var assert = require('assert')
var path = require('path')
var sqScannerParams = require('../src/sonar-scanner-params')
const assert = require('assert')
const path = require('path')
const sqScannerParams = require('../src/sonar-scanner-params')

describe('sqScannerParams', function() {
function pathForProject(projectFolder) {
return path.join(process.cwd(), 'specs', 'resources', projectFolder)
}

var exclusions = 'node_modules/**,bower_components/**,jspm_packages/**,typings/**,lib-cov/**'
const exclusions = 'node_modules/**,bower_components/**,jspm_packages/**,typings/**,lib-cov/**'

it('should provide default values', function() {
var expectedResult = {
const expectedResult = {
'sonar.projectDescription': 'No description.',
'sonar.sources': '.',
'sonar.exclusions': exclusions
Expand All @@ -19,15 +19,15 @@ describe('sqScannerParams', function() {
})

it('should not set default values if sonar-project.properties file exists', function() {
var expectedResult = {}
const expectedResult = {}
assert.deepEqual(
sqScannerParams({}, pathForProject('fake_project_with_sonar_properties_file'), null),
expectedResult
)
})

it('should propagate custom server and token', function() {
var expectedResult = {
const expectedResult = {
'sonar.host.url': 'https://sonarcloud.io',
'sonar.login': 'my_token',
'sonar.projectDescription': 'No description.',
Expand All @@ -45,7 +45,7 @@ describe('sqScannerParams', function() {
})

it('should allow to override default settings and add new ones', function() {
var expectedResult = {
const expectedResult = {
'sonar.projectName': 'Foo',
'sonar.projectDescription': 'No description.',
'sonar.sources': '.',
Expand All @@ -63,7 +63,7 @@ describe('sqScannerParams', function() {
})

it('should get mandatory information from basic package.json file', function() {
var expectedResult = {
const expectedResult = {
'sonar.javascript.lcov.reportPaths': 'coverage/lcov.info',
'sonar.projectKey': 'fake-basic-project',
'sonar.projectName': 'fake-basic-project',
Expand All @@ -76,7 +76,7 @@ describe('sqScannerParams', function() {
})

it('should get mandatory information from scoped packages package.json file', function() {
var expectedResult = {
const expectedResult = {
'sonar.projectKey': 'myfake-basic-project',
'sonar.projectName': '@my/fake-basic-project',
'sonar.projectDescription': 'No description.',
Expand All @@ -88,7 +88,7 @@ describe('sqScannerParams', function() {
})

it('should get all information from package.json file', function() {
var expectedResult = {
const expectedResult = {
'sonar.projectKey': 'fake-project',
'sonar.projectName': 'fake-project',
'sonar.projectDescription': 'A fake project',
Expand All @@ -107,7 +107,7 @@ describe('sqScannerParams', function() {
})

it('should take into account SONARQUBE_SCANNER_PARAMS env variable', function() {
var expectedResult = {
const expectedResult = {
'sonar.host.url': 'https://sonarcloud.io',
'sonar.login': 'my_token',
'sonar.projectDescription': 'No description.',
Expand All @@ -124,7 +124,7 @@ describe('sqScannerParams', function() {
})

it('should make priority to user options over SONARQUBE_SCANNER_PARAMS env variable', function() {
var expectedResult = {
const expectedResult = {
'sonar.host.url': 'https://sonarcloud.io',
'sonar.login': 'my_token',
'sonar.projectDescription': 'No description.',
Expand All @@ -145,7 +145,7 @@ describe('sqScannerParams', function() {
})

it('should get nyc lcov file path from package.json file', function() {
var expectedResult = {
const expectedResult = {
'sonar.javascript.lcov.reportPaths': 'nyc-coverage/lcov.info',
'sonar.projectKey': 'fake-basic-project',
'sonar.projectName': 'fake-basic-project',
Expand All @@ -158,7 +158,7 @@ describe('sqScannerParams', function() {
})

it('should get jest lcov file path from package.json file', function() {
var expectedResult = {
const expectedResult = {
'sonar.javascript.lcov.reportPaths': 'jest-coverage/lcov.info',
'sonar.projectKey': 'fake-basic-project',
'sonar.projectName': 'fake-basic-project',
Expand Down
14 changes: 7 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
var exec = require('child_process').execFileSync
var log = require('fancy-log')
var prepareExecEnvironment = require('./sonar-scanner-executable').prepareExecEnvironment
var scannerExecutable = require('./sonar-scanner-executable').getSonarScannerExecutable
var localscannerExecutable = require('./sonar-scanner-executable').getLocalSonarScannerExecutable
const exec = require('child_process').execFileSync
const log = require('fancy-log')
const prepareExecEnvironment = require('./sonar-scanner-executable').prepareExecEnvironment
const scannerExecutable = require('./sonar-scanner-executable').getSonarScannerExecutable
const localscannerExecutable = require('./sonar-scanner-executable').getLocalSonarScannerExecutable

module.exports = scan
module.exports.cli = scanCLI
Expand All @@ -25,7 +25,7 @@ function scanCLI(cliArgs, params, callback) {
log('Starting analysis...')

// prepare the exec options, most notably with the SQ params
var optionsExec = prepareExecEnvironment(params, process)
const optionsExec = prepareExecEnvironment(params, process)

// determine the command to run and execute it
scannerExecutable(sqScannerCommand => {
Expand All @@ -46,7 +46,7 @@ function scanUsingCustomScanner(params, callback) {
log('Starting analysis (with local install of the SonarScanner)...')

// prepare the exec options, most notably with the SQ params
var optionsExec = prepareExecEnvironment(params, process)
const optionsExec = prepareExecEnvironment(params, process)

// determine the command to run and execute it
localscannerExecutable(sqScannerCommand => {
Expand Down
2 changes: 1 addition & 1 deletion src/sonar-scanner-executable.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function prepareExecEnvironment(params, process) {
const sqScannerParams = sonarScannerParams(params, process.cwd(), processEnvParams)

// We need to merge the existing env variables (process.env) with the SQ ones
let mergedEnv = {}
const mergedEnv = {}
extend(mergedEnv, process.env, {
SONARQUBE_SCANNER_PARAMS: JSON.stringify(sqScannerParams)
})
Expand Down
28 changes: 14 additions & 14 deletions src/sonar-scanner-params.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
var fs = require('fs')
var path = require('path')
var extend = require('extend')
var readPackage = require('read-pkg').sync
var slugify = require('slugify')
var log = require('fancy-log')
var get = require('lodash.get')
var uniq = require('lodash.uniq')
const fs = require('fs')
const path = require('path')
const extend = require('extend')
const readPackage = require('read-pkg').sync
const slugify = require('slugify')
const log = require('fancy-log')
const get = require('lodash.get')
const uniq = require('lodash.uniq')

module.exports = defineSonarScannerParams

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

/*
* Try to be smart and guess most SQ parameters from JS files that
* might exist - like 'package.json'.
*/
function defineSonarScannerParams(params, projectBaseDir, sqScannerParamsFromEnvVariable) {
// #1 - set default values
var sonarScannerParams = {}
const sonarScannerParams = {}
try {
var sqFile = path.join(projectBaseDir, 'sonar-project.properties')
const sqFile = path.join(projectBaseDir, 'sonar-project.properties')
fs.accessSync(sqFile, fs.F_OK)
// there's a 'sonar-project.properties' file - no need to set default values
} catch (e) {
Expand Down Expand Up @@ -60,8 +60,8 @@ function defineSonarScannerParams(params, projectBaseDir, sqScannerParamsFromEnv
}

function extractInfoFromPackageFile(sonarScannerParams, projectBaseDir) {
var packageFile = path.join(projectBaseDir, 'package.json')
var pkg = readPackage(packageFile)
const packageFile = path.join(projectBaseDir, 'package.json')
const pkg = readPackage(packageFile)
log('Getting info from "package.json" file')
function fileExistsInProjectSync(file) {
return fs.existsSync(path.resolve(projectBaseDir, file))
Expand Down Expand Up @@ -108,7 +108,7 @@ function extractInfoFromPackageFile(sonarScannerParams, projectBaseDir) {
'coverage'
)
).find(function(lcovReportDir) {
var lcovReportPath = path.posix.join(lcovReportDir, 'lcov.info')
const lcovReportPath = path.posix.join(lcovReportDir, 'lcov.info')
if (fileExistsInProjectSync(lcovReportPath)) {
sonarScannerParams['sonar.exclusions'] += ',' + path.posix.join(lcovReportDir, '**')
// https://docs.sonarqube.org/display/PLUG/JavaScript+Coverage+Results+Import
Expand Down

0 comments on commit b5406fc

Please sign in to comment.