Skip to content

Commit

Permalink
Tune lints for 1.80 Rust
Browse files Browse the repository at this point in the history
  • Loading branch information
tyranron committed Jul 26, 2024
1 parent e3a4887 commit a5daa52
Show file tree
Hide file tree
Showing 15 changed files with 53 additions and 47 deletions.
2 changes: 2 additions & 0 deletions .clippy.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ absolute-paths-allowed-crates = [

doc-valid-idents = ["JUnit"]

ignore-interior-mutability = ["cucumber::step::HashableRegex"]

standard-macro-braces = [
{ name = "assert", brace = "(" },
{ name = "assert_eq", brace = "(" },
Expand Down
2 changes: 2 additions & 0 deletions codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
clippy::read_zero_byte_vec,
clippy::redundant_clone,
clippy::redundant_type_annotations,
clippy::renamed_function_params,
clippy::ref_patterns,
clippy::rest_pat_in_fully_bound_structs,
clippy::same_name_method,
Expand Down Expand Up @@ -130,6 +131,7 @@
clippy::use_self,
clippy::useless_let_if_seq,
clippy::verbose_file_reads,
clippy::while_float,
clippy::wildcard_enum_match_arm,
explicit_outlives_requirements,
future_incompatible,
Expand Down
4 changes: 2 additions & 2 deletions src/cucumber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,8 +572,8 @@ where
/// [`cli::Opts`].
///
/// > ⚠️ __WARNING__: Any CLI options of [`Parser`], [`Runner`], [`Writer`]
/// or custom ones should not overlap, otherwise
/// [`cli::Opts`] will fail to parse on startup.
/// > or custom ones should not overlap, otherwise
/// > [`cli::Opts`] will fail to parse on startup.
///
/// # Example
///
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
clippy::read_zero_byte_vec,
clippy::redundant_clone,
clippy::redundant_type_annotations,
clippy::renamed_function_params,
clippy::ref_patterns,
clippy::rest_pat_in_fully_bound_structs,
clippy::same_name_method,
Expand Down Expand Up @@ -131,6 +132,7 @@
clippy::use_self,
clippy::useless_let_if_seq,
clippy::verbose_file_reads,
clippy::while_float,
clippy::wildcard_enum_match_arm,
explicit_outlives_requirements,
future_incompatible,
Expand Down
4 changes: 2 additions & 2 deletions src/parser/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl<I: AsRef<Path>> Parser<I> for Basic {
type Output =
stream::Iter<vec::IntoIter<Result<gherkin::Feature, ParseError>>>;

fn parse(self, path: I, cli: Self::Cli) -> Self::Output {
fn parse(self, input: I, cli: Self::Cli) -> Self::Output {
let walk = |walker: GlobWalker| {
walker
.filter_map(Result::ok)
Expand All @@ -78,7 +78,7 @@ impl<I: AsRef<Path>> Parser<I> for Basic {
};

let get_features_path = || {
let path = path.as_ref();
let path = input.as_ref();
path.canonicalize()
.or_else(|_| {
let mut buf = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
Expand Down
4 changes: 2 additions & 2 deletions src/tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,13 +403,13 @@ where
{
fn on_new_span(
&self,
attr: &span::Attributes<'_>,
attrs: &span::Attributes<'_>,
id: &span::Id,
ctx: layer::Context<'_, S>,
) {
if let Some(span) = ctx.span(id) {
let mut visitor = GetScenarioId(None);
attr.values().record(&mut visitor);
attrs.values().record(&mut visitor);

if let Some(scenario_id) = visitor.0 {
let mut ext = span.extensions_mut();
Expand Down
28 changes: 14 additions & 14 deletions src/writer/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,14 @@ where

async fn handle_event(
&mut self,
ev: parser::Result<Event<event::Cucumber<W>>>,
opts: &Self::Cli,
event: parser::Result<Event<event::Cucumber<W>>>,
cli: &Self::Cli,
) {
use event::{Cucumber, Feature};

self.apply_cli(*opts);
self.apply_cli(*cli);

match ev.map(Event::into_inner) {
match event.map(Event::into_inner) {
Err(err) => self.parsing_failed(&err),
Ok(
Cucumber::Started
Expand Down Expand Up @@ -263,7 +263,7 @@ impl<Out: io::Write> Basic<Out> {
error: impl Display,
) -> io::Result<()> {
self.output
.write_line(&self.styles.err(format!("Failed to parse: {error}")))
.write_line(self.styles.err(format!("Failed to parse: {error}")))
}

/// Outputs the [started] [`Feature`].
Expand All @@ -275,7 +275,7 @@ impl<Out: io::Write> Basic<Out> {
feature: &gherkin::Feature,
) -> io::Result<()> {
let out = format!("{}: {}", feature.keyword, feature.name);
self.output.write_line(&self.styles.ok(out))
self.output.write_line(self.styles.ok(out))
}

/// Outputs the [`Rule`]'s [started]/[scenario]/[finished] event.
Expand Down Expand Up @@ -321,7 +321,7 @@ impl<Out: io::Write> Basic<Out> {
indent = " ".repeat(self.indent)
);
self.indent += 2;
self.output.write_line(&self.styles.ok(out))
self.output.write_line(self.styles.ok(out))
}

/// Outputs the [`Scenario`]'s [started]/[background]/[step] event.
Expand Down Expand Up @@ -404,7 +404,7 @@ impl<Out: io::Write> Basic<Out> {
}
};

self.output.write_line(&style(format!(
self.output.write_line(style(format!(
"{indent}✘ Scenario's {which} hook failed {}:{}:{}\n\
{indent} Captured output: {}{}",
feat.path
Expand Down Expand Up @@ -448,15 +448,15 @@ impl<Out: io::Write> Basic<Out> {
retries.current,
retries.left + retries.current,
);
self.output.write_line(&self.styles.retry(out))
self.output.write_line(self.styles.retry(out))
} else {
let out = format!(
"{}{}: {}",
" ".repeat(self.indent),
scenario.keyword,
scenario.name,
);
self.output.write_line(&self.styles.ok(out))
self.output.write_line(self.styles.ok(out))
}
}

Expand Down Expand Up @@ -598,7 +598,7 @@ impl<Out: io::Write> Basic<Out> {
.unwrap_or_default(),
);

self.output.write_line(&style(format!(
self.output.write_line(style(format!(
"{indent}{step_keyword}{step_value}{doc_str}{step_table}",
indent = " ".repeat(self.indent.saturating_sub(3)),
)))
Expand All @@ -614,7 +614,7 @@ impl<Out: io::Write> Basic<Out> {
step: &gherkin::Step,
) -> io::Result<()> {
self.clear_last_lines_if_term_present()?;
self.output.write_line(&self.styles.skipped(format!(
self.output.write_line(self.styles.skipped(format!(
"{indent}? {}{}{}{}\n\
{indent} Step skipped: {}:{}:{}",
step.keyword,
Expand Down Expand Up @@ -877,7 +877,7 @@ impl<Out: io::Write> Basic<Out> {
.unwrap_or_default(),
);

self.output.write_line(&style(format!(
self.output.write_line(style(format!(
"{step_keyword}{step_value}{doc_str}{step_table}",
)))
}
Expand All @@ -893,7 +893,7 @@ impl<Out: io::Write> Basic<Out> {
step: &gherkin::Step,
) -> io::Result<()> {
self.clear_last_lines_if_term_present()?;
self.output.write_line(&self.styles.skipped(format!(
self.output.write_line(self.styles.skipped(format!(
"{indent}?> {}{}{}{}\n\
{indent} Background step failed: {}:{}:{}",
step.keyword,
Expand Down
8 changes: 4 additions & 4 deletions src/writer/discard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ impl<W: World, Wr: Writer<W> + ?Sized> Writer<W> for Arbitrary<Wr> {

async fn handle_event(
&mut self,
ev: parser::Result<Event<Cucumber<W>>>,
event: parser::Result<Event<Cucumber<W>>>,
cli: &Self::Cli,
) {
self.0.handle_event(ev, cli).await;
self.0.handle_event(event, cli).await;
}
}

Expand Down Expand Up @@ -114,10 +114,10 @@ impl<W: World, Wr: Writer<W> + ?Sized> Writer<W> for Stats<Wr> {

async fn handle_event(
&mut self,
ev: parser::Result<Event<Cucumber<W>>>,
event: parser::Result<Event<Cucumber<W>>>,
cli: &Self::Cli,
) {
self.0.handle_event(ev, cli).await;
self.0.handle_event(event, cli).await;
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/writer/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -799,18 +799,18 @@ impl Feature {
}

impl PartialEq<gherkin::Feature> for Feature {
fn eq(&self, feature: &gherkin::Feature) -> bool {
fn eq(&self, other: &gherkin::Feature) -> bool {
self.uri
.as_ref()
.and_then(|uri| {
feature
other
.path
.as_ref()
.and_then(|p| p.to_str().map(trim_path))
.map(|path| uri == path)
})
.unwrap_or_default()
&& self.name == feature.name
&& self.name == other.name
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/writer/junit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,14 @@ where

async fn handle_event(
&mut self,
ev: parser::Result<Event<event::Cucumber<W>>>,
opts: &Self::Cli,
event: parser::Result<Event<event::Cucumber<W>>>,
cli: &Self::Cli,
) {
use event::{Cucumber, Feature, Rule};

self.apply_cli(*opts);
self.apply_cli(*cli);

match ev.map(Event::split) {
match event.map(Event::split) {
Err(err) => self.handle_error(&err),
Ok((Cucumber::Started | Cucumber::ParsingFinished { .. }, _)) => {}
Ok((Cucumber::Feature(feat, ev), meta)) => match ev {
Expand Down
6 changes: 3 additions & 3 deletions src/writer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub trait Writer<World> {
/// [`Cucumber`]: crate::event::Cucumber
fn handle_event(
&mut self,
ev: parser::Result<Event<event::Cucumber<World>>>,
event: parser::Result<Event<event::Cucumber<World>>>,
cli: &Self::Cli,
) -> impl Future<Output = ()>;
}
Expand Down Expand Up @@ -285,15 +285,15 @@ impl<T> Ext for T {
FailOnSkipped::from(self)
}

fn fail_on_skipped_with<F>(self, f: F) -> FailOnSkipped<Self, F>
fn fail_on_skipped_with<F>(self, with: F) -> FailOnSkipped<Self, F>
where
F: Fn(
&gherkin::Feature,
Option<&gherkin::Rule>,
&gherkin::Scenario,
) -> bool,
{
FailOnSkipped::with(self, f)
FailOnSkipped::with(self, with)
}

fn repeat_skipped<W>(self) -> Repeat<W, Self> {
Expand Down
6 changes: 3 additions & 3 deletions src/writer/normalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -702,17 +702,17 @@ impl<'me, World> Emitter<World> for &'me mut FeatureQueue<World> {

async fn emit<W: Writer<World>>(
self,
feature: Self::EmittedPath,
path: Self::EmittedPath,
writer: &mut W,
cli: &W::Cli,
) -> Option<Self::Emitted> {
match self.current_item()? {
Either::Left((rule, events)) => events
.emit((feature, rule), writer, cli)
.emit((path, rule), writer, cli)
.await
.map(Either::Left),
Either::Right((scenario, events)) => events
.emit((feature, None, scenario), writer, cli)
.emit((path, None, scenario), writer, cli)
.await
.map(Either::Right),
}
Expand Down
8 changes: 4 additions & 4 deletions src/writer/or.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ where

async fn handle_event(
&mut self,
ev: parser::Result<Event<event::Cucumber<W>>>,
event: parser::Result<Event<event::Cucumber<W>>>,
cli: &Self::Cli,
) {
if (self.predicate)(&ev, cli) {
self.left.handle_event(ev, &cli.left).await;
if (self.predicate)(&event, cli) {
self.left.handle_event(event, &cli.left).await;
} else {
self.right.handle_event(ev, &cli.right).await;
self.right.handle_event(event, &cli.right).await;
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/writer/summarize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ where

async fn handle_event(
&mut self,
ev: parser::Result<Event<event::Cucumber<W>>>,
event: parser::Result<Event<event::Cucumber<W>>>,
cli: &Self::Cli,
) {
use event::{Cucumber, Feature, Rule};
Expand All @@ -212,7 +212,7 @@ where
// This is done to avoid miscalculations if this `Writer` happens to be
// wrapped by a `writer::Repeat` or similar.
if matches!(self.state, State::InProgress) {
match ev.as_deref() {
match event.as_deref() {
Err(_) => self.parsing_errors += 1,
Ok(Cucumber::Feature(feat, ev)) => match ev {
Feature::Started => self.features += 1,
Expand Down Expand Up @@ -244,7 +244,7 @@ where
};
}

self.writer.handle_event(ev, cli).await;
self.writer.handle_event(event, cli).await;

if matches!(self.state, State::FinishedButNotOutput) {
self.state = State::FinishedAndOutput;
Expand Down
6 changes: 3 additions & 3 deletions src/writer/tee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ where

async fn handle_event(
&mut self,
ev: parser::Result<Event<event::Cucumber<W>>>,
event: parser::Result<Event<event::Cucumber<W>>>,
cli: &Self::Cli,
) {
future::join(
self.left.handle_event(ev.clone(), &cli.left),
self.right.handle_event(ev, &cli.right),
self.left.handle_event(event.clone(), &cli.left),
self.right.handle_event(event, &cli.right),
)
.await;
}
Expand Down

0 comments on commit a5daa52

Please sign in to comment.