Skip to content

Commit 6cab0cc

Browse files
committed
libs: Add envoy.code.check[spelling]
Signed-off-by: Ryan Northey <[email protected]>
1 parent 816be6a commit 6cab0cc

File tree

6 files changed

+66
-1
lines changed

6 files changed

+66
-1
lines changed

envoy.code.check/envoy/code/check/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pytooling_library(
1515
"abstract/base.py",
1616
"abstract/checker.py",
1717
"abstract/flake8.py",
18+
"abstract/spelling.py",
1819
"abstract/yapf.py",
1920
"checker.py",
2021
"cmd.py",

envoy.code.check/envoy/code/check/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
ACodeCheck,
55
ACodeChecker,
66
AFlake8Check,
7+
ASpellingCheck,
78
AYapfCheck)
89
from .checker import (
910
CodeChecker,
1011
Flake8Check,
12+
SpellingCheck,
1113
YapfCheck)
1214
from .cmd import run, main
1315
from . import checker
@@ -26,4 +28,5 @@
2628
"main",
2729
"run",
2830
"typing",
31+
"SpellingCheck",
2932
"YapfCheck")

envoy.code.check/envoy/code/check/abstract/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,24 @@
22
from .base import ACodeCheck
33
from .checker import ACodeChecker
44
from .flake8 import AFlake8Check
5+
from .spelling import ASpellingCheck
56
from .yapf import AYapfCheck
67
from . import (
78
base,
89
checker,
910
flake8,
11+
spelling,
1012
yapf)
1113

1214

1315
__all__ = (
1416
"ACodeCheck",
1517
"ACodeChecker",
1618
"AFlake8Check",
19+
"ASpellingCheck",
1720
"AYapfCheck",
1821
"base",
1922
"checker",
2023
"flake8",
24+
"spelling",
2125
"yapf")

envoy.code.check/envoy/code/check/abstract/checker.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class ACodeChecker(
2525
metaclass=abstracts.Abstraction):
2626
"""Code checker."""
2727

28-
checks = ("python_yapf", "python_flake8")
28+
checks = ("python_yapf", "python_flake8", "spelling")
2929

3030
@property
3131
def all_files(self) -> bool:
@@ -104,6 +104,16 @@ def grep_matching_re(self) -> Optional[Pattern[str]]:
104104
def path(self) -> pathlib.Path:
105105
return super().path
106106

107+
@cached_property
108+
def spelling(self) -> "abstract.ASpellingCheck":
109+
"""SPELLING checker."""
110+
return self.spelling_class(self.directory, fix=self.fix)
111+
112+
@property # type:ignore
113+
@abstracts.interfacemethod
114+
def spelling_class(self) -> Type["abstract.ASpellingCheck"]:
115+
raise NotImplementedError
116+
107117
@cached_property
108118
def yapf(self) -> "abstract.AYapfCheck":
109119
"""YAPF checker."""
@@ -129,6 +139,10 @@ async def check_python_yapf(self) -> None:
129139
"""Check for yapf issues."""
130140
await self._code_check(self.yapf)
131141

142+
async def check_spelling(self) -> None:
143+
"""Check for yapf issues."""
144+
await self._code_check(self.spelling)
145+
132146
@checker.preload(
133147
when=["python_flake8"])
134148
async def preload_flake8(self) -> None:
@@ -139,6 +153,11 @@ async def preload_flake8(self) -> None:
139153
async def preload_yapf(self) -> None:
140154
await self.yapf.problem_files
141155

156+
@checker.preload(
157+
when=["spelling"])
158+
async def preload_spelling(self) -> None:
159+
await self.spelling.problem_files
160+
142161
async def _code_check(self, check: "abstract.ACodeCheck") -> None:
143162
problem_files = await check.problem_files
144163
for path in sorted(await check.files):
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import pathlib
2+
import re
3+
import sys
4+
from functools import cached_property
5+
from typing import Dict, Iterator, List, Pattern, Set, Tuple
6+
7+
import abstracts
8+
9+
from envoy.code.check import abstract
10+
11+
from aio.core.functional import async_property
12+
13+
14+
class ASpellingCheck(abstract.ACodeCheck, metaclass=abstracts.Abstraction):
15+
16+
@async_property
17+
async def checker_files(self) -> Set[str]:
18+
return set()
19+
20+
@async_property(cache=True)
21+
async def problem_files(self) -> Dict[str, List[str]]:
22+
return (
23+
dict(await self.errors)
24+
if await self.files
25+
else {})
26+
27+
@async_property
28+
async def errors(self):
29+
return {}

envoy.code.check/envoy/code/check/checker.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ class YapfCheck:
1919
pass
2020

2121

22+
@abstracts.implementer(check.ASpellingCheck)
23+
class SpellingCheck:
24+
pass
25+
26+
2227
@abstracts.implementer(check.ACodeChecker)
2328
class CodeChecker:
2429

@@ -38,6 +43,10 @@ def git_directory_class(self):
3843
def path(self) -> pathlib.Path:
3944
return super().path
4045

46+
@property
47+
def spelling_class(self):
48+
return SpellingCheck
49+
4150
@property
4251
def yapf_class(self):
4352
return YapfCheck

0 commit comments

Comments
 (0)