Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint to prevent floating promises #2497

Merged
merged 41 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
095f3b8
Lint to prevent floating promises
AndreasArvidsson Jul 12, 2024
b3fc5dc
enable project
AndreasArvidsson Jul 12, 2024
29c8180
added void
AndreasArvidsson Jul 12, 2024
9f06d3f
Exclude playground
AndreasArvidsson Jul 12, 2024
42165d0
Added void
AndreasArvidsson Jul 12, 2024
4e5c7f7
More void
AndreasArvidsson Jul 12, 2024
d337103
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Jul 12, 2024
5f8d6fc
revert
AndreasArvidsson Jul 12, 2024
02dcef6
Merge branch 'noFloatingPromises' of github.com:cursorless-dev/cursor…
AndreasArvidsson Jul 12, 2024
d48e395
Merge branch 'main' into noFloatingPromises
AndreasArvidsson Jul 12, 2024
bfaee04
fixed
AndreasArvidsson Jul 12, 2024
1b6ccb8
work work
AndreasArvidsson Jul 12, 2024
5ef0a2b
stuff
AndreasArvidsson Jul 12, 2024
66427ed
docs
AndreasArvidsson Jul 12, 2024
6424ec2
fix
AndreasArvidsson Jul 12, 2024
0429723
Add const
AndreasArvidsson Jul 28, 2024
5415f53
Merge branch 'main' into noFloatingPromises
AndreasArvidsson Jul 28, 2024
8d10575
More fixes
AndreasArvidsson Jul 28, 2024
f47b3f2
fixed failing test
AndreasArvidsson Jul 29, 2024
4b57cd2
Merge branch 'main' into noFloatingPromises
AndreasArvidsson Jul 30, 2024
38e9e95
Fix type
AndreasArvidsson Jul 30, 2024
394452a
Merge branch 'main' into noFloatingPromises
pokey Jul 30, 2024
af97012
cleanup
pokey Jul 30, 2024
691035f
attempt to get rid of typescript version warning by bumping deps
pokey Jul 30, 2024
b424e1d
change type
AndreasArvidsson Jul 30, 2024
fc824af
Updates
AndreasArvidsson Jul 30, 2024
c558926
Update lint config
AndreasArvidsson Jul 30, 2024
b89d193
Add comment
AndreasArvidsson Jul 30, 2024
7a6436c
tweaks
pokey Jul 30, 2024
376fdb8
Fixes
pokey Jul 30, 2024
8ee5ebc
Tweaks
pokey Jul 30, 2024
7aac800
More tweaks
pokey Jul 30, 2024
ba3945f
tweaks
pokey Jul 30, 2024
56b2490
More tweaks
pokey Jul 30, 2024
d88a858
Tweaks
pokey Jul 30, 2024
4868442
cleanup lint ignores
pokey Jul 30, 2024
5f40350
tweak ignore
pokey Jul 30, 2024
1cb6e01
fix overrides
pokey Jul 30, 2024
9c39a30
Empty commit
pokey Jul 30, 2024
23ee3da
fix keyboard tests
pokey Jul 30, 2024
1486cd4
Merge branch 'main' into noFloatingPromises
pokey Jul 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
// We want to enable this in the long run. For now there are a lot of errors that needs to be handled.
// "plugin:@typescript-eslint/recommended-requiring-type-checking",
"plugin:import/typescript",
"prettier"
],
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
"sourceType": "module",
"project": true
},
"plugins": [
"@typescript-eslint",
Expand Down Expand Up @@ -37,6 +40,7 @@
}
}
],
"@typescript-eslint/no-floating-promises": "error",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/no-non-null-assertion": "off",
Expand Down Expand Up @@ -85,22 +89,30 @@
}
]
}
},
{
"files": [
"jest.config.ts",
"docusaurus.config.mts",
"mdx-components.tsx",
"typings/**"
],
"extends": ["plugin:@typescript-eslint/disable-type-checked"]
}
],
"settings": {
"import/resolver": {
"typescript": {
"alwaysTryTypes": true, // always try to resolve types under `<root>@types` directory even it doesn't contain any source code, like `@types/unist`

"project": ["tsconfig.json", "packages/*/tsconfig.json"]
}
}
},
"ignorePatterns": [
AndreasArvidsson marked this conversation as resolved.
Show resolved Hide resolved
"**/vendor/**/*.ts",
"**/vendor/**/*.js",
"**/out/**",
"**/generated/**",
"data/playground/**"
"**/out/**",
"**/vendor/**/*.js",
"**/vendor/**/*.ts",
"/data/playground/**"
]
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"@pnpm/meta-updater": "1.0.0",
"@types/node": "18.18.2",
"@typescript-eslint/eslint-plugin": "^7.4.0",
"@typescript-eslint/parser": "^7.4.0",
"@typescript-eslint/parser": "^7.18.0",
"esbuild": "^0.20.2",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/types/command/command.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { CommandV5 } from "./legacy/CommandV5.types";

export type CommandComplete = Required<Omit<CommandLatest, "spokenForm">> &
Pick<CommandLatest, "spokenForm">;
export const LATEST_VERSION = 7 as const;
export const LATEST_VERSION = 7;
AndreasArvidsson marked this conversation as resolved.
Show resolved Hide resolved

export type CommandLatest = Command & {
version: typeof LATEST_VERSION;
Expand Down
11 changes: 9 additions & 2 deletions packages/common/src/util/splitKey.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import type { HatStyleName } from "../ide/types/hatStyles.types";

export function splitKey(key: string) {
interface SplitKey {
hatStyle: string;
// If the character is `.` then it will appear as a zero length string
// due to the way the split on `.` works
character: HatStyleName;
}

export function splitKey(key: string): SplitKey {
const [hatStyle, character] = key.split(".");

return {
hatStyle: hatStyle as HatStyleName,
hatStyle,
// If the character is `.` then it will appear as a zero length string
// due to the way the split on `.` works
character: character.length === 0 ? "." : character,
Expand Down
4 changes: 2 additions & 2 deletions packages/common/src/util/uniqWithHash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function uniqWithHash<T>(
// For hash collisions, uniq the items,
// letting uniqWith provide correct semantics.
needsUniq.forEach((key) => {
hashToItems.set(key, uniqWith(hashToItems.get(key)!, isEqual));
hashToItems.set(key, uniqWith(hashToItems.get(key), isEqual));
});

// To preserve order, step through the original items
Expand All @@ -67,7 +67,7 @@ export function uniqWithHash<T>(
// Removed by uniqWith.
return [];
}
const first = items[0]!;
const first = items[0];
if (!isEqual(first, item)) {
// Removed by uniqWith.
// Note that it is sufficient to check the first item,
Expand Down
2 changes: 1 addition & 1 deletion packages/cursorless-engine/src/actions/Find.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ abstract class Find implements SimpleAction {
let query: string;
if (text.length > 200) {
query = text.substring(0, 200);
showWarning(
void showWarning(
ide().messages,
"truncatedSearchText",
"Search text is longer than 200 characters; truncating",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default class GenerateSnippet {
// immediately starts saying the name of the snippet (eg command chain
// "snippet make funk camel my function"), we're more likely to
// win the race and have the input box ready for them
flashTargets(ide(), targets, FlashStyle.referenced);
void flashTargets(ide(), targets, FlashStyle.referenced);

if (snippetName == null) {
snippetName = await ide().showInputBox({
Expand Down
3 changes: 2 additions & 1 deletion packages/cursorless-engine/src/actions/ShowParseTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export default class ShowParseTree {
results.push(parseTree(editor.document, tree, contentRange));
}

ide().openUntitledTextDocument({
// FIXME: If we await this our test break. We should probably find out when this actually resolves.
void ide().openUntitledTextDocument({
AndreasArvidsson marked this conversation as resolved.
Show resolved Hide resolved
language: "markdown",
content: results.join("\n\n"),
});
Expand Down
2 changes: 1 addition & 1 deletion packages/cursorless-engine/src/actions/Sort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ abstract class SortBase implements SimpleAction {

async run(targets: Target[]): Promise<ActionReturnValue> {
if (targets.length < 2) {
showWarning(
void showWarning(
ide().messages,
"tooFewTargets",
'This action works on multiple targets, e.g. "sort every line block" instead of "sort block".',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import {
CommandV6,
DestinationDescriptor,
EnforceUndefined,
ExecuteCommandOptions,
GetTextActionOptions,
HighlightActionDescriptor,
HighlightId,
ImplicitDestinationDescriptor,
Expand All @@ -28,6 +26,8 @@ import {
PrimitiveDestinationDescriptor,
ReplaceWith,
WrapWithSnippetArg,
type ExecuteCommandOptions,
type GetTextActionOptions,
} from "@cursorless/common";
import canonicalizeActionName from "./canonicalizeActionName";

Expand Down
1 change: 1 addition & 0 deletions packages/cursorless-engine/src/cursorlessEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export async function createCursorlessEngine({

const debug = new Debug(ide);
const rangeUpdater = new RangeUpdater();

const storedTargets = new StoredTargetMap();
const keyboardTargetUpdater = new KeyboardTargetUpdater(ide, storedTargets);
const customSpokenFormGenerator = new CustomSpokenFormGeneratorImpl(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@ export function parseAction(input: string): WithPlaceholders<ActionDescriptor> {
);
}

return parser.results[0] as WithPlaceholders<ActionDescriptor>;
return parser.results[0];
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ async function readQueryFileAndImports(
return undefined;
}

showError(
void showError(
ide.messages,
"LanguageDefinition.readQueryFileAndImports.queryNotFound",
`Could not find imported query file ${queryName}`,
Expand Down Expand Up @@ -193,7 +193,7 @@ function validateImportSyntax(
let isError = false;

if (/[/\\]/g.test(importName)) {
showError(
void showError(
ide.messages,
"LanguageDefinition.readQueryFileAndImports.invalidImport",
`Invalid import statement in ${file}: "${actual}". Relative import paths not supported`,
Expand All @@ -204,7 +204,7 @@ function validateImportSyntax(

const canonicalSyntax = `;; import ${importName}`;
if (actual !== canonicalSyntax) {
showError(
void showError(
ide.messages,
"LanguageDefinition.readQueryFileAndImports.malformedImport",
`Malformed import statement in ${file}: "${actual}". Import statements must be of the form "${canonicalSyntax}"`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class LanguageDefinitionsImpl
private treeSitterQueryProvider: RawTreeSitterQueryProvider,
) {
ide.onDidOpenTextDocument((document) => {
this.loadLanguage(document.languageId);
void this.loadLanguage(document.languageId);
});
ide.onDidChangeVisibleTextEditors((editors) => {
editors.forEach(({ document }) => this.loadLanguage(document.languageId));
Expand Down Expand Up @@ -111,7 +111,7 @@ export class LanguageDefinitionsImpl
languageIds.map((languageId) => this.loadLanguage(languageId)),
);
} catch (err) {
showError(
void showError(
this.ide.messages,
"Failed to load language definitions",
toString(err),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class TreeSitterQuery {
)}\``,
].join(", ");

showError(
void showError(
ide().messages,
"TreeSitterQuery.parsePredicates",
`Error parsing predicate for ${context}: ${error.error}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function checkCaptureStartEnd(
.at(0);
if (lastStart != null && firstEnd != null) {
if (lastStart.isAfter(firstEnd)) {
showError(
void showError(
messages,
"TreeSitterQuery.checkCaptures.badOrder",
`Start capture must be before end capture: ${captures}`,
Expand All @@ -57,7 +57,7 @@ export function checkCaptureStartEnd(
if (regularCount > 0 && (startCount > 0 || endCount > 0)) {
// Found a mix of regular captures and start/end captures, which is not
// allowed
showError(
void showError(
messages,
"TreeSitterQuery.checkCaptures.mixRegularStartEnd",
`Please do not mix regular captures and start/end captures: ${captures.map(
Expand All @@ -69,7 +69,7 @@ export function checkCaptureStartEnd(

if (regularCount > 1) {
// Found duplicate captures
showError(
void showError(
messages,
"TreeSitterQuery.checkCaptures.duplicate",
`A capture with the same name may only appear once in a single pattern: ${captures.map(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function validateQueryCaptures(file: string, rawQuery: string): void {
}

if (!allowedCaptures.has(captureName)) {
const lineNumber = match.input!.slice(0, match.index!).split("\n").length;
const lineNumber = match.input.slice(0, match.index).split("\n").length;
errors.push(`${file}(${lineNumber}) invalid capture '@${captureName}'.`);
}
}
Expand All @@ -91,7 +91,7 @@ export function validateQueryCaptures(file: string, rawQuery: string): void {

const message = errors.join("\n");

showError(
void showError(
ide().messages,
"validateQueryCaptures.invalidCaptureName",
message,
Expand Down
4 changes: 2 additions & 2 deletions packages/cursorless-engine/src/languages/getNodeMatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function matcherIncludeSiblings(matcher: NodeMatcher): NodeMatcher {
selectionWithEditorFromRange(selection, match.selection.selection),
matcher,
),
) as NodeMatcherValue[];
);
if (matches.length > 0) {
return matches;
}
Expand All @@ -83,7 +83,7 @@ function iterateNearestIterableAncestor(
) {
let parent: SyntaxNode | null = node.parent;
while (parent != null) {
const matches = parent!.namedChildren
const matches = parent.namedChildren
.flatMap((sibling) => nodeMatcher(selection, sibling))
.filter((match) => match != null) as NodeMatcherValue[];
if (matches.length > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export abstract class BaseTreeSitterScopeHandler extends BaseScopeHandler {
const message =
"Please use #allow-multiple! predicate in your query to allow multiple matches for this scope type";

showError(
void showError(
ide().messages,
"BaseTreeSitterScopeHandler.allow-multiple",
message,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,7 @@ function constructTarget(
const isInDelimitedList =
leadingDelimiterRange != null || trailingDelimiterRange != null;
const insertionDelimiter = isInDelimitedList
? editor.document.getText(
(leadingDelimiterRange ?? trailingDelimiterRange)!,
)
? editor.document.getText(leadingDelimiterRange ?? trailingDelimiterRange)
: "";

return new SubTokenWordTarget({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class ScopeRangeWatcher {
config,
);
} catch (err) {
showError(
void showError(
ide().messages,
"ScopeRangeWatcher.provide",
(err as Error).message,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,4 @@ function parseCommandLineArguments(args: string[]) {
return { transformationName, minimumVersion, paths };
}

main(process.argv.slice(2));
void main(process.argv.slice(2));
6 changes: 5 additions & 1 deletion packages/cursorless-engine/src/snippets/snippet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,13 @@ function findMatchingSnippetDefinitionForSingleTarget(
}
}

if (matchingScopeType == null) {
return false;
}

return (
matchingTarget != null &&
!(excludeDescendantScopeTypes ?? []).includes(matchingScopeType!)
!(excludeDescendantScopeTypes ?? []).includes(matchingScopeType)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class CustomSpokenForms {
} else {
console.error("Error loading custom spoken forms", err);
const msg = (err as Error).message.replace(/\.$/, "");
showError(
void showError(
ide().messages,
"CustomSpokenForms.updateSpokenFormMaps",
`Error loading custom spoken forms: ${msg}. Falling back to default spoken forms.`,
Expand Down
2 changes: 1 addition & 1 deletion packages/cursorless-engine/src/util/targetUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export function createThatMark(
: new Selection(range!.start, range!.end),
}))
: targets.map((target) => ({
editor: target!.editor,
editor: target.editor,
selection: target.contentSelection,
}));
return thatMark;
Expand Down
3 changes: 3 additions & 0 deletions packages/cursorless-everywhere-talon-e2e/src/types/std.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare module "std" {
function exit(code: number): void;
}
1 change: 0 additions & 1 deletion packages/cursorless-everywhere-talon-e2e/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"target": "ES2022"
},
"include": ["src/**/*.ts", "src/**/*.json", "../../typings/**/*.d.ts"],
"exclude": ["src/quickjsTest.ts"],
"references": [
{
"path": "../common"
Expand Down
Loading
Loading