automate braceless return substitution for long lines

Per [bjorn3][https://github.com/bjorn3] suggestion resolves cases where
an early return is moved to a separate line due to line width formatting.

This setting changes
```
if (a very long condition) return;
```
to
```
if (a very long
    condition) {
  return;
}
```
while keeping
```
if (short) return;
```
as is.

In pathological cases this may cause `npm run fix` not to fix formatting
in one go and may require running it twice.
This commit is contained in:
Andrei Listochkin 2022-05-17 18:31:51 +01:00
parent e0df2c9bee
commit 00a97272f2
3 changed files with 5 additions and 2 deletions

View File

@ -14,6 +14,7 @@ module.exports = {
rules: {
camelcase: ["error"],
eqeqeq: ["error", "always", { null: "ignore" }],
curly: ["error", "multi-line"],
"no-console": ["error", { allow: ["warn", "error"] }],
"prefer-const": "error",
"@typescript-eslint/member-delimiter-style": [

View File

@ -101,8 +101,9 @@ export class AstInspector implements vscode.HoverProvider, vscode.DefinitionProv
doc: vscode.TextDocument,
pos: vscode.Position
): vscode.ProviderResult<vscode.DefinitionLink[]> {
if (!this.rustEditor || doc.uri.toString() !== this.rustEditor.document.uri.toString())
if (!this.rustEditor || doc.uri.toString() !== this.rustEditor.document.uri.toString()) {
return;
}
const astEditor = this.findAstTextEditor();
if (!astEditor) return;

View File

@ -11,7 +11,7 @@ export async function applySnippetWorkspaceEdit(edit: vscode.WorkspaceEdit) {
}
for (const [uri, edits] of edit.entries()) {
const editor = await editorFromUri(uri);
if (editor)
if (editor) {
await editor.edit((builder) => {
for (const indel of edits) {
assert(
@ -21,6 +21,7 @@ export async function applySnippetWorkspaceEdit(edit: vscode.WorkspaceEdit) {
builder.replace(indel.range, indel.newText);
}
});
}
}
}