Repository navigation
Add ProhibitMisplacedVim9script policy - #6
Merged
Merged
Conversation
Vim gives E1039 when any command runs before :vim9script, and E1038 or E1039 when it is used inside a block or function. Report a :vim9script that is nested, or that follows a top-level command other than a comment or the vim9-mix pattern `if ... finish | endif` (:help vim9-mix). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
New
ProhibitMisplacedVim9scriptpolicy (Level.ERROR, enabled by default). Vim gives E1039 when any command runs before:vim9script, and E1038/E1039 when it's used inside a block or function. The policy reports avim9scriptthat:if, loop, or function, orifblock (noelseif/else) whose last command isfinish. This is the vim9-mix pattern from:help vim9-mix:Why
Vim only checks this when the script is sourced, so a misplaced
vim9scriptbreaks the whole file without any warning until then. The allowed cases follow Vim's own logic (ex_vim9script()insrc/vim9script.cand theSN_STATE_HAD_COMMANDhandling insrc/ex_docmd.c): comments and skippedifbodies don't count as commands.Testing
test_prohibit_misplaced_vim9script.py, covering: comments beforevim9script, vim9-mix, a command first,vim9scriptinside anif, and anifwithoutfinish.test_exec_vint_with_color_flag, which also fails onmasterlocally, so this change didn't cause it.Notes for reviewers
if … finish | endifbeforevim9scriptis accepted, matching the documented pattern even when the condition would make Vim stop early.🤖 Generated with Claude Code