Skip to content

fix(editorconfig): "[!seq]" glob matches seq instead of excluding it - #42648

Merged
justinmk merged 1 commit into
neovim:masterfrom
b84330808:editorconfig-negated-class
Nov 3, 2026
Merged

justinmk merged 1 commit into
neovim:masterfrom
b84330808:editorconfig-negated-class

Conversation

@b84330808

Copy link
Copy Markdown
Contributor

Problem

EditorConfig uses [!seq] for a negated character class (https://spec.editorconfig.org/#glob-expressions), but glob2regpat() keeps the ! literal, so [!a] matches a or ! and nothing else. For example, Checkmk's .editorconfig has a [checks/[!.]*] section, which Nvim applies only to dotfiles in checks/, the opposite of what it says.

Solution

Convert [! to [^ before calling glob2regpat(). Added a "[!seq]" glob excludes seq case to test/functional/plugin/editorconfig_spec.lua; it fails without the change and passes with it.

AI-assisted: this change was written with an AI coding agent.

Comment thread runtime/lua/editorconfig.lua Outdated
'g'
)
-- EditorConfig negates a character class with "[!seq]", Vim with "[^seq]".
glob1 = vim.fn.substitute(glob1, '\\\\\\@<!\\[!', '[^', 'g')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gsub() ...? and [=[...]=] to reduce the escaping

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, it uses gsub() with a [=[...]=] pattern now. Same results as the substitute() version for [!a], \[!a], [![!b] and a[!b][!c], and the editorconfig tests pass.

@justinmk

justinmk commented Nov 2, 2026

Copy link
Copy Markdown
Member

@gpanders

Problem:
EditorConfig uses "[!seq]" for a negated character class, but
glob2regpat() keeps the "!" literal, so "[!a]" matches "a" or "!" and
nothing else. For example, a "[checks/[!.]*]" section only applies to
dotfiles in "checks/", the opposite of what it says.

Solution:
Convert "[!" to "[^" before calling glob2regpat().

AI-assisted
@b84330808
b84330808 force-pushed the editorconfig-negated-class branch from 004b8bb to 0cc6f58 Compare November 2, 2026 10:18
@justinmk
justinmk merged commit 2c1e884 into neovim:master Nov 3, 2026
43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants