Skip to content

Commit 034bfc2

Browse files
committed
Remove unnecessary namespace imports
This removes all unnecessary namespace imports. The only namespace imports that are left are those that are needed for spying on functions in tests.
1 parent d342b06 commit 034bfc2

File tree

95 files changed

+616
-586
lines changed

Some content is hidden

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

95 files changed

+616
-586
lines changed

extensions/ql-vscode/.eslintrc.js

Lines changed: 2 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
{

extensions/ql-vscode/.storybook/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"target": "es6",
66
"outDir": "out",
77
"lib": ["ES2021", "dom"],
8-
"jsx": "react",
8+
"jsx": "react-jsx",
99
"sourceMap": true,
1010
"rootDir": "..",
1111
"strict": true,

extensions/ql-vscode/.storybook/vscode-theme-addon/ThemeSelector.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as React from "react";
21
import { FunctionComponent, useCallback } from "react";
32

43
import { useGlobals } from "@storybook/manager-api";

extensions/ql-vscode/.storybook/vscode-theme-addon/manager.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as React from "react";
21
import { addons, types } from "@storybook/manager-api";
32
import { ThemeSelector } from "./ThemeSelector";
43

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: 12 additions & 8 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";
@@ -219,7 +223,7 @@ type VersionChangedListener = (newVersion: SemVer | undefined) => void;
219223
*/
220224
export class CodeQLCliServer implements Disposable {
221225
/** The process for the cli server, or undefined if one doesn't exist yet */
222-
process?: child_process.ChildProcessWithoutNullStreams;
226+
process?: ChildProcessWithoutNullStreams;
223227
/** Queue of future commands*/
224228
commandQueue: Array<() => void>;
225229
/** Whether a command is running */
@@ -335,7 +339,7 @@ export class CodeQLCliServer implements Disposable {
335339
/**
336340
* Launch the cli server
337341
*/
338-
private async launchProcess(): Promise<child_process.ChildProcessWithoutNullStreams> {
342+
private async launchProcess(): Promise<ChildProcessWithoutNullStreams> {
339343
const codeQlPath = await this.getCodeQlPath();
340344
const args = [];
341345
if (shouldDebugCliServer()) {
@@ -1101,7 +1105,7 @@ export class CodeQLCliServer implements Disposable {
11011105
interpretedResultsPath: string,
11021106
sourceInfo?: SourceInfo,
11031107
args?: string[],
1104-
): Promise<sarif.Log> {
1108+
): Promise<Log> {
11051109
const additionalArgs = [
11061110
// TODO: This flag means that we don't group interpreted results
11071111
// by primary location. We may want to revisit whether we call
@@ -1592,7 +1596,7 @@ export function spawnServer(
15921596
stderrListener: (data: any) => void,
15931597
stdoutListener?: (data: any) => void,
15941598
progressReporter?: ProgressReporter,
1595-
): child_process.ChildProcessWithoutNullStreams {
1599+
): ChildProcessWithoutNullStreams {
15961600
// Enable verbose logging.
15971601
const args = command.concat(commandArgs).concat(LOGGING_FLAGS);
15981602

@@ -1603,7 +1607,7 @@ export function spawnServer(
16031607
progressReporter.report({ message: `Starting ${name}` });
16041608
}
16051609
void logger.log(`Starting ${name} using CodeQL CLI: ${base} ${argsString}`);
1606-
const child = child_process.spawn(base, args);
1610+
const child = spawnChildProcess(base, args);
16071611
if (!child || !child.pid) {
16081612
throw new Error(
16091613
`Failed to start ${name} using command ${base} ${argsString}.`,
@@ -1670,7 +1674,7 @@ export async function runCodeQlCliCommand(
16701674
void logger.log(
16711675
`${description} using CodeQL CLI: ${codeQlPath} ${argsString}...`,
16721676
);
1673-
const result = await promisify(child_process.execFile)(codeQlPath, args);
1677+
const result = await promisify(execFile)(codeQlPath, args);
16741678
void logger.log(result.stderr);
16751679
void logger.log("CLI command succeeded.");
16761680
return result.stdout;

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)