How to use the hacking.core function in hacking

To help you get started, we’ve selected a few hacking 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 openstack / mistral / mistral / hacking / checks.py View on Github external
@core.flake8ext
def check_python3_xrange(logical_line):
    if re.search(r"\bxrange\s*\(", logical_line):
        yield(0, "M327: Do not use xrange(). 'xrange()' is not compatible "
              "with Python 3. Use range() or six.moves.range() instead.")
github openstack / glance / glance / hacking / checks.py View on Github external
@core.flake8ext
def assert_equal_type(logical_line):
    """Check for assertEqual(type(A), B) sentences

    G317
    """
    if asse_equal_type_re.match(logical_line):
        yield (0, "G317: assertEqual(type(A), B) sentences not allowed")
github openstack / hacking / hacking / checks / localization.py View on Github external
@core.flake8ext
def hacking_localization_strings(logical_line, tokens, noqa):
    r"""Check localization in line.

    Okay: _("This is fine")
    Okay: _LI("This is fine")
    Okay: _LW("This is fine")
    Okay: _LE("This is fine")
    Okay: _LC("This is fine")
    Okay: _("This is also fine %s")
    Okay: _("So is this %s, %(foo)s") % {foo: 'foo'}
    H701: _('')
    Okay: def _(msg):\n    pass
    Okay: def _LE(msg):\n    pass
    H701: _LI('')
    H701: _LW('')
    H701: _LE('')
github openstack / hacking / hacking / checks / other.py View on Github external
@core.flake8ext
def hacking_no_cr(physical_line):
    r"""Check that we only use newlines not carriage returns.

    Okay: import os\nimport sys
    # pep8 doesn't yet replace \r in strings, will work on an
    # upstream fix
    H903 import os\r\nimport sys
    """
    pos = physical_line.find('\r')
    if pos != -1 and pos == (len(physical_line) - 2):
        return (pos, "H903: Windows style line endings not allowed in code")
github openstack / murano / murano / hacking / checks.py View on Github external
@core.flake8ext
def no_mutable_default_args(logical_line):
    msg = "M322: Method's default argument shouldn't be mutable!"
    if mutable_default_args.match(logical_line):
        yield (0, msg)
github openstack / hacking / hacking / checks / comments.py View on Github external
@core.flake8ext
def hacking_todo_format(physical_line, tokens):
    """Check for 'TODO()'.

    OpenStack HACKING guide recommendation for TODO:
    Include your name with TODOs as in "# TODO(termie)"

    Okay: # TODO(sdague)
    H101: # TODO fail
    H101: # TODO
    H101: # TODO (jogo) fail
    Okay: TODO = 5
    """
    # TODO(jogo): make the following doctests pass:
    #            H101: #TODO(jogo fail
    #            H101: #TODO(jogo
    # TODO(jogo): make this check docstrings as well (don't have to be at top
github openstack / osprofiler / osprofiler / hacking / checks.py View on Github external
@core.flake8ext
def skip_ignored_lines(func):

    @functools.wraps(func)
    def wrapper(logical_line, filename):
        line = logical_line.strip()
        if not line or line.startswith("#") or line.endswith("# noqa"):
            return
        yield next(func(logical_line, filename))

    return wrapper
github openstack / senlin / senlin / hacking / checks.py View on Github external
@core.flake8ext
def assert_equal_none(logical_line):
    """Check for assertEqual(A, None) or assertEqual(None, A) sentences

    S318
    """
    res = (asse_equal_start_with_none_re.search(logical_line) or
           asse_equal_end_with_none_re.search(logical_line))
    if res:
        yield (0, "S318: assertEqual(A, None) or assertEqual(None, A) "
               "sentences not allowed")
github openstack / hacking / hacking / checks / other.py View on Github external
@core.flake8ext
@core.off_by_default
def hacking_delayed_string_interpolation(logical_line, noqa):
    r"""String interpolation should be delayed at logging calls.

    H904: LOG.debug('Example: %s' % 'bad')
    Okay: LOG.debug('Example: %s', 'good')
    """
    msg = ("H904: String interpolation should be delayed to be "
           "handled by the logging code, rather than being done "
           "at the point of the logging call. "
           "Use ',' instead of '%'.")

    if noqa:
        return

    if log_string_interpolation.match(logical_line):