90 Commits

Author SHA1 Message Date
0dd109a3e8 fix: typos in comments
Ironically, the word "mispelled" is misspelled in some doc comments. I
_think_ this is not intentional?
2024-01-03 21:14:17 +01:00
cfd21096ff Apply a selection of refurb rules (#3244) 2023-12-11 15:01:44 -05:00
86b30db41a Ignore line endings in exclude-file (#1889)
Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com>
Co-authored-by: Peter Newman <peternewman@users.noreply.github.com>
2023-11-23 09:16:24 +01:00
f73f0cc105 Add --stdin-single-line option (#3224)
Co-authored-by: Jedrzej Orbik <jedrzej.orbik@roboception.de>
2023-11-20 12:56:33 -05:00
f2deec14a6 Ignore ill-formed INI files instead of crashing (#3213) 2023-11-13 12:47:22 -05:00
55365585f3 Modify structure of dict read from TOML to match dict read from INI (#3046) 2023-08-31 09:04:00 -04:00
12d677b875 [pre-commit.ci] fix new ruff issue (#3042) 2023-08-25 09:03:50 -04:00
b29233a807 Generate alternative typos with a translation table (#2985) 2023-08-08 09:24:37 -04:00
44f22e2436 Remove the grave accent (`) from the default word regex (#2983) 2023-08-07 09:45:56 -04:00
c5bc4d7b5e Test to check our string escape word triggers on its own (#2879) 2023-06-15 10:45:22 -04:00
463ac02940 Ignore 'misspellings' due to string escapes (#2875) 2023-06-14 12:43:16 -04:00
ca016c1d2c Fix new ruff errors reported by CI (#2834) 2023-04-24 15:01:12 -04:00
9e383bcf04 MAINT: Cleanup conditionals (#2820) 2023-04-18 17:11:17 +00:00
cc93cc2624 Skip subdirectories of hidden directories (#2541) 2023-03-20 13:43:13 -04:00
a239c801c7 Fix CI issues (#2796) 2023-03-15 14:41:04 +00:00
b15260750f Add test for unknown encoding using chardet 2023-03-15 09:34:02 +01:00
8fa416764c Switch from pytest tmpdir to tmp_path in tests (#2625) 2023-03-08 17:58:44 +00:00
65b2f88ae4 Simplify evaluation 2023-01-26 20:59:47 +01:00
7b107a70cb Adjust test for python3.11 2023-01-26 20:59:47 +01:00
56a6f7567b Don't print config files by default (#2618) 2022-12-17 14:16:05 -05:00
cff8215d4f Move Windows CI from AppVeyor to GitHub Actions (#2628) 2022-12-05 13:55:59 -05:00
041bd02a1c Simplify some file reading in tests by opening in text mode 2022-11-27 22:04:01 +01:00
a7d80cf9a4 Use black to format Python files
Black is a popular Python code formatter. By using it, contributors
don't need to think about the project's styles preferences and avoids
the need for hand-formatting. Instead, let the tool handle it. This can
help smooth the review process.

Updated existing tools to follow the integration docs:
https://black.readthedocs.io/en/stable/guides/using_black_with_other_tools.html

For more details, see the project:
https://github.com/psf/black
2022-11-11 11:47:22 -08:00
8d0d82bcc0 Add type annotations to the project and use mypy (#2588)
Provide type annotations and use mypy for static type checking. Type
checkers help ensure that the project is using variables and functions
in the code correctly. With mypy, CI will warn when those types are used
incorrectly.

The mypy project and docs:
https://github.com/python/mypy
https://mypy.readthedocs.io/en/stable/index.html
2022-11-07 11:10:00 -05:00
3576f32eee Remove obsolete Python 2 workaround 2022-11-06 22:25:23 +01:00
62bd5ce330 Fix Deepsource issues (#2085)
* DeepSource issue: Built-in function `len` used as condition

Using the `len` function to check if a sequence is empty is not idiomatic
and can be less performant than checking the truthiness of the object.

`len` doesn't know the context in which it is called, so if computing the
length means traversing the entire sequence, it must; it doesn't know
that the result is just being compared to 0. Computing the boolean value
can stop after it sees the first element, regardless of how long the
sequence actually is.

* DeepSource issue: Consider using literal syntax to create the data structure

Using the literal syntax can give minor performance bumps compared to
using function calls to create `dict`, `list` and `tuple`.

This is because here, the name dict must be looked up in the global
scope in case it has been rebound. Same goes for the other two types
`list()` and `tuple()`.

* DeepSource issue: Consider decorating method with `@staticmethod`

The method doesn't use its bound instance. Decorate this method with
`@staticmethod` decorator, so that Python does not have to instantiate
a bound method for every instance of this class thereby saving memory
and computation. Read more about staticmethods here.

* DeepSource issue: Consider using `in`

To check if a variable is equal to one of many values, combine the values
into a tuple and check if the variable is contained `in` it instead of
checking for equality against each of the values. This is faster, less
verbose, and more readable.

* DeepSource issue: Implicit enumerate calls found

Using `range(len(...))` is not pythonic. Python does not have not
index-based loops. Instead, it uses collection iterators.

Python has a built-in method enumerate which adds a counter to an
iterable. Using this, you can access the counter and the value from
the iterable at the same time. It is therefore recommended to replace
`range(len(...))` with `enumerate(...)`.
2022-11-02 11:44:15 -04:00
50106dd578 Add isort to project (#2564)
isort is a utility to sort Python imports alphabetically, and
automatically separate into sections and by type. This will provide a
consistent import style from contributors. As well, by using a tool, a
contributor doesn't need to think about or anticipate the project's
preferred style, just let the tool handle it.

Run isort GitHub action as part of CI.
2022-11-02 11:42:44 -04:00
0b675f6b99 Handle bad globs passed to if --skip/-S (#2159)
Co-authored-by: Peter Newman <peternewman@users.noreply.github.com>
2022-10-31 07:17:40 -04:00
458de804cd Update subprocess usage to use modern subprocess.run()
https://docs.python.org/3/library/subprocess.html#subprocess.run

> The recommended approach to invoking subprocesses is to use the run()
> function for all use cases it can handle.
2022-10-30 00:22:47 +02:00
b2866507b9 Remove the broken tests for now 2022-10-20 15:10:55 +02:00
f590535d7d Recreate Dimitri's demo as a test 2022-10-20 15:10:55 +02:00
b98f2c66d3 Fix the expected typo numbers 2022-10-20 15:10:55 +02:00
9c5c6ec444 Test a hidden subdirectory too 2022-10-20 15:10:55 +02:00
04f93cfd28 Add relative hidden directory tests 2022-10-20 15:10:55 +02:00
a050986bf8 Fix uncaught exception on unreadable files (#2196)
* Avoid bailing out with uncaught `PermissionError`

* Update codespell_lib/tests/test_basic.py

* FIX: Coverage

* FIX: Already short-circuited

Co-authored-by: Eric Larson <larson.eric.d@gmail.com>
2022-10-19 11:44:09 -04:00
d31e0df51a Apply pyupgrade to project (#2364)
Update patterns to modern Python syntax and features. Drops unnecessary
legacy syntax that was required for Python 2 (removed in
9c3db1a5c5e02739eedba9e9915acd51736300b3).

Details on pyupgrade can be found at:
https://github.com/asottile/pyupgrade
2022-10-18 13:58:43 -04:00
900f18654b Fix encoding detection and exception on empty files (#2195)
The encoding detection code was trying to catch encoding-related
exceptions when the file is opened. This doesn't make sense, because
at this point no data has been read, therefore no encoding errors can be
detected. Instead, catch encoding-related exceptions when the file
contents are read.

Also avoid bailing out with `Exception('Unknown encoding')` on empty
files.
2022-10-12 13:17:12 -04:00
4792904cb7 ENH: CWD 2022-10-05 12:16:29 -04:00
wzy
2a0ee4b4b9 Fix #2055: Add support for PEP 518 (#2290)
Co-authored-by: Eric Larson <larson.eric.d@gmail.com>
2022-10-05 10:36:19 -04:00
81e4092793 Add some alternative line endings and whitespace checks (#2490)
Co-authored-by: vikivivi <22041592+vikivivi@users.noreply.github.com>
2022-09-12 11:31:25 -04:00
e8befc136d Simplify code
The list comprehension is shorter than the map() version.
I feel it is also simpler, although that is debatable.

This is consistent with the previous commit.
2022-01-07 18:26:23 +01:00
fd75e950ea Capitalize all suggested fixes
When a wrong word is capitalized, capitalize all the suggested fixes,
instead of only the first fix.
2022-01-04 21:43:50 +01:00
01f5c77d84 print("ERROR: ...") should print to sys.stderr 2021-11-16 11:31:30 +01:00
aaee230f1f __future__ not needed by Python >= 3.6 2021-09-30 10:47:09 +02:00
0338e3cc0e Merge pull request #1656 from jonmeow/ignore-uris
Add support for ignoring spelling mistakes in URIs specifically.
2021-06-02 00:17:26 +01:00
ad7211810b test 2021-06-01 15:22:08 -07:00
19c223f2c7 skip files passed in if matching the skip glob 2021-05-04 15:43:58 -07:00
a5402ec769 Merge remote-tracking branch 'upstream/master' into ignore-uris 2020-11-06 11:55:12 -08:00
6bb3ef4e96 Rephrase rejected to un-ignored 2020-10-12 14:16:46 -07:00
909f0dce08 More tests 2020-10-12 14:15:38 -07:00