Skip to content

Commit

Permalink
Use knip to refactor dead code and unused exports
Browse files Browse the repository at this point in the history
  • Loading branch information
domsleee committed Oct 15, 2023
1 parent ad3d16a commit 1865e90
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 49 deletions.
17 changes: 0 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,12 @@
"@types/vscode": "^1.72.0",
"@typescript-eslint/eslint-plugin": "^5.40.0",
"@typescript-eslint/parser": "^5.40.0",
"babylon": "^6.18.0",
"eslint": "^8.25.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.2.1",
"jest": "^29.1.2",
"ovsx": "^0.5.1",
"prettier": "^2.7.1",
"source-map-support": "^0.5.21",
"ts-jest": "^29.0.3",
"ts-loader": "^9.4.1",
"typescript": "^4.8.4",
Expand Down
21 changes: 3 additions & 18 deletions src/jestRunnerConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,11 @@ export class JestRunnerConfig {
return normalizePath(jestPath);
}

public get projectPath(): string {
return this.projectPathFromConfig || this.currentWorkspaceFolderPath;
}

public get cwd(): string {
return this.projectPathFromConfig || this.currentPackagePath || this.currentWorkspaceFolderPath;
}

public get projectPathFromConfig(): string | undefined {
private get projectPathFromConfig(): string | undefined {
const projectPathFromConfig = vscode.workspace.getConfiguration().get<string>('jestrunner.projectPath');
if (projectPathFromConfig) {
return path.resolve(this.currentWorkspaceFolderPath, projectPathFromConfig);
Expand All @@ -80,23 +76,12 @@ export class JestRunnerConfig {
return '';
}

public get currentWorkspaceFolderPath(): string {
private get currentWorkspaceFolderPath(): string {
const editor = vscode.window.activeTextEditor;
return vscode.workspace.getWorkspaceFolder(editor.document.uri).uri.fsPath;
}

public get jestConfigPath(): string {
// custom
const configPath: string = vscode.workspace.getConfiguration().get('jestrunner.configPath');
if (!configPath) {
return this.findConfigPath();
}

// default
return normalizePath(path.join(this.currentWorkspaceFolderPath, configPath));
}

getJestConfigPath(targetPath: string): string {
public getJestConfigPath(targetPath: string): string {
// custom
const configPath: string = vscode.workspace.getConfiguration().get('jestrunner.configPath');
if (!configPath) {
Expand Down
7 changes: 4 additions & 3 deletions src/test/jestRunnerConfig.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import * as vscode from 'vscode';
import { JestRunnerConfig } from '../jestRunnerConfig';
import { Uri, WorkspaceConfiguration, WorkspaceFolder } from './__mocks__/vscode';
import { isWindows } from '../util';

const describes = {
windows: process.platform === 'win32' ? describe : describe.skip,
windows: isWindows() ? describe : describe.skip,
linux: ['linux', 'darwin'].includes(process.platform) ? describe : describe.skip,
};

Expand All @@ -28,7 +29,7 @@ describe('JestRunnerConfig', () => {
})
);

expect(jestRunnerConfig.projectPath).toBe('C:\\project\\jestProject');
expect(jestRunnerConfig.cwd).toBe('C:\\project\\jestProject');
});
});

Expand All @@ -52,7 +53,7 @@ describe('JestRunnerConfig', () => {
})
);

expect(jestRunnerConfig.projectPath).toBe('/home/user/project/jestProject');
expect(jestRunnerConfig.cwd).toBe('/home/user/project/jestProject');
});
});
});
10 changes: 1 addition & 9 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,12 @@ const QUOTES = {
'`': true,
};

export function resolveTestNameStringInterpolation(s: string): string {
function resolveTestNameStringInterpolation(s: string): string {
const variableRegex = /(\${?[A-Za-z0-9_]+}?|%[psdifjo#%])/gi;
const matchAny = '(.*?)';
return s.replace(variableRegex, matchAny);
}

export function exactRegexMatch(s: string): string {
return ['^', s, '$'].join('');
}

export function escapeSingleQuotes(s: string): string {
return isWindows() ? s : s.replace(/'/g, "'\\''");
}
Expand All @@ -78,10 +74,6 @@ export function pushMany<T>(arr: T[], items: T[]): number {
return Array.prototype.push.apply(arr, items);
}

export function escapePlusSign(s: string): string {
return s.replace(/[+]/g, '\\$&');
}

export type CodeLensOption = 'run' | 'debug' | 'watch' | 'coverage';

function isCodeLensOption(option: string): option is CodeLensOption {
Expand Down

0 comments on commit 1865e90

Please sign in to comment.