Skip to content

Commit

Permalink
chore: Clippy lints
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Dygalo <[email protected]>
  • Loading branch information
Stranger6667 committed Jan 22, 2025
1 parent 7a2ac3e commit 210eebb
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub(crate) fn load_suite(

for entry in WalkDir::new(&full_path).into_iter().filter_map(Result::ok) {
let path = entry.path();
if path.is_file() && path.extension().map_or(false, |ext| ext == "json") {
if path.is_file() && path.extension().is_some_and(|ext| ext == "json") {
let file = File::open(path)?;
let reader = BufReader::new(file);
let case: Case = serde_json::from_reader(reader)?;
Expand Down
2 changes: 1 addition & 1 deletion crates/jsonschema-testsuite-codegen/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub(crate) fn load_suite(

for entry in WalkDir::new(&full_path).into_iter().filter_map(Result::ok) {
let path = entry.path();
if path.is_file() && path.extension().map_or(false, |ext| ext == "json") {
if path.is_file() && path.extension().is_some_and(|ext| ext == "json") {
let relative_path = path.strip_prefix(&full_path)?;
let file = File::open(path)?;
let reader = BufReader::new(file);
Expand Down
2 changes: 1 addition & 1 deletion crates/jsonschema/src/ecma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl<'a> Ecma262Translator<'a> {
);
}
}
self.offset += replacement.as_bytes().len() - (end.offset - start.offset);
self.offset += replacement.len() - (end.offset - start.offset);
self.has_changes = true;
}

Expand Down
15 changes: 3 additions & 12 deletions crates/jsonschema/src/keywords/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,17 +200,11 @@ pub(crate) fn compile_media_type<'a>(
) -> Option<CompilationResult<'a>> {
match subschema {
Value::String(media_type) => {
let func = match ctx.get_content_media_type_check(media_type.as_str()) {
Some(f) => f,
None => return None,
};
let func = ctx.get_content_media_type_check(media_type.as_str())?;
if let Some(content_encoding) = schema.get("contentEncoding") {
match content_encoding {
Value::String(content_encoding) => {
let converter = match ctx.get_content_encoding_convert(content_encoding) {
Some(f) => f,
None => return None,
};
let converter = ctx.get_content_encoding_convert(content_encoding)?;
Some(ContentMediaTypeAndEncodingValidator::compile(
media_type,
content_encoding,
Expand Down Expand Up @@ -256,10 +250,7 @@ pub(crate) fn compile_content_encoding<'a>(
}
match subschema {
Value::String(content_encoding) => {
let func = match ctx.get_content_encoding_check(content_encoding) {
Some(f) => f,
None => return None,
};
let func = ctx.get_content_encoding_check(content_encoding)?;
Some(ContentEncodingValidator::compile(
content_encoding,
func,
Expand Down
2 changes: 1 addition & 1 deletion crates/jsonschema/src/keywords/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ fn is_valid_idn_hostname(hostname: &str) -> bool {
'\u{0375}'
if !chars
.peek()
.map_or(false, |next| ('\u{0370}'..='\u{03FF}').contains(next)) =>
.is_some_and(|next| ('\u{0370}'..='\u{03FF}').contains(next)) =>
{
return false
}
Expand Down
2 changes: 1 addition & 1 deletion crates/jsonschema/src/keywords/one_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl OneOfValidator {
impl Validate for OneOfValidator {
fn is_valid(&self, instance: &Value) -> bool {
let first_valid_idx = self.get_first_valid(instance);
first_valid_idx.map_or(false, |idx| !self.are_others_valid(instance, idx))
first_valid_idx.is_some_and(|idx| !self.are_others_valid(instance, idx))
}
fn validate<'i>(
&self,
Expand Down
4 changes: 2 additions & 2 deletions crates/jsonschema/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ mod tests {
path: Location,
) -> Result<Box<dyn Keyword>, ValidationError<'a>> {
const EXPECTED: &str = "ascii-keys";
if schema.as_str().map_or(true, |key| key != EXPECTED) {
if schema.as_str() != Some(EXPECTED) {
Err(ValidationError::constant_string(
Location::new(),
path,
Expand Down Expand Up @@ -505,7 +505,7 @@ mod tests {
};
let with_currency_format = parent
.get("format")
.map_or(false, |format| format == "currency");
.is_some_and(|format| format == "currency");
Ok(Box::new(CustomMinimumValidator {
limit,
limit_val: schema.clone(),
Expand Down

0 comments on commit 210eebb

Please sign in to comment.