Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix linting autocmd #260

Merged
merged 3 commits into from
Jun 18, 2018
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
au BufNewFile * echo 'foo'

aug my_group
aug END
aug end

autocmd BufNewFile * echo 'foo'
autocmd BufNewFile,BufRead * echo 'foo'
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def test_get_violation_if_found_with_invalid_file(self):
expected_violations = [
self.create_violation(1, INVALID_VIM_SCRIPT),
self.create_violation(6, INVALID_VIM_SCRIPT),
self.create_violation(7, INVALID_VIM_SCRIPT),
]
self.assertFoundViolationsEqual(INVALID_VIM_SCRIPT,
ProhibitAutocmdWithNoGroup,
Expand Down
172 changes: 86 additions & 86 deletions vint/ast/dictionary/autocmd_events.py
Original file line number Diff line number Diff line change
@@ -1,88 +1,88 @@
AutoCmdEvents = {
'BufAdd': True,
'BufCreate': True,
'BufDelete': True,
'BufEnter': True,
'BufFilePost': True,
'BufFilePre': True,
'BufHidden': True,
'BufLeave': True,
'BufNew': True,
'BufNewFile': True,
'BufRead': True,
'BufReadCmd': True,
'BufReadPost': True,
'BufReadPre': True,
'BufUnload': True,
'BufWinEnter': True,
'BufWinLeave': True,
'BufWipeout': True,
'BufWrite': True,
'BufWriteCmd': True,
'BufWritePost': True,
'BufWritePre': True,
'CmdUndefined': True,
'CmdwinEnter': True,
'CmdwinLeave': True,
'ColorScheme': True,
'CompleteDone': True,
'CursorHold': True,
'CursorHoldI': True,
'CursorMoved': True,
'CursorMovedI': True,
'EncodingChanged': True,
'FileAppendCmd': True,
'FileAppendPost': True,
'FileAppendPre': True,
'FileChangedRO': True,
'FileChangedShell': True,
'FileChangedShellPost': True,
'FileReadCmd': True,
'FileReadPost': True,
'FileReadPre': True,
'FileType': True,
'FileWriteCmd': True,
'FileWritePost': True,
'FileWritePre': True,
'FilterReadPost': True,
'FilterReadPre': True,
'FilterWritePost': True,
'FilterWritePre': True,
'FocusGained': True,
'FocusLost': True,
'FuncUndefined': True,
'GUIEnter': True,
'GUIFailed': True,
'InsertChange': True,
'InsertCharPre': True,
'InsertEnter': True,
'InsertLeave': True,
'MenuPopup': True,
'QuickFixCmdPost': True,
'QuickFixCmdPre': True,
'QuitPre': True,
'RemoteReply': True,
'SessionLoadPost': True,
'ShellCmdPost': True,
'ShellFilterPost': True,
'SourceCmd': True,
'SourcePre': True,
'SpellFileMissing': True,
'StdinReadPost': True,
'StdinReadPre': True,
'SwapExists': True,
'Syntax': True,
'TabEnter': True,
'TabLeave': True,
'TermChanged': True,
'TermResponse': True,
'TextChanged': True,
'TextChangedI': True,
'User': True,
'VimEnter': True,
'VimLeave': True,
'VimLeavePre': True,
'VimResized': True,
'WinEnter': True,
'WinLeave': True,
'BUFADD': True,
'BUFCREATE': True,
'BUFDELETE': True,
'BUFENTER': True,
'BUFFILEPOST': True,
'BUFFILEPRE': True,
'BUFHIDDEN': True,
'BUFLEAVE': True,
'BUFNEW': True,
'BUFNEWFILE': True,
'BUFREAD': True,
'BUFREADCMD': True,
'BUFREADPOST': True,
'BUFREADPRE': True,
'BUFUNLOAD': True,
'BUFWINENTER': True,
'BUFWINLEAVE': True,
'BUFWIPEOUT': True,
'BUFWRITE': True,
'BUFWRITECMD': True,
'BUFWRITEPOST': True,
'BUFWRITEPRE': True,
'CMDUNDEFINED': True,
'CMDWINENTER': True,
'CMDWINLEAVE': True,
'COLORSCHEME': True,
'COMPLETEDONE': True,
'CURSORHOLD': True,
'CURSORHOLDI': True,
'CURSORMOVED': True,
'CURSORMOVEDI': True,
'ENCODINGCHANGED': True,
'FILEAPPENDCMD': True,
'FILEAPPENDPOST': True,
'FILEAPPENDPRE': True,
'FILECHANGEDRO': True,
'FILECHANGEDSHELL': True,
'FILECHANGEDSHELLPOST': True,
'FILEREADCMD': True,
'FILEREADPOST': True,
'FILEREADPRE': True,
'FILETYPE': True,
'FILEWRITECMD': True,
'FILEWRITEPOST': True,
'FILEWRITEPRE': True,
'FILTERREADPOST': True,
'FILTERREADPRE': True,
'FILTERWRITEPOST': True,
'FILTERWRITEPRE': True,
'FOCUSGAINED': True,
'FOCUSLOST': True,
'FUNCUNDEFINED': True,
'GUIENTER': True,
'GUIFAILED': True,
'INSERTCHANGE': True,
'INSERTCHARPRE': True,
'INSERTENTER': True,
'INSERTLEAVE': True,
'MENUPOPUP': True,
'QUICKFIXCMDPOST': True,
'QUICKFIXCMDPRE': True,
'QUITPRE': True,
'REMOTEREPLY': True,
'SESSIONLOADPOST': True,
'SHELLCMDPOST': True,
'SHELLFILTERPOST': True,
'SOURCECMD': True,
'SOURCEPRE': True,
'SPELLFILEMISSING': True,
'STDINREADPOST': True,
'STDINREADPRE': True,
'SWAPEXISTS': True,
'SYNTAX': True,
'TABENTER': True,
'TABLEAVE': True,
'TERMCHANGED': True,
'TERMRESPONSE': True,
'TEXTCHANGED': True,
'TEXTCHANGEDI': True,
'USER': True,
'VIMENTER': True,
'VIMLEAVE': True,
'VIMLEAVEPRE': True,
'VIMRESIZED': True,
'WINENTER': True,
'WINLEAVE': True,
}
6 changes: 3 additions & 3 deletions vint/linting/policy/prohibit_autocmd_with_no_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ def is_valid(self, node, lint_context):
# Looks like autocmd with a bang
return True

has_no_group = matched.group(1) in AutoCmdEvents
return not has_no_group
has_group = any(x and x.upper() not in AutoCmdEvents for x in matched.group(1).split(','))
return has_group

is_augroup = cmd_name == 'augroup'
if is_augroup:
matched = re.match(r'aug(?:roup)?\s+END', node['str'])
matched = re.match(r'aug(?:roup)?\s+[eE][nN][dD]$', node['str'])
is_augroup_end = bool(matched)
self.is_inside_of_augroup = not is_augroup_end

Expand Down