diff options
author | Rubén Rincón Blanco <ruben@rinconblanco.es> | 2020-08-04 22:39:02 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-04 16:39:02 -0400 |
commit | ccff4b9ee5a37c13f0973b52e8f90a8be8359fea (patch) | |
tree | 0022c9364824c5b4e4f5818c4abbf654aa99f2e8 /lib/compilers | |
parent | 7126b39a6bdeabffc312c8a117ec7af072ef6a1c (diff) | |
download | compiler-explorer-ccff4b9ee5a37c13f0973b52e8f90a8be8359fea.tar.gz compiler-explorer-ccff4b9ee5a37c13f0973b52e8f90a8be8359fea.zip |
Add new eslint rules (#2121)
The largest changes here are:
- enforcing single quotes for strings
- enforcing trailing commas where possible
In addition to those we have enabled several eslint plugins:
- plugin:requirejs/recommended, to enforce some conventions in require statements
- plugin:node/recommended, to enforce correct usage of various node.js APIs
- plugin:unicorn/recommended, which contains a pretty mixed bag of useful rules
This PR attempts to not change code behavior when possible. In cases where fixing
existing code would change semantics, a linting exclusion has been placed in the
code base to silence the error. You can find these by searching for `eslint-disable-next-line`.
Co-authored-by: Austin Morton <austinpmorton@gmail.com>
Diffstat (limited to 'lib/compilers')
30 files changed, 234 insertions, 235 deletions
diff --git a/lib/compilers/ada.js b/lib/compilers/ada.js index 1f3c58e52..c77d7c02f 100644 --- a/lib/compilers/ada.js +++ b/lib/compilers/ada.js @@ -24,7 +24,7 @@ const BaseCompiler = require('../base-compiler'), utils = require('../utils'), - path = require("path"); + path = require('path'); class AdaCompiler extends BaseCompiler { constructor(info, env) { @@ -34,11 +34,11 @@ class AdaCompiler extends BaseCompiler { } getExecutableFilename(dirPath) { - return path.join(dirPath, "example"); + return path.join(dirPath, 'example'); } getOutputFilename(dirPath) { - return path.join(dirPath, "example.o"); + return path.join(dirPath, 'example.o'); } optionsForFilter(filters, outputFilename) { @@ -59,7 +59,7 @@ class AdaCompiler extends BaseCompiler { ); if (this.compiler.intelAsm && filters.intel) { - options = options.concat(this.compiler.intelAsm.split(" ")); + options = options.concat(this.compiler.intelAsm.split(' ')); } } else { options.push( @@ -67,7 +67,7 @@ class AdaCompiler extends BaseCompiler { '-eS', '-g', 'example', - '-cargs' + '-cargs', ); } diff --git a/lib/compilers/analysis-tool.js b/lib/compilers/analysis-tool.js index 0bd2aa642..1ef49d1c5 100644 --- a/lib/compilers/analysis-tool.js +++ b/lib/compilers/analysis-tool.js @@ -40,7 +40,7 @@ class AnalysisTool extends BaseCompiler { commentOnly: false, directives: false, labels: false, - optOutput: false + optOutput: false, }; } } diff --git a/lib/compilers/argument-parsers.js b/lib/compilers/argument-parsers.js index 660995ab5..744a1d4ab 100644 --- a/lib/compilers/argument-parsers.js +++ b/lib/compilers/argument-parsers.js @@ -39,11 +39,11 @@ class BaseParser { const match = line.match(optionRegex); if (!match) { if (previousOption && (line.trim().length !== 0)) { - if (options[previousOption].description.endsWith("-")) + if (options[previousOption].description.endsWith('-')) options[previousOption].description += line.trim(); else { if (options[previousOption].description.length !== 0) - options[previousOption].description += " " + line.trim(); + options[previousOption].description += ' ' + line.trim(); else options[previousOption].description = line.trim(); } @@ -57,7 +57,7 @@ class BaseParser { if (previousOption) { options[previousOption] = { description: match[2].trim(), - timesused: 0 + timesused: 0, }; } }); @@ -66,7 +66,7 @@ class BaseParser { } static async getOptions(compiler, helpArg) { - const optionFinder = /^\s*(--?[a-z0-9=+,[\]<>|-]*)\s*(.*)/i; + const optionFinder = /^\s*(--?[\d+,<=>[\]a-z|-]*)\s*(.*)/i; const result = await compiler.execCompilerCached(compiler.compiler.exe, [helpArg]); const options = result.code === 0 ? BaseParser.parseLines(result.stdout + result.stderr, optionFinder) : {}; @@ -82,26 +82,27 @@ class BaseParser { class GCCParser extends BaseParser { static async parse(compiler) { const results = await Promise.all([ - GCCParser.getOptions(compiler, "-fsyntax-only --target-help"), - GCCParser.getOptions(compiler, "-fsyntax-only --help=common"), - GCCParser.getOptions(compiler, "-fsyntax-only --help=optimizers") + GCCParser.getOptions(compiler, '-fsyntax-only --target-help'), + GCCParser.getOptions(compiler, '-fsyntax-only --help=common'), + GCCParser.getOptions(compiler, '-fsyntax-only --help=optimizers'), ]); const options = Object.assign({}, ...results); const keys = _.keys(options); - logger.debug(`gcc-like compiler options: ${keys.join(" ")}`); - if (BaseParser.hasSupport(options, "-masm=")) { + logger.debug(`gcc-like compiler options: ${keys.join(' ')}`); + if (BaseParser.hasSupport(options, '-masm=')) { // -masm= may be available but unsupported by the compiler. - compiler.exec(compiler.compiler.exe, ["-fsyntax-only", "--target-help", "-masm=intel"]) + // eslint-disable-next-line promise/catch-or-return + compiler.exec(compiler.compiler.exe, ['-fsyntax-only', '--target-help', '-masm=intel']) .then(result => { if (result.code === 0) { - compiler.compiler.intelAsm = "-masm=intel"; + compiler.compiler.intelAsm = '-masm=intel'; compiler.compiler.supportsIntel = true; } }); } - if (BaseParser.hasSupport(options, "-fdiagnostics-color")) { - if (compiler.compiler.options) compiler.compiler.options += " "; - compiler.compiler.options += "-fdiagnostics-color=always"; + if (BaseParser.hasSupport(options, '-fdiagnostics-color')) { + if (compiler.compiler.options) compiler.compiler.options += ' '; + compiler.compiler.options += '-fdiagnostics-color=always'; } // This check is not infallible, but takes care of Rust and Swift being picked up :) if (_.find(keys, key => key.startsWith('-fdump-'))) { @@ -111,7 +112,7 @@ class GCCParser extends BaseParser { } static async getOptions(compiler, helpArg) { - const optionFinder = /^\s*(--?[a-z0-9=+,[\]<>|-]*)\s*(.*)/i; + const optionFinder = /^\s*(--?[\d+,<=>[\]a-z|-]*)\s*(.*)/i; const result = await compiler.execCompilerCached(compiler.compiler.exe, helpArg.split(' ')); const options = result.code === 0 ? BaseParser.parseLines(result.stdout + result.stderr, optionFinder) : {}; @@ -122,23 +123,23 @@ class GCCParser extends BaseParser { class ClangParser extends BaseParser { static async parse(compiler) { - const options = await ClangParser.getOptions(compiler, "--help"); - logger.debug(`clang-like compiler options: ${_.keys(options).join(" ")}`); + const options = await ClangParser.getOptions(compiler, '--help'); + logger.debug(`clang-like compiler options: ${_.keys(options).join(' ')}`); if (BaseParser.hasSupport(options, '-fsave-optimization-record')) { - compiler.compiler.optArg = "-fsave-optimization-record"; + compiler.compiler.optArg = '-fsave-optimization-record'; compiler.compiler.supportsOptOutput = true; } - if (BaseParser.hasSupport(options, "-fcolor-diagnostics")) { - if (compiler.compiler.options) compiler.compiler.options += " "; - compiler.compiler.options += "-fcolor-diagnostics"; + if (BaseParser.hasSupport(options, '-fcolor-diagnostics')) { + if (compiler.compiler.options) compiler.compiler.options += ' '; + compiler.compiler.options += '-fcolor-diagnostics'; } - if (BaseParser.hasSupport(options, "-emit-llvm")) { + if (BaseParser.hasSupport(options, '-emit-llvm')) { compiler.compiler.supportsIrView = true; compiler.compiler.irArg = ['-Xclang', '-emit-llvm', '-fsyntax-only']; } - if (BaseParser.hasSupport(options, "-fno-crash-diagnostics")) { - if (compiler.compiler.options) compiler.compiler.options += " "; - compiler.compiler.options += "-fno-crash-diagnostics"; + if (BaseParser.hasSupport(options, '-fno-crash-diagnostics')) { + if (compiler.compiler.options) compiler.compiler.options += ' '; + compiler.compiler.options += '-fno-crash-diagnostics'; } return compiler; } @@ -146,16 +147,16 @@ class ClangParser extends BaseParser { class PascalParser extends BaseParser { static async parse(compiler) { - await PascalParser.getOptions(compiler, "-help"); + await PascalParser.getOptions(compiler, '-help'); return compiler; } } class ISPCParser extends BaseParser { static async parse(compiler) { - const options = await ISPCParser.getOptions(compiler, "--help"); - if (BaseParser.hasSupport(options, "--x86-asm-syntax")) { - compiler.compiler.intelAsm = "--x86-asm-syntax=intel"; + const options = await ISPCParser.getOptions(compiler, '--help'); + if (BaseParser.hasSupport(options, '--x86-asm-syntax')) { + compiler.compiler.intelAsm = '--x86-asm-syntax=intel'; compiler.compiler.supportsIntel = true; } return compiler; @@ -163,7 +164,7 @@ class ISPCParser extends BaseParser { static async getOptions(compiler, helpArg) { const result = await compiler.execCompilerCached(compiler.compiler.exe, [helpArg]); - const optionFinder = /^\s*\[(--?[a-z0-9=+,{}()\s<>/|-]*)\]\s*(.*)/i; + const optionFinder = /^\s*\[(--?[\d\s()+,/<=>a-z{|}-]*)]\s*(.*)/i; const options = result.code === 0 ? BaseParser.parseLines(result.stdout + result.stderr, optionFinder) : {}; compiler.possibleArguments.populateOptions(options); @@ -173,14 +174,14 @@ class ISPCParser extends BaseParser { class JavaParser extends BaseParser { static async parse(compiler) { - await JavaParser.getOptions(compiler, "-help"); + await JavaParser.getOptions(compiler, '-help'); return compiler; } } class VCParser extends BaseParser { static async parse(compiler) { - await VCParser.getOptions(compiler, "/help"); + await VCParser.getOptions(compiler, '/help'); return compiler; } @@ -189,16 +190,16 @@ class VCParser extends BaseParser { let options = {}; const matchLine = (line) => { - if (line.startsWith("/?")) return; + if (line.startsWith('/?')) return; const match = line.match(optionRegex); if (!match) { if (previousOption && (line.trim().length !== 0)) { - if (options[previousOption].description.endsWith(":")) - options[previousOption].description += " " + line.trim(); + if (options[previousOption].description.endsWith(':')) + options[previousOption].description += ' ' + line.trim(); else { if (options[previousOption].description.length !== 0) - options[previousOption].description += ", " + line.trim(); + options[previousOption].description += ', ' + line.trim(); else options[previousOption].description = line.trim(); } @@ -212,15 +213,15 @@ class VCParser extends BaseParser { if (previousOption) { options[previousOption] = { description: match[2].trim(), - timesused: 0 + timesused: 0, }; } }; utils.eachLine(stdout, line => { if (line.length === 0) return; - if (line.includes("C/C++ COMPILER OPTIONS")) return; - if (line.match(/^\s\s*-.*-$/)) return; + if (line.includes('C/C++ COMPILER OPTIONS')) return; + if (line.match(/^\s+-.*-$/)) return; let col1; let col2; @@ -229,7 +230,7 @@ class VCParser extends BaseParser { col2 = line.substr(40); } else { col1 = line; - col2 = ""; + col2 = ''; } if (col1) matchLine(col1); @@ -241,7 +242,7 @@ class VCParser extends BaseParser { static async getOptions(compiler, helpArg) { const result = await compiler.execCompilerCached(compiler.compiler.exe, [helpArg]); - const optionFinder = /^\s*(\/[a-z0-9=:+#.,[\]{}<>|_-]*)\s*(.*)/i; + const optionFinder = /^\s*(\/[\w#+,.:<=>[\]{|}-]*)\s*(.*)/i; const options = result.code === 0 ? this.parseLines(result.stdout, optionFinder) : {}; compiler.possibleArguments.populateOptions(options); @@ -253,14 +254,14 @@ class VCParser extends BaseParser { class RustParser extends BaseParser { static async parse(compiler) { const results = await Promise.all([ - RustParser.getOptions(compiler, "--help"), - RustParser.getOptions(compiler, "-C help"), - RustParser.getOptions(compiler, "--help -v") + RustParser.getOptions(compiler, '--help'), + RustParser.getOptions(compiler, '-C help'), + RustParser.getOptions(compiler, '--help -v'), ]); const options = Object.assign({}, ...results); - if (BaseParser.hasSupport(options, "--color")) { - if (compiler.compiler.options) compiler.compiler.options += " "; - compiler.compiler.options += "--color=always"; + if (BaseParser.hasSupport(options, '--color')) { + if (compiler.compiler.options) compiler.compiler.options += ' '; + compiler.compiler.options += '--color=always'; } return compiler; } @@ -269,12 +270,12 @@ class RustParser extends BaseParser { const result = await compiler.execCompilerCached(compiler.compiler.exe, helpArg.split(' ')); let options = {}; if (result.code === 0) { - if (helpArg === "-C help") { - const optionFinder = /^\s*(-C\s*[a-z0-9=-]*)\s--\s(.*)/i; + if (helpArg === '-C help') { + const optionFinder = /^\s*(-c\s*[\d=a-z-]*)\s--\s(.*)/i; options = BaseParser.parseLines(result.stdout + result.stderr, optionFinder); } else { - const optionFinder = /^\s*(--?[a-z0-9=+,[\]<>|-]*)\s*(.*)/i; + const optionFinder = /^\s*(--?[\d+,<=>[\]a-z|-]*)\s*(.*)/i; options = BaseParser.parseLines(result.stdout + result.stderr, optionFinder); } @@ -286,7 +287,7 @@ class RustParser extends BaseParser { class NimParser extends BaseParser { static async parse(compiler) { - await NimParser.getOptions(compiler, "-help"); + await NimParser.getOptions(compiler, '-help'); return compiler; } } @@ -300,5 +301,5 @@ module.exports = { Pascal: PascalParser, ISPC: ISPCParser, Rust: RustParser, - Nim: NimParser + Nim: NimParser, }; diff --git a/lib/compilers/assembly.js b/lib/compilers/assembly.js index 25156ae22..ef792ca3a 100644 --- a/lib/compilers/assembly.js +++ b/lib/compilers/assembly.js @@ -21,14 +21,14 @@ // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. -"use strict"; +'use strict'; const BaseCompiler = require('../base-compiler'), AsmRaw = require('../asm-raw').AsmParser, utils = require('../utils'), - fs = require("fs"), - path = require("path"), - argumentParsers = require("./argument-parsers"); + fs = require('fs'), + path = require('path'), + argumentParsers = require('./argument-parsers'); class AssemblyCompiler extends BaseCompiler { constructor(info, env) { @@ -76,7 +76,7 @@ class AssemblyCompiler extends BaseCompiler { resolve(path.join(outputFolder, file)); } }); - reject("No output file was generated"); + reject('No output file was generated'); }); }); } @@ -84,14 +84,14 @@ class AssemblyCompiler extends BaseCompiler { async objdump(outputFilename, result, maxSize, intelAsm, demangle) { const realOutputFilename = await this.getGeneratedOutputFilename(outputFilename); const dirPath = path.dirname(realOutputFilename); - let args = ["-d", realOutputFilename, "-l", "--insn-width=16"]; - if (demangle) args = args.concat("-C"); - if (intelAsm) args = args.concat(["-M", "intel"]); + let args = ['-d', realOutputFilename, '-l', '--insn-width=16']; + if (demangle) args = args.concat('-C'); + if (intelAsm) args = args.concat(['-M', 'intel']); const objResult = await this.exec( this.compiler.objdumper, args, {maxOutput: maxSize, customCwd: dirPath}); result.asm = objResult.stdout; if (objResult.code !== 0) { - result.asm = "<No output: objdump returned " + objResult.code + ">"; + result.asm = '<No output: objdump returned ' + objResult.code + '>'; } return result; } diff --git a/lib/compilers/clean.js b/lib/compilers/clean.js index e9f724954..704a55444 100644 --- a/lib/compilers/clean.js +++ b/lib/compilers/clean.js @@ -38,38 +38,38 @@ class CleanCompiler extends BaseCompiler { } getOutputFilename(dirPath) { - return path.join(dirPath, "Clean System Files/example.s"); + return path.join(dirPath, 'Clean System Files/example.s'); } preprocessOutput(output) { - const errorRegex = /^Error \[.*,(\d*),(.*)\]:\s?(.*)/i; - const errorLineRegex = /^Error \[.*,(\d*)\]:\s?(.*)/i; - const parseerrorRegex = /^Parse error \[.*,(\d*);(\d*),(.*)\]:\s?(.*)/i; - const typeeerrorRegex = /^Type error \[.*,(\d*),(.*)\]:\s?(.*)/i; + const errorRegex = /^error \[.*,(\d*),(.*)]:\s?(.*)/i; + const errorLineRegex = /^error \[.*,(\d*)]:\s?(.*)/i; + const parseerrorRegex = /^parse error \[.*,(\d*);(\d*),(.*)]:\s?(.*)/i; + const typeeerrorRegex = /^type error \[.*,(\d*),(.*)]:\s?(.*)/i; return utils.splitLines(output).map(line => { let matches = line.match(errorRegex); if (!matches) matches = line.match(typeeerrorRegex); if (matches) { - return "<source>:" + matches[1] + ",0: error: (" + matches[2] + ") " + matches[3]; + return '<source>:' + matches[1] + ',0: error: (' + matches[2] + ') ' + matches[3]; } matches = line.match(errorLineRegex); if (matches) { - return "<source>:" + matches[1] + ",0: error: " + matches[2]; + return '<source>:' + matches[1] + ',0: error: ' + matches[2]; } matches = line.match(parseerrorRegex); if (matches) { - if (matches[3] === "") { - return "<source>:" + matches[1] + "," + matches[2] + ": error: " + matches[4]; + if (matches[3] === '') { + return '<source>:' + matches[1] + ',' + matches[2] + ': error: ' + matches[4]; } else { - return "<source>:" + matches[1] + "," + matches[2] + ": error: (" + matches[3] + ") " + matches[4]; + return '<source>:' + matches[1] + ',' + matches[2] + ': error: (' + matches[3] + ') ' + matches[4]; } } return line; - }).join("\n"); + }).join('\n'); } async runCompiler(compiler, options, inputFilename, execOptions) { @@ -78,7 +78,7 @@ class CleanCompiler extends BaseCompiler { const compilerPath = path.dirname(compiler); execOptions = this.getDefaultExecOptions(); execOptions.customCwd = tmpDir; - execOptions.env.CLEANLIB = path.join(compilerPath, "../exe"); + execOptions.env.CLEANLIB = path.join(compilerPath, '../exe'); execOptions.env.CLEANPATH = this.compiler.libPath; options.pop(); options.push(moduleName); @@ -88,8 +88,8 @@ class CleanCompiler extends BaseCompiler { result.stdout = utils.parseOutput(this.preprocessOutput(result.stdout), inputFilename); result.stderr = utils.parseOutput(this.preprocessOutput(result.stderr), inputFilename); - if (!options.includes("-S")) { - const aOut = path.join(tmpDir, "a.out"); + if (!options.includes('-S')) { + const aOut = path.join(tmpDir, 'a.out'); if (await fs.pathExists(aOut)) { await fs.copyFile(aOut, this.getOutputFilename(tmpDir)); result.code = 0; diff --git a/lib/compilers/dmd.js b/lib/compilers/dmd.js index 89a8d753d..562108bfe 100644 --- a/lib/compilers/dmd.js +++ b/lib/compilers/dmd.js @@ -23,7 +23,7 @@ // POSSIBILITY OF SUCH DAMAGE. const BaseCompiler = require('../base-compiler'), - argumentParsers = require("./argument-parsers"), + argumentParsers = require('./argument-parsers'), path = require('path'); class DMDCompiler extends BaseCompiler { @@ -45,7 +45,7 @@ class DMDCompiler extends BaseCompiler { const lPath = path.basename(outputFilename); return this.handlePostProcessResult( result, - await this.exec(postProcesses[0], ["-l", lPath], {customCwd: dirPath, maxOutput: maxSize})); + await this.exec(postProcesses[0], ['-l', lPath], {customCwd: dirPath, maxOutput: maxSize})); } getOutputFilename(dirPath, outputFilebase) { @@ -53,16 +53,16 @@ class DMDCompiler extends BaseCompiler { } buildExecutable(compiler, options, inputFilename, execOptions) { - options = options.filter((param) => param !== "-c"); + options = options.filter((param) => param !== '-c'); return this.runCompiler(compiler, options, inputFilename, execOptions); } async objdump(outputFilename, result, maxSize, intelAsm, demangle) { const dirPath = path.dirname(outputFilename); - let args = ["-d", outputFilename, "-l", "--insn-width=16"]; - if (demangle) args = args.concat("-C"); - if (intelAsm) args = args.concat(["-M", "intel"]); + let args = ['-d', outputFilename, '-l', '--insn-width=16']; + if (demangle) args = args.concat('-C'); + if (intelAsm) args = args.concat(['-M', 'intel']); const objResult = await this.exec( this.compiler.objdumper, args, {maxOutput: maxSize, customCwd: dirPath}); result.asm = objResult.stdout; @@ -77,7 +77,7 @@ class DMDCompiler extends BaseCompiler { } filterUserOptions(userOptions) { - return userOptions.filter(option => option !== '-run' && option !== '-man' && !option.startsWith("-Xf")); + return userOptions.filter(option => option !== '-run' && option !== '-man' && !option.startsWith('-Xf')); } } diff --git a/lib/compilers/ellcc.js b/lib/compilers/ellcc.js index 2d025e253..7d74a1eca 100644 --- a/lib/compilers/ellcc.js +++ b/lib/compilers/ellcc.js @@ -26,7 +26,7 @@ const class EllccCompiler extends ClangCompiler { getSharedLibraryPathsAsArguments() { - const pathFlag = this.compiler.rpathFlag || "-Wl,-rpath,"; + const pathFlag = this.compiler.rpathFlag || '-Wl,-rpath,'; return this.compiler.ldPath.map(path => pathFlag + path); } diff --git a/lib/compilers/ewavr.js b/lib/compilers/ewavr.js index 025e0141b..93ed9b1bb 100644 --- a/lib/compilers/ewavr.js +++ b/lib/compilers/ewavr.js @@ -22,11 +22,11 @@ // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. -"use strict"; +'use strict'; const BaseCompiler = require('../base-compiler'), temp = require('temp'), - AsmEWAVRParser = require('../asm-parser-ewavr.js'); + AsmEWAVRParser = require('../asm-parser-ewavr'); class EWAVRCompiler extends BaseCompiler { constructor(info, env) { @@ -54,7 +54,7 @@ class EWAVRCompiler extends BaseCompiler { return [ '-lB', this.filename(outputFilename), - '-o', this.filename(outputFilename + '.obj') + '-o', this.filename(outputFilename + '.obj'), ]; } } diff --git a/lib/compilers/fake-for-test.js b/lib/compilers/fake-for-test.js index c5d456fbf..ff0c43a7d 100644 --- a/lib/compilers/fake-for-test.js +++ b/lib/compilers/fake-for-test.js @@ -29,7 +29,7 @@ class FakeCompiler { this.compiler = { id: info.id || 'fake-for-test', lang: info.lang || 'fake-lang', - options: info.options || '' + options: info.options || '', }; this.info = info; } @@ -52,8 +52,8 @@ class FakeCompiler { source: source, options: options, backendOptions: backendOptions, - filters: filters - } + filters: filters, + }, })); } diff --git a/lib/compilers/golang.js b/lib/compilers/golang.js index ea9bb6fc5..2f7bc85b7 100644 --- a/lib/compilers/golang.js +++ b/lib/compilers/golang.js @@ -23,7 +23,7 @@ // POSSIBILITY OF SUCH DAMAGE. const BaseCompiler = require('../base-compiler'), - argumentParsers = require("./argument-parsers"), + argumentParsers = require('./argument-parsers'), _ = require('underscore'), utils = require('../utils'); @@ -39,13 +39,13 @@ const jumpPrefixes = [ // s390x 'cmpb', - 'cmpub' + 'cmpub', ]; class GolangCompiler extends BaseCompiler { convertNewGoL(code) { - const re = /^\s+(0[xX]?[0-9A-Za-z]+)?\s?([0-9]+)\s*\(([^:]+):([0-9]+)\)\s*([A-Z]+)(.*)/; - const reUnknown = /^\s+(0[xX]?[0-9A-Za-z]+)?\s?([0-9]+)\s*\(<unknown line number>\)\s*([A-Z]+)(.*)/; + const re = /^\s+(0[Xx]?[\dA-Za-z]+)?\s?(\d+)\s*\(([^:]+):(\d+)\)\s*([A-Z]+)(.*)/; + const reUnknown = /^\s+(0[Xx]?[\dA-Za-z]+)?\s?(\d+)\s*\(<unknown line number>\)\s*([A-Z]+)(.*)/; const reFunc = /TEXT\s+[".]*(\S+)\(SB\)/; let prevLine = null; let file = null; @@ -83,7 +83,7 @@ class GolangCompiler extends BaseCompiler { match = line.match(reFunc); if (match) { // Normalize function name. - func = match[1].replace(/[.()*]+/g, "_"); + func = match[1].replace(/[()*.]+/g, '_'); // It's possible for normalized function names to collide. // Keep a count of collisions per function name. Labels get @@ -139,12 +139,12 @@ class GolangCompiler extends BaseCompiler { .compact() .filter(line => !unusedLabels[line]) .value() - .join("\n"); + .join('\n'); } replaceJump(func, collisions, ins, args, usedLabels) { // Check if last argument is a decimal number. - const re = /(\s+)([0-9]+)(\s?)$/; + const re = /(\s+)(\d+)(\s?)$/; const match = args.match(re); if (!match) { return args; @@ -156,7 +156,7 @@ class GolangCompiler extends BaseCompiler { if (collisions > 0) { label += `_${collisions}`; } - usedLabels[label + ":"] = true; // record label use for later filtering + usedLabels[label + ':'] = true; // record label use for later filtering return `${match[1]}${label}${match[3]}`; } @@ -180,7 +180,7 @@ class GolangCompiler extends BaseCompiler { result.asm = this.convertNewGoL(out); result.stderr = null; result.stdout = utils.parseOutput(logging, result.inputFilename); - return [result, ""]; + return [result, '']; } optionsForFilter(filters, outputFilename, userOptions) { diff --git a/lib/compilers/haskell.js b/lib/compilers/haskell.js index 63394b3e7..bc0522ec8 100644 --- a/lib/compilers/haskell.js +++ b/lib/compilers/haskell.js @@ -23,7 +23,7 @@ // POSSIBILITY OF SUCH DAMAGE. const BaseCompiler = require('../base-compiler'), - argumentParsers = require("./argument-parsers"); + argumentParsers = require('./argument-parsers'); class HaskellCompiler extends BaseCompiler { optionsForFilter(filters, outputFilename) { diff --git a/lib/compilers/ispc.js b/lib/compilers/ispc.js index d59361b23..92ec9f71c 100644 --- a/lib/compilers/ispc.js +++ b/lib/compilers/ispc.js @@ -23,13 +23,13 @@ // POSSIBILITY OF SUCH DAMAGE. const BaseCompiler = require('../base-compiler'), - argumentParsers = require("./argument-parsers"); + argumentParsers = require('./argument-parsers'); class ISPCCompiler extends BaseCompiler { optionsForFilter(filters, outputFilename) { let options = ['--target=avx2-i32x8', '--emit-asm', '-g', '-o', this.filename(outputFilename)]; if (this.compiler.intelAsm && filters.intel && !filters.binary) { - options = options.concat(this.compiler.intelAsm.split(" ")); + options = options.concat(this.compiler.intelAsm.split(' ')); } return options; } diff --git a/lib/compilers/java.js b/lib/compilers/java.js index 18e89947f..fc45a2975 100644 --- a/lib/compilers/java.js +++ b/lib/compilers/java.js @@ -23,9 +23,9 @@ // POSSIBILITY OF SUCH DAMAGE. const BaseCompiler = require('../base-compiler'), - argumentParsers = require("./argument-parsers"), + argumentParsers = require('./argument-parsers'), fs = require('fs-extra'), - utils = require('../utils.js'), + utils = require('../utils'), path = require('path'), logger = require('../logger').logger; @@ -46,7 +46,7 @@ class JavaCompiler extends BaseCompiler { async objdump(outputFilename, result, maxSize) { const dirPath = path.dirname(outputFilename); const files = await fs.readdir(dirPath); - logger.verbose("Class files: ", files); + logger.verbose('Class files: ', files); const results = await Promise.all(files.filter(f => f.endsWith('.class')).map(async classFile => { const args = [ // Prints out disassembled code, i.e., the instructions that comprise the Java bytecodes, @@ -54,13 +54,15 @@ class JavaCompiler extends BaseCompiler { '-c', // Prints out line and local variable tables. '-l', - classFile + classFile, ]; const objResult = await this.exec(this.compiler.objdumper, args, {maxOutput: maxSize, customCwd: dirPath}); - const oneResult = {}; - oneResult.asm = objResult.stdout; + const oneResult = { + asm: objResult.stdout, + }; + if (objResult.code !== 0) { - oneResult.asm = "<No output: javap returned " + objResult.code + ">"; + oneResult.asm = '<No output: javap returned ' + objResult.code + '>'; } return oneResult; })); @@ -82,7 +84,7 @@ class JavaCompiler extends BaseCompiler { filters.binary = true; return [ - '-Xlint:all' + '-Xlint:all', ]; } @@ -99,24 +101,24 @@ class JavaCompiler extends BaseCompiler { const filteredOptions = []; let toSkip = 0; - const oneArgForbiddenList = [ + const oneArgForbiddenList = new Set([ // -d directory // Sets the destination directory for class files. - "-d", + '-d', // -s directory // Specifies the directory used to place the generated source files. - "-s", + '-s', // --source-path path or -sourcepath path // Specifies where to find input source files. - "--source-path", "-sourcepath" - ]; + '--source-path', '-sourcepath', + ]); for (const userOption of userOptions) { if (toSkip > 0) { toSkip--; continue; } - if (oneArgForbiddenList.indexOf(userOption) !== -1) { + if (oneArgForbiddenList.has(userOption)) { toSkip = 1; continue; } @@ -129,7 +131,7 @@ class JavaCompiler extends BaseCompiler { processAsm(result) { // Handle "error" documents. - if (result.asm.indexOf("\n") === -1 && result.asm[0] === '<') { + if (!result.asm.includes('\n') && result.asm[0] === '<') { return [{text: result.asm, source: null}]; } @@ -142,8 +144,8 @@ class JavaCompiler extends BaseCompiler { parseds.forEach((parsed, classNumber) => { if (classNumber > 0) { // Separate classes with two line breaks - segments.push({text: "", source: null}); - segments.push({text: "", source: null}); + segments.push({text: '', source: null}); + segments.push({text: '', source: null}); } for (let i = 0; i < parsed.textsBeforeMethod.length; i++) { // Line-based highlighting doesn't work if some segments span multiple lines, @@ -151,12 +153,12 @@ class JavaCompiler extends BaseCompiler { // -> split the lines and create segment for each separately for (const line of utils.splitLines(parsed.textsBeforeMethod[i])) { // javap output always starts with "Compiled from" on first line, discard these lines. - if (line.startsWith("Compiled from")) { + if (line.startsWith('Compiled from')) { continue; } segments.push({ text: line, - source: null + source: null, }); } @@ -186,7 +188,7 @@ class JavaCompiler extends BaseCompiler { for (const codeAndLineNumberTable of codeAndLineNumberTables) { const method = { - instructions: [] + instructions: [], }; methods.push(method); @@ -201,7 +203,7 @@ class JavaCompiler extends BaseCompiler { instrOffset: instrOffset, // Should an instruction ever not be followed by a line number table, // it might contain a trailing \r on Windows -> trim it, otherwise this would not be necessary - text: codeLineCandidate.trimRight() + text: codeLineCandidate.trimEnd(), }); } else { break; @@ -221,7 +223,7 @@ class JavaCompiler extends BaseCompiler { // therefore, cache value here on match lastIndex = lineRegex.lastIndex; const [, sourceLineS, instructionS] = m; - logger.verbose("Found source mapping: ", sourceLineS, "to instruction", instructionS); + logger.verbose('Found source mapping: ', sourceLineS, 'to instruction', instructionS); const instrOffset = Number.parseInt(instructionS); // Some instructions don't receive an explicit line number. @@ -234,7 +236,7 @@ class JavaCompiler extends BaseCompiler { // instructions without explicit line number get assigned the last explicit/same line number method.instructions[currentInstr].sourceLine = currentSourceLine; } else { - logger.error("Skipping over instruction even though currentSourceLine == -1"); + logger.error('Skipping over instruction even though currentSourceLine == -1'); } currentInstr++; } @@ -243,7 +245,7 @@ class JavaCompiler extends BaseCompiler { currentSourceLine = sourceLine; method.instructions[currentInstr].sourceLine = currentSourceLine; - if (typeof method.startLine === "undefined") { + if (typeof method.startLine === 'undefined') { method.startLine = sourceLine; } // method.instructions.push({sourceLine: instrOffset}); @@ -252,7 +254,7 @@ class JavaCompiler extends BaseCompiler { if (lastIndex !== -1) { // Get "interesting" text after the LineNumbers table (header of next method/tail of file) // trimRight() because of trailing \r on Windows - textsBeforeMethod.push(codeAndLineNumberTable.substr(lastIndex).trimRight()); + textsBeforeMethod.push(codeAndLineNumberTable.substr(lastIndex).trimEnd()); } if (currentSourceLine !== -1) { @@ -267,7 +269,7 @@ class JavaCompiler extends BaseCompiler { // Used for sorting firstSourceLine: methods.reduce((p, m) => p === -1 ? m.startLine : Math.min(p, m.startLine), -1), methods: methods, - textsBeforeMethod + textsBeforeMethod, }; } } diff --git a/lib/compilers/ldc.js b/lib/compilers/ldc.js index 65dcd587a..eab2d235a 100644 --- a/lib/compilers/ldc.js +++ b/lib/compilers/ldc.js @@ -23,7 +23,7 @@ // POSSIBILITY OF SUCH DAMAGE. const BaseCompiler = require('../base-compiler'), - argumentParsers = require("./argument-parsers"), + argumentParsers = require('./argument-parsers'), fs = require('fs-extra'), logger = require('./../logger').logger, path = require('path'), @@ -63,12 +63,12 @@ class LDCCompiler extends BaseCompiler { couldSupportASTDump(version) { const versionRegex = /\((\d\.\d+)\.\d+/; const versionMatch = versionRegex.exec(version); - return versionMatch ? semverParser.compare(versionMatch[1] + ".0", "1.4.0") >= 0 : false; + return versionMatch ? semverParser.compare(versionMatch[1] + '.0', '1.4.0') >= 0 : false; } async generateAST(inputFilename, options) { // These options make LDC produce an AST dump in a separate file `<inputFilename>.cg`. - const newOptions = options.concat("-vcg-ast"); + const newOptions = options.concat('-vcg-ast'); const execOptions = this.getDefaultExecOptions(); return this.loadASTOutput( await this.runCompiler(this.compiler.exe, newOptions, this.filename(inputFilename), execOptions)); @@ -80,13 +80,13 @@ class LDCCompiler extends BaseCompiler { } // Load the AST output from the `.cg` file. // Demangling is not needed. - const astFilename = output.inputFilename.concat(".cg"); + const astFilename = output.inputFilename.concat('.cg'); try { return await fs.readFile(astFilename, 'utf-8'); } catch (e) { if (e instanceof Error && e.code === 'ENOENT') { logger.warn(`LDC AST file ${astFilename} requested but it does not exist`); - return ""; + return ''; } throw e; } diff --git a/lib/compilers/llc.js b/lib/compilers/llc.js index 2f84066bc..a57d06196 100644 --- a/lib/compilers/llc.js +++ b/lib/compilers/llc.js @@ -23,7 +23,7 @@ // POSSIBILITY OF SUCH DAMAGE. const BaseCompiler = require('../base-compiler'), - argumentParsers = require("./argument-parsers"); + argumentParsers = require('./argument-parsers'); class LLCCompiler extends BaseCompiler { constructor(info, env) { diff --git a/lib/compilers/llvm-mca.js b/lib/compilers/llvm-mca.js index fc8e84b4c..eb885e21a 100644 --- a/lib/compilers/llvm-mca.js +++ b/lib/compilers/llvm-mca.js @@ -23,7 +23,7 @@ // POSSIBILITY OF SUCH DAMAGE. const AnalysisTool = require('./analysis-tool'), - argumentParsers = require("./argument-parsers"); + argumentParsers = require('./argument-parsers'); // Plain compiler, which just runs the tool and returns whatever the output was class LLVMmcaTool extends AnalysisTool { diff --git a/lib/compilers/nim.js b/lib/compilers/nim.js index de920d9d7..26a7ff482 100644 --- a/lib/compilers/nim.js +++ b/lib/compilers/nim.js @@ -25,15 +25,15 @@ const BaseCompiler = require('../base-compiler'), _ = require('underscore'), path = require('path'), - argumentParsers = require("./argument-parsers"), + argumentParsers = require('./argument-parsers'), fs = require('fs-extra'); const NimCommands = [ - "compile", "compileToC", "c", - "compileToCpp", "cpp", "cc", - "compileToOC", "objc", - "js", - "check" + 'compile', 'compileToC', 'c', + 'compileToCpp', 'cpp', 'cc', + 'compileToOC', 'objc', + 'js', + 'check', ]; class NimCompiler extends BaseCompiler { @@ -48,25 +48,25 @@ class NimCompiler extends BaseCompiler { optionsForFilter(filters, outputFilename) { return [ - "-o:" + outputFilename, //output file, only for js mode - "--nolinking", //disable linking, only compile to nimcache - "--nimcache:" + this.cacheDir(outputFilename) //output folder for the nimcache + '-o:' + outputFilename, //output file, only for js mode + '--nolinking', //disable linking, only compile to nimcache + '--nimcache:' + this.cacheDir(outputFilename), //output folder for the nimcache ]; } filterUserOptions(userOptions) { //If none of the allowed commands is present in userOptions add 'compile' command if (_.intersection(userOptions, NimCommands).length === 0) { - userOptions.unshift("compile"); + userOptions.unshift('compile'); } return userOptions.filter(option => !['--run', '-r'].includes(option)); } expectedExtensionFromCommand(command) { - const isC = ["compile", "compileToC", "c"], - isCpp = ["compileToCpp", "cpp", "cc"], - isObjC = ["compileToOC", "objc"]; + const isC = ['compile', 'compileToC', 'c'], + isCpp = ['compileToCpp', 'cpp', 'cc'], + isObjC = ['compileToOC', 'objc']; if (isC.includes(command)) return '.c.o'; @@ -80,7 +80,7 @@ class NimCompiler extends BaseCompiler { getCacheFile(options, inputFilename, cacheDir) { const commandsInOptions = _.intersection(options, NimCommands); - if (!commandsInOptions.length) + if (commandsInOptions.length === 0) return null; const command = commandsInOptions[0]; const extension = this.expectedExtensionFromCommand(command); @@ -95,7 +95,7 @@ class NimCompiler extends BaseCompiler { const options = result.compilationOptions; const cacheDir = this.cacheDir(outputFilename); try { - if (_.intersection(options, ["js", "check"]).length) + if (_.intersection(options, ['js', 'check']).length > 0) filters.binary = false; else { filters.binary = true; diff --git a/lib/compilers/nvcc.js b/lib/compilers/nvcc.js index 7aed5a4c6..6f337cfd8 100644 --- a/lib/compilers/nvcc.js +++ b/lib/compilers/nvcc.js @@ -24,13 +24,13 @@ const BaseCompiler = require('../base-compiler'), path = require('path'), - argumentParsers = require("./argument-parsers"); + argumentParsers = require('./argument-parsers'); class NvccCompiler extends BaseCompiler { constructor(info, env) { super(info, env); // These are for parsing the output of nvdisasm. - this.asm.asmOpcodeRe = /^\s*\/\*([^*]+)\*\/()()\s*{?\s*([^};]+)(?:}|;\s*\/\* 0x([0-9a-f]+) \*\/)$/; + this.asm.asmOpcodeRe = /^\s*\/\*([^*]+)\*\/()()\s*{?\s*([^;}]+)(?:}|;\s*\/\* 0x([\da-f]+) \*\/)$/; this.asm.lineRe = /^\s*\/\/## File "([^"]+)", line (\d+)$/; this.asm.labelRe = /^(?!\.text\.)()(\S[^:]+):$/; } @@ -51,7 +51,7 @@ class NvccCompiler extends BaseCompiler { async objdump(outputFilename, result, maxSize) { // For nvdisasm. - const args = [outputFilename, "-c", "-g", "-hex"]; + const args = [outputFilename, '-c', '-g', '-hex']; const execOptions = {maxOutput: maxSize, customCwd: path.dirname(outputFilename)}; const objResult = await this.exec(this.compiler.objdumper, args, execOptions); diff --git a/lib/compilers/ocaml.js b/lib/compilers/ocaml.js index 9c1f12555..d5fe2cfa7 100644 --- a/lib/compilers/ocaml.js +++ b/lib/compilers/ocaml.js @@ -22,10 +22,10 @@ // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. -"use strict"; +'use strict'; const BaseCompiler = require('../base-compiler'), - path = require("path"); + path = require('path'); class OCamlCompiler extends BaseCompiler { optionsForFilter() { diff --git a/lib/compilers/opt.js b/lib/compilers/opt.js index 7a833bad6..406a81f78 100644 --- a/lib/compilers/opt.js +++ b/lib/compilers/opt.js @@ -23,13 +23,9 @@ // POSSIBILITY OF SUCH DAMAGE. const BaseCompiler = require('../base-compiler'), - argumentParsers = require("./argument-parsers"); + argumentParsers = require('./argument-parsers'); class OptCompiler extends BaseCompiler { - constructor(info, env) { - super(info, env); - } - optionsForFilter(filters, outputFilename) { return ['-o', this.filename(outputFilename), '-S']; } diff --git a/lib/compilers/pascal.js b/lib/compilers/pascal.js index 8f82fb824..424a6381f 100644 --- a/lib/compilers/pascal.js +++ b/lib/compilers/pascal.js @@ -21,14 +21,14 @@ // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. -"use strict"; +'use strict'; const BaseCompiler = require('../base-compiler'), utils = require('../utils'), _ = require('underscore'), - fs = require("fs-extra"), - path = require("path"), - argumentParsers = require("./argument-parsers"); + fs = require('fs-extra'), + path = require('path'), + argumentParsers = require('./argument-parsers'); class FPCCompiler extends BaseCompiler { constructor(info, env) { @@ -66,7 +66,7 @@ class FPCCompiler extends BaseCompiler { let options = ['-g', '-al']; if (this.compiler.intelAsm && filters.intel && !filters.binary) { - options = options.concat(this.compiler.intelAsm.split(" ")); + options = options.concat(this.compiler.intelAsm.split(' ')); } filters.preProcessLines = _.bind(this.preProcessLines, this); @@ -79,20 +79,20 @@ class FPCCompiler extends BaseCompiler { } getExecutableFilename(dirPath) { - return path.join(dirPath, "prog"); + return path.join(dirPath, 'prog'); } static preProcessBinaryAsm(input) { - const relevantAsmStartsAt = input.indexOf("<OUTPUT"); + const relevantAsmStartsAt = input.indexOf('<OUTPUT'); if (relevantAsmStartsAt !== -1) { - const lastLinefeedBeforeStart = input.lastIndexOf("\n", relevantAsmStartsAt); + const lastLinefeedBeforeStart = input.lastIndexOf('\n', relevantAsmStartsAt); if (lastLinefeedBeforeStart !== -1) { input = - input.substr(0, input.indexOf("00000000004")) + "\n" + + input.substr(0, input.indexOf('00000000004')) + '\n' + input.substr(lastLinefeedBeforeStart + 1); } else { input = - input.substr(0, input.indexOf("00000000004")) + "\n" + + input.substr(0, input.indexOf('00000000004')) + '\n' + input.substr(relevantAsmStartsAt); } } @@ -102,13 +102,13 @@ class FPCCompiler extends BaseCompiler { async objdump(outputFilename, result, maxSize, intelAsm, demangle) { const dirPath = path.dirname(outputFilename); outputFilename = this.getExecutableFilename(dirPath); - let args = ["-d", outputFilename, "-l", "--insn-width=16"]; - if (demangle) args = args.concat(["-C"]); - if (intelAsm) args = args.concat(["-M", "intel"]); + let args = ['-d', outputFilename, '-l', '--insn-width=16']; + if (demangle) args = args.concat(['-C']); + if (intelAsm) args = args.concat(['-M', 'intel']); const objResult = await this.exec( this.compiler.objdumper, args, {maxOutput: maxSize, customCwd: dirPath}); if (objResult.code !== 0) { - result.asm = "<No output: objdump returned " + objResult.code + ">"; + result.asm = '<No output: objdump returned ' + objResult.code + '>'; } else { result.asm = FPCCompiler.preProcessBinaryAsm(objResult.stdout); } @@ -119,10 +119,10 @@ class FPCCompiler extends BaseCompiler { const unitName = path.basename(this.compileFilename, this.lang.extensions[0]); await fs.writeFile(filename, - "program prog; " + - "uses " + unitName + " in '" + this.compileFilename + "'; " + - "begin " + - "end."); + 'program prog; ' + + 'uses ' + unitName + " in '" + this.compileFilename + "'; " + + 'begin ' + + 'end.'); } async runCompiler(compiler, options, inputFilename, execOptions) { @@ -131,7 +131,7 @@ class FPCCompiler extends BaseCompiler { } const dirPath = path.dirname(inputFilename); - const projectFile = path.join(dirPath, "prog.dpr"); + const projectFile = path.join(dirPath, 'prog.dpr'); execOptions.customCwd = dirPath; await this.saveDummyProjectFile(projectFile); @@ -163,23 +163,23 @@ class FPCCompiler extends BaseCompiler { } getExtraAsmHint(asm) { - if (asm.startsWith("# [")) { - const bracketEndPos = asm.indexOf("]", 3); + if (asm.startsWith('# [')) { + const bracketEndPos = asm.indexOf(']', 3); let valueInBrackets = asm.substr(3, bracketEndPos - 3); - const colonPos = valueInBrackets.indexOf(":"); + const colonPos = valueInBrackets.indexOf(':'); if (colonPos !== -1) { valueInBrackets = valueInBrackets.substr(0, colonPos - 1); } if (!isNaN(valueInBrackets)) { - return " .loc 1 " + valueInBrackets + " 0"; + return ' .loc 1 ' + valueInBrackets + ' 0'; } else if (valueInBrackets.includes(this.compileFilename)) { - return " .file 1 \"<stdin>\""; + return ' .file 1 "<stdin>"'; } else { return false; } - } else if (asm.startsWith(".Le")) { - return " .cfi_endproc"; + } else if (asm.startsWith('.Le')) { + return ' .cfi_endproc'; } else { return false; } diff --git a/lib/compilers/ppci.js b/lib/compilers/ppci.js index 0ad446071..cd23c9121 100644 --- a/lib/compilers/ppci.js +++ b/lib/compilers/ppci.js @@ -26,18 +26,18 @@ const BaseCompiler = require('../base-compiler'), exec = require('../exec'), logger = require('../logger').logger; -const forbiddenOptions = [ +const forbiddenOptions = new Set([ '--report', '--text-report', - '--html-report' -]; + '--html-report', +]); class PPCICompiler extends BaseCompiler { filterUserOptions(args) { return args.filter((item) => { - if (typeof item !== "string") return true; + if (typeof item !== 'string') return true; - return !forbiddenOptions.includes(item.toLowerCase()); + return !forbiddenOptions.has(item.toLowerCase()); }); } diff --git a/lib/compilers/python.js b/lib/compilers/python.js index 09f1053f6..a35b34b5e 100644 --- a/lib/compilers/python.js +++ b/lib/compilers/python.js @@ -23,7 +23,7 @@ // POSSIBILITY OF SUCH DAMAGE. const BaseCompiler = require('../base-compiler'), - argumentParsers = require("./argument-parsers"), + argumentParsers = require('./argument-parsers'), path = require('path'); class PythonCompiler extends BaseCompiler { @@ -36,9 +36,9 @@ class PythonCompiler extends BaseCompiler { // eslint-disable-next-line no-unused-vars processAsm(result, filters) { - const lineRe = /^\s{0,4}([0-9]+)(.*)/; + const lineRe = /^\s{0,4}(\d+)(.*)/; - const bytecodeLines = result.asm.split("\n"); + const bytecodeLines = result.asm.split('\n'); const bytecodeResult = []; let lastLineNo = null; diff --git a/lib/compilers/rust.js b/lib/compilers/rust.js index 2b073a918..78a06c7b6 100644 --- a/lib/compilers/rust.js +++ b/lib/compilers/rust.js @@ -25,7 +25,7 @@ const BaseCompiler = require('../base-compiler'), _ = require('underscore'), path = require('path'), - argumentParsers = require("./argument-parsers"); + argumentParsers = require('./argument-parsers'); class RustCompiler extends BaseCompiler { constructor(info, env) { @@ -33,7 +33,7 @@ class RustCompiler extends BaseCompiler { this.compiler.supportsIntel = true; this.compiler.supportsIrView = true; this.compiler.irArg = ['--emit', 'llvm-ir']; - this.linker = this.compilerProps("linker"); + this.linker = this.compilerProps('linker'); } getSharedLibraryPathsAsArguments() { @@ -43,7 +43,7 @@ class RustCompiler extends BaseCompiler { optionsForFilter(filters, outputFilename, userOptions) { let options = ['-C', 'debuginfo=1', '-o', this.filename(outputFilename)]; - const userRequestedEmit = _.any(userOptions, opt => opt.indexOf("--emit") > -1); + const userRequestedEmit = _.any(userOptions, opt => opt.includes('--emit')); if (filters.binary) { options = options.concat(['--crate-type', 'bin']); if (this.linker) { diff --git a/lib/compilers/swift.js b/lib/compilers/swift.js index b1c6fb558..cef6c8941 100644 --- a/lib/compilers/swift.js +++ b/lib/compilers/swift.js @@ -23,7 +23,7 @@ // POSSIBILITY OF SUCH DAMAGE. const BaseCompiler = require('../base-compiler'), - argumentParsers = require("./argument-parsers"); + argumentParsers = require('./argument-parsers'); class SwiftCompiler extends BaseCompiler { getSharedLibraryPathsAsArguments() { diff --git a/lib/compilers/win32-vc.js b/lib/compilers/win32-vc.js index 1a109445f..932d0fdeb 100644 --- a/lib/compilers/win32-vc.js +++ b/lib/compilers/win32-vc.js @@ -23,8 +23,8 @@ // POSSIBILITY OF SUCH DAMAGE. const Win32Compiler = require('./win32'), - argumentParsers = require("./argument-parsers"), - AsmParser = require('../asm-parser-vc.js'); + argumentParsers = require('./argument-parsers'), + AsmParser = require('../asm-parser-vc'); class Win32VcCompiler extends Win32Compiler { constructor(info, env) { diff --git a/lib/compilers/win32.js b/lib/compilers/win32.js index 5b9616cec..6d4e9f97a 100644 --- a/lib/compilers/win32.js +++ b/lib/compilers/win32.js @@ -22,13 +22,13 @@ // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. -"use strict"; +'use strict'; const BaseCompiler = require('../base-compiler'), temp = require('temp'), path = require('path'), _ = require('underscore'), - PELabelReconstructor = require("../pe32-support").labelReconstructor; + PELabelReconstructor = require('../pe32-support').labelReconstructor; class Win32Compiler extends BaseCompiler { newTempDir() { @@ -43,18 +43,18 @@ class Win32Compiler extends BaseCompiler { } getExecutableFilename(dirPath, outputFilebase) { - return this.getOutputFilename(dirPath, outputFilebase) + ".exe"; + return this.getOutputFilename(dirPath, outputFilebase) + '.exe'; } async objdump(outputFilename, result, maxSize, intelAsm) { const dirPath = path.dirname(outputFilename); - outputFilename = this.getExecutableFilename(path.dirname(outputFilename), "output"); + outputFilename = this.getExecutableFilename(path.dirname(outputFilename), 'output'); - let args = ["-d", outputFilename]; - if (intelAsm) args = args.concat(["-M", "intel"]); + let args = ['-d', outputFilename]; + if (intelAsm) args = args.concat(['-M', 'intel']); const objResult = await this.exec(this.compiler.objdumper, args, {maxOutput: 0, customCwd: dirPath}); if (objResult.code !== 0) { - result.asm = "<No output: objdump returned " + objResult.code + ">"; + result.asm = '<No output: objdump returned ' + objResult.code + '>'; } else { result.asm = objResult.stdout; } @@ -63,7 +63,7 @@ class Win32Compiler extends BaseCompiler { } getSharedLibraryPathsAsArguments(libraries) { - const libPathFlag = this.compiler.libpathFlag || "/LIBPATH:"; + const libPathFlag = this.compiler.libpathFlag || '/LIBPATH:'; return this.getSharedLibraryPaths(libraries).map(path => libPathFlag + path); } @@ -94,7 +94,7 @@ class Win32Compiler extends BaseCompiler { backendOptions = backendOptions || {}; if (this.compiler.options) { - options = options.concat(this.compiler.options.split(" ")); + options = options.concat(this.compiler.options.split(' ')); } if (this.compiler.supportsOptOutput && backendOptions.produceOptInfo) { @@ -108,7 +108,7 @@ class Win32Compiler extends BaseCompiler { let staticlibLinks = []; if (filters.binary) { - preLink = ["/link"]; + preLink = ['/link']; libLinks = this.getSharedLibraryLinks(libraries); libPaths = this.getSharedLibraryPathsAsArguments(libraries); staticlibLinks = this.getStaticLibraryLinks(libraries); @@ -124,8 +124,8 @@ class Win32Compiler extends BaseCompiler { const mapFilename = outputFilename + '.map'; filters.preProcessBinaryAsmLines = (asmLines) => { - const reconstructor = new PELabelReconstructor(asmLines, mapFilename, false, "vs"); - reconstructor.run("output.s.obj"); + const reconstructor = new PELabelReconstructor(asmLines, mapFilename, false, 'vs'); + reconstructor.run('output.s.obj'); return reconstructor.asmLines; }; @@ -133,10 +133,10 @@ class Win32Compiler extends BaseCompiler { return [ '/nologo', '/FA', - '/Fa' + this.filename(outputFilename.replace(/\.exe$/, "")), - '/Fo' + this.filename(outputFilename.replace(/\.exe$/, "") + '.obj'), + '/Fa' + this.filename(outputFilename.replace(/\.exe$/, '')), + '/Fo' + this.filename(outputFilename.replace(/\.exe$/, '') + '.obj'), '/Fm' + this.filename(mapFilename), - '/Fe' + this.filename(this.getExecutableFilename(path.dirname(outputFilename), "output")) + '/Fe' + this.filename(this.getExecutableFilename(path.dirname(outputFilename), 'output')), ]; } else { return [ @@ -144,7 +144,7 @@ class Win32Compiler extends BaseCompiler { '/FA', '/c', '/Fa' + this.filename(outputFilename), - '/Fo' + this.filename(outputFilename + '.obj') + '/Fo' + this.filename(outputFilename + '.obj'), ]; } } diff --git a/lib/compilers/wine-vc.js b/lib/compilers/wine-vc.js index c8a50bf03..cd862ee2e 100644 --- a/lib/compilers/wine-vc.js +++ b/lib/compilers/wine-vc.js @@ -24,9 +24,9 @@ const BaseCompiler = require('../base-compiler'), AsmParser = require('../asm-parser-vc'), - argumentParsers = require("./argument-parsers"), + argumentParsers = require('./argument-parsers'), path = require('path'), - PELabelReconstructor = require("../pe32-support").labelReconstructor; + PELabelReconstructor = require('../pe32-support').labelReconstructor; class WineVcCompiler extends BaseCompiler { constructor(info, env) { @@ -54,18 +54,18 @@ class WineVcCompiler extends BaseCompiler { } getExecutableFilename(dirPath, outputFilebase) { - return this.getOutputFilename(dirPath, outputFilebase) + ".exe"; + return this.getOutputFilename(dirPath, outputFilebase) + '.exe'; } async objdump(outputFilename, result, maxSize, intelAsm) { const dirPath = path.dirname(outputFilename); - outputFilename = this.getExecutableFilename(dirPath, "output"); + outputFilename = this.getExecutableFilename(dirPath, 'output'); - let args = ["-d", outputFilename]; - if (intelAsm) args = args.concat(["-M", "intel"]); + let args = ['-d', outputFilename]; + if (intelAsm) args = args.concat(['-M', 'intel']); const objResult = await this.exec(this.compiler.objdumper, args, {maxOutput: 0, customCwd: dirPath}); if (objResult.code !== 0) { - result.asm = "<No output: objdump returned " + objResult.code + ">"; + result.asm = '<No output: objdump returned ' + objResult.code + '>'; } else { result.asm = objResult.stdout; } @@ -78,8 +78,8 @@ class WineVcCompiler extends BaseCompiler { const mapFilename = outputFilename + '.map'; filters.preProcessBinaryAsmLines = (asmLines) => { - const reconstructor = new PELabelReconstructor(asmLines, mapFilename, false, "vs"); - reconstructor.run("output.s.obj"); + const reconstructor = new PELabelReconstructor(asmLines, mapFilename, false, 'vs'); + reconstructor.run('output.s.obj'); return reconstructor.asmLines; }; @@ -90,7 +90,7 @@ class WineVcCompiler extends BaseCompiler { '/Fa' + this.filename(outputFilename), '/Fo' + this.filename(outputFilename + '.obj'), '/Fm' + this.filename(mapFilename), - '/Fe' + this.filename(this.getExecutableFilename(path.dirname(outputFilename), "output")) + '/Fe' + this.filename(this.getExecutableFilename(path.dirname(outputFilename), 'output')), ]; } else { return [ @@ -98,7 +98,7 @@ class WineVcCompiler extends BaseCompiler { '/FA', '/c', '/Fa' + this.filename(outputFilename), - '/Fo' + this.filename(outputFilename + '.obj') + '/Fo' + this.filename(outputFilename + '.obj'), ]; } } diff --git a/lib/compilers/wsl-vc.js b/lib/compilers/wsl-vc.js index f379f89bc..a3cc3060b 100644 --- a/lib/compilers/wsl-vc.js +++ b/lib/compilers/wsl-vc.js @@ -43,7 +43,7 @@ class WslVcCompiler extends Win32VcCompiler { // We know process.env.tmpDir is of format /mnt/X/dir where X is drive letter. const driveLetter = process.env.winTmp.substring(5, 6); const directoryPath = process.env.winTmp.substring(7); - const windowsStyle = driveLetter.concat(":/", directoryPath); + const windowsStyle = driveLetter.concat(':/', directoryPath); return fn.replace(process.env.winTmp, windowsStyle); } @@ -85,7 +85,7 @@ class WslVcCompiler extends Win32VcCompiler { const inputDirectory = path.dirname(inputFilename); const driveLetter = inputDirectory.substring(0, 1).toLowerCase(); const directoryPath = inputDirectory.substring(2).trim(); - execOptions.customCwd = path.join("/mnt", driveLetter, directoryPath); + execOptions.customCwd = path.join('/mnt', driveLetter, directoryPath); return super.runCompiler(compiler, options, inputFilename, execOptions); } diff --git a/lib/compilers/zig.js b/lib/compilers/zig.js index f498ba046..bf4b18908 100644 --- a/lib/compilers/zig.js +++ b/lib/compilers/zig.js @@ -77,7 +77,7 @@ class ZigCompiler extends BaseCompiler { } if (!filters.binary) { - let userRequestedEmit = _.any(userOptions, opt => opt.indexOf("--emit") > -1); + let userRequestedEmit = _.any(userOptions, opt => opt.includes('--emit')); if (!userRequestedEmit) { options = options.concat('--emit', 'asm'); } |