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

Filter account name #50

Merged
merged 2 commits into from
Jun 16, 2020
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ let g:spelunker_disable_uri_checking = 1
" Disable email-like words checking. (default: 0)
let g:spelunker_disable_email_checking = 1

" Disable account name checking. (default: 0)
let g:spelunker_disable_account_name_checking = 1

" Disable checking words in backtick/backquote. (default: 0)
let g:spelunker_disable_backquoted_checking = 1

Expand Down
11 changes: 11 additions & 0 deletions autoload/spelunker/get_buffer.vim
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ function! spelunker#get_buffer#all()

let l:window_text = spelunker#get_buffer#filter_uri(l:window_text)
let l:window_text = spelunker#get_buffer#filter_email(l:window_text)
let l:window_text = spelunker#get_buffer#filter_account_name(l:window_text)
let l:window_text = spelunker#get_buffer#filter_backquoted_words(l:window_text, l:newline_character)

return split(l:window_text, l:newline_character)
Expand Down Expand Up @@ -71,6 +72,16 @@ function! spelunker#get_buffer#filter_email(text)
return substitute(a:text, '[a-zA-Z0-9.!#$%&''*+\/=?^_`{|}~-]\+@[a-zA-Z0-9]\([a-zA-Z0-9-]\{0,61}[a-zA-Z0-9]\)\?\(\.[a-zA-Z0-9]\([a-zA-Z0-9-]\{0,61}[a-zA-Z0-9]\)\?\)*', '', 'g')
endfunction

function! spelunker#get_buffer#filter_account_name(text)
if g:spelunker_disable_account_name_checking == 0
return a:text
endif

" memo: single quote ' -> ''
let l:text = substitute(a:text, '\%([a-zA-Z0-9.!#$%&''*+\/=?^_`{|}~-]\+\)\@<!@[a-zA-Z0-9.!#$%&''*+\/=?^_`{|}~-]\+', '', 'g')
return substitute(l:text, '[a-zA-Z0-9.!#$%&''*+\/=?^_`{|}~-]\+@\%([a-zA-Z0-9]\([a-zA-Z0-9-]\{0,61}[a-zA-Z0-9]\)\?\(\.[a-zA-Z0-9]\([a-zA-Z0-9-]\{0,61}[a-zA-Z0-9]\)\?\)*\)\@!', '', 'g')
endfunction

function! spelunker#get_buffer#filter_backquoted_words(text, newline_character)
" for shell command
" ex) `ls -la`
Expand Down
26 changes: 26 additions & 0 deletions autoload/spelunker/test/test_get_buffer.vim
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ function! spelunker#test#test_get_buffer#test()
let g:spelunker_disable_backquoted_checking = 1
let g:spelunker_disable_uri_checking = 1
let g:spelunker_disable_email_checking = 1
let g:spelunker_disable_account_name_checking = 1

call s:test_all()
call s:test_displayed()
call s:test_disable_url_checking()
call s:test_disable_email_checking()
call s:test_disable_account_name_checking()
call s:test_disable_backquoted_checking()
call s:test_folded()
endfunction
Expand Down Expand Up @@ -45,6 +47,9 @@ function! s:test_disable_url_checking()
endfunction

function! s:test_disable_email_checking()
" 似ている書式なのでオプションをオフにしてテスト
let g:spelunker_disable_account_name_checking = 0

let g:spelunker_disable_email_checking = 1
call spelunker#test#open_unit_test_buffer('get_buffer', 'disable_email.txt')
call assert_equal(
Expand All @@ -58,9 +63,30 @@ function! s:test_disable_email_checking()
\ spelunker#get_buffer#all()
\ )

let g:spelunker_disable_account_name_checking = 1
let g:spelunker_disable_email_checking = 1
endfunction

function! s:test_disable_account_name_checking()
" 似ている書式なのでオプションをオフにしてテスト
let g:spelunker_disable_email_checking = 0

let g:spelunker_disable_account_name_checking = 1
call spelunker#test#open_unit_test_buffer('get_buffer', 'disable_account_name.txt')
call assert_equal(
\ ['[email protected]', '', 'abc [email protected] def', '', 'ghi', '[email protected]', 'jkl', '', 'mno pqr', 'stu vwx'],
\ spelunker#get_buffer#all()
\ )

let g:spelunker_disable_account_name_checking = 0
call assert_equal(
\ ['[email protected]', '', 'abc [email protected] def', '', 'ghi', '[email protected]', 'jkl', '@Annotation', 'mno @mrfoobar pqr', 'stu mrfoobar@ vwx'],
\ spelunker#get_buffer#all()
\ )

let g:spelunker_disable_email_checking = 1
let g:spelunker_disable_account_name_checking = 1
endfunction

function! s:test_disable_backquoted_checking()
let g:spelunker_disable_backquoted_checking = 1
Expand Down
3 changes: 3 additions & 0 deletions autoload/spelunker/white_list.vim
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ function! spelunker#white_list#init_white_list()
let l:wl += ['referer', 'localhost', 'serializer', 'mutex', 'autoload', 'varchar', 'popup', 'header']
let l:wl += ['neo', 'fazzy']

" spelunker.vim option name
let l:wl += ['backquoted']

" Don't you think it is terrible?
let l:wl += ['don', 'doesn', 'didn', 'ain', 'isn', 'wasn', 'aren', 'weren']

Expand Down
4 changes: 4 additions & 0 deletions plugin/spelunker.vim
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ if !exists('g:spelunker_disable_email_checking')
let g:spelunker_disable_email_checking = 0
endif

if !exists('g:spelunker_disable_account_name_checking')
let g:spelunker_disable_account_name_checking = 0
endif

let g:spelunker_check_type_buf_lead_write = 1
let g:spelunker_check_type_cursor_hold = 2

Expand Down
11 changes: 11 additions & 0 deletions test/unit_test/get_buffer/disable_account_name.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

[email protected]

abc [email protected] def

ghi
[email protected]
jkl
@Annotation
mno @mrfoobar pqr
stu mrfoobar@ vwx