Skip to content

Commit 3a2729e

Browse files
authored
Support --stdin-display-name and the mixed style of files and stdin (#278)
* Support --stdin-alt-name and the mix style such as `vint a.vim - b.vim` * Care Python 2 * Add available options in README * fixup! Care Python 2 * fixup! Care Python 2 * Update README * Rename --stdin-alt-path to --stdin-display-name * Add a test for stdin * fixup! Support --stdin-alt-name and the mix style such as `vint a.vim - b.vim`
1 parent efff450 commit 3a2729e

38 files changed

+510
-285
lines changed

README.rst

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,40 @@ You can configure linting severity, max errors, ... as following:
122122

123123
$ vint --color --style ~/.vimrc
124124

125+
And you can see all available options by using `--help`:
126+
127+
::
128+
$ vint --help
129+
usage: vint [-h] [-v] [-V] [-e] [-w] [-s] [-m MAX_VIOLATIONS] [-c]
130+
[--no-color] [-j] [-t] [--enable-neovim] [-f FORMAT]
131+
[--stdin-alt-path STDIN_ALT_PATH]
132+
[files [files ...]]
133+
134+
Lint Vim script
135+
136+
positional arguments:
137+
files file or directory path to lint
138+
139+
optional arguments:
140+
-h, --help show this help message and exit
141+
-v, --version show program's version number and exit
142+
-V, --verbose output verbose message
143+
-e, --error report only errors
144+
-w, --warning report errors and warnings
145+
-s, --style-problem report errors, warnings and style problems
146+
-m MAX_VIOLATIONS, --max-violations MAX_VIOLATIONS
147+
limit max violations count
148+
-c, --color colorize output when possible
149+
--no-color do not colorize output
150+
-j, --json output json style
151+
-t, --stat output statistic info
152+
--enable-neovim enable Neovim syntax
153+
-f FORMAT, --format FORMAT
154+
set output format
155+
--stdin-display-name STDIN_DISPLAY_NAME
156+
specify a file path that is used for reporting when
157+
linting standard inputs
158+
125159
Comment config
126160
~~~~~~~~~~~~~~
127161

dev_tool/show_encoding.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@
1919

2020
file_path = Path(namespace['file'][0])
2121
decoder = Decoder(default_decoding_strategy)
22-
decoder.read(file_path)
22+
decoder.decode(file_path)
2323
pprint(decoder.debug_hint)

test/acceptance/test_cli.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,5 +144,17 @@ def test_exec_vint_with_color_flag(self):
144144
self.assertRegex(got_output, expected_output_pattern)
145145

146146

147+
def test_exec_vint_with_pipe(self):
148+
cmd = 'echo "foo" =~ "bar" | bin/vint --stdin-display-name STDIN_TEST -'
149+
150+
with self.assertRaises(subprocess.CalledProcessError) as context_manager:
151+
subprocess.check_output(cmd, shell=True, universal_newlines=True)
152+
153+
got_output = context_manager.exception.output
154+
155+
expected_output_pattern = '^STDIN_TEST:'
156+
self.assertRegex(got_output, expected_output_pattern)
157+
158+
147159
if __name__ == '__main__':
148160
unittest.main()

test/asserting/policy.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
from vint.compat.itertools import zip_longest
55
from vint.linting.policy_set import PolicySet
66
from vint.linting.linter import Linter
7+
from vint.linting.config.config_default_source import ConfigDefaultSource
8+
from vint.linting.lint_target import LintTargetFile
79
from vint.linting.level import Level
810

911

@@ -31,7 +33,7 @@ def assertFoundViolationsEqual(self, path, Policy, expected_violations, policy_o
3133
config_dict['policies'][policy_name] = policy_options
3234

3335
linter = Linter(policy_set, config_dict)
34-
violations = linter.lint_file(path)
36+
violations = linter.lint(LintTargetFile(path))
3537

3638
pprint(violations)
3739
self.assertEqual(len(violations), len(expected_violations))
@@ -43,9 +45,13 @@ def assertFoundViolationsEqual(self, path, Policy, expected_violations, policy_o
4345
def assertViolation(self, actual_violation, expected_violation):
4446
self.assertIsNot(actual_violation, None)
4547
self.assertIsNot(expected_violation, None)
48+
49+
pprint(actual_violation)
50+
4651
self.assertEqual(actual_violation['name'], expected_violation['name'])
4752
self.assertEqual(actual_violation['position'], expected_violation['position'])
4853
self.assertEqual(actual_violation['level'], expected_violation['level'])
54+
4955
self.assertIsInstance(actual_violation['description'], str)
5056

5157

test/fixture/lint_target.vim

Whitespace-only changes.

test/integration/vint/ast/plugin/test_scope_plugin.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
is_declarative_identifier,
1111
)
1212
from vint.ast.plugin.scope_plugin import ScopePlugin
13+
from vint.linting.lint_target import LintTargetFile
1314

1415

1516
FIXTURE_BASE_PATH = Path('test', 'fixture', 'ast', 'scope_plugin')
@@ -41,7 +42,7 @@ class Fixtures(enum.Enum):
4142
class TestScopePlugin(unittest.TestCase):
4243
def create_ast(self, file_path):
4344
parser = Parser()
44-
ast = parser.parse_file(file_path.value)
45+
ast = parser.parse(LintTargetFile(file_path.value))
4546
return ast
4647

4748

test/integration/vint/linting/test_linter.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from vint.linting.level import Level
55
from vint.linting.policy.abstract_policy import AbstractPolicy
66
from vint.linting.linter import Linter
7+
from vint.linting.lint_target import LintTargetFile
78

89
INVALID_VIM_SCRIPT = Path('test', 'fixture', 'linter', 'invalid.vim')
910
BROKEN_VIM_SCRIPT = Path('test', 'fixture', 'linter', 'broken.vim')
@@ -86,7 +87,7 @@ def test_lint(self):
8687
}
8788

8889
linter = Linter(policy_set, config_dict_global)
89-
got_violations = linter.lint_file(INVALID_VIM_SCRIPT)
90+
got_violations = linter.lint(LintTargetFile(INVALID_VIM_SCRIPT))
9091

9192
expected_violations = [
9293
{
@@ -147,7 +148,7 @@ def test_lint_with_broken_file(self):
147148
}
148149

149150
linter = Linter(policy_set, config_dict_global)
150-
got_violations = linter.lint_file(BROKEN_VIM_SCRIPT)
151+
got_violations = linter.lint(LintTargetFile(BROKEN_VIM_SCRIPT))
151152

152153
expected_violations = [
153154
{

test/unit/vint/ast/plugin/scope_plugin/test_call_node_parser.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
get_lambda_string_expr_content,
1111
FUNCTION_REFERENCE_STRING_EXPR_CONTENT,
1212
)
13+
from vint.linting.lint_target import LintTargetFile
1314

1415

1516
FIXTURE_BASE_PATH = Path('test', 'fixture', 'ast', 'scope_plugin')
@@ -27,7 +28,7 @@ class Fixtures(enum.Enum):
2728
class TestCallNodeParser(unittest.TestCase):
2829
def create_ast(self, file_path):
2930
parser = Parser()
30-
ast = parser.parse_file(file_path.value)
31+
ast = parser.parse(LintTargetFile(file_path.value))
3132
return ast
3233

3334

test/unit/vint/ast/plugin/scope_plugin/test_identifier_classifier.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
IDENTIFIER_ATTRIBUTE_LAMBDA_ARGUMENT_FLAG,
2222
IDENTIFIER_ATTRIBUTE_LAMBDA_BODY_CONTEXT,
2323
)
24+
from vint.linting.lint_target import LintTargetFile
2425

2526

2627
FIXTURE_BASE_PATH = Path('test', 'fixture', 'ast', 'scope_plugin')
@@ -64,7 +65,7 @@
6465
class TestIdentifierClassifier(unittest.TestCase):
6566
def create_ast(self, file_path):
6667
parser = Parser()
67-
ast = parser.parse_file(file_path)
68+
ast = parser.parse(LintTargetFile(file_path))
6869
return ast
6970

7071

test/unit/vint/ast/plugin/scope_plugin/test_identifier_collector.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from vint.ast.parsing import Parser
55
from vint.ast.plugin.scope_plugin.identifier_classifier import IdentifierClassifier
6+
from vint.linting.lint_target import LintTargetFile
67

78
FIXTURE_BASE_PATH = Path('test', 'fixture', 'ast', 'scope_plugin')
89

@@ -15,7 +16,7 @@
1516
class TestIdentifierCollector(unittest.TestCase):
1617
def create_ast(self, file_path):
1718
parser = Parser()
18-
ast = parser.parse_file(file_path)
19+
ast = parser.parse(LintTargetFile(file_path))
1920

2021
id_classifier = IdentifierClassifier()
2122
attached_ast = id_classifier.attach_identifier_attributes(ast)

0 commit comments

Comments
 (0)