From 32fe37f4bf56713f45a48275db5c90c91fa12b5e Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Fri, 15 Nov 2019 10:48:18 +0300 Subject: [PATCH 1/8] Add configuration for Vint vimscript linter --- .vintrc.yaml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .vintrc.yaml diff --git a/.vintrc.yaml b/.vintrc.yaml new file mode 100644 index 0000000..c44b6ab --- /dev/null +++ b/.vintrc.yaml @@ -0,0 +1,5 @@ +cmdargs: + severity: style_problem + color: true + env: + neovim: false From 460b8a0304cb1c61f7da72c11e0f4fb92dcbce55 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Fri, 15 Nov 2019 10:51:10 +0300 Subject: [PATCH 2/8] Explicitly set script encoding so RegEx behave --- autoload/pencil.vim | 3 +++ plugin/pencil.vim | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/autoload/pencil.vim b/autoload/pencil.vim index 25d59e5..ba52183 100644 --- a/autoload/pencil.vim +++ b/autoload/pencil.vim @@ -5,6 +5,9 @@ " Created: December 28, 2013 " License: The MIT License (MIT) " ============================================================================ + +scriptencoding utf-8 + if exists("autoloaded_pencil") | fini | en let autoloaded_pencil = 1 diff --git a/plugin/pencil.vim b/plugin/pencil.vim index 55cdbc3..4831131 100644 --- a/plugin/pencil.vim +++ b/plugin/pencil.vim @@ -5,7 +5,9 @@ " Created: December 28, 2013 " License: The MIT License (MIT) " ============================================================================ -" + +scriptencoding utf-8 + if exists('g:loaded_pencil') || &cp | fini | en let g:loaded_pencil = 1 From c6727cac476d9f5590991b14b9537c7cf986c6bf Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Fri, 15 Nov 2019 10:53:36 +0300 Subject: [PATCH 3/8] Add missing abort option to autoload function --- autoload/pencil.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/pencil.vim b/autoload/pencil.vim index ba52183..8d30a5e 100644 --- a/autoload/pencil.vim +++ b/autoload/pencil.vim @@ -522,7 +522,7 @@ fun! s:doModelines() abort en endf -function! Mapkey (keys, mode) +function! Mapkey (keys, mode) abort " Pass in a key sequence and the first letter of a vim mode. " Returns key mapping mapped to it in that mode, else 0 if none. " example: From ed3630df12804d38fe31ba9052b914cbef8a4745 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Fri, 15 Nov 2019 10:55:43 +0300 Subject: [PATCH 4/8] Use robust comparison operators --- autoload/pencil.vim | 6 +++--- plugin/pencil.vim | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/autoload/pencil.vim b/autoload/pencil.vim index 8d30a5e..13223b4 100644 --- a/autoload/pencil.vim +++ b/autoload/pencil.vim @@ -248,7 +248,7 @@ fun! pencil#init(...) abort " flag to suspend autoformat for next Insert " optional user-defined mapping if exists('g:pencil#map#suspend_af') && - \ g:pencil#map#suspend_af != '' + \ g:pencil#map#suspend_af !=# '' exe 'no ' . g:pencil#map#suspend_af . ' :let b:pencil_suspend_af=1' en @@ -478,7 +478,7 @@ endf fun! s:doOne(item) abort let l:matches = matchlist(a:item, '^\([a-z]\+\)=\([a-zA-Z0-9_\-.]\+\)$') if len(l:matches) > 1 - if l:matches[1] =~ 'textwidth\|tw' + if l:matches[1] =~# 'textwidth\|tw' let l:tw = str2nr(l:matches[2]) if l:tw > b:max_textwidth let b:max_textwidth = l:tw @@ -511,7 +511,7 @@ fun! s:doModelines() abort let l:lines={ } call map(filter(getline(1, &modelines) + \ getline(line("$") - &modelines, "$"), - \ 'v:val =~ ":"'), 'extend(l:lines, { v:val : 0 } )') + \ 'v:val =~# ":"'), 'extend(l:lines, { v:val : 0 } )') for l:line in keys(l:lines) call s:doModeline(l:line) endfo diff --git a/plugin/pencil.vim b/plugin/pencil.vim index 4831131..d0dab82 100644 --- a/plugin/pencil.vim +++ b/plugin/pencil.vim @@ -33,7 +33,7 @@ fun! PencilMode() if b:pencil_wrap_mode ==# s:WRAP_MODE_SOFT return get(g:pencil#mode_indicators, 'soft', 'S') elsei b:pencil_wrap_mode ==# s:WRAP_MODE_HARD - if &fo =~ 'a' + if &fo =~# 'a' return get(g:pencil#mode_indicators, 'auto', 'A') el return get(g:pencil#mode_indicators, 'hard', 'H') From dae22f99b59a3eae3e5d261231300d714aac2f9b Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Fri, 15 Nov 2019 10:59:26 +0300 Subject: [PATCH 5/8] Use single quoted strings by default --- autoload/pencil.vim | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/autoload/pencil.vim b/autoload/pencil.vim index 13223b4..5f1a156 100644 --- a/autoload/pencil.vim +++ b/autoload/pencil.vim @@ -8,7 +8,7 @@ scriptencoding utf-8 -if exists("autoloaded_pencil") | fini | en +if exists('autoloaded_pencil') | fini | en let autoloaded_pencil = 1 let s:WRAP_MODE_DEFAULT = -1 @@ -49,9 +49,9 @@ endf fun! s:imap(preserve_completion, key, icmd) abort if a:preserve_completion - exe ":ino " . a:key . " pumvisible() ? \"" . a:key . "\" : \"" . a:icmd . "\"" + exe ':ino ' . a:key . " pumvisible() ? '" . a:key . "' : '" . a:icmd . "'" el - exe ":ino " . a:key . " " . a:icmd + exe ':ino ' . a:key . ' ' . a:icmd en endf @@ -175,7 +175,7 @@ fun! pencil#setAutoFormat(af) abort sil! au! pencil_autoformat * if l:nu_af && !l:is_hard echohl WarningMsg - echo "autoformat can only be enabled in hard line break mode" + echo 'autoformat can only be enabled in hard line break mode' echohl NONE return en @@ -195,7 +195,7 @@ fun! pencil#init(...) abort if !exists('b:pencil_wrap_mode') let b:pencil_wrap_mode = s:WRAP_MODE_OFF en - if !exists("b:max_textwidth") + if !exists('b:max_textwidth') let b:max_textwidth = -1 en @@ -408,10 +408,10 @@ fun! pencil#init(...) abort en if b:pencil_wrap_mode - exe 'nn ' . Mapkey("j", "n") . ' gj' - exe 'nn ' . Mapkey("k", "n") . ' gk' - exe 'vn ' . Mapkey("j", "v") . ' gj' - exe 'vn ' . Mapkey("k", "v") . ' gk' + exe 'nn ' . Mapkey('j', 'n') . ' gj' + exe 'nn ' . Mapkey('k', 'n') . ' gk' + exe 'vn ' . Mapkey('j', 'v') . ' gj' + exe 'vn ' . Mapkey('k', 'v') . ' gk' no gk no gj nn gj j @@ -507,16 +507,16 @@ endf " modeline(s) and max line length " Hat tip to https://github.com/ciaranm/securemodelines fun! s:doModelines() abort - if line("$") > &modelines + if line('$') > &modelines let l:lines={ } call map(filter(getline(1, &modelines) + - \ getline(line("$") - &modelines, "$"), + \ getline(line('$') - &modelines, '$'), \ 'v:val =~# ":"'), 'extend(l:lines, { v:val : 0 } )') for l:line in keys(l:lines) call s:doModeline(l:line) endfo el - for l:line in getline(1, "$") + for l:line in getline(1, '$') call s:doModeline(l:line) endfo en From 8848dedb70f8a204f64d36d49d5103548a1bf206 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Fri, 15 Nov 2019 11:02:32 +0300 Subject: [PATCH 6/8] Use full option names instead of abreviations --- autoload/pencil.vim | 4 ++-- plugin/pencil.vim | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/autoload/pencil.vim b/autoload/pencil.vim index 5f1a156..63dd0d8 100644 --- a/autoload/pencil.vim +++ b/autoload/pencil.vim @@ -65,8 +65,8 @@ fun! s:maybe_enable_autoformat() abort return en - let l:ft = get(g:pencil#autoformat_aliases, &ft, &ft) - let l:af_cfg = get(g:pencil#autoformat_config, l:ft, {}) + let l:filetype = get(g:pencil#autoformat_aliases, &filetype, &filetype) + let l:af_cfg = get(g:pencil#autoformat_config, l:filetype, {}) let l:black = get(l:af_cfg, 'black', []) let l:white = get(l:af_cfg, 'white', []) let l:has_black_re = len(l:black) > 0 diff --git a/plugin/pencil.vim b/plugin/pencil.vim index d0dab82..ab5b905 100644 --- a/plugin/pencil.vim +++ b/plugin/pencil.vim @@ -8,12 +8,12 @@ scriptencoding utf-8 -if exists('g:loaded_pencil') || &cp | fini | en +if exists('g:loaded_pencil') || &compatible | fini | en let g:loaded_pencil = 1 " Save 'cpoptions' and set Vim default to enable line continuations. -let s:save_cpo = &cpo -set cpo&vim +let s:save_cpoptions = &cpoptions +set cpoptions&vim let s:WRAP_MODE_DEFAULT = -1 let s:WRAP_MODE_OFF = 0 @@ -33,7 +33,7 @@ fun! PencilMode() if b:pencil_wrap_mode ==# s:WRAP_MODE_SOFT return get(g:pencil#mode_indicators, 'soft', 'S') elsei b:pencil_wrap_mode ==# s:WRAP_MODE_HARD - if &fo =~# 'a' + if &formatoptions =~# 'a' return get(g:pencil#mode_indicators, 'auto', 'A') el return get(g:pencil#mode_indicators, 'hard', 'H') @@ -205,7 +205,7 @@ if g:pencil#legacyCommands com -nargs=0 ShiftPencil call pencil#setAutoFormat(-1) en -let &cpo = s:save_cpo -unlet s:save_cpo +let &cpoptions = s:save_cpoptions +unlet s:save_cpoptions " vim:ts=2:sw=2:sts=2 From 0914c05ed6976b93550225bae2214122e4040434 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Fri, 15 Nov 2019 11:09:30 +0300 Subject: [PATCH 7/8] Add Github Actions CI job that lints vimscript --- .github/workflows/vint.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 .github/workflows/vint.yml diff --git a/.github/workflows/vint.yml b/.github/workflows/vint.yml new file mode 100644 index 0000000..1f38411 --- /dev/null +++ b/.github/workflows/vint.yml @@ -0,0 +1,16 @@ +name: Vint +on: [push, pull_request] +jobs: + vint: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@master + - name: Set up Python + uses: actions/setup-python@v1 + with: + python-version: 3.7 + - name: Setup dependencies + run: pip install vim-vint + - name: Run Vimscript Linter + run: vint . From 0ff06322b7cc2ca352258ddd4e80930b7b0e0a56 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Fri, 15 Nov 2019 11:12:47 +0300 Subject: [PATCH 8/8] Add linter status badge to README --- README.markdown | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.markdown b/README.markdown index 136ba5e..bdbc4a0 100644 --- a/README.markdown +++ b/README.markdown @@ -1,5 +1,7 @@ # vim-pencil +[![Vint](https://github.com/reedes/vim-pencil/workflows/Vint/badge.svg)](https://github.com/reedes/vim-pencil/actions?workflow=Vint) + > Rethinking Vim as a tool for writers