ruff/scripts
Micha Reiser c4578162d5
[red-knot] Add support for knot check <paths> (#16375)
## Summary

This PR adds support for an optional list of paths that should be
checked to `knot check`.

E.g. to only check the `src` directory

```sh
knot check src
```

The default is to check all files in the project but users can reduce
the included files by specifying one or multiple optional paths.

The main two challenges with adding this feature were:

* We now need to show an error when one of the provided paths doesn't
exist. That's why this PR now collects errors from the project file
indexing phase and adds them to the output diagnostics. The diagnostic
looks similar to ruffs (see CLI test)
* The CLI should pick up new files added to included folders. For
example, `knot check src --watch` should pick up new files that are
added to the `src` folder. This requires that we now filter the files
before adding them to the project. This is a good first step to
supporting `include` and `exclude`.


The PR makes two simplifications:

1. I didn't test the changes with case-insensitive file systems. We may
need to do some extra path normalization to support those well. See
https://github.com/astral-sh/ruff/issues/16400
2. Ideally, we'd accumulate the IO errors from the initial indexing
phase and subsequent incremental indexing operations. For example, we
should preserve the IO diagnostic for a non existing `test.py` if it was
specified as an explicit CLI argument until the file gets created and we
should show it again when the file gets deleted. However, this is
somewhat complicated because we'd need to track which files we revisited
(or were removed because the entire directory is gone). I considered
this too low a priority as it's worth dealing with right now.

The implementation doesn't support symlinks within the project but that
is the same as Ruff and is unchanged from before this PR.



Closes https://github.com/astral-sh/ruff/issues/14193

## Test Plan

Added CLI and file watching integration tests. Manually testing.
2025-03-03 12:59:56 +00:00
..
benchmarks Bump version to Ruff 0.9.9 (#16434) 2025-02-28 10:17:38 +01:00
knot_benchmark [red-knot] Add support for knot check <paths> (#16375) 2025-03-03 12:59:56 +00:00
release Update release script to match uv (#11496) 2024-07-03 07:35:28 -05:00
_utils.py Use __future__ imports in scripts (#5301) 2023-06-22 11:40:16 -04:00
add_plugin.py [pydoclint] Implement docstring-missing-exception and docstring-extraneous-exception (DOC501, DOC502) (#11471) 2024-07-20 19:41:51 +00:00
add_rule.py Use a derive macro for Violations (#14557) 2024-11-27 09:41:40 +00:00
check_docs_formatted.py Check for backtick-quoted shortcut links in CI (#16114) 2025-02-14 08:37:46 +01:00
check_ecosystem.py Standardise ruff config (#15558) 2025-01-21 12:09:11 +01:00
Dockerfile.ecosystem Remove outdated feature flag from Dockerfile.ecosystem (#4620) 2023-05-24 08:19:08 +00:00
ecosystem_all_check.py Update pre-commit dependencies (#10698) 2024-04-06 23:00:41 +00:00
ecosystem_all_check.sh Rename Autofix to Fix (#7657) 2023-09-28 10:53:05 +00:00
ecosystem_all_check_entrypoint.sh Make ecosystem all check more generic (#4629) 2023-05-24 16:26:23 +02:00
formatter_ecosystem_checks.sh Improve the performance of the formatter instability check job (#14471) 2024-11-20 08:55:10 -06:00
generate_builtin_modules.py Add a new script to generate builtin module names (#12696) 2024-08-05 21:33:36 +01:00
generate_known_standard_library.py Add a new script to generate builtin module names (#12696) 2024-08-05 21:33:36 +01:00
generate_mkdocs.py Generate documentation redirects for lowercase rule codes (#15564) 2025-01-18 10:09:23 +05:30
pyproject.toml Standardise ruff config (#15558) 2025-01-21 12:09:11 +01:00
release.sh Update release script to match uv (#11496) 2024-07-03 07:35:28 -05:00
transform_readme.py Update pre-commit dependencies (#10698) 2024-04-06 23:00:41 +00:00
update_ambiguous_characters.py Update pre-commit dependencies (#10698) 2024-04-06 23:00:41 +00:00
update_schemastore.py Use https by default in schema store update script (#11882) 2024-06-14 17:30:54 -05:00