Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/guide/rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ The `name` is used to reference the rule in `apply` blocks and in `# pnl: ignore

| Field | Required | Description |
|-------|----------|-------------|
| `name` | Yes | Unique identifier, referenced in `apply` and `# pnl: ignore` |
| `name` | Yes | Unique identifier, referenced in `apply` and `# pnl: ignore`. Must match `[a-zA-Z0-9_.-]+` |
| `description` | No | Human-readable description shown in violation output |
| `type` | Yes | What kind of name to lint (`variable`, `function`, `class`, `module`, `package`) |
| `filter` | No | Narrow which names are checked (see [Filters](#filters) below) |
Expand Down Expand Up @@ -917,7 +917,7 @@ apply:

| Field | Required | Description |
|-------|----------|-------------|
| `name` | Yes | Unique identifier, referenced in `apply` and `# pnl: ignore` |
| `name` | Yes | Unique identifier, referenced in `apply` and `# pnl: ignore`. Must match `[a-zA-Z0-9_.-]+` |
| `description` | No | Human-readable description shown in violation output |
| `type` | Yes | What kind of name to lint (`variable`, `function`, `class`, `module`, `package`) |
| `filter` | No | Narrow which names are checked |
Expand Down
4 changes: 2 additions & 2 deletions python_naming_linter/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import yaml

_VALID_RULE_NAME_RE = re.compile(r"^[a-zA-Z0-9_-]+$")
_VALID_RULE_NAME_RE = re.compile(r"^[a-zA-Z0-9_.\-]+$")


@dataclass
Expand Down Expand Up @@ -36,7 +36,7 @@ class Config:
def _validate_rule_name(name: str) -> None:
if not _VALID_RULE_NAME_RE.match(name):
raise ValueError(
f"Invalid rule name '{name}'. Rule names must match [a-zA-Z0-9_-]+"
f"Invalid rule name '{name}'. Rule names must match [a-zA-Z0-9_.-]+"
)


Expand Down
2 changes: 1 addition & 1 deletion python_naming_linter/ignore.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from python_naming_linter.checkers import Violation

_IGNORE_RE = re.compile(r"#\s*pnl:\s*ignore(?:=([a-zA-Z0-9_,\s-]+))?$")
_IGNORE_RE = re.compile(r"#\s*pnl:\s*ignore(?:=([a-zA-Z0-9_.,\s-]+))?$")


def parse_ignore_comments(source: str) -> dict[int, set[str] | None]:
Expand Down
11 changes: 9 additions & 2 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,14 @@ def test_find_config_skips_pyproject_without_section(tmp_path, monkeypatch):

@pytest.mark.parametrize(
"name",
["attribute-matches-type", "bool_method", "rule1", "My-Rule_2"],
[
"attribute-matches-type",
"bool_method",
"rule1",
"My-Rule_2",
"rule.name",
"shared.domain",
],
)
def test_valid_rule_names(tmp_path, name):
config_content = f"""\
Expand All @@ -148,7 +155,7 @@ def test_valid_rule_names(tmp_path, name):

@pytest.mark.parametrize(
"name",
["my rule", "rule!name", "rule name 123", "rule.name", "rule@name"],
["my rule", "rule!name", "rule name 123", "rule@name"],
)
def test_invalid_rule_names(tmp_path, name):
config_content = f"""\
Expand Down
10 changes: 10 additions & 0 deletions tests/test_ignore.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ def test_extra_space_after_pnl(self):
source = "x: int = 1 # pnl: ignore\n"
assert parse_ignore_comments(source) == {1: None}

def test_ignore_rule_with_dot(self):
source = "x: int = 1 # pnl: ignore=shared.domain\n"
assert parse_ignore_comments(source) == {1: {"shared.domain"}}

def test_ignore_multiple_rules_with_dots(self):
source = "x: int = 1 # pnl: ignore=shared.domain,context.adapters\n"
assert parse_ignore_comments(source) == {
1: {"shared.domain", "context.adapters"}
}


class TestFilterViolations:
def _make_violation(self, rule_name: str, lineno: int) -> Violation:
Expand Down
Loading