Skip to content

Commit 386e9bb

Browse files
Merge pull request #1791 from github/elena/eslint-github
Install `eslint-plugin-github` and apply autofixes where possible
2 parents b273db1 + 168ce8f commit 386e9bb

162 files changed

Lines changed: 2325 additions & 1605 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

extensions/ql-vscode/.eslintrc.js

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,22 @@ module.exports = {
55
sourceType: "module",
66
project: ["tsconfig.json", "./src/**/tsconfig.json", "./gulpfile.ts/tsconfig.json", "./scripts/tsconfig.json", "./.storybook/tsconfig.json"],
77
},
8-
plugins: ["@typescript-eslint"],
8+
plugins: [
9+
"github",
10+
"@typescript-eslint"
11+
],
912
env: {
1013
node: true,
1114
es6: true,
1215
},
1316
extends: [
1417
"eslint:recommended",
15-
"plugin:@typescript-eslint/recommended",
18+
"plugin:github/react",
19+
"plugin:github/recommended",
20+
"plugin:github/typescript",
1621
"plugin:jest-dom/recommended",
17-
"plugin:prettier/recommended"
22+
"plugin:prettier/recommended",
23+
"plugin:@typescript-eslint/recommended"
1824
],
1925
rules: {
2026
"@typescript-eslint/no-use-before-define": 0,
@@ -31,8 +37,36 @@ module.exports = {
3137
"@typescript-eslint/no-non-null-assertion": "off",
3238
"@typescript-eslint/no-explicit-any": "off",
3339
"@typescript-eslint/no-floating-promises": [ "error", { ignoreVoid: true } ],
40+
"@typescript-eslint/no-invalid-this": "off",
41+
"@typescript-eslint/no-shadow": "off",
3442
"prefer-const": ["warn", { destructuring: "all" }],
3543
"@typescript-eslint/no-throw-literal": "error",
3644
"no-useless-escape": 0,
45+
"camelcase": "off",
46+
"eqeqeq": "off",
47+
"escompat/no-regexp-lookbehind": "off",
48+
"filenames/match-regex": "off",
49+
"filenames/match-regexp": "off",
50+
"func-style": "off",
51+
"i18n-text/no-en": "off",
52+
"import/named": "off",
53+
"import/no-dynamic-require": "off",
54+
"import/no-dynamic-required": "off",
55+
"import/no-anonymous-default-export": "off",
56+
"import/no-commonjs": "off",
57+
"import/no-mutable-exports": "off",
58+
"import/no-namespace": "off",
59+
"import/no-unresolved": "off",
60+
"import/no-webpack-loader-syntax": "off",
61+
"jsx-a11y/anchor-is-valid": "off",
62+
"jsx-a11y/no-noninteractive-element-interactions": "off",
63+
"jsx-a11y/no-static-element-interactions": "off",
64+
"jsx-a11y/click-events-have-key-events": "off",
65+
"no-invalid-this": "off",
66+
"no-fallthrough": "off",
67+
"no-console": "off",
68+
"no-shadow": "off",
69+
"github/array-foreach": "off",
70+
"github/no-then": "off",
3771
},
3872
};

extensions/ql-vscode/gulpfile.ts/appInsights.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as gulp from "gulp";
1+
import { src, dest } from "gulp";
22
// eslint-disable-next-line @typescript-eslint/no-var-requires
33
const replace = require("gulp-replace");
44

@@ -13,8 +13,7 @@ export function injectAppInsightsKey() {
1313
}
1414

1515
// replace the key
16-
return gulp
17-
.src(["out/telemetry.js"])
16+
return src(["out/telemetry.js"])
1817
.pipe(replace(/REPLACE-APP-INSIGHTS-KEY/, process.env.APP_INSIGHTS_KEY))
19-
.pipe(gulp.dest("out/"));
18+
.pipe(dest("out/"));
2019
}

extensions/ql-vscode/gulpfile.ts/deploy.ts

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1-
import * as fs from "fs-extra";
2-
import * as path from "path";
1+
import {
2+
copy,
3+
readFile,
4+
mkdirs,
5+
readdir,
6+
unlinkSync,
7+
remove,
8+
writeFile,
9+
} from "fs-extra";
10+
import { resolve, join } from "path";
311

412
export interface DeployedPackage {
513
distPath: string;
@@ -25,12 +33,9 @@ async function copyPackage(
2533
): Promise<void> {
2634
for (const file of packageFiles) {
2735
console.log(
28-
`copying ${path.resolve(sourcePath, file)} to ${path.resolve(
29-
destPath,
30-
file,
31-
)}`,
36+
`copying ${resolve(sourcePath, file)} to ${resolve(destPath, file)}`,
3237
);
33-
await fs.copy(path.resolve(sourcePath, file), path.resolve(destPath, file));
38+
await copy(resolve(sourcePath, file), resolve(destPath, file));
3439
}
3540
}
3641

@@ -39,53 +44,52 @@ export async function deployPackage(
3944
): Promise<DeployedPackage> {
4045
try {
4146
const packageJson: any = JSON.parse(
42-
await fs.readFile(packageJsonPath, "utf8"),
47+
await readFile(packageJsonPath, "utf8"),
4348
);
4449

4550
// Default to development build; use flag --release to indicate release build.
4651
const isDevBuild = !process.argv.includes("--release");
47-
const distDir = path.join(__dirname, "../../../dist");
48-
await fs.mkdirs(distDir);
52+
const distDir = join(__dirname, "../../../dist");
53+
await mkdirs(distDir);
4954

5055
if (isDevBuild) {
5156
// NOTE: rootPackage.name had better not have any regex metacharacters
5257
const oldDevBuildPattern = new RegExp(
53-
"^" + packageJson.name + "[^/]+-dev[0-9.]+\\.vsix$",
58+
`^${packageJson.name}[^/]+-dev[0-9.]+\\.vsix$`,
5459
);
5560
// Dev package filenames are of the form
5661
// vscode-codeql-0.0.1-dev.2019.9.27.19.55.20.vsix
57-
(await fs.readdir(distDir))
62+
(await readdir(distDir))
5863
.filter((name) => name.match(oldDevBuildPattern))
5964
.map((build) => {
6065
console.log(`Deleting old dev build ${build}...`);
61-
fs.unlinkSync(path.join(distDir, build));
66+
unlinkSync(join(distDir, build));
6267
});
6368
const now = new Date();
6469
packageJson.version =
65-
packageJson.version +
66-
`-dev.${now.getUTCFullYear()}.${
70+
`${packageJson.version}-dev.${now.getUTCFullYear()}.${
6771
now.getUTCMonth() + 1
6872
}.${now.getUTCDate()}` +
6973
`.${now.getUTCHours()}.${now.getUTCMinutes()}.${now.getUTCSeconds()}`;
7074
}
7175

72-
const distPath = path.join(distDir, packageJson.name);
73-
await fs.remove(distPath);
74-
await fs.mkdirs(distPath);
76+
const distPath = join(distDir, packageJson.name);
77+
await remove(distPath);
78+
await mkdirs(distPath);
7579

76-
await fs.writeFile(
77-
path.join(distPath, "package.json"),
80+
await writeFile(
81+
join(distPath, "package.json"),
7882
JSON.stringify(packageJson, null, 2),
7983
);
8084

81-
const sourcePath = path.join(__dirname, "..");
85+
const sourcePath = join(__dirname, "..");
8286
console.log(
8387
`Copying package '${packageJson.name}' and its dependencies to '${distPath}'...`,
8488
);
8589
await copyPackage(sourcePath, distPath);
8690

8791
return {
88-
distPath: distPath,
92+
distPath,
8993
name: packageJson.name,
9094
version: packageJson.version,
9195
};

extensions/ql-vscode/gulpfile.ts/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import * as gulp from "gulp";
1+
import { series, parallel } from "gulp";
22
import { compileTypeScript, watchTypeScript, cleanOutput } from "./typescript";
33
import { compileTextMateGrammar } from "./textmate";
44
import { copyTestData, watchTestData } from "./tests";
55
import { compileView, watchView } from "./webpack";
66
import { packageExtension } from "./package";
77
import { injectAppInsightsKey } from "./appInsights";
88

9-
export const buildWithoutPackage = gulp.series(
9+
export const buildWithoutPackage = series(
1010
cleanOutput,
11-
gulp.parallel(
11+
parallel(
1212
compileTypeScript,
1313
compileTextMateGrammar,
1414
compileView,
@@ -27,7 +27,7 @@ export {
2727
injectAppInsightsKey,
2828
compileView,
2929
};
30-
export default gulp.series(
30+
export default series(
3131
buildWithoutPackage,
3232
injectAppInsightsKey,
3333
packageExtension,

extensions/ql-vscode/gulpfile.ts/package.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
import * as path from "path";
1+
import { resolve } from "path";
22
import { deployPackage } from "./deploy";
3-
import * as childProcess from "child-process-promise";
3+
import { spawn } from "child-process-promise";
44

55
export async function packageExtension(): Promise<void> {
6-
const deployedPackage = await deployPackage(path.resolve("package.json"));
6+
const deployedPackage = await deployPackage(resolve("package.json"));
77
console.log(
88
`Packaging extension '${deployedPackage.name}@${deployedPackage.version}'...`,
99
);
1010
const args = [
1111
"package",
1212
"--out",
13-
path.resolve(
13+
resolve(
1414
deployedPackage.distPath,
1515
"..",
1616
`${deployedPackage.name}-${deployedPackage.version}.vsix`,
1717
),
1818
];
19-
const proc = childProcess.spawn("./node_modules/.bin/vsce", args, {
19+
const proc = spawn("./node_modules/.bin/vsce", args, {
2020
cwd: deployedPackage.distPath,
2121
});
2222
proc.childProcess.stdout!.on("data", (data) => {
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
import * as gulp from "gulp";
1+
import { watch, src, dest } from "gulp";
22

33
export function copyTestData() {
44
return Promise.all([copyNoWorkspaceData(), copyCliIntegrationData()]);
55
}
66

77
export function watchTestData() {
8-
return gulp.watch(["src/vscode-tests/*/data/**/*"], copyTestData);
8+
return watch(["src/vscode-tests/*/data/**/*"], copyTestData);
99
}
1010

1111
function copyNoWorkspaceData() {
12-
return gulp
13-
.src("src/vscode-tests/no-workspace/data/**/*")
14-
.pipe(gulp.dest("out/vscode-tests/no-workspace/data"));
12+
return src("src/vscode-tests/no-workspace/data/**/*").pipe(
13+
dest("out/vscode-tests/no-workspace/data"),
14+
);
1515
}
1616

1717
function copyCliIntegrationData() {
18-
return gulp
19-
.src("src/vscode-tests/cli-integration/data/**/*")
20-
.pipe(gulp.dest("out/vscode-tests/cli-integration/data"));
18+
return src("src/vscode-tests/cli-integration/data/**/*").pipe(
19+
dest("out/vscode-tests/cli-integration/data"),
20+
);
2121
}

extensions/ql-vscode/gulpfile.ts/textmate.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import * as gulp from "gulp";
2-
import * as jsYaml from "js-yaml";
3-
import * as through from "through2";
1+
import { src, dest } from "gulp";
2+
import { load } from "js-yaml";
3+
import { obj } from "through2";
44
import * as PluginError from "plugin-error";
55
import * as Vinyl from "vinyl";
66

@@ -61,11 +61,11 @@ function getNodeMatchText(rule: any): string {
6161
for (const patternIndex in rule.patterns) {
6262
const pattern = rule.patterns[patternIndex];
6363
if (pattern.include !== null) {
64-
patterns.push("(?" + pattern.include + ")");
64+
patterns.push(`(?${pattern.include})`);
6565
}
6666
}
6767

68-
return "(?:" + patterns.join("|") + ")";
68+
return `(?:${patterns.join("|")})`;
6969
} else {
7070
return "";
7171
}
@@ -149,8 +149,8 @@ function visitAllMatchesInRule(rule: any, action: (match: any) => any) {
149149
* @param key Base key of the property to be transformed.
150150
*/
151151
function expandPatternMatchProperties(rule: any, key: "begin" | "end") {
152-
const patternKey = key + "Pattern";
153-
const capturesKey = key + "Captures";
152+
const patternKey = `${key}Pattern`;
153+
const capturesKey = `${key}Captures`;
154154
const pattern = rule[patternKey];
155155
if (pattern !== undefined) {
156156
const patterns: string[] = Array.isArray(pattern) ? pattern : [pattern];
@@ -207,7 +207,7 @@ function transformFile(yaml: any) {
207207
});
208208

209209
if (yaml.regexOptions !== undefined) {
210-
const regexOptions = "(?" + yaml.regexOptions + ")";
210+
const regexOptions = `(?${yaml.regexOptions})`;
211211
visitAllRulesInFile(yaml, (rule) => {
212212
visitAllMatchesInRule(rule, (match) => {
213213
return regexOptions + match;
@@ -219,7 +219,7 @@ function transformFile(yaml: any) {
219219
}
220220

221221
export function transpileTextMateGrammar() {
222-
return through.obj(
222+
return obj(
223223
(
224224
file: Vinyl,
225225
_encoding: string,
@@ -230,7 +230,7 @@ export function transpileTextMateGrammar() {
230230
} else if (file.isBuffer()) {
231231
const buf: Buffer = file.contents;
232232
const yamlText: string = buf.toString("utf8");
233-
const jsonData: any = jsYaml.load(yamlText);
233+
const jsonData: any = load(yamlText);
234234
transformFile(jsonData);
235235

236236
file.contents = Buffer.from(JSON.stringify(jsonData, null, 2), "utf8");
@@ -247,8 +247,7 @@ export function transpileTextMateGrammar() {
247247
}
248248

249249
export function compileTextMateGrammar() {
250-
return gulp
251-
.src("syntaxes/*.tmLanguage.yml")
250+
return src("syntaxes/*.tmLanguage.yml")
252251
.pipe(transpileTextMateGrammar())
253-
.pipe(gulp.dest("out/syntaxes"));
252+
.pipe(dest("out/syntaxes"));
254253
}

0 commit comments

Comments
 (0)