Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 0 additions & 8 deletions oxlint.config.mts
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
import type { OxlintConfig } from "oxlint";
import { defineConfig } from "oxlint";

// These rules should probably be re-enabled eventually
const temporarilyDisabledRules = [
// Requires es2023
"unicorn/no-array-sort",
"unicorn/no-array-reverse",
];

const disabledRules = [
...temporarilyDisabledRules,
"eslint/arrow-body-style",
"eslint/capitalized-comments",
"eslint/class-methods-use-this",
Expand Down
43 changes: 24 additions & 19 deletions packages/app-vscode/src/ScopeTreeProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export class ScopeTreeProvider implements TreeDataProvider<MyTreeItem> {
};
})();

return this.supportLevels
const supportLevels = this.supportLevels
.filter(
(supportLevel) =>
supportLevel.support === scopeSupport &&
Expand All @@ -201,26 +201,11 @@ export class ScopeTreeProvider implements TreeDataProvider<MyTreeItem> {
isEqual(supportLevel.scopeType, this.scopeVisualizer.scopeType),
getContainmentIcon?.(supportLevel.scopeType),
),
)
.sort((a, b) => {
if (
a.scopeTypeInfo.spokenForm.type !== b.scopeTypeInfo.spokenForm.type
) {
// Scopes with no spoken form are sorted to the bottom
return a.scopeTypeInfo.spokenForm.type === "error" ? 1 : -1;
}
);

if (
a.scopeTypeInfo.isLanguageSpecific !==
b.scopeTypeInfo.isLanguageSpecific
) {
// Then language-specific scopes are sorted to the top
return a.scopeTypeInfo.isLanguageSpecific ? -1 : 1;
}
supportLevels.sort(compareScopeTypes);

// Then alphabetical by label
return a.label.label.localeCompare(b.label.label);
});
return supportLevels;
}

private getContainmentIcon(
Expand Down Expand Up @@ -255,6 +240,26 @@ export class ScopeTreeProvider implements TreeDataProvider<MyTreeItem> {
}
}

function compareScopeTypes(
a: ScopeSupportTreeItem,
b: ScopeSupportTreeItem,
): number {
if (a.scopeTypeInfo.spokenForm.type !== b.scopeTypeInfo.spokenForm.type) {
// Scopes with no spoken form are sorted to the bottom
return a.scopeTypeInfo.spokenForm.type === "error" ? 1 : -1;
}

if (
a.scopeTypeInfo.isLanguageSpecific !== b.scopeTypeInfo.isLanguageSpecific
) {
// Then language-specific scopes are sorted to the top
return a.scopeTypeInfo.isLanguageSpecific ? -1 : 1;
}

// Then alphabetical by label
return a.label.label.localeCompare(b.label.label);
}

function getSupportCategories(): SupportCategoryTreeItem[] {
return [
new SupportCategoryTreeItem(ScopeSupport.supportedAndPresentInEditor),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class KeyboardCommandsModal {
const acceptableTokenTypeInfos = getAcceptableTokenTypes(this.parser);
// FIXME: Here's where we'd update sidebar
const acceptableTokenTypes = sortedUniq(
acceptableTokenTypeInfos.map(({ type }) => type).sort(),
acceptableTokenTypeInfos.map(({ type }) => type).toSorted(),
);
let layer = this.layerCache.get(acceptableTokenTypes);
if (layer == null) {
Expand Down
4 changes: 3 additions & 1 deletion packages/app-vscode/src/keyboard/KeyboardHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ export class KeyboardHandler {
// one. Eg if you're in the middle of typing a command and we turn off
// the modal mode, we want to cancel the command
if (index !== -1) {
const listenersToCancel = this.listeners.slice(index + 1).reverse();
const listenersToCancel = this.listeners
.slice(index + 1)
.toReversed();
for (const entry of listenersToCancel) {
entry.listener.handleCancelled();
}
Expand Down
2 changes: 1 addition & 1 deletion packages/app-vscode/src/keyboard/buildSuffixTrie.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ suite("buildSuffixTrie", () => {
const { trie, conflicts } = buildSuffixTrie<string>(
input.map((key) => [key, key]),
);
const chars = uniq(input.flatMap((key) => key.split(""))).sort();
const chars = uniq(input.flatMap((key) => key.split(""))).toSorted();
const actual = uniqWith(
sortEntries(chars.flatMap((char) => trie.search(char))),
isEqual,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ const testCases: TestCase[] = [

suite("keyboard.getAcceptableTokenTypes", () => {
let parser: nearley.Parser;

setup(() => {
parser = new nearley.Parser(nearley.Grammar.fromCompiled(grammar));
});
Expand Down
1 change: 1 addition & 0 deletions packages/app-vscode/src/keyboard/grammar/grammar.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ const testCases: TestCase[] = [

suite("keyboard grammar", () => {
let parser: nearley.Parser;

setup(() => {
parser = new nearley.Parser(nearley.Grammar.fromCompiled(grammar));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ function getScopeFixtures(
}

const result: Scopes = { public: [], internal: [] };
const sortedScopes = Object.values(scopeMap).sort(nameComparator);
const sortedScopes = Object.values(scopeMap).toSorted(nameComparator);

for (const scope of sortedScopes) {
scope.facets.sort(facetComparator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function getUniquePositions(highlights: Highlight[]): Position[] {
const result: Position[] = [];
const positions = highlights
.flatMap((h) => [h.range.start, h.range.end])
.sort((a, b) =>
.toSorted((a, b) =>
a.line === b.line ? a.character - b.character : a.line - b.line,
);
for (let i = 0; i < positions.length; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {

export function MissingLanguageScopes(): React.JSX.Element {
const [showPrivate, setShowPrivate] = useState(false);
const languageIds = Object.keys(languageScopeSupport).sort();
const languageIds = Object.keys(languageScopeSupport).toSorted();

return (
<>
Expand Down Expand Up @@ -48,10 +48,10 @@ function Language({
.filter(
(facet) => scopeSupport[facet] === ScopeSupportFacetLevel.unsupported,
)
.sort();
.toSorted();
let unspecifiedFacets = scopeSupportFacets
.filter((facet) => scopeSupport[facet] == null)
.sort();
.toSorted();

if (!showPrivate) {
unsupportedFacets = unsupportedFacets.filter((f) => !isPrivate(f));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ function createChangeEvents(
*/
const sortedEdits = edits
.map((edit, index) => ({ edit, index }))
// oxlint-disable-next-line unicorn/no-array-sort
.sort((a, b) => {
// Edits starting at the same position are sorted in reverse given order.
if (a.edit.range.start.isEqual(b.edit.range.start)) {
Expand Down
10 changes: 5 additions & 5 deletions packages/lib-engine/src/actions/Sort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ abstract class SortBase implements SimpleAction {
}

// First sort target by document order
const sortedTargets = targets
.slice()
.sort((a, b) => a.contentRange.start.compareTo(b.contentRange.start));
const sortedTargets = targets.toSorted((a, b) =>
a.contentRange.start.compareTo(b.contentRange.start),
);

const { returnValue: unsortedTexts } = await this.actions.getText.run(
sortedTargets,
Expand All @@ -49,7 +49,7 @@ abstract class SortBase implements SimpleAction {

export class Sort extends SortBase {
protected sortTexts(texts: string[]) {
return texts.sort((a, b) =>
return texts.toSorted((a, b) =>
a.localeCompare(b, undefined, {
numeric: true,
caseFirst: "upper",
Expand All @@ -60,7 +60,7 @@ export class Sort extends SortBase {

export class Reverse extends SortBase {
protected sortTexts(texts: string[]) {
return texts.reverse();
return texts.toReversed();
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/lib-engine/src/core/getPreferredSnippet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function getUniqueLanguagesString(snippets: CustomInsertSnippetArg[]): string {
const languages = new Set(
snippets.flatMap((snippet) => snippet.languages ?? []),
);
return Array.from(languages).sort().join(", ");
return Array.from(languages).toSorted().join(", ");
}

function tryToFindPreferredSnippet<
Expand Down
2 changes: 1 addition & 1 deletion packages/lib-engine/src/core/handleHoistedModifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export function handleHoistedModifiers(
// modifier to the range owns the range. For example if you say "every line
// every funk air past bat", the "every line" owns the range, and the "every
// funk" is applied to the output.
for (const [modifier, idx] of indexedModifiers.reverse()) {
for (const [modifier, idx] of indexedModifiers.toReversed()) {
for (const hoistedModifierType of hoistedModifierTypes) {
const acceptanceInfo = hoistedModifierType.accept(modifier);
if (acceptanceInfo.accepted) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ export function checkCaptureStartEnd(
const lastStart = captures
.filter(({ name }) => name.endsWith(".start"))
.map(({ range: { end } }) => end)
.sort((a, b) => a.compareTo(b))
.toSorted((a, b) => a.compareTo(b))
.at(-1);
const firstEnd = captures
.filter(({ name }) => name.endsWith(".end"))
.map(({ range: { start } }) => start)
.sort((a, b) => a.compareTo(b))
.toSorted((a, b) => a.compareTo(b))
.at(0);
if (lastStart != null && firstEnd != null) {
if (lastStart.isAfter(firstEnd)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ export function getModifierStagesFromTargetModifiers(
) {
// Reverse target modifiers because they are returned in reverse order from
// the api, to match the order in which they are spoken.
return targetModifiers.map(modifierStageFactory.create).reverse();
return targetModifiers.map(modifierStageFactory.create).toReversed();
}

/** Run all targets through the modifier stages */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ suite("BaseScopeHandler", () => {
}));

assert.deepEqual(
[...inputScopes]
.sort((a, b) =>
inputScopes
.toSorted((a, b) =>
compareTargetScopes(testCase.direction, position, a, b),
)
.map(fromScope),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function getNotebookCells(
) {
return direction === "forward"
? notebook.cells.slice(cell.index + 1)
: notebook.cells.slice(0, cell.index).reverse();
: notebook.cells.slice(0, cell.index).toReversed();
}

// Every scope
Expand All @@ -81,7 +81,7 @@ function getNotebookCells(

return direction === "forward"
? notebook.cells.slice(cell.index)
: notebook.cells.slice(0, cell.index + 1).reverse();
: notebook.cells.slice(0, cell.index + 1).toReversed();
}

function getNotebook(ide: IDE, editor: TextEditor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export class SentenceScopeHandler extends NestedScopeHandler {

return direction === "forward"
? imap(sentences, sentenceToScope)
: Array.from(sentences, sentenceToScope).reverse();
: // oxlint-disable-next-line unicorn/no-array-reverse
Array.from(sentences, sentenceToScope).reverse();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export class SurroundingPairScopeHandler extends BaseScopeHandler {
this.scopeType.requireStrongContainment ?? false,
),
)
// oxlint-disable-next-line unicorn/no-array-sort
.sort((a, b) => compareTargetScopes(direction, position, a, b));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,6 @@ function getSortedCaptures(items?: QueryCapture[]): QueryCapture[] {
if (items == null) {
return [];
}
return items.sort((a, b) => a.range.start.compareTo(b.range.start));
items.sort((a, b) => a.range.start.compareTo(b.range.start));
return items;
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export abstract class BaseTreeSitterScopeHandler extends BaseScopeHandler {
.matches(document, start, end)
.map((match) => this.matchToScope(editor, match, isEveryScope))
.filter((scope): scope is ExtendedTargetScope => scope != null)
// oxlint-disable-next-line unicorn/no-array-sort
.sort((a, b) => compareTargetScopes(direction, position, a, b));

// Merge scopes that have the same domain into a single scope with multiple
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ export class ScopeSupportWatcher {

const scopeTypeInfos = this.scopeInfoProvider.getScopeTypeInfos();

// oxlint-disable-next-line oxc/no-map-spread
return scopeTypeInfos.map((scopeTypeInfo) => ({
...scopeTypeInfo,
support: getScopeTypeSupport(scopeTypeInfo.scopeType),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ export function checkMarks(originalFixture: TestCaseFixtureLegacy): undefined {
const actualMarks = Object.keys(originalFixture.initialState.marks ?? {});

assert.deepEqual(
uniq(actualMarks.map(normalizeGraphemes)).sort(),
uniq(expectedMarks.map(normalizeGraphemes)).sort(),
uniq(actualMarks.map(normalizeGraphemes)).toSorted(),
uniq(expectedMarks.map(normalizeGraphemes)).toSorted(),
);

return undefined;
Expand Down
6 changes: 3 additions & 3 deletions packages/lib-engine/src/test/scopes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ suite("Scope test cases", () => {
languages[language] ??= [];
}

for (const languageId of Object.keys(languages).sort()) {
for (const languageId of Object.keys(languages).toSorted()) {
const tests = languages[languageId];
test(`${languageId} facet coverage`, () =>
testLanguageSupport(
Expand Down Expand Up @@ -91,7 +91,7 @@ function testLanguageSupport(languageId: string, testedFacets: string[]) {
(testedFacet) => !supportedFacets.includes(testedFacet),
);
if (unsupportedFacets.length > 0) {
const values = uniq(unsupportedFacets).sort().join(", ");
const values = uniq(unsupportedFacets).toSorted().join(", ");
assert.fail(
`Facets [${values}] are tested but not listed in getLanguageScopeSupport`,
);
Expand All @@ -102,7 +102,7 @@ function testLanguageSupport(languageId: string, testedFacets: string[]) {
(supportedFacet) => !testedFacets.includes(supportedFacet),
);
if (untestedFacets.length > 0) {
const values = untestedFacets.sort().join(", ");
const values = untestedFacets.toSorted().join(", ");
assert.fail(`Missing test for scope support facets [${values}]`);
}
}
Expand Down
10 changes: 4 additions & 6 deletions packages/lib-engine/src/tokenizer/tokenizer.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as assert from "node:assert/strict";
import { flatten, range } from "lodash-es";
import { range } from "lodash-es";
import { FakeIDE } from "@cursorless/lib-common";
import { tokenize } from ".";

Expand Down Expand Up @@ -167,11 +167,9 @@ function getAsciiSymbols() {
["[", "`"],
["{", "~"],
];
return flatten(
rangesToTest.map(([start, end]) =>
range(start.codePointAt(0)!, end.codePointAt(0)! + 1).map((charCode) =>
String.fromCodePoint(charCode),
),
return rangesToTest.flatMap(([start, end]) =>
range(start.codePointAt(0)!, end.codePointAt(0)! + 1).map((charCode) =>
String.fromCodePoint(charCode),
),
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ export function getDisplayLineMap(
...editor.visibleRanges.flatMap((visibleRange) =>
range(visibleRange.start.line, visibleRange.end.line + 1),
),
]).sort((a, b) => a - b);
]);

lines.sort((a, b) => a - b);

return new Map(lines.map((value, index) => [value, index]));
}
Loading
Loading