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
4 changes: 4 additions & 0 deletions packages/decorators/src/plugin/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import { FunctionOptions } from './types';

export function Function(name: string, options: FunctionOptions = {}) {
return function (cls: any, methodName: string | null) {
// Validate that function name starts with a capital letter
if (!/^[A-Z]/.test(name)) {
throw new Error(`Function: function name '${name}' must start with a capital letter`);
}
const sync = options && !!options.sync;
const isMethod = typeof methodName === 'string';
const f = isMethod ? cls[methodName] : cls;
Expand Down
6 changes: 6 additions & 0 deletions packages/neovim/src/host/NvimPlugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ describe('NvimPlugin', () => {
expect(plugin.functions.MyFunction).toEqual({ fn, spec });
});

it('should not register functions with lowercase names', () => {
const plugin = new NvimPlugin('/tmp/filename', () => {}, getFakeNvimClient());
plugin.registerFunction('myLowercaseFunction', () => {}, {});
expect(Object.keys(plugin.functions)).toHaveLength(0);
});

it('should not add autocmds with no pattern option', () => {
const plugin = new NvimPlugin('/tmp/filename', () => {}, getFakeNvimClient());
plugin.registerAutocmd('BufWritePre', () => {}, { pattern: '' });
Expand Down
7 changes: 7 additions & 0 deletions packages/neovim/src/host/NvimPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,13 @@ export class NvimPlugin {
registerFunction(name: string, fn: [any, Function], options?: NvimFunctionOptions): void;

registerFunction(name: string, fn: any, options?: NvimFunctionOptions): void {
if (!/^[A-Z]/.test(name)) {
this.nvim.logger.error(
`registerFunction: function name '${name}' must start with a capital letter`
);
return;
}

const spec: Spec = {
type: 'function',
name,
Expand Down
4 changes: 4 additions & 0 deletions packages/neovim/src/plugin/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ export function nvimFunction(name: string, options: NvimFunctionOptions = {}) {
// sync,
// ...opts,
// } = options;
// Validate that function name starts with a capital letter
if (!/^[A-Z]/.test(name)) {
throw new Error(`nvimFunction: function name '${name}' must start with a capital letter`);
}
const sync = options && !!options.sync;
const isMethod = typeof methodName === 'string';
const f = isMethod ? cls[methodName] : cls;
Expand Down