Skip to content

Commit f8ee29b

Browse files
0xSwapFeeder0xmemorygrinder
authored andcommitted
fix: lint and format
1 parent 40c38ac commit f8ee29b

File tree

3 files changed

+90
-35
lines changed

3 files changed

+90
-35
lines changed

Diff for: libs/path-utils/src/lib.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ pub fn escape_path(path: &str) -> String {
5353
path.to_string()
5454
}
5555

56-
5756
#[cfg(test)]
5857
mod tests {
5958
use super::*;
@@ -74,7 +73,10 @@ mod tests {
7473
fn test_join_path() {
7574
let base_path = "C:/Users/username/Documents";
7675
let file = "file.sol";
77-
assert_eq!(join_path(base_path, file), "C:/Users/username/Documents/file.sol");
76+
assert_eq!(
77+
join_path(base_path, file),
78+
"C:/Users/username/Documents/file.sol"
79+
);
7880
}
7981

8082
#[test]

Diff for: vscode/src/fmt-wrapper.ts

+75
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,81 @@ function registerForgeFmtLinter(context: vscode.ExtensionContext): {
168168
});
169169
});
170170

171+
const formatter = vscode.languages.registerDocumentFormattingEditProvider('solidity', {
172+
provideDocumentFormattingEdits: (document) => {
173+
if (!isFmtInstalled()) {
174+
vscode.window.showErrorMessage('Forge fmt is not installed. Please install it and try again.');
175+
return;
176+
}
177+
178+
const options: ForgeFmtOptions = {
179+
root: vscode.workspace.workspaceFolders?.[0].uri.fsPath,
180+
check: false,
181+
raw: false,
182+
};
183+
184+
const args: ForgeFmtArgs = {
185+
options,
186+
files: [document.fileName],
187+
};
188+
189+
forgeFmt(args)
190+
.then((result) => {
191+
if (result.exitCode === 0) {
192+
vscode.window.showInformationMessage('Forge fmt ran successfully.');
193+
} else {
194+
vscode.window.showErrorMessage('Forge fmt failed. Please check the output for details.');
195+
196+
console.log(result.output);
197+
}
198+
})
199+
.catch((error) => {
200+
vscode.window.showErrorMessage('Forge fmt failed. Please check the output for details.');
201+
console.error(error);
202+
});
203+
} else {
204+
vscode.window.showErrorMessage('Forge fmt is only available for solidity files.');
205+
}
206+
});
207+
208+
const lintSolWorkspace = vscode.commands.registerCommand('osmium.format-sol-workspace', function () {
209+
if (!isFmtInstalled()) {
210+
vscode.window.showErrorMessage('Forge fmt is not installed. Please install it and try again.');
211+
return;
212+
}
213+
214+
if (!vscode.workspace.workspaceFolders?.[0]) {
215+
vscode.window.showErrorMessage('Unable to find workspace root. Please open a folder and try again.');
216+
return;
217+
}
218+
219+
const options: ForgeFmtOptions = {
220+
root: vscode.workspace.workspaceFolders?.[0].uri.fsPath,
221+
check: false,
222+
raw: false,
223+
};
224+
225+
const args: ForgeFmtArgs = {
226+
options,
227+
files: [vscode.workspace.workspaceFolders?.[0].uri.fsPath],
228+
};
229+
230+
forgeFmt(args)
231+
.then((result) => {
232+
if (result.exitCode === 0) {
233+
vscode.window.showInformationMessage('Forge fmt ran successfully.');
234+
} else {
235+
vscode.window.showErrorMessage('Forge fmt failed. Please check the output for details.');
236+
237+
console.log(result.output);
238+
}
239+
})
240+
.catch((error) => {
241+
vscode.window.showErrorMessage('Forge fmt failed. Please check the output for details.');
242+
console.error(error);
243+
});
244+
});
245+
171246
const formatter = vscode.languages.registerDocumentFormattingEditProvider('solidity', {
172247
provideDocumentFormattingEdits: (document) => {
173248
if (!isFmtInstalled()) {

Diff for: vscode/src/sidebar-provider.ts

+11-33
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ export class SidebarProvider implements vscode.WebviewViewProvider {
3333
) {}
3434

3535
async _osmiumWatcherCallback(uri: vscode.Uri) {
36-
if (!this._view) {
37-
return;
38-
}
36+
if (!this._view) {return;}
3937
const basename = path.basename(uri.fsPath, '.json');
4038
if (basename === 'contracts') {
4139
this._interactContractRepository?.load();
@@ -186,15 +184,9 @@ export class SidebarProvider implements vscode.WebviewViewProvider {
186184
walletPk: 'Enter private key',
187185
walletRpc: 'Enter rpc',
188186
});
189-
if (!inputs) {
190-
return;
191-
}
192-
if (!inputs.walletAddress.startsWith('0x') || !inputs.walletPk.startsWith('0x')) {
193-
return;
194-
}
195-
if (!inputs.walletRpc.startsWith('http') && !inputs.walletRpc.startsWith('ws')) {
196-
return;
197-
}
187+
if (!inputs) {return;}
188+
if (!inputs.walletAddress.startsWith('0x') || !inputs.walletPk.startsWith('0x')) {return;}
189+
if (!inputs.walletRpc.startsWith('http') && !inputs.walletRpc.startsWith('ws')) {return;}
198190

199191
this._walletRepository.createWallet(
200192
inputs.walletName,
@@ -212,9 +204,7 @@ export class SidebarProvider implements vscode.WebviewViewProvider {
212204
ignoreFocusOut: true,
213205
},
214206
);
215-
if (!walletName) {
216-
return;
217-
}
207+
if (!walletName) {return;}
218208
this._walletRepository.deleteWallet(walletName);
219209
}
220210
break;
@@ -232,12 +222,8 @@ export class SidebarProvider implements vscode.WebviewViewProvider {
232222
contractRpc: 'Enter rpc',
233223
contractChainId: 'Enter chain id',
234224
});
235-
if (!inputs || !inputs.contractAddress.startsWith('0x')) {
236-
return;
237-
}
238-
if (!inputs.contractRpc.startsWith('http') && !inputs.contractRpc.startsWith('ws')) {
239-
return;
240-
}
225+
if (!inputs || !inputs.contractAddress.startsWith('0x')) {return;}
226+
if (!inputs.contractRpc.startsWith('http') && !inputs.contractRpc.startsWith('ws')) {return;}
241227
this._interactContractRepository.createContract(
242228
<Address>inputs['contractAddress'],
243229
JSON.parse(inputs['contractAbi']),
@@ -254,9 +240,7 @@ export class SidebarProvider implements vscode.WebviewViewProvider {
254240
ignoreFocusOut: true,
255241
},
256242
);
257-
if (!contractName) {
258-
return;
259-
}
243+
if (!contractName) {return;}
260244
this._interactContractRepository.deleteContract(contractName);
261245
}
262246
break;
@@ -270,12 +254,8 @@ export class SidebarProvider implements vscode.WebviewViewProvider {
270254
environmentName: 'Enter name',
271255
environmentRpc: 'Enter rpc',
272256
});
273-
if (!inputs) {
274-
return;
275-
}
276-
if (!inputs.environmentRpc.startsWith('http') && !inputs.environmentRpc.startsWith('ws')) {
277-
return;
278-
}
257+
if (!inputs) {return;}
258+
if (!inputs.environmentRpc.startsWith('http') && !inputs.environmentRpc.startsWith('ws')) {return;}
279259

280260
this._environmentRepository.createEnvironment(inputs.environmentName, <RpcUrl>inputs.environmentRpc);
281261
}
@@ -287,9 +267,7 @@ export class SidebarProvider implements vscode.WebviewViewProvider {
287267
ignoreFocusOut: true,
288268
},
289269
);
290-
if (!environmentName) {
291-
return;
292-
}
270+
if (!environmentName) {return;}
293271
this._environmentRepository.deleteEnvironment(environmentName);
294272
}
295273
break;

0 commit comments

Comments
 (0)