Skip to content

Commit a751119

Browse files
authored
Merge pull request #131 from semgrep/austin/pre-commit-fix
Pre-commit
2 parents 6513b42 + 2a04ccc commit a751119

19 files changed

+95
-91
lines changed

.pre-commit-config.yaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
repos:
22
- repo: https://github.com/pre-commit/mirrors-prettier
3-
rev: v2.7.1
3+
rev: v4.0.0-alpha.8
44
hooks:
55
- id: prettier
66
- repo: https://github.com/pre-commit/pre-commit-hooks
7-
rev: v2.3.0
7+
rev: v4.6.0
88
hooks:
99
- id: check-yaml
1010
- id: end-of-file-fixer
1111
- id: trailing-whitespace
1212
- id: check-json
1313
- repo: https://github.com/returntocorp/semgrep
14-
rev: v1.5.1
14+
rev: v1.69.0
1515
hooks:
1616
- id: semgrep
1717
name: Semgrep Typescript
1818
types: [javascript, ts, tsx]
1919
args: ["--config", "p/typescript", "--error"]
2020

2121
- repo: https://github.com/pre-commit/mirrors-eslint
22-
rev: "v8.19.0" # Use the sha / tag you want to point at
22+
rev: "v9.1.1" # Use the sha / tag you want to point at
2323
hooks:
2424
- id: eslint
2525
files: \.[jt]sx?$ # *.js, *.jsx, *.ts and *.tsx

src/commands.ts

+17-16
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import { handleSearch } from "./search";
3838
async function replaceAndOpenUriContent(
3939
uri: vscode.Uri,
4040
content: string,
41-
active_editor: vscode.TextEditor
41+
active_editor: vscode.TextEditor,
4242
): Promise<void> {
4343
const doc = await vscode.workspace.openTextDocument(uri);
4444
const edit = new vscode.WorkspaceEdit();
@@ -83,7 +83,7 @@ export function registerCommands(env: Environment): void {
8383
const resp = await vscode.window.showInformationMessage(
8484
"Sign in to use your team's shared Semgrep rule configuration",
8585
"Sign in",
86-
"Do not show again"
86+
"Do not show again",
8787
);
8888
if (resp == "Sign in") {
8989
vscode.commands.executeCommand("semgrep.login");
@@ -101,13 +101,14 @@ export function registerCommands(env: Environment): void {
101101
const onlyGitDirty = env.config.onlyGitDirty;
102102
if (!onlyGitDirty) {
103103
vscode.window.showInformationMessage(
104-
'Semgrep is now only scanning files and lines that have been changed since the last commit. You can disable this in settings by unchecking "Only Git Dirty", or by running "Scan all files in workspace"'
104+
'Semgrep is now only scanning files and lines that have been changed since the last commit. You can disable this in settings by unchecking "Only Git Dirty", or by running "Scan all files in workspace"',
105105
);
106106
// This will always restart the LS, since the LS restarts on config change
107107
// And on startup we always refresh rules
108108
env.config.onlyGitDirty = true;
109-
env.onRulesRefreshed(() =>
110-
env.client?.sendNotification(scanWorkspace, { full: false }), true
109+
env.onRulesRefreshed(
110+
() => env.client?.sendNotification(scanWorkspace, { full: false }),
111+
true,
111112
);
112113
} else {
113114
env.client?.sendNotification(scanWorkspace, { full: false });
@@ -117,15 +118,15 @@ export function registerCommands(env: Environment): void {
117118
vscode.commands.registerCommand("semgrep.scanWorkspaceFull", async () => {
118119
const onlyGitDirty = env.config.onlyGitDirty;
119120
if (onlyGitDirty) {
120-
121121
vscode.window.showInformationMessage(
122-
'Semgrep is now always scanning all files and lines regardless of if they have been changed since the last commit. You can disable this in settings by checking "Only Git Dirty", or by running "Scan changed files in workspace"'
122+
'Semgrep is now always scanning all files and lines regardless of if they have been changed since the last commit. You can disable this in settings by checking "Only Git Dirty", or by running "Scan changed files in workspace"',
123123
);
124124
// This will always restart the LS, since the LS restarts on config change
125125
// And on startup we always refresh rules
126126
env.config.onlyGitDirty = false;
127-
env.onRulesRefreshed(() =>
128-
env.client?.sendNotification(scanWorkspace, { full: true }), true
127+
env.onRulesRefreshed(
128+
() => env.client?.sendNotification(scanWorkspace, { full: true }),
129+
true,
129130
);
130131
} else {
131132
env.client?.sendNotification(scanWorkspace, { full: true });
@@ -176,7 +177,7 @@ export function registerCommands(env: Environment): void {
176177
"semgrep.search",
177178
async (searchParams: SearchParams) => {
178179
await handleSearch(env, searchParams);
179-
}
180+
},
180181
);
181182

182183
vscode.commands.registerCommand("semgrep.search.clear", () => {
@@ -191,12 +192,12 @@ export function registerCommands(env: Environment): void {
191192
const selection = await vscode.window.showWarningMessage(
192193
`Really apply fix to ${matches.locations.length} files?`,
193194
"Yes",
194-
"No"
195+
"No",
195196
);
196197
if (selection === "Yes") {
197198
replaceAll(matches);
198199
}
199-
}
200+
},
200201
);
201202

202203
vscode.commands.registerCommand(
@@ -213,7 +214,7 @@ export function registerCommands(env: Environment): void {
213214
const edit = new vscode.WorkspaceEdit();
214215
edit.replace(vscode.Uri.parse(uri), range, fix);
215216
await applyFixAndSave(edit);
216-
}
217+
},
217218
);
218219

219220
/********/
@@ -230,18 +231,18 @@ export function registerCommands(env: Environment): void {
230231
vscode.window.showInformationMessage("Restarting Semgrep Language Server");
231232
restartLsp(env);
232233
vscode.window.showInformationMessage(
233-
"Semgrep Language Server has finished restarting"
234+
"Semgrep Language Server has finished restarting",
234235
);
235236
});
236237

237238
vscode.commands.registerCommand("semgrep.showDemoFile", async () => {
238239
const path = env.context.asAbsolutePath(
239-
"walkthrough/semgrep-extension.demo.py"
240+
"walkthrough/semgrep-extension.demo.py",
240241
);
241242
const content = await vscode.workspace.fs.readFile(vscode.Uri.parse(path));
242243
let dir = vscode.Uri.joinPath(
243244
env.context.globalStorageUri,
244-
"demo-workspace"
245+
"demo-workspace",
245246
);
246247
dir = vscode.Uri.parse(dir.fsPath); // So dumb
247248
await vscode.workspace.fs.createDirectory(dir);

src/extension.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,22 @@ import { SemgrepSearchWebviewProvider } from "./views/webview";
1212
export let global_env: Environment | null = null;
1313

1414
async function initEnvironment(
15-
context: ExtensionContext
15+
context: ExtensionContext,
1616
): Promise<Environment> {
1717
global_env = await Environment.create(context);
1818
return global_env;
1919
}
2020

2121
async function createOrUpdateEnvironment(
22-
context: ExtensionContext
22+
context: ExtensionContext,
2323
): Promise<Environment> {
2424
return global_env ? global_env.reloadConfig() : initEnvironment(context);
2525
}
2626

2727
async function afterClientStart(context: ExtensionContext, env: Environment) {
2828
if (!env.client) {
2929
vscode.window.showErrorMessage(
30-
"Semgrep Extension failed to activate, please check output"
30+
"Semgrep Extension failed to activate, please check output",
3131
);
3232
return;
3333
}
@@ -42,15 +42,15 @@ async function afterClientStart(context: ExtensionContext, env: Environment) {
4242
SemgrepSearchWebviewProvider.viewType,
4343
provider,
4444
// This makes it so that we don't lose matches hwen we close the sidebar!
45-
{ webviewOptions: { retainContextWhenHidden: true } }
46-
)
45+
{ webviewOptions: { retainContextWhenHidden: true } },
46+
),
4747
);
4848
env.provider = provider;
4949

5050
// register content provider for the AST showing document
5151
vscode.workspace.registerTextDocumentContentProvider(
5252
SemgrepDocumentProvider.scheme,
53-
env.documentView
53+
env.documentView,
5454
);
5555
// Handle configuration changes
5656
context.subscriptions.push(
@@ -60,8 +60,8 @@ async function afterClientStart(context: ExtensionContext, env: Environment) {
6060
await env.reloadConfig();
6161
restartLsp(env);
6262
}
63-
}
64-
)
63+
},
64+
),
6565
);
6666
vscode.commands.executeCommand("semgrep.loginStatus").then(async () => {
6767
vscode.commands.executeCommand("semgrep.loginNudge");
@@ -70,7 +70,7 @@ async function afterClientStart(context: ExtensionContext, env: Environment) {
7070
const selection = await vscode.window.showInformationMessage(
7171
"Semgrep Extension succesfully installed. Would you like to try performing a full workspace scan (may take longer on bigger workspaces)?",
7272
"Scan Full Workspace",
73-
"Dismiss"
73+
"Dismiss",
7474
);
7575
if (selection == "Scan Full Workspace") {
7676
vscode.commands.executeCommand("semgrep.scanWorkspaceFull");
@@ -80,7 +80,7 @@ async function afterClientStart(context: ExtensionContext, env: Environment) {
8080
}
8181

8282
export async function activate(
83-
context: ExtensionContext
83+
context: ExtensionContext,
8484
): Promise<Environment | undefined> {
8585
const env: Environment = await createOrUpdateEnvironment(context);
8686
await activateLsp(env);

src/interface/interface.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export const activeLang = "extension/semgrep/activeLang";
7575
export const clear = "extension/semgrep/clear";
7676
export const exportRuleRequest = "extension/semgrep/exportRuleRequest";
7777

78-
export type SearchLanguage = typeof SUPPORTED_LANGS[number];
78+
export type SearchLanguage = (typeof SUPPORTED_LANGS)[number];
7979

8080
export type extensionToWebviewCommand =
8181
| {

src/lsp.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ async function findSemgrep(env: Environment): Promise<Executable | null> {
4949
}
5050
if (!pip) {
5151
vscode.window.showErrorMessage(
52-
"Python 3.7+ required for the Semgrep Extension"
52+
"Python 3.7+ required for the Semgrep Extension",
5353
);
5454
return null;
5555
}
@@ -60,7 +60,7 @@ async function findSemgrep(env: Environment): Promise<Executable | null> {
6060
await execShell(cmd);
6161
} catch {
6262
vscode.window.showErrorMessage(
63-
"Semgrep binary could not be installed, please see https://semgrep.dev/docs/getting-started/ for instructions"
63+
"Semgrep binary could not be installed, please see https://semgrep.dev/docs/getting-started/ for instructions",
6464
);
6565
return null;
6666
}
@@ -101,7 +101,7 @@ function semgrepCmdLineOpts(env: Environment): string[] {
101101
}
102102

103103
async function serverOptionsCli(
104-
env: Environment
104+
env: Environment,
105105
): Promise<ServerOptions | null> {
106106
const server = await findSemgrep(env);
107107
if (!server) {
@@ -128,20 +128,20 @@ async function serverOptionsCli(
128128
vscode.commands.executeCommand("setContext", "semgrep.cli.major", major);
129129
if (!semver.satisfies(version, MIN_VERSION)) {
130130
vscode.window.showErrorMessage(
131-
`The Semgrep Extension requires a Semgrep CLI version ${MIN_VERSION}, the current installed version is ${version}, please upgrade.`
131+
`The Semgrep Extension requires a Semgrep CLI version ${MIN_VERSION}, the current installed version is ${version}, please upgrade.`,
132132
);
133133
return null;
134134
}
135135
if (!semver.satisfies(version, LATEST_VERSION)) {
136136
vscode.window.showWarningMessage(
137-
`Some features of the Semgrep Extension require a Semgrep CLI version ${LATEST_VERSION}, but the current installed version is ${version}, some features may be disabled, please upgrade.`
137+
`Some features of the Semgrep Extension require a Semgrep CLI version ${LATEST_VERSION}, but the current installed version is ${version}, some features may be disabled, please upgrade.`,
138138
);
139139
}
140140
}
141141

142142
const serverOptions: ServerOptions = server;
143143
env.logger.log(
144-
`Semgrep LSP server configuration := ${JSON.stringify(server, null, 2)}`
144+
`Semgrep LSP server configuration := ${JSON.stringify(server, null, 2)}`,
145145
);
146146
return serverOptions;
147147
}
@@ -175,13 +175,13 @@ function serverOptionsJs(env: Environment) {
175175
},
176176
};
177177
vscode.window.showWarningMessage(
178-
"Semgrep Extension is using the experimental JS LSP server, this is due to the current platform being Windows, or the setting 'semgrep.useJS' being set to true. There may be bugs or performance issues!"
178+
"Semgrep Extension is using the experimental JS LSP server, this is due to the current platform being Windows, or the setting 'semgrep.useJS' being set to true. There may be bugs or performance issues!",
179179
);
180180
return serverOptionsJs;
181181
}
182182

183183
async function lspOptions(
184-
env: Environment
184+
env: Environment,
185185
): Promise<[ServerOptions, LanguageClientOptions] | [null, null]> {
186186
const metrics = {
187187
machineId: vscode.env.machineId,
@@ -200,8 +200,8 @@ async function lspOptions(
200200
`Semgrep Initialization Options := ${JSON.stringify(
201201
initializationOptions,
202202
null,
203-
2
204-
)}`
203+
2,
204+
)}`,
205205
);
206206
const clientOptions: LanguageClientOptions = {
207207
diagnosticCollectionName: DIAGNOSTIC_COLLECTION_NAME,
@@ -223,7 +223,7 @@ async function lspOptions(
223223
serverOptions = await serverOptionsCli(env);
224224
if (!serverOptions) {
225225
vscode.window.showErrorMessage(
226-
"Semgrep Extension failed to activate, please check output"
226+
"Semgrep Extension failed to activate, please check output",
227227
);
228228
return [null, null];
229229
}
@@ -245,7 +245,7 @@ async function start(env: Environment): Promise<void> {
245245
CLIENT_ID,
246246
CLIENT_NAME,
247247
serverOptions,
248-
clientOptions
248+
clientOptions,
249249
);
250250
// register commands
251251
// Start the client. This will also launch the server

src/lspExtensions.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export type ShowAstParams = {
1717
};
1818

1919
export const scanWorkspace = new lc.NotificationType<ScanWorkspaceParams>(
20-
"semgrep/scanWorkspace"
20+
"semgrep/scanWorkspace",
2121
);
2222

2323
export interface LoginParams {
@@ -49,37 +49,37 @@ export interface SearchResults {
4949
locations: SearchResult[];
5050
}
5151
export const login = new lc.RequestType0<LoginParams | null, void>(
52-
"semgrep/login"
52+
"semgrep/login",
5353
);
5454

5555
export const loginFinish = new lc.NotificationType<LoginParams>(
56-
"semgrep/loginFinish"
56+
"semgrep/loginFinish",
5757
);
5858

5959
export const logout = new lc.NotificationType("semgrep/logout");
6060

6161
export const refreshRules = new lc.NotificationType("semgrep/refreshRules");
6262

6363
export const rulesRefreshed = new lc.NotificationType0(
64-
"semgrep/rulesRefreshed"
64+
"semgrep/rulesRefreshed",
6565
);
6666

6767
export const workspaceRules = new lc.RequestType0<any[], void>(
68-
"semgrep/workspaceRules"
68+
"semgrep/workspaceRules",
6969
);
7070

7171
export const loginStatus = new lc.RequestType0<LoginStatusParams | null, void>(
72-
"semgrep/loginStatus"
72+
"semgrep/loginStatus",
7373
);
7474

7575
export const search = new lc.RequestType<LspSearchParams, SearchResults, void>(
76-
"semgrep/search"
76+
"semgrep/search",
7777
);
7878

7979
export const searchOngoing = new lc.RequestType0<SearchResults, void>(
80-
"semgrep/searchOngoing"
80+
"semgrep/searchOngoing",
8181
);
8282

8383
export const showAst = new lc.RequestType<ShowAstParams, string, void>(
84-
"semgrep/showAst"
84+
"semgrep/showAst",
8585
);

0 commit comments

Comments
 (0)