Skip to content

Commit

Permalink
Merge pull request #3200 from github/koesie10/remove-namespace-imports
Browse files Browse the repository at this point in the history
Remove unnecessary namespace imports
  • Loading branch information
koesie10 authored Jan 5, 2024
2 parents 1d42d48 + 38a3778 commit 5c7efe5
Show file tree
Hide file tree
Showing 92 changed files with 652 additions and 620 deletions.
15 changes: 14 additions & 1 deletion extensions/ql-vscode/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ const baseConfig = {
"github/no-then": "off",
"react/jsx-key": ["error", { checkFragmentShorthand: true }],
"import/no-cycle": "off",
"import/no-namespace": "off",
// Never allow extensions in import paths, except for JSON files where they are required.
"import/extensions": ["error", "never", { json: "always" }],
},
Expand Down Expand Up @@ -147,6 +146,8 @@ module.exports = {
},
rules: {
...baseConfig.rules,
// We want to allow mocking of functions in modules, so we need to allow namespace imports.
"import/no-namespace": "off",
"@typescript-eslint/ban-types": [
"error",
{
Expand Down Expand Up @@ -181,5 +182,17 @@ module.exports = {
"@typescript-eslint/no-var-requires": "off",
},
},
{
files: [".storybook/**/*.tsx"],
parserOptions: {
project: resolve(__dirname, ".storybook/tsconfig.json"),
},
rules: {
...baseConfig.rules,
// Storybook doesn't use the automatic JSX runtime in the addon yet, so we need to allow
// `React` to be imported.
"import/no-namespace": ["error", { ignore: ["react"] }],
},
},
],
};
2 changes: 1 addition & 1 deletion extensions/ql-vscode/gulpfile.ts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from "fs-extra";
import { resolve, join } from "path";
import { isDevBuild } from "./dev";
import type * as packageJsonType from "../package.json";
import type packageJsonType from "../package.json";

export interface DeployedPackage {
distPath: string;
Expand Down
2 changes: 1 addition & 1 deletion extensions/ql-vscode/gulpfile.ts/textmate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { dest, src } from "gulp";
import { load } from "js-yaml";
import { obj } from "through2";
import PluginError from "plugin-error";
import * as Vinyl from "vinyl";
import Vinyl from "vinyl";

/**
* Replaces all rule references with the match pattern of the referenced rule.
Expand Down
2 changes: 1 addition & 1 deletion extensions/ql-vscode/gulpfile.ts/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import esbuild from "gulp-esbuild";
import { createProject } from "gulp-typescript";
import { goodReporter } from "./typescript";

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

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

Expand Down
6 changes: 3 additions & 3 deletions extensions/ql-vscode/src/codeql-cli/cli-version.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as semver from "semver";
import { parse, SemVer } from "semver";
import { runCodeQlCliCommand } from "./cli";
import { Logger } from "../common/logging";
import { getErrorMessage } from "../common/helpers-pure";
Expand All @@ -9,7 +9,7 @@ import { getErrorMessage } from "../common/helpers-pure";
export async function getCodeQlCliVersion(
codeQlPath: string,
logger: Logger,
): Promise<semver.SemVer | undefined> {
): Promise<SemVer | undefined> {
try {
const output: string = await runCodeQlCliCommand(
codeQlPath,
Expand All @@ -18,7 +18,7 @@ export async function getCodeQlCliVersion(
"Checking CodeQL version",
logger,
);
return semver.parse(output.trim()) || undefined;
return parse(output.trim()) || undefined;
} catch (e) {
// Failed to run the version command. This might happen if the cli version is _really_ old, or it is corrupted.
// Either way, we can't determine compatibility.
Expand Down
56 changes: 25 additions & 31 deletions extensions/ql-vscode/src/codeql-cli/cli.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { EOL } from "os";
import { spawn } from "child-process-promise";
import * as child_process from "child_process";
import {
ChildProcessWithoutNullStreams,
execFile,
spawn as spawnChildProcess,
} from "child_process";
import { readFile } from "fs-extra";
import { delimiter, dirname, join } from "path";
import * as sarif from "sarif";
import { Log } from "sarif";
import { SemVer } from "semver";
import { Readable } from "stream";
import tk from "tree-kill";
Expand Down Expand Up @@ -51,16 +55,6 @@ const CSV_FORMAT = "csv";
*/
const LOGGING_FLAGS = ["-v", "--log-to-stderr"];

/**
* The expected output of `codeql resolve library-path`.
*/
export interface QuerySetup {
libraryPath: string[];
dbscheme: string;
relativeName?: string;
compilationCache?: string;
}

/**
* The expected output of `codeql resolve queries --format bylanguage`.
*/
Expand Down Expand Up @@ -88,7 +82,7 @@ export interface DbInfo {
/**
* The expected output of `codeql resolve upgrades`.
*/
export interface UpgradesInfo {
interface UpgradesInfo {
scripts: string[];
finalDbscheme: string;
matchesTarget?: boolean;
Expand All @@ -102,33 +96,33 @@ export type QlpacksInfo = { [name: string]: string[] };
/**
* The expected output of `codeql resolve languages`.
*/
export type LanguagesInfo = { [name: string]: string[] };
type LanguagesInfo = { [name: string]: string[] };

/** Information about an ML model, as resolved by `codeql resolve ml-models`. */
export type MlModelInfo = {
type MlModelInfo = {
checksum: string;
path: string;
};

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

/** Information about a data extension predicate, as resolved by `codeql resolve extensions`. */
export type DataExtensionResult = {
type DataExtensionResult = {
predicate: string;
file: string;
index: number;
};

/** The expected output of `codeql resolve extensions`. */
export type ResolveExtensionsResult = {
type ResolveExtensionsResult = {
models: MlModelInfo[];
data: {
[path: string]: DataExtensionResult[];
};
};

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

// `codeql bqrs interpret` requires both of these to be present or
// both absent.
Expand All @@ -152,17 +146,17 @@ export interface SourceInfo {
/**
* The expected output of `codeql resolve queries`.
*/
export type ResolvedQueries = string[];
type ResolvedQueries = string[];

/**
* The expected output of `codeql resolve tests`.
*/
export type ResolvedTests = string[];
type ResolvedTests = string[];

/**
* A compilation message for a test message (either an error or a warning)
*/
export interface CompilationMessage {
interface CompilationMessage {
/**
* The text of the message
*/
Expand Down Expand Up @@ -205,7 +199,7 @@ interface BqrsDecodeOptions {
entities?: string[];
}

export type OnLineCallback = (
type OnLineCallback = (
line: string,
) => Promise<string | undefined> | string | undefined;

Expand All @@ -219,7 +213,7 @@ type VersionChangedListener = (newVersion: SemVer | undefined) => void;
*/
export class CodeQLCliServer implements Disposable {
/** The process for the cli server, or undefined if one doesn't exist yet */
process?: child_process.ChildProcessWithoutNullStreams;
process?: ChildProcessWithoutNullStreams;
/** Queue of future commands*/
commandQueue: Array<() => void>;
/** Whether a command is running */
Expand Down Expand Up @@ -335,7 +329,7 @@ export class CodeQLCliServer implements Disposable {
/**
* Launch the cli server
*/
private async launchProcess(): Promise<child_process.ChildProcessWithoutNullStreams> {
private async launchProcess(): Promise<ChildProcessWithoutNullStreams> {
const codeQlPath = await this.getCodeQlPath();
const args = [];
if (shouldDebugCliServer()) {
Expand Down Expand Up @@ -1101,7 +1095,7 @@ export class CodeQLCliServer implements Disposable {
interpretedResultsPath: string,
sourceInfo?: SourceInfo,
args?: string[],
): Promise<sarif.Log> {
): Promise<Log> {
const additionalArgs = [
// TODO: This flag means that we don't group interpreted results
// by primary location. We may want to revisit whether we call
Expand Down Expand Up @@ -1592,7 +1586,7 @@ export function spawnServer(
stderrListener: (data: any) => void,
stdoutListener?: (data: any) => void,
progressReporter?: ProgressReporter,
): child_process.ChildProcessWithoutNullStreams {
): ChildProcessWithoutNullStreams {
// Enable verbose logging.
const args = command.concat(commandArgs).concat(LOGGING_FLAGS);

Expand All @@ -1603,7 +1597,7 @@ export function spawnServer(
progressReporter.report({ message: `Starting ${name}` });
}
void logger.log(`Starting ${name} using CodeQL CLI: ${base} ${argsString}`);
const child = child_process.spawn(base, args);
const child = spawnChildProcess(base, args);
if (!child || !child.pid) {
throw new Error(
`Failed to start ${name} using command ${base} ${argsString}.`,
Expand Down Expand Up @@ -1670,7 +1664,7 @@ export async function runCodeQlCliCommand(
void logger.log(
`${description} using CodeQL CLI: ${codeQlPath} ${argsString}...`,
);
const result = await promisify(child_process.execFile)(codeQlPath, args);
const result = await promisify(execFile)(codeQlPath, args);
void logger.log(result.stderr);
void logger.log("CLI command succeeded.");
return result.stdout;
Expand Down Expand Up @@ -1710,7 +1704,7 @@ export function shouldDebugQueryServer() {
return isEnvTrue("QUERY_SERVER_JAVA_DEBUG");
}

export function shouldDebugCliServer() {
function shouldDebugCliServer() {
return isEnvTrue("CLI_SERVER_JAVA_DEBUG");
}

Expand Down
19 changes: 9 additions & 10 deletions extensions/ql-vscode/src/codeql-cli/distribution.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { pathExists, mkdtemp, createWriteStream, remove } from "fs-extra";
import { createWriteStream, mkdtemp, pathExists, remove } from "fs-extra";
import { tmpdir } from "os";
import { delimiter, dirname, join } from "path";
import * as semver from "semver";
import { ExtensionContext, Event } from "vscode";
import { Range, satisfies, SemVer } from "semver";
import { Event, ExtensionContext } from "vscode";
import { DistributionConfig } from "../config";
import { extLogger } from "../common/logging/vscode";
import { getCodeQlCliVersion } from "./cli-version";
Expand Down Expand Up @@ -50,8 +50,7 @@ const NIGHTLY_DISTRIBUTION_REPOSITORY_NWO = "dsp-testing/codeql-cli-nightlies";
*
* This applies to both extension-managed and CLI distributions.
*/
export const DEFAULT_DISTRIBUTION_VERSION_RANGE: semver.Range =
new semver.Range("2.x");
export const DEFAULT_DISTRIBUTION_VERSION_RANGE: Range = new Range("2.x");

export interface DistributionProvider {
getCodeQlPathWithoutVersionCheck(): Promise<string | undefined>;
Expand All @@ -62,7 +61,7 @@ export interface DistributionProvider {
export class DistributionManager implements DistributionProvider {
constructor(
public readonly config: DistributionConfig,
private readonly versionRange: semver.Range,
private readonly versionRange: Range,
extensionContext: ExtensionContext,
) {
this._onDidChangeDistribution = config.onDidChangeConfiguration;
Expand Down Expand Up @@ -121,7 +120,7 @@ export class DistributionManager implements DistributionProvider {
distribution.kind !== DistributionKind.ExtensionManaged ||
this.config.includePrerelease;

if (!semver.satisfies(version, this.versionRange, { includePrerelease })) {
if (!satisfies(version, this.versionRange, { includePrerelease })) {
return {
distribution,
kind: FindDistributionResultKind.IncompatibleDistribution,
Expand Down Expand Up @@ -278,7 +277,7 @@ export class DistributionManager implements DistributionProvider {
class ExtensionSpecificDistributionManager {
constructor(
private readonly config: DistributionConfig,
private readonly versionRange: semver.Range,
private readonly versionRange: Range,
private readonly extensionContext: ExtensionContext,
) {
/**/
Expand Down Expand Up @@ -601,7 +600,7 @@ interface DistributionResult {

interface CompatibleDistributionResult extends DistributionResult {
kind: FindDistributionResultKind.CompatibleDistribution;
version: semver.SemVer;
version: SemVer;
}

interface UnknownCompatibilityDistributionResult extends DistributionResult {
Expand All @@ -610,7 +609,7 @@ interface UnknownCompatibilityDistributionResult extends DistributionResult {

interface IncompatibleDistributionResult extends DistributionResult {
kind: FindDistributionResultKind.IncompatibleDistribution;
version: semver.SemVer;
version: SemVer;
}

interface NoDistributionResult {
Expand Down
Loading

0 comments on commit 5c7efe5

Please sign in to comment.