FIX: Make clippy happy
This commit is contained in:
committed by
Nicolás Hatcher Andrés
parent
46ea92966f
commit
0be7d9b85a
@@ -22,7 +22,7 @@ fn main() {
|
||||
let file_name = &args[1];
|
||||
println!("Testing file: {file_name}");
|
||||
if let Err(message) = test_file(file_name) {
|
||||
println!("{}", message);
|
||||
println!("{message}");
|
||||
panic!("Model was evaluated inconsistently with XLSX data.")
|
||||
}
|
||||
|
||||
|
||||
@@ -176,7 +176,7 @@ pub(crate) fn compare_models(m1: &Model, m2: &Model) -> Result<(), String> {
|
||||
diff.reason
|
||||
);
|
||||
}
|
||||
Err(format!("Models are different: {}", message))
|
||||
Err(format!("Models are different: {message}"))
|
||||
}
|
||||
}
|
||||
Err(r) => Err(format!("Models are different: {}", r.message)),
|
||||
|
||||
@@ -19,10 +19,9 @@ pub(crate) fn get_app_xml(_: &Workbook) -> String {
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>
|
||||
<Properties xmlns=\"http://schemas.openxmlformats.org/officeDocument/2006/extended-properties\" \
|
||||
xmlns:vt=\"http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes\">\
|
||||
<Application>{}</Application>\
|
||||
<AppVersion>{}</AppVersion>\
|
||||
</Properties>",
|
||||
APPLICATION, APP_VERSION
|
||||
<Application>{APPLICATION}</Application>\
|
||||
<AppVersion>{APP_VERSION}</AppVersion>\
|
||||
</Properties>"
|
||||
)
|
||||
}
|
||||
|
||||
@@ -40,8 +39,7 @@ pub(crate) fn get_core_xml(workbook: &Workbook, milliseconds: i64) -> Result<Str
|
||||
Some(s) => s,
|
||||
None => {
|
||||
return Err(XlsxError::Xml(format!(
|
||||
"Invalid timestamp: {}",
|
||||
milliseconds
|
||||
"Invalid timestamp: {milliseconds}"
|
||||
)))
|
||||
}
|
||||
};
|
||||
@@ -54,16 +52,15 @@ pub(crate) fn get_core_xml(workbook: &Workbook, milliseconds: i64) -> Result<Str
|
||||
xmlns:dcmitype=\"http://purl.org/dc/dcmitype/\" \
|
||||
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"> \
|
||||
<dc:title></dc:title><dc:subject></dc:subject>\
|
||||
<dc:creator>{}</dc:creator>\
|
||||
<dc:creator>{creator}</dc:creator>\
|
||||
<cp:keywords></cp:keywords>\
|
||||
<dc:description></dc:description>\
|
||||
<cp:lastModifiedBy>{}</cp:lastModifiedBy>\
|
||||
<cp:lastModifiedBy>{last_modified_by}</cp:lastModifiedBy>\
|
||||
<cp:revision></cp:revision>\
|
||||
<dcterms:created xsi:type=\"dcterms:W3CDTF\">{}</dcterms:created>\
|
||||
<dcterms:modified xsi:type=\"dcterms:W3CDTF\">{}</dcterms:modified>\
|
||||
<dcterms:created xsi:type=\"dcterms:W3CDTF\">{created}</dcterms:created>\
|
||||
<dcterms:modified xsi:type=\"dcterms:W3CDTF\">{last_modified}</dcterms:modified>\
|
||||
<cp:category></cp:category>\
|
||||
<cp:contentStatus></cp:contentStatus>\
|
||||
</cp:coreProperties>",
|
||||
creator, last_modified_by, created, last_modified
|
||||
</cp:coreProperties>"
|
||||
))
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ fn get_content_types_xml(workbook: &Workbook) -> String {
|
||||
pub fn save_to_xlsx(model: &Model, file_name: &str) -> Result<(), XlsxError> {
|
||||
let file_path = std::path::Path::new(&file_name);
|
||||
if file_path.exists() {
|
||||
return Err(XlsxError::IO(format!("file {} already exists", file_name)));
|
||||
return Err(XlsxError::IO(format!("file {file_name} already exists")));
|
||||
}
|
||||
let file = fs::File::create(file_path).unwrap();
|
||||
let writer = BufWriter::new(file);
|
||||
@@ -140,7 +140,7 @@ pub fn save_xlsx_to_writer<W: Write + Seek>(model: &Model, writer: W) -> Result<
|
||||
pub fn save_to_icalc(model: &Model, file_name: &str) -> Result<(), XlsxError> {
|
||||
let file_path = std::path::Path::new(&file_name);
|
||||
if file_path.exists() {
|
||||
return Err(XlsxError::IO(format!("file {} already exists", file_name)));
|
||||
return Err(XlsxError::IO(format!("file {file_name} already exists")));
|
||||
}
|
||||
let s = bitcode::encode(&model.workbook);
|
||||
let mut file = fs::File::create(file_path)?;
|
||||
|
||||
@@ -35,7 +35,7 @@ fn get_cell_style_attribute(s: i32) -> String {
|
||||
if s == 0 {
|
||||
"".to_string()
|
||||
} else {
|
||||
format!(" s=\"{}\"", s)
|
||||
format!(" s=\"{s}\"")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -148,8 +148,8 @@ pub fn load_from_xlsx(file_name: &str, locale: &str, tz: &str) -> Result<Model,
|
||||
/// Loads a [Model] from an `ic` file (a file in the IronCalc internal representation)
|
||||
pub fn load_from_icalc(file_name: &str) -> Result<Model, XlsxError> {
|
||||
let contents = fs::read(file_name)
|
||||
.map_err(|e| XlsxError::IO(format!("Could not extract workbook name: {}", e)))?;
|
||||
.map_err(|e| XlsxError::IO(format!("Could not extract workbook name: {e}")))?;
|
||||
let workbook: Workbook = bitcode::decode(&contents)
|
||||
.map_err(|e| XlsxError::IO(format!("Failed to decode file: {}", e)))?;
|
||||
.map_err(|e| XlsxError::IO(format!("Failed to decode file: {e}")))?;
|
||||
Model::from_workbook(workbook).map_err(XlsxError::Workbook)
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ pub(super) fn load_styles<R: Read + std::io::Seek>(
|
||||
}
|
||||
"charset" => {}
|
||||
_ => {
|
||||
println!("Unexpected feature {:?}", feature);
|
||||
println!("Unexpected feature {feature:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ where
|
||||
{
|
||||
let attr_name = attr_name.into();
|
||||
node.attribute(attr_name)
|
||||
.ok_or_else(|| XlsxError::Xml(format!("Missing \"{:?}\" XML attribute", attr_name)))
|
||||
.ok_or_else(|| XlsxError::Xml(format!("Missing \"{attr_name:?}\" XML attribute")))
|
||||
}
|
||||
|
||||
pub(super) fn get_value_or_default(node: &Node, tag_name: &str, default: &str) -> String {
|
||||
@@ -64,7 +64,7 @@ pub(super) fn get_color(node: Node) -> Result<Option<String>, XlsxError> {
|
||||
// A boolean value indicating the color is automatic and system color dependent.
|
||||
Ok(None)
|
||||
} else {
|
||||
println!("Unexpected color node {:?}", node);
|
||||
println!("Unexpected color node {node:?}");
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ pub(super) fn load_workbook<R: Read + std::io::Seek>(
|
||||
Some("visible") | None => SheetState::Visible,
|
||||
Some("hidden") => SheetState::Hidden,
|
||||
Some("veryHidden") => SheetState::VeryHidden,
|
||||
Some(state) => return Err(XlsxError::Xml(format!("Unknown sheet state: {}", state))),
|
||||
Some(state) => return Err(XlsxError::Xml(format!("Unknown sheet state: {state}"))),
|
||||
};
|
||||
sheets.push(Sheet {
|
||||
name,
|
||||
|
||||
@@ -81,7 +81,7 @@ fn parse_cell_reference(cell: &str) -> Result<(i32, i32), String> {
|
||||
if let Some(r) = parse_reference_a1(cell) {
|
||||
Ok((r.row, r.column))
|
||||
} else {
|
||||
Err(format!("Invalid cell reference: '{}'", cell))
|
||||
Err(format!("Invalid cell reference: '{cell}'"))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,17 +91,17 @@ fn parse_range(range: &str) -> Result<(i32, i32, i32, i32), String> {
|
||||
if let Some(r) = parse_reference_a1(parts[0]) {
|
||||
Ok((r.row, r.column, r.row, r.column))
|
||||
} else {
|
||||
Err(format!("Invalid range: '{}'", range))
|
||||
Err(format!("Invalid range: '{range}'"))
|
||||
}
|
||||
} else if parts.len() == 2 {
|
||||
match (parse_reference_a1(parts[0]), parse_reference_a1(parts[1])) {
|
||||
(Some(left), Some(right)) => {
|
||||
return Ok((left.row, left.column, right.row, right.column));
|
||||
}
|
||||
_ => return Err(format!("Invalid range: '{}'", range)),
|
||||
_ => return Err(format!("Invalid range: '{range}'")),
|
||||
}
|
||||
} else {
|
||||
return Err(format!("Invalid range: '{}'", range));
|
||||
return Err(format!("Invalid range: '{range}'"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -390,7 +390,7 @@ fn get_cell_from_excel(
|
||||
}
|
||||
"d" => {
|
||||
// Not implemented
|
||||
println!("Invalid type (d) in {}!{}", sheet_name, cell_ref);
|
||||
println!("Invalid type (d) in {sheet_name}!{cell_ref}");
|
||||
Cell::ErrorCell {
|
||||
ei: Error::NIMPL,
|
||||
s: cell_style,
|
||||
@@ -398,7 +398,7 @@ fn get_cell_from_excel(
|
||||
}
|
||||
"inlineStr" => {
|
||||
// Not implemented
|
||||
println!("Invalid type (inlineStr) in {}!{}", sheet_name, cell_ref);
|
||||
println!("Invalid type (inlineStr) in {sheet_name}!{cell_ref}");
|
||||
Cell::ErrorCell {
|
||||
ei: Error::NIMPL,
|
||||
s: cell_style,
|
||||
@@ -408,8 +408,7 @@ fn get_cell_from_excel(
|
||||
_ => {
|
||||
// error
|
||||
println!(
|
||||
"Unexpected type ({}) in {}!{}",
|
||||
cell_type, sheet_name, cell_ref
|
||||
"Unexpected type ({cell_type}) in {sheet_name}!{cell_ref}"
|
||||
);
|
||||
Cell::ErrorCell {
|
||||
ei: Error::ERROR,
|
||||
@@ -444,15 +443,15 @@ fn get_cell_from_excel(
|
||||
f: formula_index,
|
||||
ei: get_error_by_english_name(error_name).unwrap_or(Error::ERROR),
|
||||
s: cell_style,
|
||||
o: format!("{}!{}", sheet_name, cell_ref),
|
||||
o: format!("{sheet_name}!{cell_ref}"),
|
||||
m: cell_value.unwrap_or("#ERROR!").to_string(),
|
||||
}
|
||||
}
|
||||
"s" => {
|
||||
// Not implemented
|
||||
let o = format!("{}!{}", sheet_name, cell_ref);
|
||||
let o = format!("{sheet_name}!{cell_ref}");
|
||||
let m = Error::NIMPL.to_string();
|
||||
println!("Invalid type (s) in {}!{}", sheet_name, cell_ref);
|
||||
println!("Invalid type (s) in {sheet_name}!{cell_ref}");
|
||||
Cell::CellFormulaError {
|
||||
f: formula_index,
|
||||
ei: Error::NIMPL,
|
||||
@@ -471,8 +470,8 @@ fn get_cell_from_excel(
|
||||
}
|
||||
"d" => {
|
||||
// Not implemented
|
||||
println!("Invalid type (d) in {}!{}", sheet_name, cell_ref);
|
||||
let o = format!("{}!{}", sheet_name, cell_ref);
|
||||
println!("Invalid type (d) in {sheet_name}!{cell_ref}");
|
||||
let o = format!("{sheet_name}!{cell_ref}");
|
||||
let m = Error::NIMPL.to_string();
|
||||
Cell::CellFormulaError {
|
||||
f: formula_index,
|
||||
@@ -484,9 +483,9 @@ fn get_cell_from_excel(
|
||||
}
|
||||
"inlineStr" => {
|
||||
// Not implemented
|
||||
let o = format!("{}!{}", sheet_name, cell_ref);
|
||||
let o = format!("{sheet_name}!{cell_ref}");
|
||||
let m = Error::NIMPL.to_string();
|
||||
println!("Invalid type (inlineStr) in {}!{}", sheet_name, cell_ref);
|
||||
println!("Invalid type (inlineStr) in {sheet_name}!{cell_ref}");
|
||||
Cell::CellFormulaError {
|
||||
f: formula_index,
|
||||
ei: Error::NIMPL,
|
||||
@@ -498,10 +497,9 @@ fn get_cell_from_excel(
|
||||
_ => {
|
||||
// error
|
||||
println!(
|
||||
"Unexpected type ({}) in {}!{}",
|
||||
cell_type, sheet_name, cell_ref
|
||||
"Unexpected type ({cell_type}) in {sheet_name}!{cell_ref}"
|
||||
);
|
||||
let o = format!("{}!{}", sheet_name, cell_ref);
|
||||
let o = format!("{sheet_name}!{cell_ref}");
|
||||
let m = Error::ERROR.to_string();
|
||||
Cell::CellFormulaError {
|
||||
f: formula_index,
|
||||
@@ -886,7 +884,7 @@ pub(super) fn load_sheet<R: Read + std::io::Seek>(
|
||||
Some(_) => {
|
||||
// It's the mother cell. We do not use the ref attribute in IronCalc
|
||||
let formula = fs[0].text().unwrap_or("").to_string();
|
||||
let context = format!("{}!{}", sheet_name, cell_ref);
|
||||
let context = format!("{sheet_name}!{cell_ref}");
|
||||
let formula = from_a1_to_rc(
|
||||
formula,
|
||||
worksheets,
|
||||
@@ -949,7 +947,7 @@ pub(super) fn load_sheet<R: Read + std::io::Seek>(
|
||||
}
|
||||
// Its a cell with a simple formula
|
||||
let formula = fs[0].text().unwrap_or("").to_string();
|
||||
let context = format!("{}!{}", sheet_name, cell_ref);
|
||||
let context = format!("{sheet_name}!{cell_ref}");
|
||||
let formula = from_a1_to_rc(
|
||||
formula,
|
||||
worksheets,
|
||||
@@ -968,8 +966,7 @@ pub(super) fn load_sheet<R: Read + std::io::Seek>(
|
||||
}
|
||||
_ => {
|
||||
return Err(XlsxError::Xml(format!(
|
||||
"Invalid formula type {:?}.",
|
||||
formula_type,
|
||||
"Invalid formula type {formula_type:?}.",
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user