Skip to content

Commit

Permalink
Simplify naming style regexps
Browse files Browse the repository at this point in the history
Mostly remove unnecessary parenthesis.
  • Loading branch information
scop authored and PCManticore committed Dec 16, 2019
1 parent eb33a48 commit c4a954f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
24 changes: 12 additions & 12 deletions pylint/checkers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,34 +88,34 @@ class SnakeCaseStyle(NamingStyle):
"""Regex rules for snake_case naming style."""

CLASS_NAME_RGX = re.compile("[a-z_][a-z0-9_]+$")
MOD_NAME_RGX = re.compile("([a-z_][a-z0-9_]*)$")
CONST_NAME_RGX = re.compile("(([a-z_][a-z0-9_]*)|(__.*__))$")
MOD_NAME_RGX = re.compile("[a-z_][a-z0-9_]*$")
CONST_NAME_RGX = re.compile("([a-z_][a-z0-9_]*|__.*__)$")
COMP_VAR_RGX = re.compile("[a-z_][a-z0-9_]*$")
DEFAULT_NAME_RGX = re.compile(
"(([a-z_][a-z0-9_]{2,})|(_[a-z0-9_]*)|(__[a-z][a-z0-9_]+__))$"
"([a-z_][a-z0-9_]{2,}|_[a-z0-9_]*|__[a-z][a-z0-9_]+__)$"
)
CLASS_ATTRIBUTE_RGX = re.compile(r"(([a-z_][a-z0-9_]{2,}|(__.*__)))$")
CLASS_ATTRIBUTE_RGX = re.compile(r"([a-z_][a-z0-9_]{2,}|__.*__)$")


class CamelCaseStyle(NamingStyle):
"""Regex rules for camelCase naming style."""

CLASS_NAME_RGX = re.compile("[a-z_][a-zA-Z0-9]+$")
MOD_NAME_RGX = re.compile("([a-z_][a-zA-Z0-9]*)$")
CONST_NAME_RGX = re.compile("(([a-z_][A-Za-z0-9]*)|(__.*__))$")
MOD_NAME_RGX = re.compile("[a-z_][a-zA-Z0-9]*$")
CONST_NAME_RGX = re.compile("([a-z_][A-Za-z0-9]*|__.*__)$")
COMP_VAR_RGX = re.compile("[a-z_][A-Za-z0-9]*$")
DEFAULT_NAME_RGX = re.compile("(([a-z_][a-zA-Z0-9]{2,})|(__[a-z][a-zA-Z0-9_]+__))$")
CLASS_ATTRIBUTE_RGX = re.compile(r"([a-z_][A-Za-z0-9]{2,}|(__.*__))$")
DEFAULT_NAME_RGX = re.compile("([a-z_][a-zA-Z0-9]{2,}|__[a-z][a-zA-Z0-9_]+__)$")
CLASS_ATTRIBUTE_RGX = re.compile(r"([a-z_][A-Za-z0-9]{2,}|__.*__)$")


class PascalCaseStyle(NamingStyle):
"""Regex rules for PascalCase naming style."""

CLASS_NAME_RGX = re.compile("[A-Z_][a-zA-Z0-9]+$")
MOD_NAME_RGX = re.compile("[A-Z_][a-zA-Z0-9]+$")
CONST_NAME_RGX = re.compile("(([A-Z_][A-Za-z0-9]*)|(__.*__))$")
CONST_NAME_RGX = re.compile("([A-Z_][A-Za-z0-9]*|__.*__)$")
COMP_VAR_RGX = re.compile("[A-Z_][a-zA-Z0-9]+$")
DEFAULT_NAME_RGX = re.compile("[A-Z_][a-zA-Z0-9]{2,}$|(__[a-z][a-zA-Z0-9_]+__)$")
DEFAULT_NAME_RGX = re.compile("([A-Z_][a-zA-Z0-9]{2,}|__[a-z][a-zA-Z0-9_]+__)$")
CLASS_ATTRIBUTE_RGX = re.compile("[A-Z_][a-zA-Z0-9]{2,}$")


Expand All @@ -124,9 +124,9 @@ class UpperCaseStyle(NamingStyle):

CLASS_NAME_RGX = re.compile("[A-Z_][A-Z0-9_]+$")
MOD_NAME_RGX = re.compile("[A-Z_][A-Z0-9_]+$")
CONST_NAME_RGX = re.compile("(([A-Z_][A-Z0-9_]*)|(__.*__))$")
CONST_NAME_RGX = re.compile("([A-Z_][A-Z0-9_]*|__.*__)$")
COMP_VAR_RGX = re.compile("[A-Z_][A-Z0-9_]+$")
DEFAULT_NAME_RGX = re.compile("([A-Z_][A-Z0-9_]{2,}|(__[a-z][a-zA-Z0-9_]+__))$")
DEFAULT_NAME_RGX = re.compile("([A-Z_][A-Z0-9_]{2,}|__[a-z][a-zA-Z0-9_]+__)$")
CLASS_ATTRIBUTE_RGX = re.compile("[A-Z_][A-Z0-9_]{2,}$")


Expand Down
4 changes: 2 additions & 2 deletions tests/functional/n/namePresetCamelCase.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
invalid-name:3::"Constant name ""SOME_CONSTANT"" doesn't conform to camelCase naming style ('(([a-z_][A-Za-z0-9]*)|(__.*__))$' pattern)"
invalid-name:3::"Constant name ""SOME_CONSTANT"" doesn't conform to camelCase naming style ('([a-z_][A-Za-z0-9]*|__.*__)$' pattern)"
invalid-name:10:MyClass:"Class name ""MyClass"" doesn't conform to camelCase naming style ('[a-z_][a-zA-Z0-9]+$' pattern)"
invalid-name:22:say_hello:"Function name ""say_hello"" doesn't conform to camelCase naming style ('(([a-z_][a-zA-Z0-9]{2,})|(__[a-z][a-zA-Z0-9_]+__))$' pattern)"
invalid-name:22:say_hello:"Function name ""say_hello"" doesn't conform to camelCase naming style ('([a-z_][a-zA-Z0-9]{2,}|__[a-z][a-zA-Z0-9_]+__)$' pattern)"
2 changes: 1 addition & 1 deletion tests/functional/n/name_good_bad_names_regex.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
blacklisted-name:5::"Black listed name ""explicit_bad_some_constant"""
invalid-name:7::"Constant name ""snake_case_bad_SOME_CONSTANT"" doesn't conform to snake_case naming style ('(([a-z_][a-z0-9_]*)|(__.*__))$' pattern)"
invalid-name:7::"Constant name ""snake_case_bad_SOME_CONSTANT"" doesn't conform to snake_case naming style ('([a-z_][a-z0-9_]*|__.*__)$' pattern)"
blacklisted-name:19:blacklisted_2_snake_case:"Black listed name ""blacklisted_2_snake_case"""
4 changes: 2 additions & 2 deletions tests/functional/n/name_preset_snake_case.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
invalid-name:3::"Constant name ""SOME_CONSTANT"" doesn't conform to snake_case naming style ('(([a-z_][a-z0-9_]*)|(__.*__))$' pattern)"
invalid-name:3::"Constant name ""SOME_CONSTANT"" doesn't conform to snake_case naming style ('([a-z_][a-z0-9_]*|__.*__)$' pattern)"
invalid-name:10:MyClass:"Class name ""MyClass"" doesn't conform to snake_case naming style ('[a-z_][a-z0-9_]+$' pattern)"
invalid-name:22:sayHello:"Function name ""sayHello"" doesn't conform to snake_case naming style ('(([a-z_][a-z0-9_]{2,})|(_[a-z0-9_]*)|(__[a-z][a-z0-9_]+__))$' pattern)"
invalid-name:22:sayHello:"Function name ""sayHello"" doesn't conform to snake_case naming style ('([a-z_][a-z0-9_]{2,}|_[a-z0-9_]*|__[a-z][a-z0-9_]+__)$' pattern)"

0 comments on commit c4a954f

Please sign in to comment.