Skip to content

Commit

Permalink
Enabled more ESLint rules.
Browse files Browse the repository at this point in the history
  • Loading branch information
reduckted committed Dec 14, 2024
1 parent a5bdfee commit 46d461c
Show file tree
Hide file tree
Showing 30 changed files with 217 additions and 162 deletions.
24 changes: 24 additions & 0 deletions vscode/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
{
Expand All @@ -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',
{
Expand All @@ -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 }],
Expand Down
49 changes: 21 additions & 28 deletions vscode/src/commands/get-link-command.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,24 @@
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,
Repository,
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';

/**
Expand Down Expand Up @@ -265,8 +258,8 @@ export class GetLinkCommand {
* @returns The target, or undefined to cancel the operation.
*/
private async promptForLinkTarget(info: ResourceInfo): Promise<LinkTarget | undefined> {
let items: (QuickPickLinkTargetItem | QuickPickItem)[];
let selection: QuickPickLinkTargetItem | QuickPickItem | undefined;
let items: (QuickPickItem | QuickPickLinkTargetItem)[];
let selection: QuickPickItem | QuickPickLinkTargetItem | undefined;

items = [
...(await this.getPresetTargetItems(info)),
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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';
}
21 changes: 9 additions & 12 deletions vscode/src/commands/go-to-file-command.ts
Original file line number Diff line number Diff line change
@@ -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';

/**
Expand Down
15 changes: 10 additions & 5 deletions vscode/src/commands/index.ts
Original file line number Diff line number Diff line change
@@ -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';

/**
Expand Down
3 changes: 2 additions & 1 deletion vscode/src/context-manager.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
7 changes: 5 additions & 2 deletions vscode/src/extension.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
12 changes: 8 additions & 4 deletions vscode/src/git.ts
Original file line number Diff line number Diff line change
@@ -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';

/**
Expand Down Expand Up @@ -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<string> {
public async exec(root: string | Uri, ...args: string[]): Promise<string> {
let child: ChildProcessWithoutNullStreams;
// Handle non-ASCII characters in filenames.
// See https://stackoverflow.com/questions/4144417/
Expand Down
5 changes: 3 additions & 2 deletions vscode/src/link-handler-provider.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
24 changes: 14 additions & 10 deletions vscode/src/link-handler.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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';

/**
Expand Down
4 changes: 3 additions & 1 deletion vscode/src/log.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
16 changes: 9 additions & 7 deletions vscode/src/remote-server.ts
Original file line number Diff line number Diff line change
@@ -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';

/**
Expand All @@ -16,9 +18,9 @@ export class RemoteServer {
*/
public constructor(
servers:
| StaticServer
| (DynamicServer | StaticServer)[]
| DynamicServer
| (StaticServer | DynamicServer)[]
| StaticServer
| StaticServerFactory
) {
if (typeof servers === 'function') {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)) {
Expand Down
7 changes: 4 additions & 3 deletions vscode/src/repository-finder.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 2 additions & 2 deletions vscode/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
9 changes: 6 additions & 3 deletions vscode/src/settings.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
3 changes: 2 additions & 1 deletion vscode/src/strings.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Uri } from 'vscode';

import { format } from 'util';
import { Uri } from 'vscode';

export const STRINGS = {
extension: {
Expand Down
Loading

0 comments on commit 46d461c

Please sign in to comment.