Skip to content

Commit 4c85e12

Browse files
committed
fix type errors
Also ignore node_modules/ at all levels.
1 parent 3984910 commit 4c85e12

24 files changed

+111
-81
lines changed

packages/decorators/src/plugin/autocmd.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ export function Autocmd(name: string, options?: AutocmdOptions) {
1212
pattern: '',
1313
};
1414

15+
// @ts-expect-error changing `option: keyof …` to `option: string` causes other errors.
1516
['pattern', 'eval'].forEach((option: keyof AutocmdOptions) => {
1617
if (options && typeof options[option] !== 'undefined') {
1718
(opts[option] as any) = options[option];
1819
}
1920
});
2021

2122
const nameWithPattern = `${name}${
22-
options.pattern ? `:${options.pattern}` : ''
23+
options?.pattern ? `:${options.pattern}` : ''
2324
}`;
2425
Object.defineProperty(f, NVIM_METHOD_NAME, {
2526
value: `autocmd:${nameWithPattern}`,

packages/decorators/src/plugin/command.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export function Command(name: string, options?: CommandOptions) {
1212
const f = isMethod ? cls[methodName] : cls;
1313
const opts: CommandOptions = {};
1414

15+
// @ts-expect-error changing `option: keyof …` to `option: string` causes other errors.
1516
['range', 'nargs', 'complete'].forEach((option: keyof CommandOptions) => {
1617
if (options && typeof options[option] !== 'undefined') {
1718
(opts[option] as any) = options[option];

packages/decorators/src/plugin/plugin.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export interface PluginWrapperConstructor {
3030
}
3131
function wrapper(cls: PluginWrapperConstructor, options?: PluginOptions): any {
3232
return class WrapperClass extends cls implements PluginWrapperInterface {
33-
public nvim: Neovim;
33+
public nvim!: Neovim;
3434

3535
constructor(plugin: NvimPlugin) {
3636
super(plugin.nvim, plugin);
@@ -57,7 +57,11 @@ function wrapper(cls: PluginWrapperConstructor, options?: PluginOptions): any {
5757
autoCmdOpts.eval = spec.opts.eval;
5858
}
5959

60-
plugin.registerAutocmd(spec.name, [this, method], autoCmdOpts);
60+
plugin.registerAutocmd(
61+
spec.name,
62+
[this, method],
63+
autoCmdOpts as any
64+
);
6165
break;
6266
case 'command':
6367
const cmdOpts: CommandOptions = {
@@ -94,7 +98,7 @@ function wrapper(cls: PluginWrapperConstructor, options?: PluginOptions): any {
9498
});
9599
}
96100

97-
setApi(nvim: Neovim) {
101+
override setApi(nvim: Neovim) {
98102
this.nvim = nvim;
99103
}
100104
};

packages/decorators/src/plugin/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export interface FunctionOptions {
55
}
66

77
export interface AutocmdOptions {
8-
pattern: string;
8+
pattern?: string;
99
eval?: string;
1010
sync?: boolean;
1111
}

packages/neovim/src/api/Base.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Logger, getLogger } from '../utils/logger';
66
import { VimValue } from '../types/VimValue';
77

88
export interface BaseConstructorOptions {
9-
transport?: Transport;
9+
transport: Transport;
1010
logger?: Logger;
1111
data?: Buffer;
1212
metadata?: any;
@@ -28,13 +28,13 @@ const DO_REQUEST = Symbol('DO_REQUEST');
2828
export class BaseApi extends EventEmitter {
2929
protected transport: Transport;
3030

31-
protected _isReady: Promise<boolean>;
31+
protected _isReady: Promise<boolean> = Promise.resolve(false);
3232

33-
protected prefix: string;
33+
protected prefix!: string;
3434

3535
public logger: Logger;
3636

37-
public data: Buffer | number;
37+
public data?: Buffer | number;
3838

3939
// Node Buffer
4040
protected client: any;
@@ -48,7 +48,7 @@ export class BaseApi extends EventEmitter {
4848
}: BaseConstructorOptions) {
4949
super();
5050

51-
this.setTransport(transport);
51+
this.transport = transport;
5252
this.data = data;
5353
this.logger = logger || getLogger();
5454
this.client = client;
@@ -58,10 +58,6 @@ export class BaseApi extends EventEmitter {
5858
}
5959
}
6060

61-
protected setTransport(transport: Transport): void {
62-
this.transport = transport;
63-
}
64-
6561
equals(other: BaseApi): boolean {
6662
try {
6763
return String(this.data) === String(other.data);

packages/neovim/src/api/Buffer.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const DETACH = Symbol('detachBuffer');
3232
export const ATTACH = Symbol('attachBuffer');
3333

3434
export class Buffer extends BaseApi {
35-
public prefix: string = Metadata[ExtType.Buffer].prefix;
35+
public override prefix: string = Metadata[ExtType.Buffer].prefix;
3636

3737
public get isAttached(): boolean {
3838
return this.client.isAttached(this);
@@ -106,9 +106,9 @@ export class Buffer extends BaseApi {
106106
strictIndexing: true,
107107
}
108108
) {
109-
// TODO: Error checking
110-
// if (typeof start === 'undefined' || typeof end === 'undefined') {
111-
// }
109+
if (_start === undefined || _end === undefined) {
110+
throw new Error('start and end are required');
111+
}
112112
const indexing =
113113
typeof strictIndexing === 'undefined' ? true : strictIndexing;
114114
const lines = typeof _lines === 'string' ? [_lines] : _lines;

packages/neovim/src/api/Neovim.test.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/* eslint-env jest */
22
import * as path from 'node:path';
3-
import { Neovim } from './Neovim';
43
import * as testUtil from '../testUtil';
54

65
describe('Neovim API', () => {
@@ -14,14 +13,6 @@ describe('Neovim API', () => {
1413
testUtil.stopNvim();
1514
});
1615

17-
it('sets transport when initialized', () => {
18-
const transport = {};
19-
const spy = jest.spyOn(Neovim.prototype, 'setTransport');
20-
const neovim = new Neovim({ transport });
21-
expect(spy).toHaveBeenCalledWith(transport);
22-
expect(neovim.transport).toBe(transport);
23-
});
24-
2516
describe('Normal API calls', () => {
2617
it('gets a list of buffers and switches buffers', async () => {
2718
const buffers = await nvim.buffers;

packages/neovim/src/api/Neovim.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ export interface OpenWindowOptions {
128128
* Neovim API
129129
*/
130130
export class Neovim extends BaseApi {
131-
protected prefix = 'nvim_';
131+
protected override prefix = 'nvim_';
132132

133133
public Buffer = Buffer;
134134

packages/neovim/src/api/Tabpage.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { createChainableApi } from './utils/createChainableApi';
44
import { Window, AsyncWindow } from './Window';
55

66
export class Tabpage extends BaseApi {
7-
public prefix: string = Metadata[ExtType.Tabpage].prefix;
7+
public override prefix: string = Metadata[ExtType.Tabpage].prefix;
88

99
/** Returns all windows of tabpage */
1010
get windows(): Promise<Window[]> {
@@ -30,12 +30,12 @@ export class Tabpage extends BaseApi {
3030
}
3131

3232
/** Invalid */
33-
getOption(): void {
33+
override getOption(): void {
3434
this.logger.error('Tabpage does not have `getOption`');
3535
}
3636

3737
/** Invalid */
38-
setOption(): void {
38+
override setOption(): void {
3939
this.logger.error('Tabpage does not have `setOption`');
4040
}
4141
}

packages/neovim/src/api/Window.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Tabpage, AsyncTabpage } from './Tabpage';
55
import { Buffer, AsyncBuffer } from './Buffer';
66

77
export class Window extends BaseApi {
8-
public prefix: string = Metadata[ExtType.Window].prefix;
8+
public override prefix: string = Metadata[ExtType.Window].prefix;
99

1010
/**
1111
* The windowid that not change within a Vim session

0 commit comments

Comments
 (0)