From 122dab2b6dca4d58913bd4fe8209a59bd5718965 Mon Sep 17 00:00:00 2001 From: whocoder11 Date: Thu, 8 Jan 2026 20:09:40 +0530 Subject: [PATCH] fix: add validation for function names to start with capital letter --- packages/decorators/src/plugin/function.ts | 4 ++++ packages/neovim/src/host/NvimPlugin.test.ts | 6 ++++++ packages/neovim/src/host/NvimPlugin.ts | 7 +++++++ packages/neovim/src/plugin/function.ts | 4 ++++ 4 files changed, 21 insertions(+) diff --git a/packages/decorators/src/plugin/function.ts b/packages/decorators/src/plugin/function.ts index 182eedb2..c0bf108c 100644 --- a/packages/decorators/src/plugin/function.ts +++ b/packages/decorators/src/plugin/function.ts @@ -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; diff --git a/packages/neovim/src/host/NvimPlugin.test.ts b/packages/neovim/src/host/NvimPlugin.test.ts index ef6af98b..a9c3b9c8 100644 --- a/packages/neovim/src/host/NvimPlugin.test.ts +++ b/packages/neovim/src/host/NvimPlugin.test.ts @@ -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: '' }); diff --git a/packages/neovim/src/host/NvimPlugin.ts b/packages/neovim/src/host/NvimPlugin.ts index 107e1a5e..a260f36c 100644 --- a/packages/neovim/src/host/NvimPlugin.ts +++ b/packages/neovim/src/host/NvimPlugin.ts @@ -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, diff --git a/packages/neovim/src/plugin/function.ts b/packages/neovim/src/plugin/function.ts index d9fe85c4..eb895955 100644 --- a/packages/neovim/src/plugin/function.ts +++ b/packages/neovim/src/plugin/function.ts @@ -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;