aboutsummaryrefslogtreecommitdiff
path: root/lib/compilers/argument-parsers.js
diff options
context:
space:
mode:
authorRubén Rincón Blanco <ruben@rinconblanco.es>2020-08-04 22:39:02 +0200
committerGitHub <noreply@github.com>2020-08-04 16:39:02 -0400
commitccff4b9ee5a37c13f0973b52e8f90a8be8359fea (patch)
tree0022c9364824c5b4e4f5818c4abbf654aa99f2e8 /lib/compilers/argument-parsers.js
parent7126b39a6bdeabffc312c8a117ec7af072ef6a1c (diff)
downloadcompiler-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/argument-parsers.js')
-rw-r--r--lib/compilers/argument-parsers.js105
1 files changed, 53 insertions, 52 deletions
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,
};