Skip to content

Commit

Permalink
fix: Fixed clippy warnings.
Browse files Browse the repository at this point in the history
ci: Added lint check in CI.
  • Loading branch information
Shrey Bana committed Jan 23, 2025
1 parent 48213f1 commit 4d08fdf
Show file tree
Hide file tree
Showing 69 changed files with 440 additions and 360 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/ci_check_pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,12 @@ jobs:
targets: wasm32-unknown-unknown
components: rustfmt, clippy

- name: Check formatting
- name: Install leptosfmt
run: cargo install leptosfmt

- name: Check formatting & linting
shell: bash
run: cargo fmt --all --check
run: make check

- name: install cocogitto
uses: baptiste0928/[email protected]
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,4 @@ uuid = { version = "1.3.4", features = ["v4", "serde"] }

[workspace.lints.clippy]
mod_module_files = "warn"
manual_range_contains = "allow"
4 changes: 2 additions & 2 deletions crates/cac_client/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,11 +339,11 @@ pub extern "C" fn cac_get_default_config(
unwrap_safe!(
serde_json::to_string::<Map<String, Value>>(&ov)
.map(|overrides| rstring_to_cstring(overrides).into_raw()),
return std::ptr::null()
std::ptr::null()
)
})
},
return std::ptr::null()
std::ptr::null()
)
})
}
2 changes: 1 addition & 1 deletion crates/cac_client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ impl Client {
}

pub async fn get_last_modified(&self) -> DateTime<Utc> {
self.last_modified.read().await.clone()
*self.last_modified.read().await
}

pub async fn get_resolved_config(
Expand Down
14 changes: 7 additions & 7 deletions crates/context_aware_config/src/api/config/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,13 @@ use crate::{
use super::helpers::apply_prefix_filter_to_config;

pub fn endpoints() -> Scope {
let scope = Scope::new("")
#[cfg(feature = "high-performance-mode")]
let scope = scope.service(get_config_fast);
Scope::new("")
.service(get_config)
.service(get_resolved_config)
.service(reduce_config)
.service(get_config_versions);
#[cfg(feature = "high-performance-mode")]
let scope = scope.service(get_config_fast);
scope
.service(get_config_versions)
}

fn validate_version_in_params(
Expand Down Expand Up @@ -158,7 +157,7 @@ pub fn generate_config_from_version(
schema_name: &SchemaName,
) -> superposition::Result<Config> {
if let Some(val) = version {
let val = val.clone();
let val = *val;
let config = config_versions::config_versions
.select(config_versions::config)
.filter(config_versions::id.eq(val))
Expand Down Expand Up @@ -315,6 +314,7 @@ fn reduce(
Ok(dimensions)
}

#[allow(clippy::type_complexity)]
fn get_contextids_from_overrideid(
contexts: Vec<Context>,
overrides: Map<String, Value>,
Expand Down Expand Up @@ -499,7 +499,7 @@ async fn reduce_config_key(
put_req,
conn,
false,
&user,
user,
schema_name,
false,
);
Expand Down
3 changes: 2 additions & 1 deletion crates/context_aware_config/src/api/context/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ async fn update_override_handler(
Ok(http_resp.json(override_resp))
}

#[allow(clippy::too_many_arguments)]
#[put("/move/{ctx_id}")]
async fn move_handler(
state: Data<AppState>,
Expand Down Expand Up @@ -607,7 +608,7 @@ async fn weight_recompute(
diesel::update(contexts.filter(id.eq(context_id)))
.set((
weight.eq(context_weight),
last_modified_at.eq(last_modified_time.clone()),
last_modified_at.eq(last_modified_time),
last_modified_by.eq(user.get_email())
))
.schema_name(&schema_name)
Expand Down
2 changes: 1 addition & 1 deletion crates/context_aware_config/src/api/context/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ mod tests {
.expect("Invalid context override");

let expected_action = ContextAction::Put(PutReq {
context: context,
context,
r#override: override_,
description: Some("".to_string()),
change_reason: "".to_string(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ async fn update_default_config(
return Err(validation_error!(
"Schema validation failed: {}",
validation_err_to_str(verrors)
.get(0)
.first()
.unwrap_or(&String::new())
));
}
Expand Down
7 changes: 4 additions & 3 deletions crates/context_aware_config/src/api/default_config/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ impl<'de> Deserialize<'de> for FunctionNameEnum {
Value::Null => Ok(Self::Remove),
_ => {
log::error!("Expected a string or null literal as the function name.");
Err("Expected a string or null literal as the function name.")
.map_err(serde::de::Error::custom)
Err(serde::de::Error::custom(
"Expected a string or null literal as the function name.",
))
}
}
}
Expand All @@ -62,7 +63,7 @@ impl DefaultConfigKey {
impl TryFrom<String> for DefaultConfigKey {
type Error = String;
fn try_from(value: String) -> Result<Self, Self::Error> {
Ok(Self::validate_data(value)?)
Self::validate_data(value)
}
}

Expand Down
7 changes: 3 additions & 4 deletions crates/context_aware_config/src/api/dimension/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ async fn create(
log::error!("{fun_name:?} function not found with error: {e:?}");
Err(bad_argument!(
"Function {} doesn't exists",
fun_name.unwrap_or(String::new())
fun_name.unwrap_or_default()
))
}
Err(e) => {
Expand Down Expand Up @@ -165,9 +165,8 @@ async fn update(
}

dimension_row.change_reason = update_req.change_reason;
dimension_row.description = update_req
.description
.unwrap_or_else(|| dimension_row.description);
dimension_row.description =
update_req.description.unwrap_or(dimension_row.description);

dimension_row.function_name = match update_req.function_name {
Some(FunctionNameEnum::Name(func_name)) => Some(func_name),
Expand Down
18 changes: 7 additions & 11 deletions crates/context_aware_config/src/api/dimension/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ pub struct CreateReq {

#[derive(Debug, Deserialize, AsRef, Deref, DerefMut, Into, Clone)]
#[serde(try_from = "i32")]
#[derive(Default)]
pub struct Position(i32);
impl Position {
fn validate_data(position_val: i32) -> Result<Self, String> {
if position_val < 0 {
return Err("Position should be greater than equal to 0".to_string());
Err("Position should be greater than equal to 0".to_string())
} else {
Ok(Self(position_val))
}
Expand All @@ -29,13 +30,7 @@ impl Position {
impl TryFrom<i32> for Position {
type Error = String;
fn try_from(value: i32) -> Result<Self, Self::Error> {
Ok(Self::validate_data(value)?)
}
}

impl Default for Position {
fn default() -> Self {
Position(0)
Self::validate_data(value)
}
}

Expand Down Expand Up @@ -65,8 +60,9 @@ impl<'de> Deserialize<'de> for FunctionNameEnum {
Value::Null => Ok(Self::Remove),
_ => {
log::error!("Expected a string or null literal as the function name.");
Err("Expected a string or null literal as the function name.")
.map_err(serde::de::Error::custom)
Err(serde::de::Error::custom(
"Expected a string or null literal as the function name.",
))
}
}
}
Expand All @@ -87,7 +83,7 @@ impl DimensionName {
impl TryFrom<String> for DimensionName {
type Error = String;
fn try_from(value: String) -> Result<Self, Self::Error> {
Ok(Self::validate_data(value)?)
Self::validate_data(value)
}
}

Expand Down
10 changes: 5 additions & 5 deletions crates/context_aware_config/src/api/dimension/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ pub fn get_dimension_data(
}

pub fn get_dimension_data_map(
dimensions_vec: &Vec<Dimension>,
dimensions_vec: &[Dimension],
) -> superposition::Result<HashMap<String, DimensionData>> {
let dimension_schema_map = dimensions_vec
.into_iter()
.iter()
.filter_map(|item| {
let compiled_schema = JSONSchema::options()
.with_draft(Draft::Draft7)
Expand Down Expand Up @@ -70,9 +70,9 @@ pub fn get_dimension_usage_context_ids(
})?
.into_inner();

extract_dimensions(&condition)?
.get(key)
.map(|_| context_ids.push(context.id.to_owned()));
if extract_dimensions(&condition)?.get(key).is_some() {
context_ids.push(context.id.to_owned())
}
}
Ok(context_ids)
}
Expand Down
2 changes: 1 addition & 1 deletion crates/context_aware_config/src/api/functions/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl FunctionName {
impl TryFrom<String> for FunctionName {
type Error = String;
fn try_from(value: String) -> Result<Self, Self::Error> {
Ok(Self::validate_data(value)?)
Self::validate_data(value)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ async fn update_type(

let description = request.description;
let type_name: String = path.into_inner().into();
let final_description = if description.is_none() {
let final_description = if let Some(description) = description {
description
} else {
let existing_template = type_templates::table
.filter(type_templates::type_name.eq(&type_name))
.schema_name(&schema_name)
Expand All @@ -110,8 +112,6 @@ async fn update_type(
));
}
}
} else {
description.unwrap().to_string()
};
let change_reason = request.change_reason;
let timestamp = Utc::now().naive_utc();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ impl TypeTemplateName {
impl TryFrom<String> for TypeTemplateName {
type Error = String;
fn try_from(value: String) -> Result<Self, Self::Error> {
Ok(Self::validate_data(value)?)
Self::validate_data(value)
}
}
2 changes: 1 addition & 1 deletion crates/context_aware_config/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ pub fn calculate_context_weight(
log::error!("{}", msg);
msg
})?;
weight = weight + calculate_weight_from_index(position as u32)?;
weight += calculate_weight_from_index(position as u32)?;
}
Ok(weight)
}
Expand Down
16 changes: 8 additions & 8 deletions crates/experimentation_platform/src/api/experiments/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ async fn process_cac_http_response(
}
}

#[allow(clippy::too_many_arguments)]
#[post("")]
async fn create(
state: Data<AppState>,
Expand Down Expand Up @@ -176,12 +177,7 @@ async fn create(
}

// validating context
let exp_context = Exp::<Condition>::try_from(req.context.clone())
.map_err(|err| {
log::error!("failed to decode condition with error {}", err);
bad_argument!(err)
})?
.into_inner();
let exp_context = req.context.clone().into_inner();

// validating experiment against other active experiments based on permission flags
let flags = &state.experimentation_flags;
Expand Down Expand Up @@ -330,6 +326,7 @@ async fn create(
Ok(http_resp.json(response))
}

#[allow(clippy::too_many_arguments)]
#[patch("/{experiment_id}/conclude")]
async fn conclude_handler(
state: Data<AppState>,
Expand Down Expand Up @@ -376,6 +373,7 @@ async fn conclude_handler(
Ok(http_resp.json(experiment_response))
}

#[allow(clippy::too_many_arguments)]
pub async fn conclude(
state: &Data<AppState>,
experiment_id: i64,
Expand Down Expand Up @@ -695,12 +693,13 @@ pub fn get_experiment(
use superposition_types::database::schema::experiments::dsl::*;
let result: Experiment = experiments
.find(experiment_id)
.schema_name(&schema_name)
.schema_name(schema_name)
.get_result::<Experiment>(conn)?;

Ok(result)
}

#[allow(clippy::too_many_arguments)]
#[patch("/{id}/ramp")]
async fn ramp(
data: Data<AppState>,
Expand Down Expand Up @@ -780,6 +779,7 @@ async fn ramp(
Ok(Json(experiment_response))
}

#[allow(clippy::too_many_arguments)]
#[put("/{id}/overrides")]
async fn update_overrides(
params: web::Path<i64>,
Expand Down Expand Up @@ -1079,7 +1079,7 @@ async fn get_audit_logs(

Ok(Json(PaginatedResponse {
total_items: log_count,
total_pages: total_pages,
total_pages,
data: logs,
}))
}
4 changes: 1 addition & 3 deletions crates/experimentation_platform/src/api/experiments/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,7 @@ impl TryFrom<HashMap<String, String>> for ApplicableVariantsQuery {
fn try_from(value: HashMap<String, String>) -> Result<Self, Self::Error> {
let mut value = value
.into_iter()
.map(|(key, value)| {
(key, value.parse().unwrap_or_else(|_| Value::String(value)))
})
.map(|(key, value)| (key, value.parse().unwrap_or(Value::String(value))))
.collect::<Map<_, _>>();

let toss = value
Expand Down
Loading

0 comments on commit 4d08fdf

Please sign in to comment.