Skip to content
Esc

@noctcore/eslint-plugin-electron

v0.1.03 rules1 recommended2 opt-innamespace noctcore-electron

A bad fit for flags set from variables, which the literal-only check does not see, and for handlers passed by name, which it does not follow.

Electron main-process security: renderer isolation flags, IPC sender checks, and shell kept to one checked module.

An Electron renderer is a web page with a line into Node. The defaults keep that line narrow, and three kinds of edit widen it without anything failing: a webPreferences flag flipped for a debugging session, an IPC handler that acts on a message from any frame, and a shell.openExternal called with a URL nobody checked. Each works in development and becomes a path from web content to the operating system the day the app shows something it did not ship.

It will yell at you about a webPreferences flag that turns off isolation (nodeIntegration: true, contextIsolation: false, sandbox: false and the rest), the one rule recommended turns on. Two opt-in rules need a fact about your app: IPC handlers that do not check their sender first (name your guard in guards) and shell used outside the module you list in allowIn. It is a bad fit for flags set from variables, which the literal-only check does not see, and for handlers passed by name, which it does not follow.

Install
npm install --save-dev @noctcore/eslint-plugin-electron @typescript-eslint/parser
# or: bun add -D / pnpm add -D @noctcore/eslint-plugin-electron @typescript-eslint/parser

The recommended preset enables 1 of 3 rules. The rules board below builds the flat config: start from a preset, switch single rules between error and off, and copy the result.

Each rule links to its page, with the options it takes and Incorrect and Correct examples. A good first read is webpreferences-locked.

1 of 3 at error

--fixsuggestionsneeds optionstype infoEach switch sets a rule to error or off.

ipc-handler-validates-sender
Require every inline ipcMain.handle / ipcMain.on handler to check its sender (event.senderFrame) in its first statement, before it does anything else.
opt-in
no-shell-outside-allowlist
Restrict Electron's shell (openExternal, openPath) to the files listed in allowIn, so URLs and paths reach the operating system through one checked module.
Needs options
opt-in
webpreferences-locked
Disallow turning off an Electron renderer isolation flag: nodeIntegration, webviewTag or allowRunningInsecureContent set to true, or contextIsolation, sandbox or webSecurity set to false.
recommended