Skip to content

Commit 5c7efe5

Browse files
authored
Merge pull request #3200 from github/koesie10/remove-namespace-imports
Remove unnecessary namespace imports
2 parents 1d42d48 + 38a3778 commit 5c7efe5

File tree

92 files changed

+652
-620
lines changed

Some content is hidden

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

92 files changed

+652
-620
lines changed

extensions/ql-vscode/.eslintrc.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ const baseConfig = {
6666
"github/no-then": "off",
6767
"react/jsx-key": ["error", { checkFragmentShorthand: true }],
6868
"import/no-cycle": "off",
69-
"import/no-namespace": "off",
7069
// Never allow extensions in import paths, except for JSON files where they are required.
7170
"import/extensions": ["error", "never", { json: "always" }],
7271
},
@@ -147,6 +146,8 @@ module.exports = {
147146
},
148147
rules: {
149148
...baseConfig.rules,
149+
// We want to allow mocking of functions in modules, so we need to allow namespace imports.
150+
"import/no-namespace": "off",
150151
"@typescript-eslint/ban-types": [
151152
"error",
152153
{
@@ -181,5 +182,17 @@ module.exports = {
181182
"@typescript-eslint/no-var-requires": "off",
182183
},
183184
},
185+
{
186+
files: [".storybook/**/*.tsx"],
187+
parserOptions: {
188+
project: resolve(__dirname, ".storybook/tsconfig.json"),
189+
},
190+
rules: {
191+
...baseConfig.rules,
192+
// Storybook doesn't use the automatic JSX runtime in the addon yet, so we need to allow
193+
// `React` to be imported.
194+
"import/no-namespace": ["error", { ignore: ["react"] }],
195+
},
196+
},
184197
],
185198
};

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
} from "fs-extra";
1010
import { resolve, join } from "path";
1111
import { isDevBuild } from "./dev";
12-
import type * as packageJsonType from "../package.json";
12+
import type packageJsonType from "../package.json";
1313

1414
export interface DeployedPackage {
1515
distPath: string;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { dest, src } from "gulp";
22
import { load } from "js-yaml";
33
import { obj } from "through2";
44
import PluginError from "plugin-error";
5-
import * as Vinyl from "vinyl";
5+
import Vinyl from "vinyl";
66

77
/**
88
* Replaces all rule references with the match pattern of the referenced rule.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import esbuild from "gulp-esbuild";
33
import { createProject } from "gulp-typescript";
44
import { goodReporter } from "./typescript";
55

6-
import * as chromiumVersion from "./chromium-version.json";
6+
import chromiumVersion from "./chromium-version.json";
77

88
const tsProject = createProject("src/view/tsconfig.json");
99

extensions/ql-vscode/src/codeql-cli/cli-version.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as semver from "semver";
1+
import { parse, SemVer } from "semver";
22
import { runCodeQlCliCommand } from "./cli";
33
import { Logger } from "../common/logging";
44
import { getErrorMessage } from "../common/helpers-pure";
@@ -9,7 +9,7 @@ import { getErrorMessage } from "../common/helpers-pure";
99
export async function getCodeQlCliVersion(
1010
codeQlPath: string,
1111
logger: Logger,
12-
): Promise<semver.SemVer | undefined> {
12+
): Promise<SemVer | undefined> {
1313
try {
1414
const output: string = await runCodeQlCliCommand(
1515
codeQlPath,
@@ -18,7 +18,7 @@ export async function getCodeQlCliVersion(
1818
"Checking CodeQL version",
1919
logger,
2020
);
21-
return semver.parse(output.trim()) || undefined;
21+
return parse(output.trim()) || undefined;
2222
} catch (e) {
2323
// Failed to run the version command. This might happen if the cli version is _really_ old, or it is corrupted.
2424
// Either way, we can't determine compatibility.

extensions/ql-vscode/src/codeql-cli/cli.ts

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import { EOL } from "os";
22
import { spawn } from "child-process-promise";
3-
import * as child_process from "child_process";
3+
import {
4+
ChildProcessWithoutNullStreams,
5+
execFile,
6+
spawn as spawnChildProcess,
7+
} from "child_process";
48
import { readFile } from "fs-extra";
59
import { delimiter, dirname, join } from "path";
6-
import * as sarif from "sarif";
10+
import { Log } from "sarif";
711
import { SemVer } from "semver";
812
import { Readable } from "stream";
913
import tk from "tree-kill";
@@ -51,16 +55,6 @@ const CSV_FORMAT = "csv";
5155
*/
5256
const LOGGING_FLAGS = ["-v", "--log-to-stderr"];
5357

54-
/**
55-
* The expected output of `codeql resolve library-path`.
56-
*/
57-
export interface QuerySetup {
58-
libraryPath: string[];
59-
dbscheme: string;
60-
relativeName?: string;
61-
compilationCache?: string;
62-
}
63-
6458
/**
6559
* The expected output of `codeql resolve queries --format bylanguage`.
6660
*/
@@ -88,7 +82,7 @@ export interface DbInfo {
8882
/**
8983
* The expected output of `codeql resolve upgrades`.
9084
*/
91-
export interface UpgradesInfo {
85+
interface UpgradesInfo {
9286
scripts: string[];
9387
finalDbscheme: string;
9488
matchesTarget?: boolean;
@@ -102,33 +96,33 @@ export type QlpacksInfo = { [name: string]: string[] };
10296
/**
10397
* The expected output of `codeql resolve languages`.
10498
*/
105-
export type LanguagesInfo = { [name: string]: string[] };
99+
type LanguagesInfo = { [name: string]: string[] };
106100

107101
/** Information about an ML model, as resolved by `codeql resolve ml-models`. */
108-
export type MlModelInfo = {
102+
type MlModelInfo = {
109103
checksum: string;
110104
path: string;
111105
};
112106

113107
/** The expected output of `codeql resolve ml-models`. */
114-
export type MlModelsInfo = { models: MlModelInfo[] };
108+
type MlModelsInfo = { models: MlModelInfo[] };
115109

116110
/** Information about a data extension predicate, as resolved by `codeql resolve extensions`. */
117-
export type DataExtensionResult = {
111+
type DataExtensionResult = {
118112
predicate: string;
119113
file: string;
120114
index: number;
121115
};
122116

123117
/** The expected output of `codeql resolve extensions`. */
124-
export type ResolveExtensionsResult = {
118+
type ResolveExtensionsResult = {
125119
models: MlModelInfo[];
126120
data: {
127121
[path: string]: DataExtensionResult[];
128122
};
129123
};
130124

131-
export type GenerateExtensiblePredicateMetadataResult = {
125+
type GenerateExtensiblePredicateMetadataResult = {
132126
// There are other properties in this object, but they are
133127
// not relevant for its use in the extension, so we omit them.
134128
extensible_predicates: Array<{
@@ -140,7 +134,7 @@ export type GenerateExtensiblePredicateMetadataResult = {
140134
/**
141135
* The expected output of `codeql resolve qlref`.
142136
*/
143-
export type QlrefInfo = { resolvedPath: string };
137+
type QlrefInfo = { resolvedPath: string };
144138

145139
// `codeql bqrs interpret` requires both of these to be present or
146140
// both absent.
@@ -152,17 +146,17 @@ export interface SourceInfo {
152146
/**
153147
* The expected output of `codeql resolve queries`.
154148
*/
155-
export type ResolvedQueries = string[];
149+
type ResolvedQueries = string[];
156150

157151
/**
158152
* The expected output of `codeql resolve tests`.
159153
*/
160-
export type ResolvedTests = string[];
154+
type ResolvedTests = string[];
161155

162156
/**
163157
* A compilation message for a test message (either an error or a warning)
164158
*/
165-
export interface CompilationMessage {
159+
interface CompilationMessage {
166160
/**
167161
* The text of the message
168162
*/
@@ -205,7 +199,7 @@ interface BqrsDecodeOptions {
205199
entities?: string[];
206200
}
207201

208-
export type OnLineCallback = (
202+
type OnLineCallback = (
209203
line: string,
210204
) => Promise<string | undefined> | string | undefined;
211205

@@ -219,7 +213,7 @@ type VersionChangedListener = (newVersion: SemVer | undefined) => void;
219213
*/
220214
export class CodeQLCliServer implements Disposable {
221215
/** The process for the cli server, or undefined if one doesn't exist yet */
222-
process?: child_process.ChildProcessWithoutNullStreams;
216+
process?: ChildProcessWithoutNullStreams;
223217
/** Queue of future commands*/
224218
commandQueue: Array<() => void>;
225219
/** Whether a command is running */
@@ -335,7 +329,7 @@ export class CodeQLCliServer implements Disposable {
335329
/**
336330
* Launch the cli server
337331
*/
338-
private async launchProcess(): Promise<child_process.ChildProcessWithoutNullStreams> {
332+
private async launchProcess(): Promise<ChildProcessWithoutNullStreams> {
339333
const codeQlPath = await this.getCodeQlPath();
340334
const args = [];
341335
if (shouldDebugCliServer()) {
@@ -1101,7 +1095,7 @@ export class CodeQLCliServer implements Disposable {
11011095
interpretedResultsPath: string,
11021096
sourceInfo?: SourceInfo,
11031097
args?: string[],
1104-
): Promise<sarif.Log> {
1098+
): Promise<Log> {
11051099
const additionalArgs = [
11061100
// TODO: This flag means that we don't group interpreted results
11071101
// by primary location. We may want to revisit whether we call
@@ -1592,7 +1586,7 @@ export function spawnServer(
15921586
stderrListener: (data: any) => void,
15931587
stdoutListener?: (data: any) => void,
15941588
progressReporter?: ProgressReporter,
1595-
): child_process.ChildProcessWithoutNullStreams {
1589+
): ChildProcessWithoutNullStreams {
15961590
// Enable verbose logging.
15971591
const args = command.concat(commandArgs).concat(LOGGING_FLAGS);
15981592

@@ -1603,7 +1597,7 @@ export function spawnServer(
16031597
progressReporter.report({ message: `Starting ${name}` });
16041598
}
16051599
void logger.log(`Starting ${name} using CodeQL CLI: ${base} ${argsString}`);
1606-
const child = child_process.spawn(base, args);
1600+
const child = spawnChildProcess(base, args);
16071601
if (!child || !child.pid) {
16081602
throw new Error(
16091603
`Failed to start ${name} using command ${base} ${argsString}.`,
@@ -1670,7 +1664,7 @@ export async function runCodeQlCliCommand(
16701664
void logger.log(
16711665
`${description} using CodeQL CLI: ${codeQlPath} ${argsString}...`,
16721666
);
1673-
const result = await promisify(child_process.execFile)(codeQlPath, args);
1667+
const result = await promisify(execFile)(codeQlPath, args);
16741668
void logger.log(result.stderr);
16751669
void logger.log("CLI command succeeded.");
16761670
return result.stdout;
@@ -1710,7 +1704,7 @@ export function shouldDebugQueryServer() {
17101704
return isEnvTrue("QUERY_SERVER_JAVA_DEBUG");
17111705
}
17121706

1713-
export function shouldDebugCliServer() {
1707+
function shouldDebugCliServer() {
17141708
return isEnvTrue("CLI_SERVER_JAVA_DEBUG");
17151709
}
17161710

extensions/ql-vscode/src/codeql-cli/distribution.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { pathExists, mkdtemp, createWriteStream, remove } from "fs-extra";
1+
import { createWriteStream, mkdtemp, pathExists, remove } from "fs-extra";
22
import { tmpdir } from "os";
33
import { delimiter, dirname, join } from "path";
4-
import * as semver from "semver";
5-
import { ExtensionContext, Event } from "vscode";
4+
import { Range, satisfies, SemVer } from "semver";
5+
import { Event, ExtensionContext } from "vscode";
66
import { DistributionConfig } from "../config";
77
import { extLogger } from "../common/logging/vscode";
88
import { getCodeQlCliVersion } from "./cli-version";
@@ -50,8 +50,7 @@ const NIGHTLY_DISTRIBUTION_REPOSITORY_NWO = "dsp-testing/codeql-cli-nightlies";
5050
*
5151
* This applies to both extension-managed and CLI distributions.
5252
*/
53-
export const DEFAULT_DISTRIBUTION_VERSION_RANGE: semver.Range =
54-
new semver.Range("2.x");
53+
export const DEFAULT_DISTRIBUTION_VERSION_RANGE: Range = new Range("2.x");
5554

5655
export interface DistributionProvider {
5756
getCodeQlPathWithoutVersionCheck(): Promise<string | undefined>;
@@ -62,7 +61,7 @@ export interface DistributionProvider {
6261
export class DistributionManager implements DistributionProvider {
6362
constructor(
6463
public readonly config: DistributionConfig,
65-
private readonly versionRange: semver.Range,
64+
private readonly versionRange: Range,
6665
extensionContext: ExtensionContext,
6766
) {
6867
this._onDidChangeDistribution = config.onDidChangeConfiguration;
@@ -121,7 +120,7 @@ export class DistributionManager implements DistributionProvider {
121120
distribution.kind !== DistributionKind.ExtensionManaged ||
122121
this.config.includePrerelease;
123122

124-
if (!semver.satisfies(version, this.versionRange, { includePrerelease })) {
123+
if (!satisfies(version, this.versionRange, { includePrerelease })) {
125124
return {
126125
distribution,
127126
kind: FindDistributionResultKind.IncompatibleDistribution,
@@ -278,7 +277,7 @@ export class DistributionManager implements DistributionProvider {
278277
class ExtensionSpecificDistributionManager {
279278
constructor(
280279
private readonly config: DistributionConfig,
281-
private readonly versionRange: semver.Range,
280+
private readonly versionRange: Range,
282281
private readonly extensionContext: ExtensionContext,
283282
) {
284283
/**/
@@ -601,7 +600,7 @@ interface DistributionResult {
601600

602601
interface CompatibleDistributionResult extends DistributionResult {
603602
kind: FindDistributionResultKind.CompatibleDistribution;
604-
version: semver.SemVer;
603+
version: SemVer;
605604
}
606605

607606
interface UnknownCompatibilityDistributionResult extends DistributionResult {
@@ -610,7 +609,7 @@ interface UnknownCompatibilityDistributionResult extends DistributionResult {
610609

611610
interface IncompatibleDistributionResult extends DistributionResult {
612611
kind: FindDistributionResultKind.IncompatibleDistribution;
613-
version: semver.SemVer;
612+
version: SemVer;
614613
}
615614

616615
interface NoDistributionResult {

0 commit comments

Comments
 (0)