Skip to content

Commit

Permalink
fix: upgrade eslint rules
Browse files Browse the repository at this point in the history
  • Loading branch information
weirongxu committed Jan 17, 2022
1 parent 58c6b74 commit 972bca3
Show file tree
Hide file tree
Showing 68 changed files with 467 additions and 488 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/types/pkg-config.d.ts
7 changes: 7 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"root": true,
"extends": ["@raidou/eslint-config-base"],
"rules": {
"@typescript-eslint/no-loop-func": "off"
}
}
61 changes: 0 additions & 61 deletions .eslintrc.json

This file was deleted.

File renamed without changes.
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,7 @@
},
"scripts": {
"clean": "rimraf lib",
"build:types": "node scripts/gen_package_type.js",
"build:types": "ts-node scripts/gen_package_type.ts",
"build:check-type": "tsc --noEmit",
"build:pack": "node build.js",
"build:config-doc": "ts-node ./scripts/gen_doc.ts",
Expand All @@ -1174,6 +1174,7 @@
"trash": "^7.2.0"
},
"devDependencies": {
"@raidou/eslint-config-base": "^1.5.0",
"@types/color-convert": "^2.0.0",
"@types/command-exists": "^1.2.0",
"@types/jest": "^27.4.0",
Expand All @@ -1184,8 +1185,6 @@
"@types/rimraf": "^3.0.2",
"@types/uuid": "^8.3.4",
"@types/which": "^2.0.1",
"@typescript-eslint/eslint-plugin": "^5.9.1",
"@typescript-eslint/parser": "^5.9.1",
"await-semaphore": "^0.1.3",
"coc-floatinput": "^1.5.6",
"coc-helper": "^0.12.1",
Expand Down
17 changes: 0 additions & 17 deletions scripts/gen_package_type.js

This file was deleted.

17 changes: 17 additions & 0 deletions scripts/gen_package_type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import Pkg from '../package.json';
import fs from 'fs';
import { compile } from 'json-schema-to-typescript';

const fsp = fs.promises;

async function main() {
const s = await compile(Pkg.contributes.configuration as any, 'Extension', {
style: {
semi: true,
singleQuote: true,
},
});
await fsp.writeFile('src/types/pkg-config.d.ts', s);
}

main().catch(console.error);
4 changes: 2 additions & 2 deletions src/__test__/helpers/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ export function bootSource<S extends ExplorerSource<any>>(
source: S;
};

const context: Context = ({
const context: Context = {
explorer: null,
source: null,
} as unknown) as Context;
} as unknown as Context;

beforeAll(() => {
context.explorer = getExplorer();
Expand Down
4 changes: 2 additions & 2 deletions src/__test__/helpers/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ export namespace NodesHelper {
children?: TreeNode[],
): TreeNode {
const expandable = !!children;
return ({
return {
name: pathLib.basename(path),
fullpath: path,
expandable,
type: 'child',
uid: generateUri(path, 'test'),
children,
} as unknown) as TreeNode;
} as unknown as TreeNode;
}

export function flattenNodes<TreeNode extends BaseTreeNode<TreeNode>>(
Expand Down
12 changes: 5 additions & 7 deletions src/actions/actionExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@ export class ActionExplorer extends ActionRegistrar<
super(owner);
}

async doActionByKey(key: string, mode: MappingMode, count: number = 1) {
async doActionByKey(key: string, mode: MappingMode, count = 1) {
for (let c = 0; c < count; c++) {
const selectedLineIndexes = await this.explorer.getSelectedOrCursorLineIndexes(
mode,
);
const lineIndexesGroups = this.explorer.lineIndexesGroupBySource(
selectedLineIndexes,
);
const selectedLineIndexes =
await this.explorer.getSelectedOrCursorLineIndexes(mode);
const lineIndexesGroups =
this.explorer.lineIndexesGroupBySource(selectedLineIndexes);
for (const { source, lineIndexes } of lineIndexesGroups) {
const actionExp = keyMapping.getActionExp(source.sourceType, key, mode);
if (actionExp) {
Expand Down
12 changes: 4 additions & 8 deletions src/actions/actionSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { ActionExp, MappingMode } from './types';

export class ActionSource<
S extends ExplorerSource<any>,
TreeNode extends BaseTreeNode<TreeNode>
TreeNode extends BaseTreeNode<TreeNode>,
> extends ActionRegistrar<S, TreeNode> {
public readonly global: ActionExplorer;
public readonly source = this.owner;
Expand Down Expand Up @@ -58,7 +58,7 @@ export class ActionSource<
let curNodes = nodes;

const subOptions = {
mode: mode,
mode,
isSubAction: true,
};
try {
Expand Down Expand Up @@ -108,8 +108,6 @@ export class ActionSource<
await this.doAction(actionExp.name, curNodes, actionExp.args, mode);
}
}
} catch (error) {
throw error;
} finally {
waitRelease?.();
}
Expand Down Expand Up @@ -164,8 +162,6 @@ export class ActionSource<
mode,
});
}
} catch (error) {
throw error;
} finally {
if (reload) {
await source.load(source.view.rootNode);
Expand Down Expand Up @@ -212,13 +208,13 @@ export class ActionSource<
if (options.menus) {
list.push(
...ActionMenu.getNormalizeMenus(options.menus).map((menu) => {
const fullActionName = actionName + ':' + menu.args;
const fullActionName = `${actionName}:${menu.args}`;
const keys = reverseMappings[fullActionName];
const key = keys ? keys.vmap ?? keys.all : '';
return {
name: fullActionName,
key,
description: description + ' ' + menu.description,
description: `${description} ${menu.description}`,
callback: async () => {
await task.waitExplorerShow();
await callback.call(source, {
Expand Down
2 changes: 1 addition & 1 deletion src/actions/codeActionProider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class ActionMenuCodeActionProvider implements CodeActionProvider {
if (options.menus) {
list.push(
...ActionMenu.getNormalizeMenus(options.menus).map((menu) => {
const fullActionName = actionName + ':' + menu.args;
const fullActionName = `${actionName}:${menu.args}`;
const keys = reverseMappings[fullActionName];
const key = keys ? keys.vmap ?? keys.all : '';
return {
Expand Down
6 changes: 3 additions & 3 deletions src/actions/globalActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export function loadGlobalActions(action: ActionExplorer) {
await gitManager.reload(root);
}
source.view.requestRenderNodes([
{ nodes: nodes, withParents: true, withChildren: true },
{ nodes, withParents: true, withChildren: true },
]);
},
'add file to git index',
Expand All @@ -212,7 +212,7 @@ export function loadGlobalActions(action: ActionExplorer) {
await gitManager.reload(root);
}
source.view.requestRenderNodes([
{ nodes: nodes, withParents: true, withChildren: true },
{ nodes, withParents: true, withChildren: true },
]);
},
'reset file from git index',
Expand Down Expand Up @@ -723,7 +723,7 @@ export function loadGlobalActions(action: ActionExplorer) {
'normal',
async ({ args }) => {
if (args[0]) {
await nvim.command('execute "normal ' + args[0] + '"');
await nvim.command(`execute "normal ${args[0]}"`);
}
},
'execute vim normal mode commands',
Expand Down
9 changes: 5 additions & 4 deletions src/actions/openAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { argOptions } from '../arg/argOptions';
import type { Explorer } from '../explorer';
import { BaseTreeNode, ExplorerSource } from '../source/source';
import { OpenPosition, OpenStrategy } from '../types';
import { selectWindowsUI } from '../util';
import { hasOwnProperty, selectWindowsUI } from '../util';

export async function openAction(
explorer: Explorer,
Expand All @@ -27,7 +27,7 @@ export async function openAction(

const { nvim } = workspace;

const getEscapePath = async () => {
const getEscapePath = async (): Promise<string> => {
let path = await getFullpath();
if (explorer.config.get('openAction.relativePath')) {
path = await nvim.call('fnamemodify', [path, ':.']);
Expand Down Expand Up @@ -200,7 +200,8 @@ export async function openAction(
},

previousWindow: async () => {
const prevWinnr = await explorer.explorerManager.prevWinnrByPrevWindowID();
const prevWinnr =
await explorer.explorerManager.prevWinnrByPrevWindowID();
if (prevWinnr) {
await openByWinnr(prevWinnr);
} else {
Expand All @@ -221,7 +222,7 @@ export async function openAction(
if (!openStrategy) {
openStrategy = await explorer.args.value(argOptions.openActionStrategy);
}
if (!actions.hasOwnProperty(openStrategy)) {
if (!hasOwnProperty(actions, openStrategy)) {
new Error(`openStrategy(${openStrategy}) is not supported`);
}
await actions[openStrategy]();
Expand Down
10 changes: 4 additions & 6 deletions src/arg/parseArgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,8 @@ export type ResolveArgValues<T> = {
};

export class Args {
private static registeredOptions: Map<
string,
ArgOption<any, any>
> = new Map();
private static registeredOptions: Map<string, ArgOption<any, any>> =
new Map();
private optionValues: Map<string, any> = new Map();

static registerOption<T>(
Expand Down Expand Up @@ -146,7 +144,7 @@ export class Args {
typeof defaultValue === 'boolean' ? () => defaultValue : defaultValue,
};
this.registeredOptions.set(name, option);
this.registeredOptions.set('no-' + name, option);
this.registeredOptions.set(`no-${name}`, option);
return option;
}

Expand Down Expand Up @@ -260,7 +258,7 @@ export class Args {
}

async values<
T extends Record<string, ArgOptionRequired<any, any> | ArgOption<any, any>>
T extends Record<string, ArgOptionRequired<any, any> | ArgOption<any, any>>,
>(options: T): Promise<ResolveArgValues<T>> {
const entries = await Promise.all(
Object.entries(options).map(
Expand Down
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export interface ExplorerConfig {
* @deprecated
*/
export const getRevealAuto = (config: ExplorerConfig) => {
let revealAuto = config.get('file.autoReveal') as boolean | undefined;
let revealAuto = config.get<boolean>('file.autoReveal');
if (revealAuto !== undefined) {
logger.error(
'`explorer.file.autoReveal` has been deprecated, please use explorer.file.reveal.auto instead of it',
Expand Down
17 changes: 10 additions & 7 deletions src/diagnostic/binder.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Disposable } from 'coc.nvim';
import pathLib from 'path';
import { buffer, debounceTime } from 'rxjs';
import { buffer, debounceTime, switchMap } from 'rxjs';
import { internalEvents } from '../events';
import { BaseTreeNode, ExplorerSource } from '../source/source';
import { createSub, logger, mapGetWithDefault, sum } from '../util';
Expand Down Expand Up @@ -126,12 +126,15 @@ export class DiagnosticBinder {
});
}

protected reloadDebounceSubject = createSub<ExplorerSource<any>[]>((sub) => {
sub.pipe(buffer(sub.pipe(debounceTime(1000)))).subscribe(async (list) => {
const sources = new Set(list.flat());
await this.reload([...sources]);
});
});
protected reloadDebounceSubject = createSub<ExplorerSource<any>[]>((sub) =>
sub.pipe(
buffer(sub.pipe(debounceTime(1000))),
switchMap(async (list) => {
const sources = new Set(list.flat());
await this.reload([...sources]);
}),
),
);

protected async reload(sources: ExplorerSource<any>[]) {
const types = this.diagnosticTypes;
Expand Down
Loading

0 comments on commit 972bca3

Please sign in to comment.