ruff/crates/ruff_dev/src
konsti d098256c96
Add a tool for shrinking failing examples (#5731)
## Summary

For formatter instabilities, the message we get look something like
this:
```text
Unstable formatting /home/konsti/ruff/target/checkouts/deepmodeling:dpdispatcher/dpdispatcher/slurm.py
@@ -47,9 +47,9 @@
-            script_header_dict["slurm_partition_line"] = (
-                NOT_YET_IMPLEMENTED_ExprJoinedStr
-            )
+            script_header_dict[
+                "slurm_partition_line"
+            ] = NOT_YET_IMPLEMENTED_ExprJoinedStr
Unstable formatting /home/konsti/ruff/target/checkouts/deepmodeling:dpdispatcher/dpdispatcher/pbs.py
@@ -26,9 +26,9 @@
-            pbs_script_header_dict["select_node_line"] += (
-                NOT_YET_IMPLEMENTED_ExprJoinedStr
-            )
+            pbs_script_header_dict[
+                "select_node_line"
+            ] += NOT_YET_IMPLEMENTED_ExprJoinedStr
``` 

For ruff crashes. you don't even get that but just the file that crashed
it. To extract the actual bug, you'd need to manually remove parts of
the file, rerun to see if the bug still occurs (and revert if it
doesn't) until you have a minimal example.

With this script, you run

```shell
cargo run --bin ruff_shrinking -- target/checkouts/deepmodeling:dpdispatcher/dpdispatcher/slurm.py target/minirepo/code.py "Unstable formatting" "target/debug/ruff_dev format-dev --stability-check target/minirepo"
```

and get

```python
class Slurm():
    def gen_script_header(self, job):
        if resources.queue_name != "":
            script_header_dict["slurm_partition_line"] = f"#SBATCH --partition {resources.queue_name}"
```

which is an nice minimal example.

I've been using this script and it would be easier for me if this were
part of main. The main disadvantage to merging is that it adds
additional dependencies.

## Test Plan

I've been using this for a number of minimization. This is an internal
helper script you only run manually. I could add a test that minimizes a
rule violation if required.

---------

Co-authored-by: Micha Reiser <micha@reiser.io>
2023-07-18 08:03:35 +00:00
..
format_dev.rs Add a tool for shrinking failing examples (#5731) 2023-07-18 08:03:35 +00:00
generate_all.rs Document ruff_dev and format_dev (#5648) 2023-07-12 16:18:22 +02:00
generate_cli_help.rs Use `mod tests` consistently (#5278) 2023-06-22 01:50:28 +00:00
generate_docs.rs Fix `Options` section of rule docs (#5741) 2023-07-13 17:25:54 +00:00
generate_json_schema.rs Add unreachable code rule (#5384) 2023-07-04 14:27:23 +00:00
generate_options.rs Document ruff_dev and format_dev (#5648) 2023-07-12 16:18:22 +02:00
generate_rules_table.rs Document ruff_dev and format_dev (#5648) 2023-07-12 16:18:22 +02:00
main.rs Extend ruff_dev formatter script to compute statistics and format a project (#5492) 2023-07-07 11:30:12 +00:00
print_ast.rs Upgrade RustPython (#4747) 2023-05-31 08:26:35 +00:00
print_cst.rs Disallow `unreachable_pub` (#4314) 2023-05-11 18:00:00 -04:00
print_tokens.rs Disallow `unreachable_pub` (#4314) 2023-05-11 18:00:00 -04:00
round_trip.rs Experimental release for Jupyter notebook integration (#5363) 2023-06-26 21:22:42 +05:30