Skip to content

Commit

Permalink
Cargo clippy/fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
dangeross committed Apr 19, 2024
1 parent 8438648 commit 6781af6
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 102 deletions.
102 changes: 50 additions & 52 deletions lib/ls-sdk-bindings/bindings-react-native/src/gen_kotlin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,26 +89,26 @@ pub mod filters {
ci: &ComponentInterface,
) -> Result<String, askama::Error> {
let res: Result<String, askama::Error> = match type_name {
"Boolean" => Ok(format!("array.pushBoolean(value)").into()),
"Double" => Ok(format!("array.pushDouble(value)").into()),
"Int" => Ok(format!("array.pushInt(value)").into()),
"ReadableArray" => Ok(format!("array.pushArray(value)").into()),
"ReadableMap" => Ok(format!("array.pushMap(value)").into()),
"String" => Ok(format!("array.pushString(value)").into()),
"UByte" => Ok(format!("array.pushInt(value.toInt())").into()),
"UInt" => Ok(format!("array.pushInt(value.toInt())").into()),
"UShort" => Ok(format!("array.pushInt(value.toInt())").into()),
"ULong" => Ok(format!("array.pushDouble(value.toDouble())").into()),
"Boolean" => Ok("array.pushBoolean(value)".to_string()),
"Double" => Ok("array.pushDouble(value)".to_string()),
"Int" => Ok("array.pushInt(value)".to_string()),
"ReadableArray" => Ok("array.pushArray(value)".to_string()),
"ReadableMap" => Ok("array.pushMap(value)".to_string()),
"String" => Ok("array.pushString(value)".to_string()),
"UByte" => Ok("array.pushInt(value.toInt())".to_string()),
"UInt" => Ok("array.pushInt(value.toInt())".to_string()),
"UShort" => Ok("array.pushInt(value.toInt())".to_string()),
"ULong" => Ok("array.pushDouble(value.toDouble())".to_string()),
_ => match ci.get_type(type_name) {
Some(t) => match t {
Type::Enum(inner) => {
let enum_def = ci.get_enum_definition(&inner).unwrap();
match enum_def.is_flat() {
true => Ok(format!("array.pushString(value.name.lowercase())").into()),
false => Ok(format!("array.pushMap(readableMapOf(value))").into()),
true => Ok("array.pushString(value.name.lowercase())".to_string()),
false => Ok("array.pushMap(readableMapOf(value))".to_string()),
}
}
_ => Ok(format!("array.pushMap(readableMapOf(value))").into()),
_ => Ok("array.pushMap(readableMapOf(value))".to_string()),
},
None => unimplemented!("known type: {type_name}"),
},
Expand All @@ -124,40 +124,41 @@ pub mod filters {
optional: bool,
) -> Result<String, askama::Error> {
let res: Result<String, askama::Error> = match t {
Type::UInt8 => Ok(format!("{obj_name}.{field_name}").into()),
Type::Int8 => Ok(format!("{obj_name}.{field_name}").into()),
Type::UInt16 => Ok(format!("{obj_name}.{field_name}").into()),
Type::Int16 => Ok(format!("{obj_name}.{field_name}").into()),
Type::UInt32 => Ok(format!("{obj_name}.{field_name}").into()),
Type::Int32 => Ok(format!("{obj_name}.{field_name}").into()),
Type::UInt64 => Ok(format!("{obj_name}.{field_name}").into()),
Type::Int64 => Ok(format!("{obj_name}.{field_name}").into()),
Type::Float32 => Ok(format!("{obj_name}.{field_name}").into()),
Type::Float64 => Ok(format!("{obj_name}.{field_name}").into()),
Type::Boolean => Ok(format!("{obj_name}.{field_name}").into()),
Type::String => Ok(format!("{obj_name}.{field_name}").into()),
Type::UInt8 => Ok(format!("{obj_name}.{field_name}")),
Type::Int8 => Ok(format!("{obj_name}.{field_name}")),
Type::UInt16 => Ok(format!("{obj_name}.{field_name}")),
Type::Int16 => Ok(format!("{obj_name}.{field_name}")),
Type::UInt32 => Ok(format!("{obj_name}.{field_name}")),
Type::Int32 => Ok(format!("{obj_name}.{field_name}")),
Type::UInt64 => Ok(format!("{obj_name}.{field_name}")),
Type::Int64 => Ok(format!("{obj_name}.{field_name}")),
Type::Float32 => Ok(format!("{obj_name}.{field_name}")),
Type::Float64 => Ok(format!("{obj_name}.{field_name}")),
Type::Boolean => Ok(format!("{obj_name}.{field_name}")),
Type::String => Ok(format!("{obj_name}.{field_name}")),
Type::Timestamp => unimplemented!("render_to_map: Timestamp is not implemented"),
Type::Duration => unimplemented!("render_to_map: Duration is not implemented"),
Type::Object(_) => unimplemented!("render_to_map: Object is not implemented"),
Type::Record(_) => match optional {
true => Ok(format!("{obj_name}.{field_name}?.let {{ readableMapOf(it) }}").into()),
false => Ok(format!("readableMapOf({obj_name}.{field_name})").into()),
true => Ok(format!(
"{obj_name}.{field_name}?.let {{ readableMapOf(it) }}"
)),
false => Ok(format!("readableMapOf({obj_name}.{field_name})")),
},
Type::Enum(inner) => {
let enum_def = ci.get_enum_definition(inner).unwrap();
match enum_def.is_flat() {
true => match optional {
true => Ok(format!(
"{obj_name}.{field_name}?.let {{ it.name.lowercase() }}"
)
.into()),
false => Ok(format!("{obj_name}.{field_name}.name.lowercase()").into()),
)),
false => Ok(format!("{obj_name}.{field_name}.name.lowercase()")),
},
false => match optional {
true => Ok(
format!("{obj_name}.{field_name}?.let {{ readableMapOf(it) }}").into(),
),
false => Ok(format!("readableMapOf({obj_name}.{field_name})").into()),
true => Ok(format!(
"{obj_name}.{field_name}?.let {{ readableMapOf(it) }}"
)),
false => Ok(format!("readableMapOf({obj_name}.{field_name})")),
},
}
}
Expand Down Expand Up @@ -201,18 +202,18 @@ pub mod filters {
mandatory_suffix = "!!"
}
let res: String = match t {
Type::UInt8 => format!("{name}.getInt(\"{field_name}\").toUByte()").into(),
Type::Int8 => format!("{name}.getInt(\"{field_name}\").toByte()").into(),
Type::UInt16 => format!("{name}.getInt(\"{field_name}\").toUShort()").into(),
Type::Int16 => format!("{name}.getInt(\"{field_name}\").toShort()").into(),
Type::UInt32 => format!("{name}.getInt(\"{field_name}\").toUInt()").into(),
Type::Int32 => format!("{name}.getInt(\"{field_name}\")").into(),
Type::UInt64 => format!("{name}.getDouble(\"{field_name}\").toULong()").into(),
Type::Int64 => format!("{name}.getDouble(\"{field_name}\").toLong()").into(),
Type::Float32 => format!("{name}.getDouble(\"{field_name}\")").into(),
Type::Float64 => format!("{name}.getDouble(\"{field_name}\")").into(),
Type::Boolean => format!("{name}.getBoolean(\"{field_name}\")").into(),
Type::String => format!("{name}.getString(\"{field_name}\"){mandatory_suffix}").into(),
Type::UInt8 => format!("{name}.getInt(\"{field_name}\").toUByte()"),
Type::Int8 => format!("{name}.getInt(\"{field_name}\").toByte()"),
Type::UInt16 => format!("{name}.getInt(\"{field_name}\").toUShort()"),
Type::Int16 => format!("{name}.getInt(\"{field_name}\").toShort()"),
Type::UInt32 => format!("{name}.getInt(\"{field_name}\").toUInt()"),
Type::Int32 => format!("{name}.getInt(\"{field_name}\")"),
Type::UInt64 => format!("{name}.getDouble(\"{field_name}\").toULong()"),
Type::Int64 => format!("{name}.getDouble(\"{field_name}\").toLong()"),
Type::Float32 => format!("{name}.getDouble(\"{field_name}\")"),
Type::Float64 => format!("{name}.getDouble(\"{field_name}\")"),
Type::Boolean => format!("{name}.getBoolean(\"{field_name}\")"),
Type::String => format!("{name}.getString(\"{field_name}\"){mandatory_suffix}"),
Type::Timestamp => "".into(),
Type::Duration => "".into(),
Type::Object(_) => "".into(),
Expand All @@ -221,19 +222,16 @@ pub mod filters {
format!(
"{name}.getMap(\"{field_name}\")?.let {{ as{record_type_name}(it)}}{mandatory_suffix}"
)
.into()
}
Type::Enum(inner) => {
let enum_def = ci.get_enum_definition(inner).unwrap();
match enum_def.is_flat() {
false => {
format!("{name}.getMap(\"{field_name}\")?.let {{ as{inner}(it)}}{mandatory_suffix}")
.into()
}
true => format!(
"{name}.getString(\"{field_name}\")?.let {{ as{inner}(it)}}{mandatory_suffix}"
)
.into(),
),
}
}
Type::Error(_) => "".into(),
Expand Down Expand Up @@ -271,7 +269,7 @@ pub mod filters {

pub fn rn_convert_type(
t: &TypeIdentifier,
ci: &ComponentInterface,
_ci: &ComponentInterface,
) -> Result<String, askama::Error> {
match t {
Type::UInt8 | Type::UInt16 | Type::UInt32 => Ok(".toUInt()".to_string()),
Expand All @@ -280,7 +278,7 @@ pub mod filters {
Type::Float32 | Type::Float64 => Ok(".toFloat()".to_string()),
Type::Optional(inner) => {
let unboxed = inner.as_ref();
let conversion = rn_convert_type(unboxed, ci).unwrap();
let conversion = rn_convert_type(unboxed, _ci).unwrap();
let optional = match *unboxed {
Type::Int8
| Type::UInt8
Expand Down
71 changes: 34 additions & 37 deletions lib/ls-sdk-bindings/bindings-react-native/src/gen_swift/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,36 +91,33 @@ pub mod filters {
optional_suffix = "!";
}
let res: Result<String, askama::Error> = match t {
Type::UInt8 => Ok(format!("{obj_prefix}{field_name}").into()),
Type::Int8 => Ok(format!("{obj_prefix}{field_name}").into()),
Type::UInt16 => Ok(format!("{obj_prefix}{field_name}").into()),
Type::Int16 => Ok(format!("{obj_prefix}{field_name}").into()),
Type::UInt32 => Ok(format!("{obj_prefix}{field_name}").into()),
Type::Int32 => Ok(format!("{obj_prefix}{field_name}").into()),
Type::UInt64 => Ok(format!("{obj_prefix}{field_name}").into()),
Type::Int64 => Ok(format!("{obj_prefix}{field_name}").into()),
Type::Float32 => Ok(format!("{obj_prefix}{field_name}").into()),
Type::Float64 => Ok(format!("{obj_prefix}{field_name}").into()),
Type::Boolean => Ok(format!("{obj_prefix}{field_name}").into()),
Type::String => Ok(format!("{obj_prefix}{field_name}").into()),
Type::UInt8 => Ok(format!("{obj_prefix}{field_name}")),
Type::Int8 => Ok(format!("{obj_prefix}{field_name}")),
Type::UInt16 => Ok(format!("{obj_prefix}{field_name}")),
Type::Int16 => Ok(format!("{obj_prefix}{field_name}")),
Type::UInt32 => Ok(format!("{obj_prefix}{field_name}")),
Type::Int32 => Ok(format!("{obj_prefix}{field_name}")),
Type::UInt64 => Ok(format!("{obj_prefix}{field_name}")),
Type::Int64 => Ok(format!("{obj_prefix}{field_name}")),
Type::Float32 => Ok(format!("{obj_prefix}{field_name}")),
Type::Float64 => Ok(format!("{obj_prefix}{field_name}")),
Type::Boolean => Ok(format!("{obj_prefix}{field_name}")),
Type::String => Ok(format!("{obj_prefix}{field_name}")),
Type::Timestamp => unimplemented!("render_to_map: Timestamp is not implemented"),
Type::Duration => unimplemented!("render_to_map: Duration is not implemented"),
Type::Object(_) => unimplemented!("render_to_map: Object is not implemented"),
Type::Record(_) => Ok(format!(
"dictionaryOf({var_name}: {obj_prefix}{field_name}{optional_suffix})"
)
.into()),
)),
Type::Enum(inner) => {
let enum_def = ci.get_enum_definition(inner).unwrap();
match enum_def.is_flat() {
true => Ok(format!(
"valueOf( {var_name}: {obj_prefix}{field_name}{optional_suffix})"
)
.into()),
)),
false => Ok(format!(
"dictionaryOf({var_name}: {obj_prefix}{field_name}{optional_suffix})"
)
.into()),
)),
}
}
Type::Error(_) => unimplemented!("render_to_map: Error is not implemented"),
Expand Down Expand Up @@ -254,7 +251,7 @@ pub mod filters {
}
t => {
let name = filters::type_name(t)?;
Ok(format!("{name}"))
Ok(name.to_string())
}
}
}
Expand Down Expand Up @@ -311,18 +308,18 @@ pub mod filters {
map_var_name: &str,
) -> Result<String, askama::Error> {
let res: String = match t {
Type::UInt8 => format!("{map_var_name}").into(),
Type::Int8 => format!("{map_var_name}").into(),
Type::UInt16 => format!("{map_var_name}").into(),
Type::Int16 => format!("{map_var_name}").into(),
Type::UInt32 => format!("{map_var_name}").into(),
Type::Int32 => format!("{map_var_name}").into(),
Type::UInt64 => format!("{map_var_name}").into(),
Type::Int64 => format!("{map_var_name}").into(),
Type::Float32 => format!("{map_var_name}").into(),
Type::Float64 => format!("{map_var_name}").into(),
Type::Boolean => format!("{map_var_name}").into(),
Type::String => format!("{map_var_name}").into(),
Type::UInt8 => map_var_name.to_string(),
Type::Int8 => map_var_name.to_string(),
Type::UInt16 => map_var_name.to_string(),
Type::Int16 => map_var_name.to_string(),
Type::UInt32 => map_var_name.to_string(),
Type::Int32 => map_var_name.to_string(),
Type::UInt64 => map_var_name.to_string(),
Type::Int64 => map_var_name.to_string(),
Type::Float32 => map_var_name.to_string(),
Type::Float64 => map_var_name.to_string(),
Type::Boolean => map_var_name.to_string(),
Type::String => map_var_name.to_string(),
Type::Timestamp => "".into(),
Type::Duration => "".into(),
Type::Object(_) => "".into(),
Expand All @@ -334,19 +331,19 @@ pub mod filters {
}
Type::Enum(inner) => {
let enum_def = ci.get_enum_definition(inner).unwrap();
let enum_var_name = var_name(&inner)?;
let enum_var_name = var_name(inner)?;
let enum_unquoted_name = unquote(&enum_var_name)?;
match enum_def.is_flat() {
false => format!("try as{inner}({enum_unquoted_name}: {map_var_name})").into(),
true => format!("try as{inner}({enum_unquoted_name}: {map_var_name})").into(),
false => format!("try as{inner}({enum_unquoted_name}: {map_var_name})"),
true => format!("try as{inner}({enum_unquoted_name}: {map_var_name})"),
}
}
Type::Error(_) => "".into(),
Type::CallbackInterface(_) => "".into(),
Type::Optional(inner) => {
let unboxed = inner.as_ref();
let inner_res = render_from_map(unboxed, ci, map_var_name)?;
inner_res

render_from_map(unboxed, ci, map_var_name)?
}
Type::Sequence(inner) => {
let unboxed = inner.as_ref();
Expand All @@ -355,7 +352,7 @@ pub mod filters {
Type::Enum(_) | Type::Record(_) => {
format!("try as{element_type_name}List(arr: {map_var_name})")
}
_ => format!("{map_var_name}").into(),
_ => map_var_name.to_string(),
}
}
Type::Map(_, _) => "".into(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ pub mod filters {
}
_ => type_name(t),
};
res
res
}

pub fn return_type_name(t: &TypeIdentifier) -> Result<String, askama::Error> {
Expand All @@ -200,7 +200,7 @@ pub mod filters {
}
_ => type_name(t),
};
res
res
}

pub fn default_value(t: &TypeIdentifier) -> Result<String, askama::Error> {
Expand Down
16 changes: 5 additions & 11 deletions lib/ls-sdk-bindings/bindings-react-native/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ impl RNBindingGenerator {
base_output_path: &Utf8Path,
) -> Result<()> {
// Create the path
let output_path =
base_output_path.join(Utf8Path::new("android/src/main/java/com/lssdk"));
let output_path = base_output_path.join(Utf8Path::new("android/src/main/java/com/lssdk"));
// Generate and write the binding to file
let bindings_output = self::gen_kotlin::MapperGenerator::new(config.clone(), ci)
.render()
Expand All @@ -61,8 +60,7 @@ impl RNBindingGenerator {
base_output_path: &Utf8Path,
) -> Result<()> {
// Create the path
let output_path =
base_output_path.join(Utf8Path::new("android/src/main/java/com/lssdk"));
let output_path = base_output_path.join(Utf8Path::new("android/src/main/java/com/lssdk"));
// Generate and write the binding to file
let bindings_output = self::gen_kotlin::ModuleGenerator::new(config.clone(), ci)
.render()
Expand All @@ -80,11 +78,7 @@ impl RNBindingGenerator {
}

fn lint_kotlin_bindings(&self, bindings_file: &Utf8PathBuf) {
if let Err(e) = Command::new("ktlint")
.arg("-F")
.arg(&bindings_file)
.output()
{
if let Err(e) = Command::new("ktlint").arg("-F").arg(bindings_file).output() {
println!(
"Warning: Unable to auto-format {} using ktlint: {:?}",
bindings_file.file_name().unwrap(),
Expand Down Expand Up @@ -201,7 +195,7 @@ impl RNBindingGenerator {
fn lint_typescript_bindings(&self, bindings_file: &Utf8PathBuf) {
if let Err(e) = Command::new("tslint")
.arg("--fix")
.arg(&bindings_file)
.arg(bindings_file)
.output()
{
println!(
Expand All @@ -223,7 +217,7 @@ impl RNConfig {}
impl BindingGeneratorConfig for RNConfig {
fn get_entry_from_bindings_table(_bindings: &toml::value::Value) -> Option<toml::value::Value> {
if let Some(table) = _bindings.as_table() {
table.get("rn").map(|v| v.clone())
table.get("rn").cloned()
} else {
None
}
Expand Down

0 comments on commit 6781af6

Please sign in to comment.