mirror of
https://github.com/rennf93/roboco.git
synced 2026-08-03 07:23:24 +02:00
[F030] conventions: typescript-scoped custom rules now apply to .tsx files
The validator tags a .tsx file as language 'tsx' (the JSX grammar needs
that tag, distinct from plain 'typescript'), but a custom rule scoped to
'typescript' — the language the scan reports for a React+TS repo — silently
skipped every .tsx file. The two suffix maps were NOT unified: the 'tsx'
tag is load-bearing (grammars.py picks the JSX grammar on it; hygiene.py
keys on it), so unifying would make .tsx fail to parse.
Fix is in check_custom: a one-directional dialect map _DIALECT_OF =
{'tsx': 'typescript'} — a typescript-scoped rule fires on a .tsx file,
but a tsx-scoped (JSX-only) rule still does not fire on plain .ts.
TDD; ruff/mypy clean; 80 unit + 38 integration conventions tests green.
This commit is contained in:
@@ -18,6 +18,26 @@ if TYPE_CHECKING:
|
||||
CustomRule,
|
||||
)
|
||||
|
||||
# Dialect relations: the validator tags a ``.tsx`` file as language ``tsx``
|
||||
# (the JSX grammar needs that tag, distinct from plain ``typescript``), but a
|
||||
# custom rule scoped to ``typescript`` — the language the scan *reports* for a
|
||||
# React+TS repo — must still apply to ``.tsx`` files. The relation is
|
||||
# one-directional: ``tsx`` is a TypeScript dialect, so a ``typescript``-scoped
|
||||
# rule fires on ``.tsx``, but a ``tsx``-scoped (JSX-only) rule does not fire on
|
||||
# plain ``.ts``. Map each dialect tag to the language family it belongs to.
|
||||
_DIALECT_OF: dict[str, str] = {"tsx": "typescript"}
|
||||
|
||||
|
||||
def _rule_applies(rule_languages: list[str], file_language: str) -> bool:
|
||||
"""Whether a custom rule scoped to ``rule_languages`` applies to a file of
|
||||
``file_language``. An unscoped rule (empty list) applies to everything."""
|
||||
if not rule_languages:
|
||||
return True
|
||||
if file_language in rule_languages:
|
||||
return True
|
||||
family = _DIALECT_OF.get(file_language)
|
||||
return family is not None and family in rule_languages
|
||||
|
||||
|
||||
def check_custom(
|
||||
rel_path: str, source: bytes, language: str, standard: ConventionsStandard
|
||||
@@ -26,7 +46,7 @@ def check_custom(
|
||||
text = source.decode(errors="replace")
|
||||
findings: list[Finding] = []
|
||||
for rule in standard.custom:
|
||||
if rule.languages and language not in rule.languages:
|
||||
if not _rule_applies(rule.languages, language):
|
||||
continue
|
||||
findings.extend(_matches(rel_path, text, rule))
|
||||
return findings
|
||||
|
||||
Reference in New Issue
Block a user