Add ability to ignore checks on a per-file/folder basis
You can now ignore errors for a given path! Just add the following to your `pyproject.toml`:
toml
[[tool.refurb.amend]]
path = "your/path/here" <-- can be a file or folder
ignore = ["FURB123"]
Read [the docs](https://github.com/dosisod/refurb#ignore-checks-per-filefolder) for more info on how to use this new feature!
Add `use-pathlib-mkdir` check (FURB150)
Use the `mkdir` function from the `pathlib` library instead of using the `mkdir` and `makedirs` functions from the `os` library.
The following code:
python
import os
os.mkdir("new_folder")
Can be written like:
python
from pathlib import Path
Path("new_folder").mkdir()
Add `use-pathlib-touch` check (FURB151)
Don't use `open(x, "w").close()` if you just want to create an empty file, use the less confusing `Path.touch()` method instead.
<details>
<summary>Note that this check is disabled by default (expand this for a full explanation).</summary>
<br>
This check is disabled by default because `touch()` will throw a `FileExistsError` if the file already exists, and (at least on Linux) it sets different file permissions, meaning it is not a drop-in replacement. If you don't care about the file permissions or know that the file doesn't exist beforehand this check may be for you.
</details>
For example, this code:
python
open("file.txt", "w").close()
Can be written like this:
python
from pathlib import Path
Path("file.txt").touch()
Add `use-math-constant` check (FURB152)
Don't hardcode math constants like pi, tau, or e, use the `math.pi`, `math.tau`, or `math.e` constants respectively instead.
For example, this code:
python
def area(r: float) -> float:
return 3.1415 * r * r
Should be written like this:
python
import math
def area(r: float) -> float:
return math.pi * r * r
Add `simplify-path-constructor` check (FURB153)
The `Path()` constructor defaults to the current directory, so don't pass the current directory (`"."`) explicitly.
This:
python
file = Path(".")
Can be written like this:
python
file = Path()
Add names to checks
All checks now contain a `name` field which makes them easier to refer to. Although the name isn't actually used for anything, you will eventually be able to use the name field as a replacement for `FURBxxx` on the CLI, in config files, and in `noqa` comments. In addition, the name (along with the categories) will be printed at the top of the "explainer" for the check when using `--explain`.
What's Changed
* Add `--namespace-packages` flag to mypy by dosisod in https://github.com/dosisod/refurb/pull/170
* Add ability to parse path expressions resulting from `/` operator by dosisod in https://github.com/dosisod/refurb/pull/171
* Add "pathlib touch" check by dosisod in https://github.com/dosisod/refurb/pull/172
* Add missing categories to checks by dosisod in https://github.com/dosisod/refurb/pull/175
* Add "no math constants" check by dosisod in https://github.com/dosisod/refurb/pull/176
* Add "no explicit cwd" check by dosisod in https://github.com/dosisod/refurb/pull/178
* Add `name` field to checks by dosisod in https://github.com/dosisod/refurb/pull/179
* Add ability to ignore errors on a per file/folder basis by dosisod in https://github.com/dosisod/refurb/pull/183
* Fix integers not working in amend sections, bump packages by dosisod in https://github.com/dosisod/refurb/pull/184
**Full Changelog**: https://github.com/dosisod/refurb/compare/v1.9.1...v1.10.0