示例#1
0
    def build_parser(self):
        config_dict = self._config.get_config_dict()
        enable_neovim = get_config_value(config_dict,
                                         ['cmdargs', 'env', 'neovim'], False)

        parser = Parser(self._plugins, enable_neovim=enable_neovim)
        return parser
示例#2
0
文件: cli.py 项目: Kuniwak/vint
def _build_lint_target(path, config_dict):  # type: (Path, Dict[str, Any]) -> AbstractLintTarget
    if path == _stdin_symbol:
        stdin_alt_path = get_config_value(config_dict, ['cmdargs', 'stdin_display_name'])

        # NOTE: In Python 3, sys.stdin is a string not bytes. Then we can get bytes by sys.stdin.buffer.
        #       But in Python 2, sys.stdin.buffer is not defined. But we can get bytes by sys.stdin directly.
        is_python_3 = hasattr(sys.stdin, 'buffer')
        if is_python_3:
            lint_target = LintTargetBufferedStream(
                alternate_path=Path(stdin_alt_path),
                buffered_io=sys.stdin.buffer
            )
        else:
            # NOTE: Python 2 on Windows opens sys.stdin in text mode, and
            # binary data that read from it becomes corrupted on \r\n
            # SEE: https://stackoverflow.com/questions/2850893/reading-binary-data-from-stdin/38939320#38939320
            if sys.platform == 'win32':
                # set sys.stdin to binary mode
                import os, msvcrt
                msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY)

            lint_target = LintTargetBufferedStream(
                alternate_path=Path(stdin_alt_path),
                buffered_io=sys.stdin
            )

        return CachedLintTarget(lint_target)

    else:
        lint_target = LintTargetFile(path)
        return CachedLintTarget(lint_target)
示例#3
0
文件: cli.py 项目: puremourning/vint
def _build_lint_target(
        path,
        config_dict):  # type: (Path, Dict[str, Any]) -> AbstractLintTarget
    if path == _stdin_symbol:
        stdin_alt_path = get_config_value(config_dict,
                                          ['cmdargs', 'stdin_display_name'])

        # NOTE: In Python 3, sys.stdin is a string not bytes. Then we can get bytes by sys.stdin.buffer.
        #       But in Python 2, sys.stdin.buffer is not defined. But we can get bytes by sys.stdin directly.
        is_python_3 = hasattr(sys.stdin, 'buffer')
        if is_python_3:
            lint_target = LintTargetBufferedStream(
                alternate_path=Path(stdin_alt_path),
                buffered_io=sys.stdin.buffer)
        else:
            # NOTE: Python 2 on Windows opens sys.stdin in text mode, and
            # binary data that read from it becomes corrupted on \r\n
            # SEE: https://stackoverflow.com/questions/2850893/reading-binary-data-from-stdin/38939320#38939320
            if sys.platform == 'win32':
                # set sys.stdin to binary mode
                import os, msvcrt
                msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY)

            lint_target = LintTargetBufferedStream(
                alternate_path=Path(stdin_alt_path), buffered_io=sys.stdin)

        return CachedLintTarget(lint_target)

    else:
        lint_target = LintTargetFile(path)
        return CachedLintTarget(lint_target)
示例#4
0
文件: linter.py 项目: Kuniwak/vint
    def __init__(self, policy_set, config_dict_global):
        # type: (PolicySet, Dict[str, Any]) -> None
        self._is_debug = get_config_value(config_dict_global, ['cmdargs', 'verbose'], False)

        self._plugins = {
            'scope': ScopePlugin(),
        }

        self._policy_set = policy_set
        self._config_dict_global = config_dict_global
        self._parser = self.build_parser()

        self._listeners_map = {}
示例#5
0
文件: linter.py 项目: Kuniwak/vint
    def build_parser(self):
        enable_neovim = get_config_value(self._config_dict_global, ['cmdargs', 'env', 'neovim'], False)

        parser = Parser([self._plugins['scope']], enable_neovim=enable_neovim)
        return parser
示例#6
0
    def test_get_config_value_when_empty(self):
        config_dict = {}

        self.assertIsNone(get_config_value(config_dict, ['a']))
示例#7
0
    def test_get_config_value_when_given_default_but_not_used(self):
        config_dict = {'a': 'A'}

        self.assertEqual(get_config_value(config_dict, ['a'], 'DEFAULT'), 'A')
示例#8
0
    def test_get_config_value_when_given_default(self):
        config_dict = {'a': 'A'}

        self.assertEqual(get_config_value(config_dict, ['c', 'b'], 'DEFAULT'),
                         'DEFAULT')
示例#9
0
    def test_get_config_value_when_nested_2_depth(self):
        config_dict = {'a': {'b': 'B'}}

        self.assertIs(get_config_value(config_dict, ['a', 'b']), 'B')
示例#10
0
    def test_get_config_value_when_nested_2_depth(self):
        config_dict = {'a': {'b': 'B'}}

        self.assertIs(get_config_value(config_dict, ['a', 'b']), 'B')
示例#11
0
    def test_get_config_value_when_nested_1_depth(self):
        config_dict = {'a': 'A'}

        self.assertIs(get_config_value(config_dict, ['a']), 'A')
示例#12
0
    def test_get_config_value_when_empty(self):
        config_dict = {}

        self.assertIsNone(get_config_value(config_dict, ['a']))
示例#13
0
    def test_get_config_value_when_given_default_but_not_used(self):
        config_dict = {'a': 'A'}

        self.assertEqual(get_config_value(config_dict, ['a'], 'DEFAULT'), 'A')
示例#14
0
    def test_get_config_value_when_given_default(self):
        config_dict = {'a': 'A'}

        self.assertEqual(get_config_value(config_dict, ['c', 'b'], 'DEFAULT'), 'DEFAULT')
示例#15
0
    def test_get_config_value_when_target_is_depth_2_unexistent_dict(self):
        config_dict = {'a': 'A'}

        self.assertEqual(get_config_value(config_dict, ['c', 'b']), None)
示例#16
0
    def test_get_config_value_when_target_is_dict(self):
        config_dict = {'a': {'b': 'B'}}

        self.assertEqual(get_config_value(config_dict, ['a']), {'b': 'B'})
示例#17
0
    def test_get_config_value_when_target_is_dict(self):
        config_dict = {'a': {'b': 'B'}}

        self.assertEqual(get_config_value(config_dict, ['a']), {'b': 'B'})
示例#18
0
    def test_get_config_value_when_target_is_depth_2_unexistent_dict(self):
        config_dict = {'a': 'A'}

        self.assertEqual(get_config_value(config_dict, ['c', 'b']), None)
示例#19
0
文件: linter.py 项目: RianFuro/vint
    def build_parser(self):
        config_dict = self._config.get_config_dict()
        enable_neovim = get_config_value(config_dict, ['cmdargs', 'env', 'neovim'], False)

        parser = Parser(self._plugins, enable_neovim=enable_neovim)
        return parser
示例#20
0
    def test_get_config_value_when_nested_1_depth(self):
        config_dict = {'a': 'A'}

        self.assertIs(get_config_value(config_dict, ['a']), 'A')