Skip to content

Commit

Permalink
refactor: improve code quality based on clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcAntoine-Arnaud committed Jun 10, 2024
1 parent 5159ed5 commit 0822918
Show file tree
Hide file tree
Showing 42 changed files with 295 additions and 515 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ jobs:
- uses: Swatinem/rust-cache@v2
- name: Clippy check
uses: actions-rs/cargo@v1
continue-on-error: true
with:
command: clippy
args: --all-targets --all-features --workspace -- -D warnings
Expand Down
19 changes: 10 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ name = "shapes-rs"
version = "0.0.11"
description = "RDF Data shapes implementation in Rust"
license = "GPL-3.0-or-later"
authors = [
"Jose Emilio Labra Gayo",
"Ángel Iglesias Préstamo <[email protected]>",
authors = [
"Jose Emilio Labra Gayo <[email protected]>",
"Ángel Iglesias Préstamo <[email protected]>",
]
repository = "https://github.com/weso/shapes-rs"
homepage = "https://www.weso.es/shapes-rs/"


[[bin]]
path = "sx_cli/src/main.rs"
name = "sx"
name = "sx"

[workspace]
members = [
Expand Down Expand Up @@ -47,15 +47,16 @@ exclude = [
# version = "0.0.6"
edition = "2021"
license = "MIT OR Apache-2.0"
authors = ["Jose Emilio Labra Gayo <[email protected]>",
"Ángel Iglesias Préstamo <[email protected]>",
authors = [
"Jose Emilio Labra Gayo <[email protected]>",
"Ángel Iglesias Préstamo <[email protected]>",
]
description = "RDF data shapes implementation in Rust"
repository = "https://github.com/weso/shapes_rs"
repository = "https://github.com/weso/shapes-rs"
homepage = "https://www.weso.es/shapes-rs/"

readme = "./README.md"
keywords = ["rdf", "linked-data", "semantic-web", "shex"]
keywords = ["rdf", "linked-data", "semantic-web", "shex"]
categories = ["rdf"]

[workspace.dependencies]
Expand Down Expand Up @@ -89,4 +90,4 @@ oxrdf = "0.2.0-alpha.2"
serde_json = "1.0"
regex = "1.10.4"
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = [ "env-filter" ] }
tracing-subscriber = { version = "0.3", features = [ "env-filter" ] }
10 changes: 8 additions & 2 deletions dctap/src/dctap.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{tap_config::TapConfig, tap_error::TapError};
use serde_derive::{Deserialize, Serialize};
use std::path::PathBuf;
use std::path::Path;
use tracing::debug;

#[derive(Debug, Serialize, Deserialize)]
Expand All @@ -11,14 +11,20 @@ pub struct DCTap {
version: String,
}

impl Default for DCTap {
fn default() -> Self {
Self::new()
}
}

impl DCTap {
pub fn new() -> DCTap {
DCTap {
version: "0.1".to_string(),
}
}

pub fn read_buf(path_buf: &PathBuf, config: TapConfig) -> Result<DCTap, TapError> {
pub fn read_buf(_path: &Path, _config: TapConfig) -> Result<DCTap, TapError> {
let dctap = DCTap::new();
debug!("DCTap parsed: {:?}", dctap);
Ok(dctap)
Expand Down
2 changes: 0 additions & 2 deletions dctap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ pub mod tap_statement;

pub use crate::tap_config::*;
pub use crate::tap_error::*;
pub use crate::tap_error::*;
pub use crate::tap_shape::*;
pub use crate::tap_statement::*;
pub use dctap::*;
pub use dctap::*;
8 changes: 1 addition & 7 deletions dctap/src/tap_config.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
use serde_derive::{Deserialize, Serialize};

#[derive(Deserialize, Serialize, Debug, PartialEq, Clone)]
#[derive(Deserialize, Serialize, Debug, PartialEq, Clone, Default)]
pub struct TapConfig {}

impl Default for TapConfig {
fn default() -> Self {
Self {}
}
}
1 change: 0 additions & 1 deletion rbe_testsuite/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@ tracing = "0.1"

[dev-dependencies]
indoc = "2"

6 changes: 3 additions & 3 deletions shex_ast/src/ast/iri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ impl Display for Iri {
}

// This is required by serde serialization
impl Into<String> for Iri {
fn into(self) -> String {
match self {
impl From<Iri> for String {
fn from(val: Iri) -> Self {
match val {
Iri::String(s) => s,
Iri::IriS(iri_s) => iri_s.as_str().to_string(),
}
Expand Down
2 changes: 1 addition & 1 deletion shex_ast/src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ mod tests {

let shape_expr = serde_json::from_str::<ShapeExpr>(str);
if let Ok(v) = &shape_expr {
let serialized = serde_json::to_string(v).unwrap();
let _serialized = serde_json::to_string(v).unwrap();
}
assert!(shape_expr.is_ok())
}
Expand Down
2 changes: 1 addition & 1 deletion shex_ast/src/ast/shape_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl ShapeExpr {
ShapeExpr::External
}

pub fn not(se: ShapeExpr) -> ShapeExpr {
pub fn shape_not(se: ShapeExpr) -> ShapeExpr {
ShapeExpr::ShapeNot {
shape_expr: Box::new(ShapeExprWrapper { se }),
}
Expand Down
6 changes: 3 additions & 3 deletions shex_ast/src/ast/shape_expr_label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ impl Display for ShapeExprLabel {
}
}

impl Into<String> for ShapeExprLabel {
fn into(self) -> String {
self.to_string()
impl From<ShapeExprLabel> for String {
fn from(val: ShapeExprLabel) -> Self {
val.to_string()
}
}

Expand Down
6 changes: 3 additions & 3 deletions shex_ast/src/ast/triple_expr_label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ impl Display for TripleExprLabel {
}
}

impl Into<String> for TripleExprLabel {
fn into(self) -> String {
self.to_string()
impl From<TripleExprLabel> for String {
fn from(val: TripleExprLabel) -> Self {
val.to_string()
}
}
4 changes: 1 addition & 3 deletions shex_compact/benches/regex.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use nom_locate::LocatedSpan;
use pprof::criterion::{Output, PProfProfiler};
use shex_compact::ShExParser;
use shex_compact::{hex, hex_refactor};

fn regex_compare(c: &mut Criterion) {
let mut group = c.benchmark_group("Regex compare");
for i in 1..1 {
for i in 1..2 {
let txt = LocatedSpan::new("A");
group.bench_with_input(BenchmarkId::new("No_regex", i), &txt, |b, txt| {
b.iter(|| hex(*txt))
Expand Down
2 changes: 1 addition & 1 deletion shex_compact/benches/shex_parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn shex_parse_benchmark(c: &mut Criterion) {
// test once to make sure it parses correctly the first time
parse();
// real benchmark
c.bench_function("shex_parse", |b| b.iter(|| parse()));
c.bench_function("shex_parse", |b| b.iter(parse));
}

criterion_group! {
Expand Down
97 changes: 1 addition & 96 deletions shex_compact/src/compact_printer.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
use colored::*;
use iri_s::IriS;
use prefixmap::{IriRef, PrefixMap};
use pretty::{Arena, DocAllocator, DocBuilder, RefDoc};
use rust_decimal::Decimal;
use pretty::{Arena, DocAllocator, DocBuilder};
use shex_ast::{object_value::ObjectValue, BNode, ShapeExprLabel};
use srdf::literal::Literal;
use std::borrow::Cow;

pub(crate) fn space<'a, A>(doc: &'a Arena<'a, A>) -> DocBuilder<'a, Arena<'a, A>, A> {
doc.space()
}

pub(crate) fn pp_object_value<'a, A>(
v: &ObjectValue,
doc: &'a Arena<'a, A>,
Expand Down Expand Up @@ -47,22 +42,6 @@ pub(crate) fn pp_bnode<'a, A>(
doc.text(format!("{value}"))
}

fn pp_isize<'a, A>(value: &isize, doc: &'a Arena<'a, A>) -> DocBuilder<'a, Arena<'a, A>, A> {
doc.text(value.to_string())
}

fn pp_decimal<'a, A>(value: &Decimal, doc: &'a Arena<'a, A>) -> DocBuilder<'a, Arena<'a, A>, A> {
doc.text(value.to_string())
}

fn pp_double<'a, A>(value: &f64, doc: &'a Arena<'a, A>) -> DocBuilder<'a, Arena<'a, A>, A> {
doc.text(value.to_string())
}

fn pp_usize<'a, A>(value: &usize, doc: &'a Arena<'a, A>) -> DocBuilder<'a, Arena<'a, A>, A> {
doc.text(value.to_string())
}

fn pp_iri_ref<'a, A>(
value: &IriRef,
doc: &'a Arena<'a, A>,
Expand Down Expand Up @@ -98,84 +77,10 @@ where
}
}

fn pp_iri_unqualified<'a, A>(iri: &IriS, doc: &'a Arena<'a, A>) -> DocBuilder<'a, Arena<'a, A>, A> {
let str = format!("<{iri}>");
doc.text(str)
}

fn pp_iri<'a, A>(
iri: &IriS,
doc: &'a Arena<'a, A>,
prefixmap: &PrefixMap,
) -> DocBuilder<'a, Arena<'a, A>, A> {
doc.text(prefixmap.qualify(iri))
}

fn is_empty<'a, A>(d: &DocBuilder<'a, Arena<'a, A>, A>) -> bool {
use pretty::Doc::*;
match &**d {
Nil => true,
FlatAlt(t1, t2) => is_empty_ref(t1) && is_empty_ref(t2),
Group(t) => is_empty_ref(t),
Nest(_, t) => is_empty_ref(t),
Union(t1, t2) => is_empty_ref(t1) && is_empty_ref(t2),
Annotated(_, t) => is_empty_ref(t),
_ => false,
}
}

fn is_empty_ref<A>(rd: &RefDoc<'_, A>) -> bool {
use pretty::Doc::*;

match &**rd {
Nil => true,
FlatAlt(t1, t2) => is_empty_ref(t1) && is_empty_ref(t2),
Group(t) => is_empty_ref(t),
Nest(_, t) => is_empty_ref(t),
Union(t1, t2) => is_empty_ref(t1) && is_empty_ref(t2),
Annotated(_, t) => is_empty_ref(t),
_ => false,
}
}

pub(crate) fn enclose<'a, A>(
left: &'a str,
doc: DocBuilder<'a, Arena<'a, A>, A>,
right: &'a str,
arena: &'a Arena<'a, A>,
indent: isize,
) -> DocBuilder<'a, Arena<'a, A>, A> {
if is_empty(&doc) {
arena.text(left).append(right)
} else {
arena
.text(left)
.append(arena.line_())
.append(doc)
.nest(indent)
.append(arena.line_())
.append(right)
.group()
}
}

pub(crate) fn enclose_space<'a, A>(
left: &'a str,
middle: DocBuilder<'a, Arena<'a, A>, A>,
right: &'a str,
arena: &'a Arena<'a, A>,
indent: isize,
) -> DocBuilder<'a, Arena<'a, A>, A> {
if is_empty(&middle) {
arena.text(left).append(right)
} else {
arena
.text(left)
.append(arena.line())
.append(middle)
.nest(indent)
.append(arena.line())
.append(right)
.group()
}
}
Loading

0 comments on commit 0822918

Please sign in to comment.