Fix linter
This commit is contained in:
parent
c7250c8440
commit
87ff42ab0f
@ -1,21 +1,37 @@
|
|||||||
scriptencoding utf-8
|
scriptencoding utf-8
|
||||||
|
" 忽略的错误
|
||||||
|
let g:chinese_linter_disabled_nr = get(g:,'chinese_linter_disabled_nr', [])
|
||||||
|
" 中文标点符号(更全)
|
||||||
|
let s:CHINEXE_PUNCTUATION = "\u3002\uff1f\uff01\uff0c\u3001\uff1b\uff1a\u201c\u201d\u2018\u2019\uff08\uff09\u300a\u300b\u3008\u3009\u3010\u3011\u300e\u300f\u300c\u300d\ufe43\ufe44\u3014\u3015\u2026\u2014\uff5e\ufe4f\uffe5"
|
||||||
|
" 英文标点
|
||||||
|
let s:punctuation = ','
|
||||||
|
" 中文标点符号
|
||||||
|
let s:punctuation_cn = "[\u3002\uff1b\uff0c\uff1a\u201c\u201d\uff08\uff09\u3001\uff1f\u300a\u300b]"
|
||||||
|
" 中文汉字
|
||||||
|
let s:chars_cn = "[\u4e00-\u9fa5]"
|
||||||
|
" 数字
|
||||||
|
let s:numbers = '[0-9]'
|
||||||
|
" 英文字母
|
||||||
|
let s:chars = '[a-zA-Z]'
|
||||||
let s:ERRORS = {
|
let s:ERRORS = {
|
||||||
\ 'E001' : ['中文字符后不可使用英文标点', '[\u4e00-\u9fa5],'],
|
\ 'E001' : ['中文字符后存在英文标点', s:chars_cn . s:punctuation],
|
||||||
\ 'E002' : ['中英文之间需要增加空格', '([\u4e00-\u9fa5][a-zA-Z])\|([a-zA-Z][\u4e00-\u9fa5]))'],
|
\ 'E002' : ['中英文之间没有空格', '(' . s:chars_cn . s:chars . ')\|(' . s:chars . s:chars_cn . ')'],
|
||||||
\ 'E003' : ['中文与数字之间需要增加空格', '[\u4e00-\u9fa5][0-9]'],
|
\ 'E003' : ['中文与数字之间没有空格', '(' . s:chars_cn . s:numbers . ')\|(' . s:numbers . s:chars_cn . ')'],
|
||||||
\ 'E005' : ['全角标点之后不加空格', '[\u3002\uff1b\uff0c\uff1a\u201c\u201d\uff08\uff09\u3001\uff1f\u300a\u300b]\s\+'],
|
\ 'E004' : ['中文标点之后存在空格', s:punctuation_cn . '\s\+'],
|
||||||
\ }
|
\ }
|
||||||
" TODO
|
" TODO
|
||||||
|
"
|
||||||
"\ 'E004' : ['数字与单位之间需要增加空格', ''],
|
"\ 'E004' : ['数字与单位之间需要增加空格', ''],
|
||||||
"\ 'E006' : ['不重复使用标点符号', ''],
|
"\ 'E006' : ['不重复使用标点符号', ''],
|
||||||
"\ 'E007' : ['使用全角中文标点', ''],
|
"\ 'E007' : ['使用全角中文标点', ''],
|
||||||
"\ 'E008' : ['数字使用半角字符', ''],
|
"\ 'E008' : ['数字使用半角字符', ''],
|
||||||
"\ 'E009' : ['遇到完整的英文整句、特殊名词,其內容使用半角标点', ''],
|
"\ 'E009' : ['遇到完整的英文整句、特殊名词,其內容使用半角标点', ''],
|
||||||
|
|
||||||
command! -nargs=? CheckChinese call s:check(<q-args>)
|
command! -nargs=? CheckChinese call s:check(<q-args>)
|
||||||
|
|
||||||
function! s:check(...) abort
|
function! s:check(...) abort
|
||||||
let s:file = getline(1,'$')
|
let s:file = getline(1,'$')
|
||||||
let s:bufnr = bufnr('$')
|
let s:bufnr = bufnr('%')
|
||||||
let s:linenr = 0
|
let s:linenr = 0
|
||||||
let s:colnr = 0
|
let s:colnr = 0
|
||||||
let s:qf = []
|
let s:qf = []
|
||||||
@ -37,7 +53,9 @@ endfunction
|
|||||||
|
|
||||||
function! s:parser(line) abort
|
function! s:parser(line) abort
|
||||||
for l:error_nr in keys(s:ERRORS)
|
for l:error_nr in keys(s:ERRORS)
|
||||||
call s:find_error(l:error_nr, a:line)
|
if index(g:chinese_linter_disabled_nr, l:error_nr) == -1
|
||||||
|
call s:find_error(l:error_nr, a:line)
|
||||||
|
endif
|
||||||
endfor
|
endfor
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@ -55,7 +73,7 @@ function! s:add_to_qf(nr) abort
|
|||||||
\ 'lnum' : s:linenr,
|
\ 'lnum' : s:linenr,
|
||||||
\ 'col' : s:colnr,
|
\ 'col' : s:colnr,
|
||||||
\ 'vcol' : 0,
|
\ 'vcol' : 0,
|
||||||
\ 'text' : s:ERRORS[a:nr][0],
|
\ 'text' : a:nr . ' ' . s:ERRORS[a:nr][0],
|
||||||
\ 'nr' : a:nr,
|
\ 'nr' : a:nr,
|
||||||
\ 'type' : 'E'
|
\ 'type' : 'E'
|
||||||
\ }
|
\ }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user