Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modernization of proselint #1361

Closed
wants to merge 249 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
249 commits
Select commit Hold shift + click to select a range
140b3e0
added check for punctuation spacing. Issue #1342
arostkowycz15 Apr 17, 2023
451801f
Added clichés from Nigel Rees' book
mdgjohnny Sep 10, 2023
67be7fc
Tests for Nigel's clichés
mdgjohnny Sep 10, 2023
9db9d31
fix file endings and remove not needed spaces
orgua Dec 27, 2023
8defcc4
raise min py-version to 3.8 and remove future
orgua Dec 27, 2023
237ff5e
update deps
orgua Dec 27, 2023
98ce3d2
py: add commas
orgua Dec 27, 2023
9083fef
clean imports
orgua Dec 27, 2023
623d684
lint code
orgua Dec 27, 2023
f7d62d8
fix programming error
orgua Dec 27, 2023
fe731d0
chore(deps): bump ruby/setup-ruby from 1.95.0 to 1.163.0
dependabot[bot] Dec 27, 2023
e07daf6
chore(deps): bump codecov/codecov-action from 2.1.0 to 3.1.4
dependabot[bot] Dec 27, 2023
6ffbff7
chore(deps): bump actions/setup-python from 2 to 5
dependabot[bot] Dec 27, 2023
24e4032
chore(deps): bump actions/cache from 2 to 3
dependabot[bot] Dec 27, 2023
ac146da
chore(deps-dev): bump pytest from 6.2.5 to 7.4.3
dependabot[bot] Dec 27, 2023
0dc599c
Merge pull request #5 from orgua/dependabot/github_actions/actions/ca…
orgua Dec 27, 2023
d1ec014
Merge pull request #4 from orgua/dependabot/github_actions/actions/se…
orgua Dec 27, 2023
f3ab5cc
Merge pull request #6 from orgua/dependabot/pip/pytest-7.4.3
orgua Dec 27, 2023
791fbd7
chore(deps): bump actions/checkout from 2 to 4
dependabot[bot] Dec 27, 2023
53fe09f
Merge pull request #2 from orgua/dependabot/github_actions/actions/ch…
orgua Dec 27, 2023
f28b461
Merge pull request #1 from orgua/dependabot/github_actions/ruby/setup…
orgua Dec 27, 2023
2ef0a38
Merge pull request #3 from orgua/dependabot/github_actions/codecov/co…
orgua Dec 27, 2023
4aaeea6
do not pin package-versions if not needed
orgua Dec 27, 2023
62cbc93
clean up usage of paths
orgua Dec 27, 2023
873014f
remove legacy-code
orgua Dec 27, 2023
dbae823
avoid shadowing a Python builtins
orgua Dec 27, 2023
1e39e4d
sort imports
orgua Dec 28, 2023
b2ab749
add typehinting
orgua Dec 28, 2023
b24f5b1
format with black-style, ruff
orgua Dec 31, 2023
21947b0
add proper logging capability
orgua Dec 31, 2023
1af69f2
refactor internal paths
orgua Dec 31, 2023
64d4d6d
refactor cache
orgua Dec 31, 2023
147aee1
lint
orgua Dec 31, 2023
f2b91d6
refactor cache
orgua Dec 31, 2023
dd5a0f0
add chromalog and update deps
orgua Dec 31, 2023
54668e0
refactor logger
orgua Dec 31, 2023
c66ef43
various refactoring
orgua Dec 31, 2023
873022e
allow benchmarking & fix bugs
orgua Dec 31, 2023
5d8638a
small bugfixes
orgua Jan 1, 2024
8722878
chore(deps): bump ruby/setup-ruby from 1.163.0 to 1.165.1
dependabot[bot] Jan 1, 2024
6cbd9fe
chore(deps): bump crazy-max/ghaction-github-labeler from 3 to 5
dependabot[bot] Jan 1, 2024
f364082
replace memoiziation, improve code around it
orgua Jan 1, 2024
87f5832
consider age of cache-entries
orgua Jan 1, 2024
52f574e
optimize slowest funcs
orgua Jan 1, 2024
8fea336
remove tests for compiled-file-deletion
orgua Jan 1, 2024
c8368e7
refactor for modularity
orgua Jan 1, 2024
17fd756
last transformations to list comprehensions
orgua Jan 1, 2024
c24211b
Update poetry.lock
orgua Jan 1, 2024
2e468c7
refactor unittests (wip)
orgua Jan 2, 2024
bd5a3d1
remove duplicates
orgua Jan 2, 2024
458aacc
reformat
orgua Jan 2, 2024
625349c
Update config_default.py
orgua Jan 2, 2024
9f73969
refactor unittests
orgua Jan 2, 2024
ada3e7b
move tests for checks in separate folder
orgua Jan 2, 2024
666be5a
allow disabling cache
orgua Jan 2, 2024
3163e3c
small renaming & formatting
orgua Jan 2, 2024
567a517
extending sys.path not needed
orgua Jan 2, 2024
b33bc8f
propagate module-path
orgua Jan 2, 2024
69ffeab
refactor web-scripts
orgua Jan 2, 2024
8930e92
refactor new scripts
orgua Jan 2, 2024
644382a
refactor and reformat scripts
orgua Jan 2, 2024
45f657b
add cache-tests
orgua Jan 2, 2024
dae83c8
add config-tests
orgua Jan 2, 2024
f2dd797
add note to benchmark
orgua Jan 2, 2024
0c6ac6f
add printer for invoke()
orgua Jan 2, 2024
ce47da9
revert renaming txt-file for tests
orgua Jan 2, 2024
af65ec7
update configs in sync to available tests
orgua Jan 2, 2024
4d35420
fix tests
orgua Jan 2, 2024
2055bec
catch missing modules, make ppm-wrapper nicer
orgua Jan 2, 2024
7dc2f58
add exithandler and return number of results as exit-code
orgua Jan 2, 2024
4943d6d
Update test_cache_function.py
orgua Jan 2, 2024
ebef8e0
Update test_config_default.py
orgua Jan 2, 2024
2e5c2f4
workflows make version to string
orgua Jan 2, 2024
12e68ba
Merge pull request #12 from orgua/dependabot/github_actions/crazy-max…
orgua Jan 2, 2024
5f86848
Merge pull request #11 from orgua/dependabot/github_actions/ruby/setu…
orgua Jan 2, 2024
fb72dd6
sort dev-deps, also include pre-commit and remove packages covered by…
orgua Jan 2, 2024
1d69912
Update ci-lint-test.yml
orgua Jan 2, 2024
a67a7f4
Merge branch 'main' of https://github.com/orgua/proselint-modernized
orgua Jan 2, 2024
59d1eec
add multiprocessing for checks
orgua Jan 3, 2024
fb09191
ditch chromalog-package
orgua Jan 3, 2024
1bc6276
parallelize lint()
orgua Jan 3, 2024
e45b917
remove memoizer for checks
orgua Jan 3, 2024
a3b78a1
extend benchmark scripts
orgua Jan 3, 2024
82f671c
extend cache to handle const-properties
orgua Jan 3, 2024
44bfd7e
refactor sexism-check and extend unittests
orgua Jan 3, 2024
edb8b5f
minor fixes
orgua Jan 3, 2024
d2fa1b8
refactor more checks and tests
orgua Jan 3, 2024
4a845b2
fix check_option join & require_padding
orgua Jan 3, 2024
4bfb81a
even out load of checks for extreme cases
orgua Jan 4, 2024
471b241
add pytest-cov dependency
orgua Jan 4, 2024
efeb957
fix check-tests
orgua Jan 4, 2024
956f943
fix test for caching
orgua Jan 4, 2024
b87d194
remove const-cache after benchmarking
orgua Jan 4, 2024
201d7ee
refactor all multiprocessed code into submodule
orgua Jan 4, 2024
769123f
clean up from latest debug session
orgua Jan 4, 2024
7ef28ce
change config
orgua Jan 4, 2024
464f41b
fix unittests
orgua Jan 4, 2024
ccb6c8a
linting
orgua Jan 4, 2024
ccbcf7a
cache is now a singleton
orgua Jan 4, 2024
4cb1813
Update tools.py
orgua Jan 4, 2024
dc4da55
Update test_hyperlinks_on_shell.py
orgua Jan 4, 2024
f4a9fc2
add padding to text - guard against edge-cases
orgua Jan 4, 2024
8a78b9c
rename lint_cache
orgua Jan 4, 2024
f764def
force single-line imports
orgua Jan 4, 2024
7a5e4c3
add global executor and optimize memoizer
orgua Jan 4, 2024
560eabd
optimize check-message
orgua Jan 4, 2024
1de71f7
lint code
orgua Jan 4, 2024
0d87b24
add current ruff-config
orgua Jan 4, 2024
92d72f4
overhaul output-format system
orgua Jan 5, 2024
741639d
store filename in error-list
orgua Jan 5, 2024
7bd74e0
fix bug in memoizer
orgua Jan 5, 2024
87c23a6
improve memoizer
orgua Jan 5, 2024
8a4aa20
fix padding in some checks
orgua Jan 5, 2024
6ef3a1a
improve commercialese
orgua Jan 5, 2024
f3d3657
improve memoizer
orgua Jan 5, 2024
52e445a
Update score.py
orgua Jan 5, 2024
ceb06ee
add weasel words
orgua Jan 5, 2024
e72d054
fix unittests
orgua Jan 5, 2024
2632d2b
speed up scripts
orgua Jan 5, 2024
a3e9af2
move printing out of linter
orgua Jan 5, 2024
e49149e
Merge branch 'pr/1356'
orgua Jan 5, 2024
413cf62
Update test_cliches.py
orgua Jan 5, 2024
5a552be
fix code
orgua Jan 5, 2024
4b09ec2
fix unittests and lint
orgua Jan 5, 2024
ac40919
bump version
orgua Jan 14, 2024
7548c80
Merge branch 'main' into main
Nytelife26 Jan 22, 2024
3fbaaef
ci(lint-test): fix pytest
Nytelife26 Jan 24, 2024
d3213d6
fix file endings and remove not needed spaces
orgua Dec 27, 2023
6eb6949
raise min py-version to 3.8 and remove future
orgua Dec 27, 2023
a04b80b
update deps
orgua Dec 27, 2023
b552b74
py: add commas
orgua Dec 27, 2023
691a145
clean imports
orgua Dec 27, 2023
4c155b1
lint code
orgua Dec 27, 2023
1434a98
fix programming error
orgua Dec 27, 2023
912e965
chore(deps): bump actions/cache from 2 to 3
dependabot[bot] Dec 27, 2023
f14ce3a
chore(deps): bump actions/setup-python from 4 to 5
dependabot[bot] Dec 27, 2023
6d6d995
chore(deps-dev): bump pytest from 6.2.5 to 7.4.3
dependabot[bot] Dec 27, 2023
a0f8bc7
chore(deps): bump actions/checkout from 2 to 4
dependabot[bot] Dec 27, 2023
eefe9f1
chore(deps): bump ruby/setup-ruby from 1.95.0 to 1.163.0
dependabot[bot] Dec 27, 2023
03b91ab
do not pin package-versions if not needed
orgua Dec 27, 2023
75cd2b7
clean up usage of paths
orgua Dec 27, 2023
41ac3bd
remove legacy-code
orgua Dec 27, 2023
a0e43e8
avoid shadowing a Python builtins
orgua Dec 27, 2023
4b1e5c7
sort imports
orgua Dec 28, 2023
3988867
add typehinting
orgua Dec 28, 2023
18d22c0
format with black-style, ruff
orgua Dec 31, 2023
c4fdcfa
add proper logging capability
orgua Dec 31, 2023
391bafb
refactor internal paths
orgua Dec 31, 2023
938f157
refactor cache
orgua Dec 31, 2023
31cc235
lint
orgua Dec 31, 2023
ce94896
refactor cache
orgua Dec 31, 2023
2e74b61
add chromalog and update deps
orgua Dec 31, 2023
fa9f6cd
refactor logger
orgua Dec 31, 2023
a07fa34
various refactoring
orgua Dec 31, 2023
12bd14a
allow benchmarking & fix bugs
orgua Dec 31, 2023
d97811a
small bugfixes
orgua Jan 1, 2024
7e62d8b
replace memoiziation, improve code around it
orgua Jan 1, 2024
d41ca24
consider age of cache-entries
orgua Jan 1, 2024
3b51220
optimize slowest funcs
orgua Jan 1, 2024
fcc7d29
remove tests for compiled-file-deletion
orgua Jan 1, 2024
f0dc9cf
refactor for modularity
orgua Jan 1, 2024
b58f140
last transformations to list comprehensions
orgua Jan 1, 2024
6cffecf
refactor unittests (wip)
orgua Jan 2, 2024
457c832
remove duplicates
orgua Jan 2, 2024
3da41d8
reformat
orgua Jan 2, 2024
74a726c
Update config_default.py
orgua Jan 2, 2024
58b7a42
refactor unittests
orgua Jan 2, 2024
b32d853
move tests for checks in separate folder
orgua Jan 2, 2024
c1bfeea
allow disabling cache
orgua Jan 2, 2024
b8e7048
small renaming & formatting
orgua Jan 2, 2024
870671e
extending sys.path not needed
orgua Jan 2, 2024
fc8a356
propagate module-path
orgua Jan 2, 2024
7bb9d3e
refactor web-scripts
orgua Jan 2, 2024
f7fa09f
refactor new scripts
orgua Jan 2, 2024
4e4a596
refactor and reformat scripts
orgua Jan 2, 2024
9e0307e
add cache-tests
orgua Jan 2, 2024
54631fb
add config-tests
orgua Jan 2, 2024
cb23bb9
add note to benchmark
orgua Jan 2, 2024
05871d9
add printer for invoke()
orgua Jan 2, 2024
ffecc43
revert renaming txt-file for tests
orgua Jan 2, 2024
53dc973
update configs in sync to available tests
orgua Jan 2, 2024
5828288
fix tests
orgua Jan 2, 2024
14beecb
catch missing modules, make ppm-wrapper nicer
orgua Jan 2, 2024
f53c55e
add exithandler and return number of results as exit-code
orgua Jan 2, 2024
a13cc04
Update test_cache_function.py
orgua Jan 2, 2024
c1db241
Update test_config_default.py
orgua Jan 2, 2024
ac334fa
workflows make version to string
orgua Jan 2, 2024
f81bf0b
sort dev-deps, also include pre-commit and remove packages covered by…
orgua Jan 2, 2024
dd86494
Update ci-lint-test.yml
orgua Jan 2, 2024
0e7d620
chore(deps): bump crazy-max/ghaction-github-labeler from 3 to 5
dependabot[bot] Jan 1, 2024
1829d4b
chore(deps): bump ruby/setup-ruby from 1.163.0 to 1.165.1
dependabot[bot] Jan 1, 2024
66ab691
add multiprocessing for checks
orgua Jan 3, 2024
e7d70b2
ditch chromalog-package
orgua Jan 3, 2024
7ef4d60
parallelize lint()
orgua Jan 3, 2024
fd96434
remove memoizer for checks
orgua Jan 3, 2024
1ae3926
extend benchmark scripts
orgua Jan 3, 2024
9d677fe
extend cache to handle const-properties
orgua Jan 3, 2024
cf6384f
refactor sexism-check and extend unittests
orgua Jan 3, 2024
25e1a9d
minor fixes
orgua Jan 3, 2024
98a7980
refactor more checks and tests
orgua Jan 3, 2024
cae7728
fix check_option join & require_padding
orgua Jan 3, 2024
22bf2fc
even out load of checks for extreme cases
orgua Jan 4, 2024
5eab18c
add pytest-cov dependency
orgua Jan 4, 2024
f323c5d
fix check-tests
orgua Jan 4, 2024
1768bb5
fix test for caching
orgua Jan 4, 2024
78a703f
remove const-cache after benchmarking
orgua Jan 4, 2024
c177a65
refactor all multiprocessed code into submodule
orgua Jan 4, 2024
d9cdfd3
clean up from latest debug session
orgua Jan 4, 2024
521b076
change config
orgua Jan 4, 2024
a302e4c
fix unittests
orgua Jan 4, 2024
aaba845
linting
orgua Jan 4, 2024
e3b7b02
cache is now a singleton
orgua Jan 4, 2024
998d0f5
Update tools.py
orgua Jan 4, 2024
6744baf
Update test_hyperlinks_on_shell.py
orgua Jan 4, 2024
e4535c1
add padding to text - guard against edge-cases
orgua Jan 4, 2024
b03c870
rename lint_cache
orgua Jan 4, 2024
23a54f4
force single-line imports
orgua Jan 4, 2024
e294602
add global executor and optimize memoizer
orgua Jan 4, 2024
c4ecb77
optimize check-message
orgua Jan 4, 2024
4c1016e
lint code
orgua Jan 4, 2024
5e2ea1b
add current ruff-config
orgua Jan 4, 2024
3c44e3b
overhaul output-format system
orgua Jan 5, 2024
0a32450
store filename in error-list
orgua Jan 5, 2024
771788d
fix bug in memoizer
orgua Jan 5, 2024
f53a531
improve memoizer
orgua Jan 5, 2024
d7d78f6
fix padding in some checks
orgua Jan 5, 2024
529efbe
improve commercialese
orgua Jan 5, 2024
5ef1d75
improve memoizer
orgua Jan 5, 2024
52da9f3
Update score.py
orgua Jan 5, 2024
94956d5
add weasel words
orgua Jan 5, 2024
7b1a232
fix unittests
orgua Jan 5, 2024
a2c2d48
speed up scripts
orgua Jan 5, 2024
d4bf985
move printing out of linter
orgua Jan 5, 2024
a8af783
Added clichés from Nigel Rees' book
mdgjohnny Sep 10, 2023
185c344
Tests for Nigel's clichés
orgua Jan 5, 2024
c1d67df
added check for punctuation spacing. Issue #1342
arostkowycz15 Apr 17, 2023
a60cc86
fix unittests and lint
orgua Jan 5, 2024
84a40ab
bump version
orgua Jan 14, 2024
b3ebed3
ci(lint-test): fix pytest
Nytelife26 Jan 24, 2024
90d610f
chore: fix merge differences
Nytelife26 Jan 25, 2024
2104094
chore: resolve rebase issues
Nytelife26 Jan 25, 2024
64bb526
chore(deps): add ruff
Nytelife26 Jan 25, 2024
fc5e10a
lint: fix ruff suggestions
Nytelife26 Jan 25, 2024
30f1972
ci(lint-test): lint with ruff
Nytelife26 Jan 25, 2024
cefb7a3
chore: fix lint issues
Nytelife26 Jan 25, 2024
c1cc4db
Merge branch 'main' of https://github.com/orgua/proselint-modernized
orgua Jan 25, 2024
ee7dbf4
Update tests/check.py
orgua Jan 25, 2024
fa9b0cd
implement comments
orgua Jan 25, 2024
eb414d1
Merge branch 'main' of https://github.com/orgua/proselint-modernized
orgua Jan 25, 2024
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
2 changes: 1 addition & 1 deletion .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ preview = true
[lint.per-file-ignores]
"tests/**" = ["S", "N8", "SLF001", "PLR2004"]
"proselint/checks/**" = ["RUF001", "RUF002", "RUF003", "TID252"]
"scripts/**" = ["E501"]
"scripts/**" = ["E501", "DTZ005"]

"plugins/**" = ["INP001", "RUF012"]
"scripts_web/**" = ["S1", "SIM", "RET", "TCH"]
Expand Down
31 changes: 20 additions & 11 deletions proselint/checks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
ResultCheck: TypeAlias = tuple[int, int, str, str, Optional[str]]
# content: start_pos, end_pos, check_name, message, replacement)
# NOTE1: NewType() is too strict here
Nytelife26 marked this conversation as resolved.
Show resolved Hide resolved
# NOTE2: py312 can use -> type ResultCheck = tuple[int, int, str, str, Optional[str]]
# NOTE2: py312 can use ->
# type ResultCheck = tuple[int, int, str, str, Optional[str]]


###############################################################################
Expand All @@ -39,26 +40,28 @@ def get_checks(options: dict) -> list[Callable[[str, str], list[ResultCheck]]]:
# TODO: benchmark consecutive runs of this
# config should only translate once to check-list
checks = []
check_names = [key for (key, val) in options["checks"].items() if val]
check_names = ["." + key for (key, val) in options["checks"].items() if val]
Nytelife26 marked this conversation as resolved.
Show resolved Hide resolved

for check_name in check_names:
try:
module = importlib.import_module("." + check_name, "proselint.checks")
module = importlib.import_module(check_name, "proselint.checks")
except ModuleNotFoundError:
log.exception(
"requested config-flag '%s' not found in proselint.checks",
check_name,
)
continue
checks += [getattr(module, d) for d in dir(module) if re.match(r"^check", d)]
checks += [
getattr(module, d) for d in dir(module) if re.match(r"^check", d)
]

log.debug("Collected %d checks to run", len(checks))
return checks


def run_checks(_check: Callable, _text: str, source: str = "") -> list:
# TODO: frozenset is hashable (list without duplicates) -> check-list, result-lists
# padding
# TODO: frozenset is hashable (list without duplicates)
# -> check-list, result-lists padding
# -> some checks expect words in text and need something around it
# -> this prevents edge-cases
_text = f" \n{_text}\n " # maybe not the fastest OP
Expand Down Expand Up @@ -136,7 +139,9 @@ def find_ranges(_text: str) -> list[tuple[int, int]]:
pc = c
return ranges

def position_in_ranges(ranges: list[tuple[int, int]], _position: int) -> bool:
def position_in_ranges(
ranges: list[tuple[int, int]], _position: int
) -> bool:
return any(start <= _position < end for start, end in ranges)

return position_in_ranges(find_ranges(text), position)
Expand Down Expand Up @@ -258,7 +263,13 @@ def existence_check( # noqa: PLR0913, PLR0917
if any(re.search(exception, txt) for exception in exceptions):
continue
errors.append(
(m.start() + 1 + offset, m.end() + offset, err, msg.format(txt), None),
(
m.start() + 1 + offset,
m.end() + offset,
err,
msg.format(txt),
None,
),
)
# TODO: doesn't the padding alter the start+end?

Expand Down Expand Up @@ -314,9 +325,7 @@ def topics(text: str) -> list[str]:

def context(text, position, level="paragraph"):
"""Get sentence or paragraph that surrounds the given position."""
if level == "sentence":
pass
elif level == "paragraph":
if level in {"sentence", "paragraph"}:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thats really wrong, as these are placeholders for custom sub-functionality. not from me, but it had a reason to be like that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was a lint suggestion, and it checks out to me. I believe the plan was to add some eventual logic, but I see no reason not to tidy up until then.

pass

return ""
Expand Down
2 changes: 1 addition & 1 deletion proselint/checks/cliches/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,7 @@ def check_cliches_gnu_diction(text: str) -> list[ResultCheck]:

return existence_check(text, items, err, msg, ignore_case=True)


def check_cliches_nigel(text: str) -> list[ResultCheck]:
Nytelife26 marked this conversation as resolved.
Show resolved Hide resolved
"""Check the text.

Expand Down Expand Up @@ -1080,7 +1081,6 @@ def check_cliches_nigel(text: str) -> list[ResultCheck]:
"when the chips are down",
"wind of change",
"yawning gap",

]

return existence_check(text, cliches, err, msg, ignore_case=True)
5 changes: 4 additions & 1 deletion proselint/checks/cursing/filth.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
def check(text: str) -> list[ResultCheck]:
"""Check the text."""
err = "cursing.filth"
msg = "Nobody ever tells you this as a kid, but you're supposed to avoid this word."
msg = (
"Nobody ever tells you this as a kid,",
"but you're supposed to avoid this word.",
)

items = [
"shit",
Expand Down
8 changes: 6 additions & 2 deletions proselint/checks/dates_times/am_pm.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ def check_lowercase_periods(text: str) -> list[ResultCheck]:
err = "dates_times.am_pm.lowercase_periods"
msg = "With lowercase letters, the periods are standard."

return existence_check(text, [r"\d{1,2} ?[ap]m"], err, msg, ignore_case=False)
return existence_check(
text, [r"\d{1,2} ?[ap]m"], err, msg, ignore_case=False
)


def check_spacing(text: str) -> list[ResultCheck]:
Expand All @@ -36,7 +38,9 @@ def check_spacing(text: str) -> list[ResultCheck]:
def check_midnight_noon(text: str) -> list[ResultCheck]:
"""Check the text."""
err = "dates_times.am_pm.midnight_noon"
msg = "12 a.m. and 12 p.m. are wrong and confusing. Use 'midnight' or 'noon'."
msg = (
"12 a.m. and 12 p.m. are wrong and confusing. Use 'midnight' or 'noon'."
)

return existence_check(text, [r"12 ?[ap]\.?m\.?"], err, msg)

Expand Down
2 changes: 1 addition & 1 deletion proselint/checks/misc/greylist.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def check(text: str) -> list[ResultCheck]:

bad_words = {
"obviously": "This is obviously an inadvisable word to use.",
"utilize": "Do you know anyone who *needs* to utilize the word utilize?",
"utilize": "Do you know anyone who needs to utilize the word utilize?",
}

results = []
Expand Down
9 changes: 7 additions & 2 deletions proselint/checks/misc/phrasal_adjectives.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ def check_ly(text: str) -> list[ResultCheck]:

items = [r"\s[^\s-]+ly-"]

return existence_check(text, items, err, msg, padding=Pd.disabled, offset=-1)
return existence_check(
text, items, err, msg, padding=Pd.disabled, offset=-1
)


def check(text: str) -> list[ResultCheck]:
Expand Down Expand Up @@ -64,7 +66,10 @@ def check(text: str) -> list[ResultCheck]:
["hit-and-run statute", ["hit and run statute"]],
["HIV-negative person", ["HIV negative person"]],
["HIV-positive person", ["HIV positive person"]],
["information-technology personnel", ["information technology personnel"]],
[
"information-technology personnel",
["information technology personnel"],
],
["intellectual-property rights", ["intellectual property rights"]],
["interest-group pressures", ["interest group pressures"]],
["joint-stock company", ["joint stock company"]],
Expand Down
5 changes: 4 additions & 1 deletion proselint/checks/misc/preferred_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ def check(text: str) -> list[ResultCheck]:
["lent me their", ["loaned me their"]],
["lent me your", ["loaned me your"]],
["linguist", ["linguistician"]],
["matzo-ball", ["matzoh-ball", "matza-ball", "matzah-ball", "matsah-ball"]],
[
"matzo-ball",
["matzoh-ball", "matza-ball", "matzah-ball", "matsah-ball"],
],
["mayoralty", ["mayorality"]],
["mealy-mouthed", ["mealymouthed"]],
["mean-spirited", ["meanspirited"]],
Expand Down
17 changes: 14 additions & 3 deletions proselint/checks/redundancy/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,11 @@ def check_atd_1(text: str) -> list[ResultCheck]:
["earlier", ["earlier in time"]],
[
"eliminate",
["completely eliminate", "eliminate altogether", "entirely eliminate"],
[
"completely eliminate",
"eliminate altogether",
"entirely eliminate",
],
],
["ember", ["glowing ember"]],
["embers", ["burning embers"]],
Expand All @@ -272,7 +276,11 @@ def check_atd_1(text: str) -> list[ResultCheck]:
["essential", ["absolutely essential"]],
[
"estimated at",
["estimated at about", "estimated at approximately", "estimated at around"],
[
"estimated at about",
"estimated at approximately",
"estimated at around",
],
],
["etc.", ["and etc."]],
["evolve", ["evolve over time"]],
Expand Down Expand Up @@ -366,7 +374,10 @@ def check_atd_2(text: str) -> list[ResultCheck]:
# ["input", ["input into"]],
["instinct", ["natural instinct", "naturally instinct"]],
["integrate", ["integrate together", "integrate with each other"]],
["interdependent", ["interdependent on each other", "mutually interdependent"]],
[
"interdependent",
["interdependent on each other", "mutually interdependent"],
],
["introduced", ["introduced for the first time"]],
["invention", ["new invention"]],
["kneel", ["kneel down"]],
Expand Down
3 changes: 2 additions & 1 deletion proselint/checks/typography/symbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@


def check(text: str) -> list[ResultCheck]:
# NOTE: these tests are pretty fast, so they are combined for a more even load
# NOTE: these tests are pretty fast, so they are combined for a more even
# load

@limit_results(3)
def check_ellipsis(_text: str) -> list[ResultCheck]:
Expand Down
18 changes: 10 additions & 8 deletions proselint/command_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import json
import os
import signal
import subprocess
import subprocess # noqa: S404
import sys
import time
from pathlib import Path
Expand Down Expand Up @@ -43,9 +43,7 @@ def run_benchmark(corpus: str = "0.1.0") -> float:
# force a clean slate
cache.clear()
# corpus was removed in https://github.com/amperser/proselint/pull/186
log.error(
"Benchmarking the corpus does not work for the time being -> will use demo",
)
log.error("Corpus is unavailable for the time being -> using demo")
corpus_path = demo_file.parent # proselint_path.parent / "corpora" / corpus
for _type in ["uncached", "cached"]:
start = time.time()
Expand Down Expand Up @@ -93,10 +91,14 @@ def run_benchmark(corpus: str = "0.1.0") -> float:
help="Override config to change format.",
)
@click.option("--dump-config", is_flag=True, help="Prints current config.")
@click.option("--dump-default-config", is_flag=True, help="Prints default config.")
@click.option(
"--dump-default-config", is_flag=True, help="Prints default config."
)
@click.option("--version", is_flag=True)
@click.argument("paths", nargs=-1, type=click.Path(exists=True, resolve_path=True))
def proselint( # noqa: PLR0913, PLR0917, C901
@click.argument(
"paths", nargs=-1, type=click.Path(exists=True, resolve_path=True)
)
def proselint( # noqa: PLR0912, PLR0913, PLR0917, C901
paths: Union[list[Path], Path, None],
config: Optional[Path] = None,
clean: bool = False, # TODO: this should be a subcommand
Expand All @@ -105,7 +107,7 @@ def proselint( # noqa: PLR0913, PLR0917, C901
benchmark: bool = False,
demo: bool = False,
dump_config: bool = False, # TODO: this should be a subcommand
dump_default_config: bool = False, # TODO: this should be a switch in dump-cmd
dump_default_config: bool = False, # TODO: this should be a switch in dump
version: bool = False,
):
"""Create the CLI for proselint, a linter for prose."""
Expand Down
2 changes: 1 addition & 1 deletion proselint/config_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

def _get_xdg_path(variable_name: str, default_path: Path) -> Path:
_value = os.environ.get(variable_name)
if _value is None or _value == "":
if not _value:
return default_path
return Path(_value)

Expand Down
18 changes: 13 additions & 5 deletions proselint/memoizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import contextlib
import functools
import hashlib
import pickle
import pickle # noqa: S403
import shutil
from concurrent.futures import Executor
from concurrent.futures import Future
Expand Down Expand Up @@ -46,7 +46,8 @@ def __new__(cls, *_args: tuple, **_kwargs: Unpack[TypedDict]) -> Self:
def __init__(self) -> None:
self._data: dict[str, list[ResultLint]] = {}
self._age: dict[str, int] = {}
self._ts_now: int = round(datetime.now().timestamp())
# TODO: make timezone aware, possibly use UTC?
self._ts_now: int = round(datetime.now().timestamp()) # noqa: DTZ005
self._modified: bool = False
self.fname2key: dict[str, str] = {}

Expand All @@ -67,7 +68,8 @@ def __del__(self):
Cache._instance = None

def __getitem__(self, key: str) -> list[ResultLint]:
"""Allows dict access -> instance["key"], in addition to instance.data["key"]"""
"""Allows direct dict access.
This allows instance["key"], in addition to instance.data["key"]"""
return self._data[key]

def __setitem__(self, key: str, value: list[ResultLint]):
Expand Down Expand Up @@ -109,7 +111,11 @@ def from_file(cls) -> Self:
data = pickle.load(fd, fix_imports=False) # noqa: S301
# TODO: consider replacing pickle with something faster
# only restore if data fits and package-version matches
if isinstance(data, list) and len(data) >= 3 and data[2] == version:
if (
isinstance(data, list)
and len(data) >= 3
and data[2] == version
):
_inst._data = data[0] # noqa: SLF001
_inst._age = data[1] # noqa: SLF001
log.debug(" -> found & restored cache")
Expand All @@ -129,7 +135,9 @@ def calculate_key(text: str, checks: list[Callable]) -> str:

text_hash = hashlib.sha224(text.encode("utf-8")).hexdigest()[:50]
chck_list = [f"{c.__module__}.{c.__name__}" for c in checks]
chck_hash = hashlib.sha224(" ".join(chck_list).encode("utf-8")).hexdigest()[:10]
chck_hash = hashlib.sha224(
" ".join(chck_list).encode("utf-8")
).hexdigest()[:10]
# NOTE: Skip hashing config!
# -> Valid assumption that (current) config has
# no influence on result below this level
Expand Down
2 changes: 1 addition & 1 deletion proselint/score.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import os
import re
import subprocess
import subprocess # noqa: S404
Nytelife26 marked this conversation as resolved.
Show resolved Hide resolved
from pathlib import Path

from .config_paths import proselint_path
Expand Down
Loading
Loading