-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prepare to become ProhibitUnusedVariable to default-enabled (#275)
* Upgrade Vital.vim * Refactor scope_plugin internal * Add a test for #274 * Visit into NodeType.CURLYNAMEEXPR * NodeType.CURLYNAME should be classified as dynamic * Refactor IdentifierClassifier internal * Rename the fixture for #274 to prepare for a test for * Analyze NodeType.CALL for `call` or `function` when the first arg is NodeType.STRING * fixup! Add a test for #274 * Refactor scope_plugin internal * Fix false positives that is referenced at #274 comments * Support ignored patterns for ProhibitUnusedVariable * Fix a typo * "..." should be not reported by ProhibitUnusedVariable * Initial implementation for line config comments * Add a test for README * Better debugging * fixup! Initial implementation for line config comments * fixup! Add a test for README * Fix order of plugins * Keep disabled * Update README.rst * Fix tests * Change line config comment to next line config comment * `traverse()` can visit into NodeType.LAMBDA * fixup! Initial implementation for line config comments * Fix bug that caused by unexpected side-sffect of * Add `source_name` to config_dict to debugging * Fix a bug that occurred when a next line is skipped * Tweak debugging output * Fix a bug that is caused by unexpected side-effects from multiple linting * Support lambda * Allow func arg names that have a same name as builtins * Fix tests * Fix a test * Care Python 2
- Loading branch information
Showing
71 changed files
with
2,749 additions
and
1,409 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
1 change: 1 addition & 0 deletions
1
test/fixture/ast/scope_plugin/fixture_to_scope_plugin_issue_274_call.vim
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
call call('s:Foo', []) |
1 change: 1 addition & 0 deletions
1
test/fixture/ast/scope_plugin/fixture_to_scope_plugin_issue_274_curlyname.vim
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
let s:{x} = "" |
4 changes: 4 additions & 0 deletions
4
test/fixture/ast/scope_plugin/fixture_to_scope_plugin_issue_274_curlyname_complex.vim
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
function! s:foo(x) abort | ||
let x = 'x' | ||
let y = l:{x} | ||
endfunction |
1 change: 1 addition & 0 deletions
1
test/fixture/ast/scope_plugin/fixture_to_scope_plugin_issue_274_function.vim
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
call function('s:Foo') |
1 change: 1 addition & 0 deletions
1
test/fixture/ast/scope_plugin/fixture_to_scope_plugin_lambda_param.vim
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
call map([], { i, ... -> y }) |
Submodule vital.vim
updated
48 files
12 changes: 12 additions & 0 deletions
12
test/fixture/config/fixture_for_line_comment_lambda_string_expr.vim
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
echo 'report me because I have no line config comments' | ||
|
||
" vint: next-line -ProhibitStringPolicy | ||
call map([], '"do not report me"') | ||
|
||
echo 'report me because I have no line config comments, but the previous line have it' | ||
|
||
" vint: next-line -ProhibitStringPolicy | ||
call map( | ||
\ [], | ||
\ '"report me because I have no line config comments, but the parent node have it"' | ||
\) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
let s:x = 'report me because I have no line config comments' | ||
|
||
" vint: next-line -ProhibitStringPolicy | ||
let s:x = 'do not report me because I have a line config comment' | ||
|
||
let s:x = 'report me because I have no line config comments, but the previous line have it' |
This file contains 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
This file contains 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
This file contains 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
6 changes: 6 additions & 0 deletions
6
test/fixture/policy/prohibit_unused_variable_ignored_patterns.vim
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
let s:unused = 'report me' | ||
let s:unused_but_ignored = 'not report me' | ||
let s:used = 'not report me' | ||
let s:used_but_ignored = 'not report me' | ||
echo s:used_but_ignored | ||
echo s:used |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
function! s:foo() abort | ||
let x = 'x' | ||
let y = l:{x} | ||
echo y | ||
endfunction | ||
|
||
call call('s:foo', []) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
" vint: next-line -ProhibitUnusedVariable | ||
let s:foobar = 'x' | ||
echo s:{'foo' . 'bar'} |
This file contains 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
This file contains 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
51 changes: 38 additions & 13 deletions
51
test/integration/vint/linting/policy/test_prohibit_unused_variable.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,69 @@ | ||
import unittest | ||
import enum | ||
from test.asserting.policy import PolicyAssertion, get_fixture_path | ||
|
||
from vint.linting.level import Level | ||
from vint.linting.policy.prohibit_unused_variable import ProhibitUnusedVariable | ||
|
||
PATH_VALID_VIM_SCRIPT = get_fixture_path('prohibit_unused_variable_valid.vim') | ||
PATH_INVALID_VIM_SCRIPT = get_fixture_path('prohibit_unused_variable_invalid.vim') | ||
class Fixtures(enum.Enum): | ||
VALID_VIM_SCRIPT = get_fixture_path('prohibit_unused_variable_valid.vim') | ||
INVALID_VIM_SCRIPT = get_fixture_path('prohibit_unused_variable_invalid.vim') | ||
ISSUE_274 = get_fixture_path('prohibit_unused_variable_issue_274.vim') | ||
IGNORED_PATTERNS = get_fixture_path('prohibit_unused_variable_ignored_patterns.vim') | ||
README = get_fixture_path('prohibit_unused_variable_readme.vim') | ||
|
||
|
||
class TestProhibitUnusedVariable(PolicyAssertion, unittest.TestCase): | ||
def test_get_violation_if_found_when_file_is_valid(self): | ||
self.assertFoundNoViolations(PATH_VALID_VIM_SCRIPT, | ||
self.assertFoundNoViolations(Fixtures.VALID_VIM_SCRIPT.value, | ||
ProhibitUnusedVariable) | ||
|
||
|
||
def create_violation(self, line, column): | ||
def create_violation(self, line, column, path): | ||
return { | ||
'name': 'ProhibitUnusedVariable', | ||
'level': Level.WARNING, | ||
'position': { | ||
'line': line, | ||
'column': column, | ||
'path': PATH_INVALID_VIM_SCRIPT | ||
'path': path | ||
} | ||
} | ||
|
||
|
||
def test_get_violation_if_found_when_file_is_invalid(self): | ||
expected_violations = [ | ||
self.create_violation(2, 5), | ||
self.create_violation(4, 11), | ||
self.create_violation(7, 25), | ||
self.create_violation(7, 36), | ||
self.create_violation(11, 9), | ||
self.create_violation(12, 9), | ||
self.create_violation(2, 5, Fixtures.INVALID_VIM_SCRIPT.value), | ||
self.create_violation(4, 11, Fixtures.INVALID_VIM_SCRIPT.value), | ||
self.create_violation(7, 25, Fixtures.INVALID_VIM_SCRIPT.value), | ||
self.create_violation(7, 36, Fixtures.INVALID_VIM_SCRIPT.value), | ||
self.create_violation(11, 9, Fixtures.INVALID_VIM_SCRIPT.value), | ||
self.create_violation(12, 9, Fixtures.INVALID_VIM_SCRIPT.value), | ||
self.create_violation(15, 8, Fixtures.INVALID_VIM_SCRIPT.value), | ||
] | ||
|
||
self.assertFoundViolationsEqual(PATH_INVALID_VIM_SCRIPT, | ||
self.assertFoundViolationsEqual(Fixtures.INVALID_VIM_SCRIPT.value, | ||
ProhibitUnusedVariable, | ||
expected_violations) | ||
|
||
def test_issue_274(self): | ||
self.assertFoundNoViolations(Fixtures.ISSUE_274.value, ProhibitUnusedVariable) | ||
|
||
|
||
def test_ignored_patterns(self): | ||
expected_violations = [ | ||
self.create_violation(1, 5, Fixtures.IGNORED_PATTERNS.value), | ||
] | ||
|
||
self.assertFoundViolationsEqual(Fixtures.IGNORED_PATTERNS.value, | ||
ProhibitUnusedVariable, | ||
expected_violations, | ||
policy_options={'ignored_patterns': ['_ignored$']}) | ||
|
||
|
||
def test_readme(self): | ||
self.assertFoundNoViolations(Fixtures.README.value, | ||
ProhibitUnusedVariable) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
Oops, something went wrong.