Skip to content

Commit ca69d95

Browse files
authored
Add cargo fmt and cargo clippy checks to CI (#384)
1 parent 8f13fc9 commit ca69d95

File tree

8 files changed

+22
-16
lines changed

8 files changed

+22
-16
lines changed

.github/workflows/main.yml

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
workflow_dispatch:
88
merge_group:
99
types: [checks_requested]
10-
10+
1111
jobs:
1212
linux-ci:
1313
name: Linux
@@ -36,7 +36,10 @@ jobs:
3636
profile: minimal
3737
toolchain: ${{ matrix.toolchain }}
3838
override: true
39-
components: ${{ matrix.toolchain == 'nightly' && 'miri,rust-src' || '' }}
39+
components: rustfmt, clippy, ${{ matrix.toolchain == 'nightly' && 'miri,rust-src' || '' }}
40+
41+
- name: Cargo format & lint
42+
run: cargo fmt --check && cargo clippy -- -Dwarnings
4043

4144
- name: Cargo build
4245
run: cargo build ${{ matrix.features }}

color/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use std::str::FromStr;
2525
/// Matching is case-insensitive in the ASCII range.
2626
/// CSS escaping (if relevant) should be resolved before calling this function.
2727
/// (For example, the value of an `Ident` token is fine.)
28+
#[allow(clippy::result_unit_err)]
2829
#[inline]
2930
pub fn parse_color_keyword<Output>(ident: &str) -> Result<Output, ()>
3031
where

src/color.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pub fn serialize_color_alpha(
7676

7777
/// A Predefined color space specified in:
7878
/// <https://drafts.csswg.org/css-color-4/#predefined>
79-
#[derive(Clone, Copy, PartialEq, Debug)]
79+
#[derive(Clone, Copy, Eq, PartialEq, Debug)]
8080
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
8181
#[cfg_attr(feature = "serde", serde(tag = "type"))]
8282
pub enum PredefinedColorSpace {
@@ -143,6 +143,7 @@ impl ToCss for PredefinedColorSpace {
143143
}
144144

145145
/// Parse a color hash, without the leading '#' character.
146+
#[allow(clippy::result_unit_err)]
146147
#[inline]
147148
pub fn parse_hash_color(value: &[u8]) -> Result<(u8, u8, u8, f32), ()> {
148149
Ok(match value.len() {
@@ -330,6 +331,7 @@ ascii_case_insensitive_phf_map! {
330331

331332
/// Returns the named color with the given name.
332333
/// <https://drafts.csswg.org/css-color-4/#typedef-named-color>
334+
#[allow(clippy::result_unit_err)]
333335
#[inline]
334336
pub fn parse_named_color(ident: &str) -> Result<(u8, u8, u8), ()> {
335337
named_colors::get(ident).copied().ok_or(())

src/parser.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl ParserState {
5353
///
5454
/// Would need to scan the whole {} block to find a semicolon, only for parsing getting restarted
5555
/// as a qualified rule later.
56-
#[derive(Clone, Copy, Debug, PartialEq)]
56+
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
5757
pub enum ParseUntilErrorBehavior {
5858
/// Consume until we see the relevant delimiter or the end of the stream.
5959
Consume,
@@ -606,6 +606,7 @@ impl<'i: 't, 't> Parser<'i, 't> {
606606
/// See the `Parser::parse_nested_block` method to parse the content of functions or blocks.
607607
///
608608
/// This only returns a closing token when it is unmatched (and therefore an error).
609+
#[allow(clippy::should_implement_trait)]
609610
pub fn next(&mut self) -> Result<&Token<'i>, BasicParseError<'i>> {
610611
self.skip_whitespace();
611612
self.next_including_whitespace_and_comments()

src/rules_and_declarations.rs

+1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ pub trait AtRuleParser<'i> {
106106
/// This is only called when `parse_prelude` returned `WithoutBlock`, and
107107
/// either the `;` semicolon indeed follows the prelude, or parser is at
108108
/// the end of the input.
109+
#[allow(clippy::result_unit_err)]
109110
fn rule_without_block(
110111
&mut self,
111112
prelude: Self::Prelude,

src/serializer.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ where
338338

339339
macro_rules! impl_tocss_for_int {
340340
($T: ty) => {
341-
impl<'a> ToCss for $T {
341+
impl ToCss for $T {
342342
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
343343
where
344344
W: fmt::Write,
@@ -361,7 +361,7 @@ impl_tocss_for_int!(u64);
361361

362362
macro_rules! impl_tocss_for_float {
363363
($T: ty) => {
364-
impl<'a> ToCss for $T {
364+
impl ToCss for $T {
365365
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
366366
where
367367
W: fmt::Write,

src/tests.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -430,11 +430,9 @@ fn serializer(preserve_comments: bool) {
430430
preserve_comments: bool,
431431
) {
432432
while let Ok(token) = if preserve_comments {
433-
input
434-
.next_including_whitespace_and_comments()
435-
.map(|t| t.clone())
433+
input.next_including_whitespace_and_comments().cloned()
436434
} else {
437-
input.next_including_whitespace().map(|t| t.clone())
435+
input.next_including_whitespace().cloned()
438436
} {
439437
let token_type = token.serialization_type();
440438
if !preserve_comments && previous_token.needs_separator_when_before(token_type)
@@ -856,7 +854,7 @@ impl<'i> DeclarationParser<'i> for JsonParser {
856854
let mut important = false;
857855
loop {
858856
let start = input.state();
859-
if let Ok(mut token) = input.next_including_whitespace().map(|t| t.clone()) {
857+
if let Ok(mut token) = input.next_including_whitespace().cloned() {
860858
// Hack to deal with css-parsing-tests assuming that
861859
// `!important` in the middle of a declaration value is OK.
862860
// This can never happen per spec
@@ -959,7 +957,7 @@ impl<'i> RuleBodyItemParser<'i, Value, ()> for JsonParser {
959957

960958
fn component_values_to_json(input: &mut Parser) -> Vec<Value> {
961959
let mut values = vec![];
962-
while let Ok(token) = input.next_including_whitespace().map(|t| t.clone()) {
960+
while let Ok(token) = input.next_including_whitespace().cloned() {
963961
values.push(one_component_value_to_json(token, input));
964962
}
965963
values

src/tokenizer.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -566,11 +566,11 @@ fn next_token<'a>(tokenizer: &mut Tokenizer<'a>) -> Result<Token<'a>, ()> {
566566
b'#' => {
567567
tokenizer.advance(1);
568568
if is_ident_start(tokenizer) { IDHash(consume_name(tokenizer)) }
569-
else if !tokenizer.is_eof() && match tokenizer.next_byte_unchecked() {
569+
else if !tokenizer.is_eof() &&
570+
matches!(tokenizer.next_byte_unchecked(), b'0'..=b'9' | b'-') {
570571
// Any other valid case here already resulted in IDHash.
571-
b'0'..=b'9' | b'-' => true,
572-
_ => false,
573-
} { Hash(consume_name(tokenizer)) }
572+
Hash(consume_name(tokenizer))
573+
}
574574
else { Delim('#') }
575575
},
576576
b'$' => {

0 commit comments

Comments
 (0)