How to use the gitlint.linters.lint function in gitlint

To help you get started, we’ve selected a few gitlint examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sk- / git-lint / test / unittest / test_linters.py View on Github external
def test_lint_all_empty_lint(self):
        linter1 = functools.partial(linters.lint_command, 'l1', 'linter1',
                                    ['-f'], '^Line {lines}:')
        linter2 = functools.partial(linters.lint_command, 'l2', 'linter2', [],
                                    '^ line {lines}:')
        config = {'.txt': [linter1, linter2]}
        outputs = [b'', b'']
        with mock.patch('subprocess.check_output',
                        side_effect=outputs) as check_output, \
                mock.patch('os.path.getmtime', side_effect=[1, 0, 1, 0]):
            filename = 'foo.txt'
            self.assertEqual({
                filename: {
                    'comments': []
                }
            }, linters.lint(filename, lines=[4, 5], config=config))
            expected_calls = [
                mock.call(
                    ['linter1', '-f', 'foo.txt'], stderr=subprocess.STDOUT),
                mock.call(['linter2', 'foo.txt'], stderr=subprocess.STDOUT)
            ]
            self.assertEqual(expected_calls, check_output.call_args_list)
github sk- / git-lint / test / unittest / test_linters.py View on Github external
mock.patch('os.path.getmtime', side_effect=[1, 0, 1, 0]):
            filename = 'foo.txt'
            self.assertEqual({
                filename: {
                    'comments': [
                        {
                            'line': 4,
                            'message': '4'
                        },
                        {
                            'line': 5,
                            'message': '5'
                        },
                    ],
                },
            }, linters.lint(filename, lines=[4, 5], config=config))
            expected_calls = [
                mock.call(
                    ['linter1', '-f', 'foo.txt'], stderr=subprocess.STDOUT),
                mock.call(['linter2', 'foo.txt'], stderr=subprocess.STDOUT)
            ]
            self.assertEqual(expected_calls, check_output.call_args_list)
github sk- / git-lint / test / unittest / test_linters.py View on Github external
def test_lint_two_missing_programs(self):
        linter1 = functools.partial(linters.missing_requirements_command, 'l1',
                                    ['p1', 'p2'], 'Install p1 and p2')
        config = {'.txt': [linter1, linter1]}
        output = linters.lint('foo.txt', lines=[4, 5], config=config)
        self.assertEqual(2, len(output['foo.txt']['skipped']))
        output['foo.txt']['skipped'] = []
        self.assertEqual({'foo.txt': {'skipped': []}}, output)
github sk- / git-lint / test / unittest / test_linters.py View on Github external
def test_lint_missing_programs(self):
        linter1 = functools.partial(linters.missing_requirements_command, 'l1',
                                    ['p1', 'p2'], 'Install p1 and p2')
        config = {'.txt': [linter1]}
        output = linters.lint('foo.txt', lines=[4, 5], config=config)
        self.assertEqual(1, len(output['foo.txt']['skipped']))
        output['foo.txt']['skipped'] = []
        self.assertEqual({'foo.txt': {'skipped': []}}, output)
github sk- / git-lint / test / unittest / test_linters.py View on Github external
'line': 4,
                            'column': 1,
                            'message': '4.b',
                        },
                        {
                            'line': 4,
                            'column': 10,
                            'message': '4.a',
                        },
                        {
                            'line': 5,
                            'message': '5',
                        },
                    ],
                },
            }, linters.lint(filename, lines=None, config=config))
github sk- / git-lint / test / unittest / test_linters.py View on Github external
def test_lint_extension_not_defined(self):
        config = {}
        output = linters.lint('foo.txt', lines=[4, 5], config=config)
        self.assertEqual(1, len(output['foo.txt']['skipped']))
        output['foo.txt']['skipped'] = []
        self.assertEqual({'foo.txt': {'skipped': []}}, output)
github sk- / git-lint / test / unittest / test_linters.py View on Github external
config = {'.txt': [linter1, linter2]}
        outputs = [b'', os.linesep.join([' line 4: 4']).encode('utf-8')]
        with mock.patch('subprocess.check_output',
                        side_effect=outputs) as check_output, \
                mock.patch('os.path.getmtime', side_effect=[1, 0, 1, 0]):
            filename = 'foo.txt'
            self.assertEqual({
                filename: {
                    'comments': [
                        {
                            'line': 4,
                            'message': '4'
                        },
                    ],
                },
            }, linters.lint(filename, lines=[4, 5], config=config))
            expected_calls = [
                mock.call(
                    ['linter1', '-f', 'foo.txt'], stderr=subprocess.STDOUT),
                mock.call(['linter2', 'foo.txt'], stderr=subprocess.STDOUT)
            ]
            self.assertEqual(expected_calls, check_output.call_args_list)
github sk- / git-lint / gitlint / __init__.py View on Github external
def process_file(vcs, commit, force, gitlint_config, file_data):
    """Lint the file

    Returns:
      The results from the linter.
    """
    filename, extra_data = file_data

    if force:
        modified_lines = None
    else:
        modified_lines = vcs.modified_lines(
            filename, extra_data, commit=commit)
    result = linters.lint(filename, modified_lines, gitlint_config)
    result = result[filename]

    return filename, result