Skip to content

Commit

Permalink
Make contants prefixed with underscore valid, closes #223
Browse files Browse the repository at this point in the history
  • Loading branch information
Scony committed Aug 20, 2023
1 parent 61ca00e commit c9ecf76
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Changed
- Fixed `max-public-methods` linter check disabling (#222)
- Default regex for names of constants now allows underscore as a prefix to denote private contants (#223)

## [4.1.0] 2023-07-06

Expand Down
5 changes: 3 additions & 2 deletions gdtoolkit/linter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
SNAKE_CASE = r"[a-z][a-z0-9]*(_[a-z0-9]+)*"
PRIVATE_SNAKE_CASE = r"_?{}".format(SNAKE_CASE)
UPPER_SNAKE_CASE = r"[A-Z][A-Z0-9]*(_[A-Z0-9]+)*"
PRIVATE_UPPER_SNAKE_CASE = f"_?{UPPER_SNAKE_CASE}"

DEFAULT_CONFIG = MappingProxyType(
{
Expand All @@ -39,8 +40,8 @@
"loop-variable-name": PRIVATE_SNAKE_CASE,
"enum-name": PASCAL_CASE,
"enum-element-name": UPPER_SNAKE_CASE,
"constant-name": UPPER_SNAKE_CASE,
"load-constant-name": r"({}|{})".format(PASCAL_CASE, UPPER_SNAKE_CASE),
"constant-name": PRIVATE_UPPER_SNAKE_CASE,
"load-constant-name": r"({}|{})".format(PASCAL_CASE, PRIVATE_UPPER_SNAKE_CASE),
# basic checks
"duplicated-load": None,
"expression-not-assigned": None,
Expand Down
6 changes: 3 additions & 3 deletions tests/linter/test_name_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,9 @@ def test_function_preload_variable_name_nok(code):
const X = 1
""",
"""
const _X = 2
""",
"""
const X_Y_Z = 2
""",
])
Expand All @@ -324,9 +327,6 @@ def test_constant_name_ok(code):
const Xx = 1
""",
"""
const _X = 2
""",
"""
const x_x = 2
""",
])
Expand Down

0 comments on commit c9ecf76

Please sign in to comment.