You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Support linting breaking changes in manifests & add feature_missing lint (#1007)
Add support for linting of package manifests, allowing us to scan for
breaking changes there as well.
For example, deleting a feature is a major breaking change. As of this
PR, we can detect and report that:
```
--- failure feature_missing: package feature removed or renamed ---
Description:
A feature has been removed from this package's Cargo.toml. This will break downstream crates which enable that feature.
ref: https://doc.rust-lang.org/cargo/reference/semver.html#cargo-feature-remove
impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.37.0/src/lints/feature_missing.ron
Failed in:
feature going_missing in the package's Cargo.toml
feature rand in the package's Cargo.toml
Summary semver requires new major version: 1 major and 0 minor checks failed
```
Completes the first checkbox of the 2024H2 Rust Project Goal on
cargo-semver-checks:
rust-lang/rust-project-goals#104
Unblocks the lints specified in #48.
Copy file name to clipboardexpand all lines: CONTRIBUTING.md
+15-13
Original file line number
Diff line number
Diff line change
@@ -111,7 +111,7 @@ To generate this data, please run `./scripts/regenerate_test_rustdocs.sh`.
111
111
To use a specific toolchain, like beta or nightly, pass it as
112
112
an argument: `./scripts/regenerate_test_rustdocs.sh +nightly`.
113
113
114
-
## What are those `.snap` or `.snap.new` files generated via `cargo test`
114
+
## What are those `.snap` or `.snap.new` files generated via `cargo test`
115
115
116
116
As part of our overall testing strategy, we use a technique called "snapshot testing."
117
117
The tool we use for this ([`insta`](https://insta.rs/docs/)) is user friendly and has mutliple ways to interact with it:
@@ -138,7 +138,7 @@ Reviewing them is possible via these options:
138
138
```
139
139
3.**Manually**: If you can't (or don't want to) use `cargo-insta`, you can verify the snapshot
140
140
file manually. There should be a file called `test_outputs/<some_path>/<lint_name>.snap.new`.
141
-
Open it, and verify that its contents match what you expected: all expected data is present, and no unexpected data is included.
141
+
Open it, and verify that its contents match what you expected: all expected data is present, and no unexpected data is included.
142
142
Once you've checked it, remove the `.new` suffix so that the file's new path
143
143
is `test_outputs/<some_path>/<lint_name>.snap`
144
144
@@ -172,14 +172,16 @@ We'll use the [`scripts/make_new_lint.sh`](https://github.com/obi1kenobi/cargo-s
172
172
173
173
Now it's time to fill in these files!
174
174
- Define the lint in `src/lints/<lint_name>.ron`.
175
-
-Make sure your lint outputs `span_filename` and `span_begin_line` for it
176
-
to be a valid lint. The pattern we commonly use is:
175
+
-For almost all lints, make sure your lint outputs `span_filename` and `span_begin_line`
176
+
in order to be a valid lint. The pattern we commonly use is:
177
177
```
178
178
span_: span @optional {
179
179
filename @output
180
180
begin_line @output
181
181
}
182
182
```
183
+
<details><summary>Exception: lints over Cargo.toml information (click to expand)</summary>If you are writing a lint over manifest (<code>Cargo.toml</code>) information such as "a feature was deleted," you won't be able to find span data from the manifest file. To proceed, pick a value unique to each result produced by your lint query and output it as <code>ordering_key</code> instead.</details>
184
+
183
185
- Demonstrate the semver issue your lint is looking for by adding suitable code in
184
186
the `test_crates/<lint_name>/old` and `test_crates/<lint_name>/new` crates.
185
187
- Add code to the test crates that aims to catch for false-positives
@@ -269,8 +271,8 @@ Inspect the generated "actual" output in the `.snap.new` file:
269
271
If so, ensure the reported code is indeed violating semver and is not being flagged
270
272
by any other lint.
271
273
272
-
If everything looks okay, either run `cargo insta review` (see
273
-
the [snapshot instructions](#what-are-those-snap-or-snapnew-files-generated-via-cargo-test)
274
+
If everything looks okay, either run `cargo insta review` (see
275
+
the [snapshot instructions](#what-are-those-snap-or-snapnew-files-generated-via-cargo-test)
274
276
for context) or manually move `test_outputs/query_execution/<lint_name>.snap.new`
275
277
to `test_outputs/query_execution/<lint_name>.snap`.
276
278
Then re-run `cargo test` and make sure everything passes.
@@ -342,7 +344,7 @@ to update the test outputs.
342
344
> It may contain output for other test crates — this is not necessarily an error:
343
345
> See the [troubleshooting section](#troubleshooting) for more info.
344
346
345
-
To update the output, please refer to the section
347
+
To update the output, please refer to the section
346
348
on [snapshot testing](#what-are-those-snap-or-snapnew-files-generated-via-cargo-test)
347
349
348
350
Once you've update the test output, run `cargo test` again and the `<lint_name>` test should pass!
@@ -356,40 +358,40 @@ otherwise the test will fail in CI.
356
358
### Troubleshooting
357
359
358
360
- <details><summary>A valid query must output <code>span_filename</code> and/or <code>span_begin_line</code> (click to expand)</summary>
359
-
361
+
360
362
If your lint fails with an error similar to the following:
361
363
```
362
364
---- query::tests_lints::enum_missing stdout ----
363
365
thread 'query::tests_lints::enum_missing' panicked at 'A valid query must output both `span_filename` and `span_begin_line`. See https://github.com/obi1kenobi/cargo-semver-checks/blob/main/CONTRIBUTING.md for how to do this.', src/query.rs:395:26
364
366
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
365
367
```
366
-
368
+
367
369
It likely means that your lint does not specify the `span_filename` and `span_begin_line` of where the error occurs. To fix this, add the following to the part of query that catches the error:
368
370
```
369
371
span_: span @optional {
370
372
filename @output
371
373
begin_line @output
372
374
}
373
375
```
374
-
376
+
375
377
</details>
376
378
- <details><summary>Other lints' tests failed too (click to expand)</summary>
377
379
378
380
This is not always a problem! In process of testing a lint, it's frequently desirable to include
379
381
test code that contains a related semver issue in order to ensure the lint differentiates between
380
382
them.
381
-
383
+
382
384
For example, say one is testing a lint for pub field removals from a struct. Its test crate code
383
385
may then include removals of the entire struct, in order to make sure that the lint *does not*
384
386
report those. But those struct removals *will* get reported by the lint that looks for semver
385
387
violations due to struct removal!
386
-
388
+
387
389
So if you added code to a test crate, and it caused other lints to report new findings, consider:
388
390
- whether your code indeed contains the reported semver issue;
389
391
- whether the same semver issue is being reported only once, and not multiple times
390
392
by different lints,
391
393
- and whether the new reported lint result points to the correct item and span information.
392
-
394
+
393
395
If the answer to all is yes, then everything is fine! Just edit those other lints'
394
396
expected output files to include the new items, and you can get back on track.
0 commit comments