How to use the flake8.style_guide.Violation function in flake8

To help you get started, we’ve selected a few flake8 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 PyCQA / flake8 / tests / unit / test_statistics.py View on Github external
def make_error(**kwargs):
    """Create errors with a bunch of default values."""
    return style_guide.Violation(
        code=kwargs.pop('code', DEFAULT_ERROR_CODE),
        filename=kwargs.pop('filename', DEFAULT_FILENAME),
        line_number=kwargs.pop('line_number', 1),
        column_number=kwargs.pop('column_number', 1),
        text=kwargs.pop('text', DEFAULT_TEXT),
        physical_line=None,
    )
github PyCQA / flake8 / tests / unit / test_filenameonly_formatter.py View on Github external
def test_show_source_returns_nothing():
    """Verify show_source returns nothing."""
    formatter = default.FilenameOnly(options())
    error = style_guide.Violation('code', 'file.py', 1, 1, 'text', '1')

    assert formatter.show_source(error) is None
github PyCQA / flake8 / tests / unit / test_base_formatter.py View on Github external
def test_format_needs_to_be_implemented():
    """Ensure BaseFormatter#format raises a NotImplementedError."""
    formatter = base.BaseFormatter(options())
    with pytest.raises(NotImplementedError):
        formatter.format(
            style_guide.Violation('A000', 'file.py', 1, 1, 'error text', None)
        )
github PyCQA / flake8 / tests / unit / test_base_formatter.py View on Github external
def test_show_source_returns_nothing_when_there_is_source():
    """Ensure we return nothing when there is no line."""
    formatter = base.BaseFormatter(options(show_source=True))
    assert formatter.show_source(
        style_guide.Violation('A000', 'file.py', 1, 1, 'error text', None)
    ) == ''
github PyCQA / flake8 / tests / unit / test_violation.py View on Github external
def test_disable_is_inline_ignored():
    """Verify that is_inline_ignored exits immediately if disabling NoQA."""
    error = style_guide.Violation(
        'E121', 'filename.py', 1, 1, 'error text', 'line')

    with mock.patch('linecache.getline') as getline:
        assert error.is_inline_ignored(True) is False

    assert getline.called is False
github PyCQA / flake8 / tests / unit / test_nothing_formatter.py View on Github external
def test_show_source_returns_nothing():
    """Verify Nothing.show_source returns None."""
    formatter = default.Nothing(options())
    error = style_guide.Violation('code', 'file.py', 1, 1, 'text', '1')

    assert formatter.show_source(error) is None
github PyCQA / flake8 / tests / unit / test_base_formatter.py View on Github external
def test_handle_formats_the_error():
    """Verify that a formatter will call format from handle."""
    formatter = FormatFormatter(options(show_source=False))
    filemock = formatter.output_fd = mock.Mock()
    error = style_guide.Violation(
        code='A001',
        filename='example.py',
        line_number=1,
        column_number=1,
        text='Fake error',
        physical_line='a = 1',
    )

    formatter.handle(error)

    filemock.write.assert_called_once_with(repr(error) + '\n')
github PyCQA / flake8 / tests / unit / test_base_formatter.py View on Github external
def test_show_source_updates_physical_line_appropriately(line1, line2, column):
    """Ensure the error column is appropriately indicated."""
    formatter = base.BaseFormatter(options(show_source=True))
    error = style_guide.Violation('A000', 'file.py', 1, column, 'error', line1)
    output = formatter.show_source(error)
    assert output == line1 + line2
github snoack / flake8-per-file-ignores / flake8_per_file_ignores.py View on Github external
def is_inline_ignored(style_guide, checker, result):
    code, lineno, colno, text, line = result
    error = Violation(code, checker.display_name,
                      lineno, (colno or 0) + 1, text, line)

    if hasattr(error, 'is_inline_ignored'):
        return error.is_inline_ignored(style_guide.options.disable_noqa)

    # flake8 <3.4.0
    return style_guide.is_inline_ignored(error)
github life4 / flakehell / flakehell / _patched / _violation.py View on Github external
def is_inline_ignored(self, disable_noqa):
        return Violation.is_inline_ignored(self, disable_noqa)