forked from rust-lang/rust-clippy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
753629b
commit a61a355
Showing
10 changed files
with
183 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
name: New lint stabilization version check | ||
|
||
on: [pull_request, push] | ||
|
||
env: | ||
RUST_BACKTRACE: 1 | ||
CARGO_INCREMENTAL: 0 | ||
|
||
concurrency: | ||
# For a given workflow, if we push to the same PR, cancel all previous builds on that PR. | ||
group: "${{ github.workflow }}-${{ github.event.pull_request.number}}" | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
# Collect lint metadata on the PR's target branch and stores the results as an artifact | ||
base: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 2 | ||
|
||
# HEAD is the generated merge commit `refs/pull/N/merge` between the PR and `master`, `HEAD^` | ||
# being the commit from `master` that is the base of the merge | ||
- name: Checkout base | ||
run: git checkout HEAD^ | ||
|
||
- name: Cache metadata | ||
id: cache-metadata | ||
uses: actions/cache@v4 | ||
with: | ||
path: util/gh-pages/lints.json | ||
key: metadata-bin-${{ hashfiles('clippy_lints/**') }} | ||
|
||
- name: Collect metadata | ||
if: steps.cache-metadata.outputs.cache-hit != 'true' | ||
run: cargo collect-metadata | ||
|
||
- name: Upload base JSON | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: base | ||
path: util/gh-pages/lints.json | ||
|
||
head: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 2 | ||
|
||
- name: Cache metadata | ||
id: cache-metadata | ||
uses: actions/cache@v4 | ||
with: | ||
path: util/gh-pages/lints.json | ||
key: metadata-bin-${{ hashfiles('clippy_lints/**') }} | ||
|
||
- name: Collect metadata | ||
if: steps.cache-metadata.outputs.cache-hit != 'true' | ||
run: cargo collect-metadata | ||
|
||
- name: Upload base JSON | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: head | ||
path: util/gh-pages/lints.json | ||
|
||
# Retrieves the head and base JSON results and prints the diff to the GH actions step summary | ||
diff: | ||
runs-on: ubuntu-latest | ||
|
||
needs: [base, head] | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Download JSON | ||
uses: actions/download-artifact@v4 | ||
|
||
- name: Diff results | ||
run: | | ||
cargo dev check_new_lints_version base/lints.json head/lints.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use std::collections::HashMap; | ||
use std::fs::File; | ||
use std::path::Path; | ||
use std::process; | ||
|
||
use crate::new_lint::get_stabilization_version; | ||
|
||
#[derive(serde::Deserialize)] | ||
struct Lint { | ||
id: String, | ||
version: String, | ||
} | ||
|
||
pub fn load_metadata(metadata: &Path) -> HashMap<String, String> { | ||
let lints: Vec<Lint> = serde_json::from_reader(File::open(metadata).unwrap()).unwrap(); | ||
lints.into_iter().map(|lint| (lint.id, lint.version)).collect() | ||
} | ||
|
||
pub fn check_lint_version(old_metadata: &Path, new_metadata: &Path) { | ||
let stabilization_version = get_stabilization_version(); | ||
let old_lints = load_metadata(old_metadata); | ||
let mut new_lints = load_metadata(new_metadata) | ||
.into_iter() | ||
.filter(|(name, _)| !old_lints.contains_key(name)) | ||
.collect::<Vec<_>>(); | ||
if new_lints.is_empty() { | ||
println!("No new lints"); | ||
return; | ||
} | ||
new_lints.sort_unstable(); | ||
let mut error = false; | ||
println!("New lints:"); | ||
for (name, version) in new_lints { | ||
if version == stabilization_version { | ||
println!(" - {name}"); | ||
} else { | ||
println!(" - {name}: lint declares version {version}, stabilization version is {stabilization_version}"); | ||
error = true; | ||
} | ||
} | ||
if error { | ||
process::exit(1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use rustc_lint::LateLintPass; | ||
use rustc_session::declare_lint_pass; | ||
|
||
declare_clippy_lint! { | ||
/// ### What it does | ||
/// | ||
/// ### Why is this bad? | ||
/// | ||
/// ### Example | ||
/// ```no_run | ||
/// // example code where clippy issues a warning | ||
/// ``` | ||
/// Use instead: | ||
/// ```no_run | ||
/// // example code which does not raise clippy warning | ||
/// ``` | ||
#[clippy::version = "1.71.0"] | ||
pub DUMMY_LINT, | ||
suspicious, | ||
"precise lint description" | ||
} | ||
|
||
declare_lint_pass!(DummyLint => [DUMMY_LINT]); | ||
|
||
impl LateLintPass<'_> for DummyLint {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#![warn(clippy::dummy_lint)] | ||
|
||
fn main() { | ||
// test code goes here | ||
} |