refactor: add prefer-const to .eslintrc + fix errors (#14880)

This commit is contained in:
Milan Burda 2018-10-02 03:56:31 +02:00 committed by Samuel Attard
parent 07161a8452
commit 3ad3ade828
47 changed files with 239 additions and 238 deletions

View file

@ -51,7 +51,7 @@ async function makeRequest (requestOptions, parseResponse) {
async function circleCIcall (buildUrl, targetBranch, job, options) {
console.log(`Triggering CircleCI to run build job: ${job} on branch: ${targetBranch} with release flag.`)
let buildRequest = {
const buildRequest = {
'build_parameters': {
'CIRCLE_JOB': job
}
@ -67,7 +67,7 @@ async function circleCIcall (buildUrl, targetBranch, job, options) {
buildRequest.build_parameters.AUTO_RELEASE = 'true'
}
let circleResponse = await makeRequest({
const circleResponse = await makeRequest({
method: 'POST',
url: buildUrl,
headers: {
@ -117,7 +117,7 @@ async function callAppVeyor (targetBranch, job, options) {
}),
method: 'POST'
}
let appVeyorResponse = await makeRequest(requestOpts, true).catch(err => {
const appVeyorResponse = await makeRequest(requestOpts, true).catch(err => {
console.log('Error calling AppVeyor:', err)
})
const buildUrl = `https://windows-ci.electronjs.org/project/AppVeyor/${appVeyorJobs[job]}/build/${appVeyorResponse.version}`
@ -147,7 +147,7 @@ async function buildVSTS (targetBranch, options) {
environmentVariables.UPLOAD_TO_S3 = 1
}
let requestOpts = {
const requestOpts = {
url: `${vstsURL}/definitions?api-version=4.1`,
auth: {
user: '',
@ -157,7 +157,7 @@ async function buildVSTS (targetBranch, options) {
'Content-Type': 'application/json'
}
}
let vstsResponse = await makeRequest(requestOpts, true).catch(err => {
const vstsResponse = await makeRequest(requestOpts, true).catch(err => {
console.log('Error calling VSTS to get build definitions:', err)
})
let buildsToRun = []
@ -170,14 +170,14 @@ async function buildVSTS (targetBranch, options) {
}
async function callVSTSBuild (build, targetBranch, environmentVariables) {
let buildBody = {
const buildBody = {
definition: build,
sourceBranch: targetBranch
}
if (Object.keys(environmentVariables).length !== 0) {
buildBody.parameters = JSON.stringify(environmentVariables)
}
let requestOpts = {
const requestOpts = {
url: `${vstsURL}/builds?api-version=4.1`,
auth: {
user: '',
@ -189,7 +189,7 @@ async function callVSTSBuild (build, targetBranch, environmentVariables) {
body: JSON.stringify(buildBody),
method: 'POST'
}
let vstsResponse = await makeRequest(requestOpts, true).catch(err => {
const vstsResponse = await makeRequest(requestOpts, true).catch(err => {
console.log(`Error calling VSTS for job ${build.name}`, err)
})
console.log(`VSTS release build request for ${build.name} successful. Check ${vstsResponse._links.web.href} for status.`)

View file

@ -12,11 +12,11 @@ const version = process.argv[2]
async function findRelease () {
github.authenticate({ type: 'token', token: process.env.ELECTRON_GITHUB_TOKEN })
let releases = await github.repos.getReleases({
const releases = await github.repos.getReleases({
owner: 'electron',
repo: version.indexOf('nightly') > 0 ? 'nightlies' : 'electron'
})
let targetRelease = releases.data.find(release => {
const targetRelease = releases.data.find(release => {
return release.tag_name === version
})
let returnObject = {}

View file

@ -5,7 +5,7 @@ const gitDir = path.resolve(__dirname, '..')
async function determineNextMajorForMaster () {
let branchNames
let result = await GitProcess.exec(['branch', '-a', '--remote', '--list', 'origin/[0-9]-[0-9]-x'], gitDir)
const result = await GitProcess.exec(['branch', '-a', '--remote', '--list', 'origin/[0-9]-[0-9]-x'], gitDir)
if (result.exitCode === 0) {
branchNames = result.stdout.trim().split('\n')
const filtered = branchNames.map(b => b.replace('origin/', ''))

View file

@ -34,15 +34,15 @@ async function getNewVersion (dryRun) {
if (!dryRun) {
console.log(`Bumping for new "${versionType}" version.`)
}
let bumpScript = path.join(__dirname, 'bump-version.py')
let scriptArgs = [bumpScript, '--bump', versionType]
const bumpScript = path.join(__dirname, 'bump-version.py')
const scriptArgs = [bumpScript, '--bump', versionType]
if (dryRun) {
scriptArgs.push('--dry-run')
}
try {
let bumpVersion = execSync(scriptArgs.join(' '), { encoding: 'UTF-8' })
bumpVersion = bumpVersion.substr(bumpVersion.indexOf(':') + 1).trim()
let newVersion = `v${bumpVersion}`
const newVersion = `v${bumpVersion}`
if (!dryRun) {
console.log(`${pass} Successfully bumped version to ${newVersion}`)
}
@ -55,15 +55,15 @@ async function getNewVersion (dryRun) {
async function getCurrentBranch (gitDir) {
console.log(`Determining current git branch`)
let gitArgs = ['rev-parse', '--abbrev-ref', 'HEAD']
let branchDetails = await GitProcess.exec(gitArgs, gitDir)
const gitArgs = ['rev-parse', '--abbrev-ref', 'HEAD']
const branchDetails = await GitProcess.exec(gitArgs, gitDir)
if (branchDetails.exitCode === 0) {
let currentBranch = branchDetails.stdout.trim()
const currentBranch = branchDetails.stdout.trim()
console.log(`${pass} Successfully determined current git branch is ` +
`${currentBranch}`)
return currentBranch
} else {
let error = GitProcess.parseError(branchDetails.stderr)
const error = GitProcess.parseError(branchDetails.stderr)
console.log(`${fail} Could not get details for the current branch,
error was ${branchDetails.stderr}`, error)
process.exit(1)
@ -75,7 +75,7 @@ async function getReleaseNotes (currentBranch) {
return 'Nightlies do not get release notes, please compare tags for info'
}
console.log(`Generating release notes for ${currentBranch}.`)
let githubOpts = {
const githubOpts = {
owner: 'electron',
repo: targetRepo,
base: `v${pkg.version}`,
@ -88,7 +88,7 @@ async function getReleaseNotes (currentBranch) {
releaseNotes = '(placeholder)\n'
}
console.log(`Checking for commits from ${pkg.version} to ${currentBranch}`)
let commitComparison = await github.repos.compareCommits(githubOpts)
const commitComparison = await github.repos.compareCommits(githubOpts)
.catch(err => {
console.log(`${fail} Error checking for commits from ${pkg.version} to ` +
`${currentBranch}`, err)
@ -112,7 +112,7 @@ async function getReleaseNotes (currentBranch) {
let prNumber
if (prMatch) {
commitMessage = commitMessage.replace(mergeRE, '').replace('\n', '')
let newlineMatch = commitMessage.match(newlineRE)
const newlineMatch = commitMessage.match(newlineRE)
if (newlineMatch) {
commitMessage = newlineMatch[1]
}
@ -138,19 +138,19 @@ async function getReleaseNotes (currentBranch) {
}
async function createRelease (branchToTarget, isBeta) {
let releaseNotes = await getReleaseNotes(branchToTarget)
let newVersion = await getNewVersion()
const releaseNotes = await getReleaseNotes(branchToTarget)
const newVersion = await getNewVersion()
await tagRelease(newVersion)
const githubOpts = {
owner: 'electron',
repo: targetRepo
}
console.log(`Checking for existing draft release.`)
let releases = await github.repos.getReleases(githubOpts)
const releases = await github.repos.getReleases(githubOpts)
.catch(err => {
console.log('$fail} Could not get releases. Error was', err)
})
let drafts = releases.data.filter(release => release.draft &&
const drafts = releases.data.filter(release => release.draft &&
release.tag_name === newVersion)
if (drafts.length > 0) {
console.log(`${fail} Aborting because draft release for
@ -188,7 +188,7 @@ async function createRelease (branchToTarget, isBeta) {
}
async function pushRelease (branch) {
let pushDetails = await GitProcess.exec(['push', 'origin', `HEAD:${branch}`, '--follow-tags'], gitDir)
const pushDetails = await GitProcess.exec(['push', 'origin', `HEAD:${branch}`, '--follow-tags'], gitDir)
if (pushDetails.exitCode === 0) {
console.log(`${pass} Successfully pushed the release. Wait for ` +
`release builds to finish before running "npm run release".`)
@ -208,7 +208,7 @@ async function runReleaseBuilds (branch) {
async function tagRelease (version) {
console.log(`Tagging release ${version}.`)
let checkoutDetails = await GitProcess.exec([ 'tag', '-a', '-m', version, version ], gitDir)
const checkoutDetails = await GitProcess.exec([ 'tag', '-a', '-m', version, version ], gitDir)
if (checkoutDetails.exitCode === 0) {
console.log(`${pass} Successfully tagged ${version}.`)
} else {
@ -219,7 +219,7 @@ async function tagRelease (version) {
}
async function verifyNewVersion () {
let newVersion = await getNewVersion(true)
const newVersion = await getNewVersion(true)
let response
if (args.automaticRelease) {
response = 'y'
@ -249,19 +249,19 @@ async function promptForVersion (version) {
// function to determine if there have been commits to master since the last release
async function changesToRelease () {
let lastCommitWasRelease = new RegExp(`^Bump v[0-9.]*(-beta[0-9.]*)?(-nightly[0-9.]*)?$`, 'g')
let lastCommit = await GitProcess.exec(['log', '-n', '1', `--pretty=format:'%s'`], gitDir)
const lastCommitWasRelease = new RegExp(`^Bump v[0-9.]*(-beta[0-9.]*)?(-nightly[0-9.]*)?$`, 'g')
const lastCommit = await GitProcess.exec(['log', '-n', '1', `--pretty=format:'%s'`], gitDir)
return !lastCommitWasRelease.test(lastCommit.stdout)
}
async function prepareRelease (isBeta, notesOnly) {
if (args.dryRun) {
let newVersion = await getNewVersion(true)
const newVersion = await getNewVersion(true)
console.log(newVersion)
} else {
const currentBranch = (args.branch) ? args.branch : await getCurrentBranch(gitDir)
if (notesOnly) {
let releaseNotes = await getReleaseNotes(currentBranch)
const releaseNotes = await getReleaseNotes(currentBranch)
console.log(`Draft release notes are: \n${releaseNotes}`)
} else {
const changes = await changesToRelease(currentBranch)

View file

@ -141,15 +141,15 @@ new Promise((resolve, reject) => {
async function getCurrentBranch () {
const gitDir = path.resolve(__dirname, '..')
console.log(`Determining current git branch`)
let gitArgs = ['rev-parse', '--abbrev-ref', 'HEAD']
let branchDetails = await GitProcess.exec(gitArgs, gitDir)
const gitArgs = ['rev-parse', '--abbrev-ref', 'HEAD']
const branchDetails = await GitProcess.exec(gitArgs, gitDir)
if (branchDetails.exitCode === 0) {
let currentBranch = branchDetails.stdout.trim()
const currentBranch = branchDetails.stdout.trim()
console.log(`Successfully determined current git branch is ` +
`${currentBranch}`)
return currentBranch
} else {
let error = GitProcess.parseError(branchDetails.stderr)
const error = GitProcess.parseError(branchDetails.stderr)
console.log(`Could not get details for the current branch,
error was ${branchDetails.stderr}`, error)
process.exit(1)

View file

@ -24,15 +24,14 @@ const github = new GitHub({
github.authenticate({ type: 'token', token: process.env.ELECTRON_GITHUB_TOKEN })
async function getDraftRelease (version, skipValidation) {
let releaseInfo = await github.repos.getReleases({ owner: 'electron', repo: targetRepo })
let drafts
const releaseInfo = await github.repos.getReleases({ owner: 'electron', repo: targetRepo })
let versionToCheck
if (version) {
versionToCheck = version
} else {
versionToCheck = pkgVersion
}
drafts = releaseInfo.data
const drafts = releaseInfo.data
.filter(release => release.tag_name === versionToCheck &&
release.draft === true)
const draft = drafts[0]
@ -143,19 +142,19 @@ function checkVersion () {
if (args.skipVersionCheck) return
console.log(`Verifying that app version matches package version ${pkgVersion}.`)
let startScript = path.join(__dirname, 'start.py')
let scriptArgs = ['--version']
const startScript = path.join(__dirname, 'start.py')
const scriptArgs = ['--version']
if (args.automaticRelease) {
scriptArgs.unshift('-R')
}
let appVersion = runScript(startScript, scriptArgs).trim()
const appVersion = runScript(startScript, scriptArgs).trim()
check((pkgVersion.indexOf(appVersion) === 0), `App version ${appVersion} matches ` +
`package version ${pkgVersion}.`, true)
}
function runScript (scriptName, scriptArgs, cwd) {
let scriptCommand = `${scriptName} ${scriptArgs.join(' ')}`
let scriptOptions = {
const scriptCommand = `${scriptName} ${scriptArgs.join(' ')}`
const scriptOptions = {
encoding: 'UTF-8'
}
if (cwd) {
@ -171,21 +170,21 @@ function runScript (scriptName, scriptArgs, cwd) {
function uploadNodeShasums () {
console.log('Uploading Node SHASUMS file to S3.')
let scriptPath = path.join(__dirname, 'upload-node-checksums.py')
const scriptPath = path.join(__dirname, 'upload-node-checksums.py')
runScript(scriptPath, ['-v', pkgVersion])
console.log(`${pass} Done uploading Node SHASUMS file to S3.`)
}
function uploadIndexJson () {
console.log('Uploading index.json to S3.')
let scriptPath = path.join(__dirname, 'upload-index-json.py')
const scriptPath = path.join(__dirname, 'upload-index-json.py')
runScript(scriptPath, [pkgVersion])
console.log(`${pass} Done uploading index.json to S3.`)
}
async function createReleaseShasums (release) {
let fileName = 'SHASUMS256.txt'
let existingAssets = release.assets.filter(asset => asset.name === fileName)
const fileName = 'SHASUMS256.txt'
const existingAssets = release.assets.filter(asset => asset.name === fileName)
if (existingAssets.length > 0) {
console.log(`${fileName} already exists on GitHub; deleting before creating new file.`)
await github.repos.deleteAsset({
@ -197,17 +196,17 @@ async function createReleaseShasums (release) {
})
}
console.log(`Creating and uploading the release ${fileName}.`)
let scriptPath = path.join(__dirname, 'merge-electron-checksums.py')
let checksums = runScript(scriptPath, ['-v', pkgVersion])
const scriptPath = path.join(__dirname, 'merge-electron-checksums.py')
const checksums = runScript(scriptPath, ['-v', pkgVersion])
console.log(`${pass} Generated release SHASUMS.`)
let filePath = await saveShaSumFile(checksums, fileName)
const filePath = await saveShaSumFile(checksums, fileName)
console.log(`${pass} Created ${fileName} file.`)
await uploadShasumFile(filePath, fileName, release)
console.log(`${pass} Successfully uploaded ${fileName} to GitHub.`)
}
async function uploadShasumFile (filePath, fileName, release) {
let githubOpts = {
const githubOpts = {
owner: 'electron',
repo: targetRepo,
id: release.id,
@ -242,7 +241,7 @@ function saveShaSumFile (checksums, fileName) {
}
async function publishRelease (release) {
let githubOpts = {
const githubOpts = {
owner: 'electron',
repo: targetRepo,
id: release.id,
@ -264,7 +263,7 @@ async function makeRelease (releaseToValidate) {
console.log('Release to validate !=== true')
}
console.log(`Validating release ${releaseToValidate}`)
let release = await getDraftRelease(releaseToValidate)
const release = await getDraftRelease(releaseToValidate)
await validateReleaseAssets(release, true)
} else {
checkVersion()
@ -295,8 +294,8 @@ async function makeTempDir () {
}
async function verifyAssets (release) {
let downloadDir = await makeTempDir()
let githubOpts = {
const downloadDir = await makeTempDir()
const githubOpts = {
owner: 'electron',
repo: targetRepo,
headers: {
@ -304,10 +303,10 @@ async function verifyAssets (release) {
}
}
console.log(`Downloading files from GitHub to verify shasums`)
let shaSumFile = 'SHASUMS256.txt'
const shaSumFile = 'SHASUMS256.txt'
let filesToCheck = await Promise.all(release.assets.map(async (asset) => {
githubOpts.id = asset.id
let assetDetails = await github.repos.getAsset(githubOpts)
const assetDetails = await github.repos.getAsset(githubOpts)
await downloadFiles(assetDetails.meta.location, downloadDir, false, asset.name)
return asset.name
})).catch(err => {
@ -328,7 +327,7 @@ async function verifyAssets (release) {
function downloadFiles (urls, directory, quiet, targetName) {
return new Promise((resolve, reject) => {
let nuggetOpts = {
const nuggetOpts = {
dir: directory
}
if (quiet) {
@ -348,32 +347,32 @@ function downloadFiles (urls, directory, quiet, targetName) {
}
async function verifyShasums (urls, isS3) {
let fileSource = isS3 ? 'S3' : 'GitHub'
const fileSource = isS3 ? 'S3' : 'GitHub'
console.log(`Downloading files from ${fileSource} to verify shasums`)
let downloadDir = await makeTempDir()
const downloadDir = await makeTempDir()
let filesToCheck = []
try {
if (!isS3) {
await downloadFiles(urls, downloadDir)
filesToCheck = urls.map(url => {
let currentUrl = new URL(url)
const currentUrl = new URL(url)
return path.basename(currentUrl.pathname)
}).filter(file => file.indexOf('SHASUMS') === -1)
} else {
const s3VersionPath = `/atom-shell/dist/${pkgVersion}/`
await Promise.all(urls.map(async (url) => {
let currentUrl = new URL(url)
let dirname = path.dirname(currentUrl.pathname)
let filename = path.basename(currentUrl.pathname)
let s3VersionPathIdx = dirname.indexOf(s3VersionPath)
const currentUrl = new URL(url)
const dirname = path.dirname(currentUrl.pathname)
const filename = path.basename(currentUrl.pathname)
const s3VersionPathIdx = dirname.indexOf(s3VersionPath)
if (s3VersionPathIdx === -1 || dirname === s3VersionPath) {
if (s3VersionPathIdx !== -1 && filename.indexof('SHASUMS') === -1) {
filesToCheck.push(filename)
}
await downloadFiles(url, downloadDir, true)
} else {
let subDirectory = dirname.substr(s3VersionPathIdx + s3VersionPath.length)
let fileDirectory = path.join(downloadDir, subDirectory)
const subDirectory = dirname.substr(s3VersionPathIdx + s3VersionPath.length)
const fileDirectory = path.join(downloadDir, subDirectory)
try {
fs.statSync(fileDirectory)
} catch (err) {
@ -418,8 +417,8 @@ async function verifyShasums (urls, isS3) {
async function validateChecksums (validationArgs) {
console.log(`Validating checksums for files from ${validationArgs.fileSource} ` +
`against ${validationArgs.shaSumFile}.`)
let shaSumFilePath = path.join(validationArgs.fileDirectory, validationArgs.shaSumFile)
let checker = new sumchecker.ChecksumValidator(validationArgs.algorithm,
const shaSumFilePath = path.join(validationArgs.fileDirectory, validationArgs.shaSumFile)
const checker = new sumchecker.ChecksumValidator(validationArgs.algorithm,
shaSumFilePath, validationArgs.checkerOpts)
await checker.validate(validationArgs.fileDirectory, validationArgs.filesToCheck)
.catch(err => {

View file

@ -8,14 +8,14 @@ if (process.argv.length < 6) {
console.log('Usage: upload-to-github filePath fileName releaseId')
process.exit(1)
}
let filePath = process.argv[2]
let fileName = process.argv[3]
let releaseId = process.argv[4]
let releaseVersion = process.argv[5]
const filePath = process.argv[2]
const fileName = process.argv[3]
const releaseId = process.argv[4]
const releaseVersion = process.argv[5]
const targetRepo = releaseVersion.indexOf('nightly') > 0 ? 'nightlies' : 'electron'
let githubOpts = {
const githubOpts = {
owner: 'electron',
repo: targetRepo,
id: releaseId,
@ -34,7 +34,7 @@ function uploadToGitHub () {
console.log(`Error uploading ${fileName} to GitHub, will retry. Error was:`, err)
retry++
github.repos.getRelease(githubOpts).then(release => {
let existingAssets = release.data.assets.filter(asset => asset.name === fileName)
const existingAssets = release.data.assets.filter(asset => asset.name === fileName)
if (existingAssets.length > 0) {
console.log(`${fileName} already exists; will delete before retrying upload.`)
github.repos.deleteAsset({