Skip to content

Commit

Permalink
Polish.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Jan 5, 2024
1 parent 663bc02 commit f546983
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 42 deletions.
2 changes: 1 addition & 1 deletion crates/macros/src/common/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl<'l> Field<'l> {
} else {
self.env_prefix
.as_ref()
.map(|env_prefix| format!("{}{}", env_prefix, self.get_name(None)).to_uppercase())
.map(|env_prefix| format!("{env_prefix}{}", self.get_name(None)).to_uppercase())
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/macros/src/config/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl<'l> Field<'l> {
let mut stmts = vec![];

if let Some(expr) = self.args.validate.as_ref() {
let name_quoted = format!("{}", name);
let name_quoted = format!("{name}");

let func = match expr {
// func(arg)()
Expand Down
2 changes: 1 addition & 1 deletion crates/macros/src/config/field_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl<'l> FieldValue<'l> {
}

pub fn get_validate_statement(&self, name: &Ident) -> Option<TokenStream> {
let name_quoted = format!("{}", name);
let name_quoted = format!("{name}");

match self {
Self::NestedList { .. } => Some(quote! {
Expand Down
2 changes: 1 addition & 1 deletion crates/schematic/src/config/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ impl ValidatorError {

for error_type in &self.errors {
for error in error_type.to_error_list() {
message.push_str(format!("\n {}", error).as_str());
message.push_str(format!("\n {error}").as_str());
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/schematic/src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub fn partialize_schema(schema: &mut SchemaType, force_partial: bool) {
SchemaType::Struct(inner) => {
if inner.partial || force_partial {
if let Some(name) = &inner.name {
inner.name = Some(format!("Partial{}", name));
inner.name = Some(format!("Partial{name}"));
}

for field in inner.fields.iter_mut() {
Expand Down Expand Up @@ -109,7 +109,7 @@ pub fn partialize_schema(schema: &mut SchemaType, force_partial: bool) {

if inner.partial || force_partial {
if let Some(name) = &inner.name {
inner.name = Some(format!("Partial{}", name));
inner.name = Some(format!("Partial{name}"));
}
}

Expand Down
11 changes: 3 additions & 8 deletions crates/schematic/src/schema/renderers/jsonc_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,7 @@ impl SchemaRenderer<String> for JsoncTemplateRenderer {

self.ctx.depth -= 1;

Ok(format!(
"[\n{}{}\n{}]",
item_indent,
item,
self.ctx.indent()
))
Ok(format!("[\n{}{item}\n{}]", item_indent, self.ctx.indent()))
}

fn render_boolean(&mut self, boolean: &BooleanType) -> RenderResult<String> {
Expand Down Expand Up @@ -168,8 +163,8 @@ impl SchemaRenderer<String> for JsoncTemplateRenderer {
// Inject the header and footer
if self.ctx.options.comments {
template = format!(
"{}{}{}",
self.ctx.options.header, template, self.ctx.options.footer
"{}{template}{}",
self.ctx.options.header, self.ctx.options.footer
);
}

Expand Down
11 changes: 5 additions & 6 deletions crates/schematic/src/schema/renderers/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub fn lit_to_string(lit: &LiteralValue) -> String {
LiteralValue::F64(inner) => inner.to_string(),
LiteralValue::Int(inner) => inner.to_string(),
LiteralValue::UInt(inner) => inner.to_string(),
LiteralValue::String(inner) => format!("\"{}\"", inner),
LiteralValue::String(inner) => format!("\"{inner}\""),
}
}

Expand Down Expand Up @@ -150,7 +150,7 @@ impl TemplateContext {
let prefix = self.get_comment_prefix();

let mut push = |line: String| {
lines.push(format!("{indent}{prefix}{}", line));
lines.push(format!("{indent}{prefix}{line}"));
};

if let Some(comment) = &field.description {
Expand All @@ -164,12 +164,12 @@ impl TemplateContext {
push(if deprecated.is_empty() {
"@deprecated".into()
} else {
format!("@deprecated {}", deprecated)
format!("@deprecated {deprecated}")
});
}

if let Some(env_var) = &field.env_var {
push(format!("@envvar {}", env_var));
push(format!("@envvar {env_var}"));
}

if lines.is_empty() {
Expand All @@ -185,15 +185,14 @@ impl TemplateContext {
let key = self.get_stack_key();

format!(
"{}{}{}{}",
"{}{}{}{property}",
self.create_comment(field),
self.indent(),
if self.options.comment_fields.contains(&key) {
self.get_comment_prefix()
} else {
""
},
property
)
}

Expand Down
12 changes: 5 additions & 7 deletions crates/schematic/src/schema/renderers/toml_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ impl SchemaRenderer<String> for TomlTemplateRenderer {

self.ctx.options.comments = comments;

Ok(format!("{{ {} = {} }}", key, value))
Ok(format!("{{ {key} = {value} }}"))
}

fn render_reference(&mut self, reference: &str) -> RenderResult<String> {
Expand Down Expand Up @@ -204,18 +204,16 @@ impl SchemaRenderer<String> for TomlTemplateRenderer {

for (key, value) in mem::take(&mut self.arrays) {
sections.push(format!(
"{}[[{}]]\n{}",
"{}[[{key}]]\n{}",
value.comment,
key,
self.render_struct(&value.table)?
));
}

for (key, value) in mem::take(&mut self.tables) {
sections.push(format!(
"{}[{}]\n{}",
"{}[{key}]\n{}",
value.comment,
key,
self.render_struct(&value.table)?
));
}
Expand All @@ -224,8 +222,8 @@ impl SchemaRenderer<String> for TomlTemplateRenderer {

// Inject the header and footer
template = format!(
"{}{}{}",
self.ctx.options.header, template, self.ctx.options.footer
"{}{template}{}",
self.ctx.options.header, self.ctx.options.footer
);

// And always add a trailing newline
Expand Down
23 changes: 11 additions & 12 deletions crates/schematic/src/schema/renderers/typescript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl TypeScriptRenderer {
}

fn export_type_alias(&mut self, name: &str, value: String) -> RenderResult {
Ok(format!("export type {} = {};", name, value))
Ok(format!("export type {name} = {value};"))
}

fn export_enum_type(&mut self, name: &str, enu: &EnumType) -> RenderResult {
Expand All @@ -112,12 +112,12 @@ impl TypeScriptRenderer {
let output = if self.is_string_union_enum(enu) {
self.export_type_alias(name, value)?
} else {
let out = format!("enum {} {}", name, value);
let out = format!("enum {name} {value}");

if self.options.const_enum {
format!("export const {}", out)
format!("export const {out}")
} else {
format!("export {}", out)
format!("export {out}")
}
};

Expand All @@ -128,7 +128,7 @@ impl TypeScriptRenderer {
let value = self.render_struct(structure)?;

let output = if matches!(self.options.object_format, ObjectFormat::Interface) {
format!("export interface {} {}", name, value)
format!("export interface {name} {value}")
} else {
self.export_type_alias(name, value)?
};
Expand Down Expand Up @@ -263,9 +263,9 @@ impl SchemaRenderer<String> for TypeScriptRenderer {
let out = self.render_schema(&array.items_type)?;

Ok(if out.contains('|') {
format!("({})[]", out)
format!("({out})[]")
} else {
format!("{}[]", out)
format!("{out}[]")
})
}

Expand Down Expand Up @@ -329,7 +329,7 @@ impl SchemaRenderer<String> for TypeScriptRenderer {
if let Some(values) = &string.enum_values {
return Ok(values
.iter()
.map(|v| format!("'{}'", v))
.map(|v| format!("'{v}'"))
.collect::<Vec<_>>()
.join(" | "));
}
Expand Down Expand Up @@ -374,12 +374,12 @@ impl SchemaRenderer<String> for TypeScriptRenderer {
tags.push(if deprecated.is_empty() {
"@deprecated".to_owned()
} else {
format!("@deprecated {}", deprecated)
format!("@deprecated {deprecated}")
});
}

if let Some(env_var) = &field.env_var {
tags.push(format!("@envvar {}", env_var));
tags.push(format!("@envvar {env_var}"));
}

out.push(self.wrap_in_comment(field.description.as_ref(), tags, row));
Expand Down Expand Up @@ -433,9 +433,8 @@ impl SchemaRenderer<String> for TypeScriptRenderer {
imported_types.sort();

imports.push(format!(
"import type {{ {} }} from '{}';",
"import type {{ {} }} from '{import}';",
imported_types.join(", "),
import
));
}

Expand Down
4 changes: 2 additions & 2 deletions crates/schematic/src/schema/renderers/yaml_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ impl SchemaRenderer<String> for YamlTemplateRenderer {

// Inject the header and footer
template = format!(
"{}{}{}",
self.ctx.options.header, template, self.ctx.options.footer
"{}{template}{}",
self.ctx.options.header, self.ctx.options.footer
);

// And always add a trailing newline
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export interface EnvVarsPrefixed {
list1: string[];
/** @envvar ENV_LIST2 */
list2: number[];
/** @envvar ENV_NESTED */
nested: EnvVarsNested;
/** @envvar ENV_NUMBER */
number: number;
Expand Down

0 comments on commit f546983

Please sign in to comment.