From 46d461c9fdaf1edb233d31faa7c89ead1b064252 Mon Sep 17 00:00:00 2001 From: reduckted Date: Sat, 14 Dec 2024 16:20:32 +1000 Subject: [PATCH] Enabled more ESLint rules. --- vscode/eslint.config.js | 24 +++++++++ vscode/src/commands/get-link-command.ts | 49 ++++++++----------- vscode/src/commands/go-to-file-command.ts | 21 ++++---- vscode/src/commands/index.ts | 15 ++++-- vscode/src/context-manager.ts | 3 +- vscode/src/extension.ts | 7 ++- vscode/src/git.ts | 12 +++-- vscode/src/link-handler-provider.ts | 5 +- vscode/src/link-handler.ts | 24 +++++---- vscode/src/log.ts | 4 +- vscode/src/remote-server.ts | 16 +++--- vscode/src/repository-finder.ts | 7 +-- vscode/src/schema.ts | 4 +- vscode/src/settings.ts | 9 ++-- vscode/src/strings.ts | 3 +- vscode/src/templates.ts | 8 +-- vscode/src/types.ts | 12 ++--- vscode/src/utilities.ts | 6 ++- vscode/test/commands/get-link-command.test.ts | 42 ++++++++-------- .../test/commands/go-to-file-command.test.ts | 26 +++------- vscode/test/context-manager.test.ts | 7 ++- vscode/test/handlers.test.ts | 36 ++++++++------ vscode/test/helpers/git-extension.ts | 3 +- vscode/test/helpers/index.ts | 7 +-- vscode/test/link-handler.test.ts | 7 +-- vscode/test/remote-server.test.ts | 5 +- vscode/test/repository-finder.test.ts | 5 +- vscode/test/templates.test.ts | 4 +- vscode/test/test-schema.ts | 4 +- vscode/test/utilities.test.ts | 4 +- 30 files changed, 217 insertions(+), 162 deletions(-) diff --git a/vscode/eslint.config.js b/vscode/eslint.config.js index d5d6f1e..10dbd5b 100644 --- a/vscode/eslint.config.js +++ b/vscode/eslint.config.js @@ -51,6 +51,7 @@ module.exports = tseslint.config( 'warn', { assertionStyle: 'as', objectLiteralTypeAssertions: 'allow' } ], + '@typescript-eslint/consistent-type-imports': 'warn', '@typescript-eslint/explicit-function-return-type': [ 'warn', { @@ -69,6 +70,8 @@ module.exports = tseslint.config( '@typescript-eslint/prefer-readonly': 'warn', '@typescript-eslint/promise-function-async': 'warn', '@typescript-eslint/restrict-template-expressions': 'off', + 'perfectionist/sort-heritage-clauses': 'warn', + 'perfectionist/sort-named-imports': 'warn', 'perfectionist/sort-imports': [ 'warn', { @@ -83,6 +86,27 @@ module.exports = tseslint.config( ] } ], + 'perfectionist/sort-union-types': [ + 'warn', + { + groups: [ + [ + 'conditional', + 'function', + 'import', + 'intersection', + 'keyword', + 'literal', + 'named', + 'object', + 'operator', + 'tuple', + 'union' + ], + 'nullish' + ] + } + ], 'jest/no-focused-tests': 'warn', 'jsdoc/require-description': ['warn', { checkConstructors: false }], 'jsdoc/require-returns': ['warn', { checkGetters: false }], diff --git a/vscode/src/commands/get-link-command.ts b/vscode/src/commands/get-link-command.ts index bd55798..e7e8636 100644 --- a/vscode/src/commands/get-link-command.ts +++ b/vscode/src/commands/get-link-command.ts @@ -1,24 +1,10 @@ -import { - commands, - env, - MessageItem, - QuickPickItem, - QuickPickItemKind, - Range, - TextEditor, - Uri, - window -} from 'vscode'; - -import { Git } from '../git'; -import { CreateUrlResult, LinkHandler } from '../link-handler'; -import { LinkHandlerProvider, SelectedLinkHandler } from '../link-handler-provider'; -import { log } from '../log'; -import { NoRemoteHeadError } from '../no-remote-head-error'; -import { RepositoryFinder } from '../repository-finder'; -import { Settings } from '../settings'; -import { STRINGS } from '../strings'; -import { +import type { MessageItem, QuickPickItem, TextEditor } from 'vscode'; + +import type { Git } from '../git'; +import type { CreateUrlResult, LinkHandler } from '../link-handler'; +import type { LinkHandlerProvider, SelectedLinkHandler } from '../link-handler-provider'; +import type { RepositoryFinder } from '../repository-finder'; +import type { LinkFormat, LinkTarget, LinkType, @@ -26,6 +12,13 @@ import { RepositoryWithRemote, SelectedRange } from '../types'; + +import { commands, env, QuickPickItemKind, Range, Uri, window } from 'vscode'; + +import { log } from '../log'; +import { NoRemoteHeadError } from '../no-remote-head-error'; +import { Settings } from '../settings'; +import { STRINGS } from '../strings'; import { getErrorMessage, getSelectedRange, hasRemote } from '../utilities'; /** @@ -265,8 +258,8 @@ export class GetLinkCommand { * @returns The target, or undefined to cancel the operation. */ private async promptForLinkTarget(info: ResourceInfo): Promise { - let items: (QuickPickLinkTargetItem | QuickPickItem)[]; - let selection: QuickPickLinkTargetItem | QuickPickItem | undefined; + let items: (QuickPickItem | QuickPickLinkTargetItem)[]; + let selection: QuickPickItem | QuickPickLinkTargetItem | undefined; items = [ ...(await this.getPresetTargetItems(info)), @@ -365,9 +358,9 @@ export class GetLinkCommand { */ private async getRefTargetItems( info: ResourceInfo - ): Promise<(QuickPickLinkTargetItem | QuickPickItem)[]> { - let branches: (QuickPickLinkTargetItem | QuickPickItem)[]; - let commits: (QuickPickLinkTargetItem | QuickPickItem)[]; + ): Promise<(QuickPickItem | QuickPickLinkTargetItem)[]> { + let branches: (QuickPickItem | QuickPickLinkTargetItem)[]; + let commits: (QuickPickItem | QuickPickLinkTargetItem)[]; let lines: string[]; let useShortHashes: boolean; @@ -514,7 +507,7 @@ export interface GetLinkCommandOptions { * The type of link the command will produce, or 'prompt' to ask the user which ref to use a function to get the * link type, or `undefined` to use the settings to determine the link type). */ - linkType: LinkType | 'prompt' | undefined; + linkType: 'prompt' | LinkType | undefined; /** * Whether to include the selection region @@ -570,5 +563,5 @@ interface ActionMessageItem extends MessageItem { /** * The action to perform. */ - action: 'settings' | 'open' | 'copy-raw' | 'copy-markdown' | 'copy-markdown-with-preview'; + action: 'copy-markdown-with-preview' | 'copy-markdown' | 'copy-raw' | 'open' | 'settings'; } diff --git a/vscode/src/commands/go-to-file-command.ts b/vscode/src/commands/go-to-file-command.ts index 328e9c3..63c7001 100644 --- a/vscode/src/commands/go-to-file-command.ts +++ b/vscode/src/commands/go-to-file-command.ts @@ -1,25 +1,22 @@ -import { - commands, - env, +import type { FileStat, - FileType, QuickPickItem, Selection, TextDocument, TextEditor, - TextLine, - Uri, - window, - workspace + TextLine } from 'vscode'; -import { LinkHandlerProvider } from '../link-handler-provider'; +import type { LinkHandlerProvider } from '../link-handler-provider'; +import type { RepositoryFinder } from '../repository-finder'; +import type { StaticServer } from '../schema'; +import type { Repository, RepositoryWithRemote, SelectedRange, UrlInfo } from '../types'; + +import { commands, env, FileType, Uri, window, workspace } from 'vscode'; + import { log } from '../log'; import { RemoteServer } from '../remote-server'; -import { RepositoryFinder } from '../repository-finder'; -import { StaticServer } from '../schema'; import { STRINGS } from '../strings'; -import { Repository, RepositoryWithRemote, SelectedRange, UrlInfo } from '../types'; import { hasRemote, toSelection } from '../utilities'; /** diff --git a/vscode/src/commands/index.ts b/vscode/src/commands/index.ts index 8e70917..b962ca0 100644 --- a/vscode/src/commands/index.ts +++ b/vscode/src/commands/index.ts @@ -1,11 +1,16 @@ -import { commands, Disposable, Uri } from 'vscode'; +import type { Disposable, Uri } from 'vscode'; + +import type { Git } from '../git'; +import type { LinkHandlerProvider } from '../link-handler-provider'; +import type { RepositoryFinder } from '../repository-finder'; + +import type { GetLinkCommandOptions } from './get-link-command'; + +import { commands } from 'vscode'; import { COMMANDS } from '../constants'; -import { Git } from '../git'; -import { LinkHandlerProvider } from '../link-handler-provider'; -import { RepositoryFinder } from '../repository-finder'; -import { GetLinkCommand, GetLinkCommandOptions } from './get-link-command'; +import { GetLinkCommand } from './get-link-command'; import { GoToFileCommand } from './go-to-file-command'; /** diff --git a/vscode/src/context-manager.ts b/vscode/src/context-manager.ts index f6d8b02..bfadbdb 100644 --- a/vscode/src/context-manager.ts +++ b/vscode/src/context-manager.ts @@ -1,7 +1,8 @@ +import type { Git, GitRepository } from './git'; + import { commands, Disposable, workspace } from 'vscode'; import { CONFIGURATION, CONTEXT } from './constants'; -import { Git, GitRepository } from './git'; import { log } from './log'; import { Settings } from './settings'; diff --git a/vscode/src/extension.ts b/vscode/src/extension.ts index 59f5086..36d6343 100644 --- a/vscode/src/extension.ts +++ b/vscode/src/extension.ts @@ -1,6 +1,9 @@ -import { ExtensionContext, window, extensions, Disposable } from 'vscode'; +import type { Disposable, ExtensionContext } from 'vscode'; + +import type { GitExtension } from './api/git'; + +import { extensions, window } from 'vscode'; -import { GitExtension } from './api/git'; import { registerCommands } from './commands'; import { ContextManager } from './context-manager'; import { Git } from './git'; diff --git a/vscode/src/git.ts b/vscode/src/git.ts index 33d13f3..0e1f2d1 100644 --- a/vscode/src/git.ts +++ b/vscode/src/git.ts @@ -1,7 +1,11 @@ -import { ChildProcessWithoutNullStreams, spawn } from 'child_process'; -import { Disposable, EventEmitter, Event, Uri } from 'vscode'; +import type { ChildProcessWithoutNullStreams } from 'child_process'; +import type { Event, Uri } from 'vscode'; + +import type { API, Remote, Repository } from './api/git'; + +import { spawn } from 'child_process'; +import { Disposable, EventEmitter } from 'vscode'; -import { API, Remote, Repository } from './api/git'; import { log } from './log'; /** @@ -65,7 +69,7 @@ export class Git extends Disposable { * @param args The arguments to pass to Git. * @returns The output of the command. */ - public async exec(root: Uri | string, ...args: string[]): Promise { + public async exec(root: string | Uri, ...args: string[]): Promise { let child: ChildProcessWithoutNullStreams; // Handle non-ASCII characters in filenames. // See https://stackoverflow.com/questions/4144417/ diff --git a/vscode/src/link-handler-provider.ts b/vscode/src/link-handler-provider.ts index 541da65..75d4eb1 100644 --- a/vscode/src/link-handler-provider.ts +++ b/vscode/src/link-handler-provider.ts @@ -1,8 +1,9 @@ -import { Git } from './git'; +import type { Git } from './git'; +import type { RepositoryWithRemote, UrlInfo } from './types'; + import { LinkHandler } from './link-handler'; import { log } from './log'; import { load } from './schema'; -import { RepositoryWithRemote, UrlInfo } from './types'; /** * Provides access to the link handlers. diff --git a/vscode/src/link-handler.ts b/vscode/src/link-handler.ts index d7d471c..c22bc5c 100644 --- a/vscode/src/link-handler.ts +++ b/vscode/src/link-handler.ts @@ -1,19 +1,14 @@ -import { promises as fs, Stats } from 'fs'; -import * as path from 'path'; -import { URL } from 'url'; +import type { Stats } from 'fs'; -import { Git } from './git'; -import { NoRemoteHeadError } from './no-remote-head-error'; -import { RemoteServer } from './remote-server'; -import { +import type { Git } from './git'; +import type { HandlerDefinition, ReverseSelectionSettings, ReverseServerSettings, StaticServer } from './schema'; -import { Settings } from './settings'; -import { ParsedTemplate, parseTemplate } from './templates'; -import { +import type { ParsedTemplate } from './templates'; +import type { FileInfo, LinkOptions, LinkType, @@ -22,6 +17,15 @@ import { SelectedRange, UrlInfo } from './types'; + +import { promises as fs } from 'fs'; +import * as path from 'path'; +import { URL } from 'url'; + +import { NoRemoteHeadError } from './no-remote-head-error'; +import { RemoteServer } from './remote-server'; +import { Settings } from './settings'; +import { parseTemplate } from './templates'; import { getErrorMessage, normalizeUrl } from './utilities'; /** diff --git a/vscode/src/log.ts b/vscode/src/log.ts index f1de187..b90548c 100644 --- a/vscode/src/log.ts +++ b/vscode/src/log.ts @@ -1,5 +1,7 @@ +import type { OutputChannel } from 'vscode'; + import { format } from 'util'; -import { OutputChannel, window } from 'vscode'; +import { window } from 'vscode'; let channel: OutputChannel | undefined; diff --git a/vscode/src/remote-server.ts b/vscode/src/remote-server.ts index fc6be4a..d23a730 100644 --- a/vscode/src/remote-server.ts +++ b/vscode/src/remote-server.ts @@ -1,7 +1,9 @@ +import type { DynamicServer, StaticServer } from './schema'; +import type { ParsedTemplate } from './templates'; +import type { Mutable } from './types'; + import { log } from './log'; -import { DynamicServer, StaticServer } from './schema'; -import { ParsedTemplate, parseTemplate } from './templates'; -import { Mutable } from './types'; +import { parseTemplate } from './templates'; import { normalizeUrl } from './utilities'; /** @@ -16,9 +18,9 @@ export class RemoteServer { */ public constructor( servers: - | StaticServer + | (DynamicServer | StaticServer)[] | DynamicServer - | (StaticServer | DynamicServer)[] + | StaticServer | StaticServerFactory ) { if (typeof servers === 'function') { @@ -83,7 +85,7 @@ export class RemoteServer { * @param server The server definition. * @returns The matcher function. */ -function createMatcher(server: StaticServer | DynamicServer): Matcher { +function createMatcher(server: DynamicServer | StaticServer): Matcher { if ('remotePattern' in server) { return createDynamicServerMatcher(server); } else { @@ -235,7 +237,7 @@ function createLazyStaticServerMatcher(factory: StaticServerFactory): Matcher { * @param test The function to test a match. * @returns The matcher function. */ - function create(test: typeof isWebMatch | typeof isRemoteMatch): Matcher['remote'] { + function create(test: typeof isRemoteMatch | typeof isWebMatch): Matcher['remote'] { return (url) => { for (let server of factory()) { if (test(url, server)) { diff --git a/vscode/src/repository-finder.ts b/vscode/src/repository-finder.ts index 96f4b17..4181a71 100644 --- a/vscode/src/repository-finder.ts +++ b/vscode/src/repository-finder.ts @@ -1,9 +1,10 @@ -import { Uri } from 'vscode'; +import type { Uri } from 'vscode'; + +import type { Git, GitRemote, GitRepository } from './git'; +import type { Remote, Repository } from './types'; -import { Git, GitRemote, GitRepository } from './git'; import { log } from './log'; import { Settings } from './settings'; -import { Repository, Remote } from './types'; /** * Finds the repository that a workspace belongs to. diff --git a/vscode/src/schema.ts b/vscode/src/schema.ts index 3294f5e..b906684 100644 --- a/vscode/src/schema.ts +++ b/vscode/src/schema.ts @@ -6,7 +6,7 @@ import * as path from 'path'; /** * Defines a handler */ -export type HandlerDefinition = PublicHandlerDefinition | PrivateHandlerDefinition; +export type HandlerDefinition = PrivateHandlerDefinition | PublicHandlerDefinition; /** * Defines a handler for a public remote host. @@ -174,7 +174,7 @@ export type Template = string | string[]; /** * Defines the server that the handler matches to. */ -export type Server = StaticServer | DynamicServer[]; +export type Server = DynamicServer[] | StaticServer; /** * Defines a server with a fixed address. diff --git a/vscode/src/settings.ts b/vscode/src/settings.ts index 4badaa7..4cd1ce7 100644 --- a/vscode/src/settings.ts +++ b/vscode/src/settings.ts @@ -1,8 +1,11 @@ -import { workspace, WorkspaceConfiguration } from 'vscode'; +import type { WorkspaceConfiguration } from 'vscode'; + +import type { StaticServer } from './schema'; +import type { LinkFormat, LinkType } from './types'; + +import { workspace } from 'vscode'; import { CONFIGURATION } from './constants'; -import { StaticServer } from './schema'; -import { LinkFormat, LinkType } from './types'; /** * Provides access to the extension's settings. diff --git a/vscode/src/strings.ts b/vscode/src/strings.ts index e7f8326..a8b5345 100644 --- a/vscode/src/strings.ts +++ b/vscode/src/strings.ts @@ -1,5 +1,6 @@ +import type { Uri } from 'vscode'; + import { format } from 'util'; -import { Uri } from 'vscode'; export const STRINGS = { extension: { diff --git a/vscode/src/templates.ts b/vscode/src/templates.ts index f0c6480..17bb212 100644 --- a/vscode/src/templates.ts +++ b/vscode/src/templates.ts @@ -1,7 +1,9 @@ -import { Liquid, Template as LiquidTemplate } from 'liquidjs'; -import { posix } from 'path'; +import type { Template as LiquidTemplate } from 'liquidjs'; + +import type { Template } from './schema'; -import { Template } from './schema'; +import { Liquid } from 'liquidjs'; +import { posix } from 'path'; const engine: Liquid = new Liquid({ strictFilters: true diff --git a/vscode/src/types.ts b/vscode/src/types.ts index dea625b..5801990 100644 --- a/vscode/src/types.ts +++ b/vscode/src/types.ts @@ -1,16 +1,16 @@ -import { Uri } from 'vscode'; +import type { Uri } from 'vscode'; -import { StaticServer } from './schema'; +import type { StaticServer } from './schema'; /** * The type of link to generate. */ -export type LinkType = 'commit' | 'branch' | 'defaultBranch'; +export type LinkType = 'branch' | 'commit' | 'defaultBranch'; /** * The format to use when copying a link. */ -export type LinkFormat = 'raw' | 'markdown' | 'markdownWithPreview'; +export type LinkFormat = 'markdown' | 'markdownWithPreview' | 'raw'; /** * Information about a Git repository. @@ -92,7 +92,7 @@ export interface LinkOptions { /** * A link target. */ -export type LinkTarget = LinkTargetRef | LinkTargetPreset; +export type LinkTarget = LinkTargetPreset | LinkTargetRef; export interface LinkTargetRef { /** @@ -103,7 +103,7 @@ export interface LinkTargetRef { /** * What the ref refers to. */ - readonly type: 'commit' | 'branch'; + readonly type: 'branch' | 'commit'; } export interface LinkTargetPreset { diff --git a/vscode/src/utilities.ts b/vscode/src/utilities.ts index b0bccfd..9dce4e6 100644 --- a/vscode/src/utilities.ts +++ b/vscode/src/utilities.ts @@ -1,6 +1,8 @@ -import { Position, Selection, TextEditor } from 'vscode'; +import type { TextEditor } from 'vscode'; -import { Repository, RepositoryWithRemote, SelectedRange } from './types'; +import type { Repository, RepositoryWithRemote, SelectedRange } from './types'; + +import { Position, Selection } from 'vscode'; /** * Determines whether the given repository has a remote. diff --git a/vscode/test/commands/get-link-command.test.ts b/vscode/test/commands/get-link-command.test.ts index fc987b9..da77e47 100644 --- a/vscode/test/commands/get-link-command.test.ts +++ b/vscode/test/commands/get-link-command.test.ts @@ -1,29 +1,17 @@ -import * as chai from 'chai'; -import * as fs from 'fs/promises'; -import * as path from 'path'; -import * as sinon from 'sinon'; -import * as sinonChai from 'sinon-chai'; -import { +import type { CancellationToken, - env, MessageItem, - Position, QuickPickItem, QuickPickOptions, Selection, - TextDocument, - Uri, - window + TextDocument } from 'vscode'; -import { GetLinkCommand, GetLinkCommandOptions } from '../../src/commands/get-link-command'; -import { Git } from '../../src/git'; -import { CreateUrlResult, LinkHandler } from '../../src/link-handler'; -import { LinkHandlerProvider, SelectedLinkHandler } from '../../src/link-handler-provider'; -import { RepositoryFinder } from '../../src/repository-finder'; -import { Settings } from '../../src/settings'; -import { STRINGS } from '../../src/strings'; -import { +import type { GetLinkCommandOptions } from '../../src/commands/get-link-command'; +import type { Git } from '../../src/git'; +import type { CreateUrlResult } from '../../src/link-handler'; +import type { SelectedLinkHandler } from '../../src/link-handler-provider'; +import type { FileInfo, LinkFormat, LinkOptions, @@ -31,6 +19,20 @@ import { Repository, RepositoryWithRemote } from '../../src/types'; + +import * as chai from 'chai'; +import * as fs from 'fs/promises'; +import * as path from 'path'; +import * as sinon from 'sinon'; +import * as sinonChai from 'sinon-chai'; +import { env, Position, Uri, window } from 'vscode'; + +import { GetLinkCommand } from '../../src/commands/get-link-command'; +import { LinkHandler } from '../../src/link-handler'; +import { LinkHandlerProvider } from '../../src/link-handler-provider'; +import { RepositoryFinder } from '../../src/repository-finder'; +import { Settings } from '../../src/settings'; +import { STRINGS } from '../../src/strings'; import { Directory, getGitService, markAsSlow, setupRepository } from '../helpers'; const expect = chai.use(sinonChai).expect; @@ -748,7 +750,7 @@ describe('GetLinkCommand', () => { function useTextEditor( uri: Uri | undefined, - selection?: Pick, + selection?: Pick, lines?: string[], languageId?: string ): void { diff --git a/vscode/test/commands/go-to-file-command.test.ts b/vscode/test/commands/go-to-file-command.test.ts index 73954ae..f217341 100644 --- a/vscode/test/commands/go-to-file-command.test.ts +++ b/vscode/test/commands/go-to-file-command.test.ts @@ -1,29 +1,19 @@ +import type { InputBoxOptions, TextDocument, TextEditor, TextLine } from 'vscode'; + +import type { Git } from '../../src/git'; +import type { Repository, SelectedRange, UrlInfo } from '../../src/types'; + import * as chai from 'chai'; import { promises as fs } from 'fs'; import { join } from 'path'; import * as sinon from 'sinon'; import * as sinonChai from 'sinon-chai'; -import { - commands, - env, - InputBoxOptions, - Position, - Range, - Selection, - TextDocument, - TextEditor, - TextLine, - Uri, - window, - workspace -} from 'vscode'; +import { commands, env, Position, Range, Selection, Uri, window, workspace } from 'vscode'; import { GoToFileCommand } from '../../src/commands/go-to-file-command'; -import { Git } from '../../src/git'; import { LinkHandlerProvider } from '../../src/link-handler-provider'; import { RepositoryFinder } from '../../src/repository-finder'; import { STRINGS } from '../../src/strings'; -import { Repository, SelectedRange, UrlInfo } from '../../src/types'; import { toSelection } from '../../src/utilities'; import { Directory, getGitService, matchUri } from '../helpers'; @@ -540,7 +530,7 @@ describe('GoToFileLinkCommand', () => { } for (let name in folder.children) { - let childFolder: Folder | 'file'; + let childFolder: 'file' | Folder; let childPath: string; childFolder = folder.children[name]; @@ -611,6 +601,6 @@ describe('GoToFileLinkCommand', () => { interface Folder { repository?: string; - children: Record; + children: Record; } }); diff --git a/vscode/test/context-manager.test.ts b/vscode/test/context-manager.test.ts index 4ca09d4..32baa37 100644 --- a/vscode/test/context-manager.test.ts +++ b/vscode/test/context-manager.test.ts @@ -1,10 +1,13 @@ +import type { ConfigurationChangeEvent } from 'vscode'; + +import type { Git, GitRepository } from '../src/git'; + import { expect } from 'chai'; import * as sinon from 'sinon'; -import { commands, ConfigurationChangeEvent, EventEmitter, workspace } from 'vscode'; +import { commands, EventEmitter, workspace } from 'vscode'; import { CONTEXT } from '../src/constants'; import { ContextManager } from '../src/context-manager'; -import { Git, GitRepository } from '../src/git'; import { Settings } from '../src/settings'; import { getGitService } from './helpers'; diff --git a/vscode/test/handlers.test.ts b/vscode/test/handlers.test.ts index 4d613ba..0cb8f5e 100644 --- a/vscode/test/handlers.test.ts +++ b/vscode/test/handlers.test.ts @@ -1,27 +1,33 @@ -import Ajv, { AnySchema } from 'ajv'; +import type { AnySchema } from 'ajv'; + +import type { Git } from '../src/git'; +import type { CreateUrlResult } from '../src/link-handler'; +import type { SelectedLinkHandler } from '../src/link-handler-provider'; +import type { Template } from '../src/schema'; +import type { LinkOptions, RepositoryWithRemote, SelectedRange, UrlInfo } from '../src/types'; + +import type { + HandlerWithTests, + RemoteUrlTests, + SelectionTests, + TestSettings, + UrlTest, + UrlTests +} from './test-schema'; + +import Ajv from 'ajv'; import { expect } from 'chai'; import { promises as fs } from 'fs'; import * as path from 'path'; import * as sinon from 'sinon'; import { Uri, workspace } from 'vscode'; -import { Git } from '../src/git'; -import { CreateUrlResult } from '../src/link-handler'; -import { LinkHandlerProvider, SelectedLinkHandler } from '../src/link-handler-provider'; -import { findHandlersDirectory, load, Template } from '../src/schema'; +import { LinkHandlerProvider } from '../src/link-handler-provider'; +import { findHandlersDirectory, load } from '../src/schema'; import { parseTemplate } from '../src/templates'; -import { LinkOptions, RepositoryWithRemote, SelectedRange, UrlInfo } from '../src/types'; import { normalizeUrl } from '../src/utilities'; import { Directory, getGitService, markAsSlow, setupRemote, setupRepository } from './helpers'; -import { - HandlerWithTests, - RemoteUrlTests, - SelectionTests, - TestSettings, - UrlTest, - UrlTests -} from './test-schema'; const TEST_FILE_NAME: string = 'src/file.txt'; const TEST_FILE_NAME_WITH_SPACES: string = 'src/path spaces/file spaces.txt'; @@ -456,7 +462,7 @@ describe('Link handlers', function () { } type RemoteTestName = keyof Omit; - type UrlTestName = keyof Omit; + type UrlTestName = keyof Omit; type SelectionTestName = keyof Omit; }); }); diff --git a/vscode/test/helpers/git-extension.ts b/vscode/test/helpers/git-extension.ts index af8e6c6..d3bf45e 100644 --- a/vscode/test/helpers/git-extension.ts +++ b/vscode/test/helpers/git-extension.ts @@ -1,6 +1,7 @@ +import type { GitExtension } from '../../src/api/git'; + import { extensions } from 'vscode'; -import { GitExtension } from '../../src/api/git'; import { Git } from '../../src/git'; let git: Git | undefined; diff --git a/vscode/test/helpers/index.ts b/vscode/test/helpers/index.ts index 41f6797..eeb4c18 100644 --- a/vscode/test/helpers/index.ts +++ b/vscode/test/helpers/index.ts @@ -1,9 +1,10 @@ +import type { Uri } from 'vscode'; + +import type { Git } from '../../src/git'; + import { promises as fs } from 'fs'; import * as path from 'path'; import * as sinon from 'sinon'; -import { Uri } from 'vscode'; - -import { Git } from '../../src/git'; import { Directory } from './directory'; import { getGitService } from './git-extension'; diff --git a/vscode/test/link-handler.test.ts b/vscode/test/link-handler.test.ts index b543764..ccf6f1a 100644 --- a/vscode/test/link-handler.test.ts +++ b/vscode/test/link-handler.test.ts @@ -1,15 +1,16 @@ +import type { Git } from '../src/git'; +import type { HandlerDefinition, ReverseSettings, StaticServer } from '../src/schema'; +import type { LinkOptions, LinkType, RepositoryWithRemote, UrlInfo } from '../src/types'; + import { expect } from 'chai'; import { promises as fs } from 'fs'; import * as path from 'path'; import * as sinon from 'sinon'; import { Uri } from 'vscode'; -import { Git } from '../src/git'; import { LinkHandler } from '../src/link-handler'; import { NoRemoteHeadError } from '../src/no-remote-head-error'; -import { HandlerDefinition, ReverseSettings, StaticServer } from '../src/schema'; import { Settings } from '../src/settings'; -import { LinkOptions, LinkType, RepositoryWithRemote, UrlInfo } from '../src/types'; import { isErrorCode } from '../src/utilities'; import { Directory, getGitService, markAsSlow, setupRemote, setupRepository } from './helpers'; diff --git a/vscode/test/remote-server.test.ts b/vscode/test/remote-server.test.ts index 4679340..65fe7b8 100644 --- a/vscode/test/remote-server.test.ts +++ b/vscode/test/remote-server.test.ts @@ -1,7 +1,8 @@ +import type { StaticServer } from '../src/schema'; + import { expect } from 'chai'; import { RemoteServer } from '../src/remote-server'; -import { StaticServer } from '../src/schema'; describe('RemoteServer', () => { let server: RemoteServer; @@ -407,7 +408,7 @@ describe('RemoteServer', () => { function match( expectedRemoteMatch: StaticServer | undefined, - expectedWebMatch: StaticServer | 'same' | undefined + expectedWebMatch: 'same' | StaticServer | undefined ): void { expect(server.matchRemoteUrl(url), 'remote').to.deep.equal(expectedRemoteMatch); expect(server.matchWebUrl(url), 'web').to.deep.equal( diff --git a/vscode/test/repository-finder.test.ts b/vscode/test/repository-finder.test.ts index 04f11ba..ec4f23c 100644 --- a/vscode/test/repository-finder.test.ts +++ b/vscode/test/repository-finder.test.ts @@ -1,9 +1,10 @@ +import type { RepositoryState } from '../src/api/git'; +import type { Git, GitRemote, GitRepository } from '../src/git'; + import { expect } from 'chai'; import * as sinon from 'sinon'; import { Uri } from 'vscode'; -import { RepositoryState } from '../src/api/git'; -import { Git, GitRemote, GitRepository } from '../src/git'; import { RepositoryFinder } from '../src/repository-finder'; import { Settings } from '../src/settings'; diff --git a/vscode/test/templates.test.ts b/vscode/test/templates.test.ts index 6b128c2..d73617d 100644 --- a/vscode/test/templates.test.ts +++ b/vscode/test/templates.test.ts @@ -1,6 +1,8 @@ +import type { ParsedTemplate } from '../src/templates'; + import { expect } from 'chai'; -import { ParsedTemplate, parseTemplate } from '../src/templates'; +import { parseTemplate } from '../src/templates'; describe('templates', () => { describe('parseTemplate', () => { diff --git a/vscode/test/test-schema.ts b/vscode/test/test-schema.ts index 01224ee..9e197bb 100644 --- a/vscode/test/test-schema.ts +++ b/vscode/test/test-schema.ts @@ -1,5 +1,5 @@ -import { HandlerDefinition, Template } from '../src/schema'; -import { SelectedRange } from '../src/types'; +import type { HandlerDefinition, Template } from '../src/schema'; +import type { SelectedRange } from '../src/types'; /** * Settings to make available during a test. diff --git a/vscode/test/utilities.test.ts b/vscode/test/utilities.test.ts index 7bc534c..819f439 100644 --- a/vscode/test/utilities.test.ts +++ b/vscode/test/utilities.test.ts @@ -1,6 +1,8 @@ +import type { TextEditor } from 'vscode'; + import { expect } from 'chai'; import * as assert from 'node:assert'; -import { commands, Position, Selection, TextEditor, Uri, window } from 'vscode'; +import { commands, Position, Selection, Uri, window } from 'vscode'; import { getSelectedRange, hasRemote, normalizeUrl, toSelection } from '../src/utilities';