mirror of
https://github.com/adrienverge/yamllint.git
synced 2025-02-25 18:55:20 -06:00
octal-values: Pre-compile regex for performance
This commit is contained in:
parent
bdbec7dc4d
commit
5658cf7f42
@ -84,9 +84,7 @@ CONF = {'forbid-implicit-octal': bool,
|
|||||||
DEFAULT = {'forbid-implicit-octal': True,
|
DEFAULT = {'forbid-implicit-octal': True,
|
||||||
'forbid-explicit-octal': True}
|
'forbid-explicit-octal': True}
|
||||||
|
|
||||||
|
IS_OCTAL_NUMBER_PATTERN = re.compile(r'^[0-7]+$')
|
||||||
def _is_octal_number(string):
|
|
||||||
return re.match(r'^[0-7]+$', string) is not None
|
|
||||||
|
|
||||||
|
|
||||||
def check(conf, token, prev, next, nextnext, context):
|
def check(conf, token, prev, next, nextnext, context):
|
||||||
@ -98,7 +96,7 @@ def check(conf, token, prev, next, nextnext, context):
|
|||||||
if not token.style:
|
if not token.style:
|
||||||
val = token.value
|
val = token.value
|
||||||
if (val.isdigit() and len(val) > 1 and val[0] == '0' and
|
if (val.isdigit() and len(val) > 1 and val[0] == '0' and
|
||||||
_is_octal_number(val[1:])):
|
IS_OCTAL_NUMBER_PATTERN.match(val[1:]) is not None):
|
||||||
yield LintProblem(
|
yield LintProblem(
|
||||||
token.start_mark.line + 1, token.end_mark.column + 1,
|
token.start_mark.line + 1, token.end_mark.column + 1,
|
||||||
'forbidden implicit octal value "%s"' %
|
'forbidden implicit octal value "%s"' %
|
||||||
@ -109,7 +107,7 @@ def check(conf, token, prev, next, nextnext, context):
|
|||||||
if not token.style:
|
if not token.style:
|
||||||
val = token.value
|
val = token.value
|
||||||
if (len(val) > 2 and val[:2] == '0o' and
|
if (len(val) > 2 and val[:2] == '0o' and
|
||||||
_is_octal_number(val[2:])):
|
IS_OCTAL_NUMBER_PATTERN.match(val[2:]) is not None):
|
||||||
yield LintProblem(
|
yield LintProblem(
|
||||||
token.start_mark.line + 1, token.end_mark.column + 1,
|
token.start_mark.line + 1, token.end_mark.column + 1,
|
||||||
'forbidden explicit octal value "%s"' %
|
'forbidden explicit octal value "%s"' %
|
||||||
|
Loading…
Reference in New Issue
Block a user