Skip to content

Commit

Permalink
Use rustfmt config from ink! 🦑 (#505)
Browse files Browse the repository at this point in the history
* Copy ink rustfmt config

* inkify

* Add editorconfig

* Fmt

* Fmt

* Fmt
  • Loading branch information
ascjones authored Apr 12, 2022
1 parent bce9301 commit cfd55bd
Show file tree
Hide file tree
Showing 33 changed files with 1,313 additions and 513 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org

root = true

[*]
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
indent_style = space
indent_size = 4
64 changes: 64 additions & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,67 @@
max_width = 90 # changed
hard_tabs = false
tab_spaces = 4
newline_style = "Auto"
use_small_heuristics = "Default"
indent_style = "Block"
wrap_comments = false
format_code_in_doc_comments = false
comment_width = 80
normalize_comments = true # changed
normalize_doc_attributes = false
license_template_path = "FILE_HEADER" # changed
format_strings = false
format_macro_matchers = false
format_macro_bodies = true
empty_item_single_line = true
struct_lit_single_line = true
fn_single_line = false
where_single_line = false
imports_indent = "Block"
imports_layout = "Vertical" # changed
imports_granularity = "Crate" # changed
reorder_imports = true
reorder_modules = true
reorder_impl_items = false
type_punctuation_density = "Wide"
space_before_colon = false
space_after_colon = true
spaces_around_ranges = false
binop_separator = "Front"
remove_nested_parens = true
combine_control_expr = false # changed
overflow_delimited_expr = false
struct_field_align_threshold = 0
enum_discrim_align_threshold = 0
match_arm_blocks = true
force_multiline_blocks = true # changed
fn_args_layout = "Tall"
brace_style = "SameLineWhere"
control_brace_style = "AlwaysSameLine"
trailing_semicolon = false # changed
trailing_comma = "Vertical"
match_block_trailing_comma = false
blank_lines_upper_bound = 1
blank_lines_lower_bound = 0
edition = "2021" # changed
version = "One"
merge_derives = true
use_try_shorthand = true # changed
use_field_init_shorthand = true # changed
force_explicit_abi = true
condense_wildcard_suffixes = false
color = "Auto"
unstable_features = true # changed
disable_all_formatting = false
skip_children = false
hide_parse_errors = false
error_on_line_overflow = false
error_on_unformatted = false
report_todo = "Always"
report_fixme = "Always"
ignore = []

# Below are `rustfmt` internal settings
#
# emit_mode = "Files"
# make_backup = false
41 changes: 33 additions & 8 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,31 @@ use std::{
env,
ffi::OsStr,
fs::File,
io::{prelude::*, Write},
io::{
prelude::*,
Write,
},
iter::Iterator,
path::{Path, PathBuf},
path::{
Path,
PathBuf,
},
process::Command,
};

use anyhow::Result;
use walkdir::WalkDir;
use zip::{write::FileOptions, CompressionMethod, ZipWriter};
use zip::{
write::FileOptions,
CompressionMethod,
ZipWriter,
};

use platforms::{TARGET_ARCH, TARGET_ENV, TARGET_OS};
use platforms::{
TARGET_ARCH,
TARGET_ENV,
TARGET_OS,
};
use substrate_build_script_utils::rerun_if_git_head_changed;

const DEFAULT_UNIX_PERMISSIONS: u32 = 0o755;
Expand Down Expand Up @@ -59,7 +73,10 @@ fn main() {
/// * Creates a zip archive of the `new` project template.
/// * Builds the `dylint` driver found in `ink_linting`, the compiled
/// driver is put into a zip archive as well.
fn zip_template_and_build_dylint_driver(manifest_dir: PathBuf, out_dir: PathBuf) -> Result<()> {
fn zip_template_and_build_dylint_driver(
manifest_dir: PathBuf,
out_dir: PathBuf,
) -> Result<()> {
zip_template(&manifest_dir, &out_dir)?;

check_dylint_link_installed()?;
Expand Down Expand Up @@ -108,7 +125,11 @@ fn zip_template_and_build_dylint_driver(manifest_dir: PathBuf, out_dir: PathBuf)
)
})?;

let res = build_and_zip_dylint_driver(ink_dylint_driver_dir, out_dir, dylint_driver_dst_file);
let res = build_and_zip_dylint_driver(
ink_dylint_driver_dir,
out_dir,
dylint_driver_dst_file,
);

// After the build process of `ink_linting` happened we need to name back to the original
// `_Cargo.toml` name, otherwise the directory would be "dirty" and `cargo publish` would
Expand Down Expand Up @@ -295,7 +316,11 @@ fn zip_dir(src_dir: &Path, dst_file: &Path, method: CompressionMethod) -> Result
///
/// `dylint` drivers have a file name of the form `libink_linting@toolchain.[so,dll]`.
#[cfg(not(feature = "cargo-clippy"))]
fn zip_dylint_driver(src_dir: &Path, dst_file: &Path, method: CompressionMethod) -> Result<()> {
fn zip_dylint_driver(
src_dir: &Path,
dst_file: &Path,
method: CompressionMethod,
) -> Result<()> {
if !src_dir.exists() {
anyhow::bail!("src_dir '{}' does not exist", src_dir.display());
}
Expand Down Expand Up @@ -333,7 +358,7 @@ fn zip_dylint_driver(src_dir: &Path, dst_file: &Path, method: CompressionMethod)

zip.finish()?;
lib_found = true;
break;
break
}
}

Expand Down
6 changes: 4 additions & 2 deletions metadata/byte_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ where
{
if bytes.is_empty() {
// Return empty string without prepended `0x`.
return serializer.serialize_str("");
return serializer.serialize_str("")
}
serde_hex::serialize(bytes, serializer)
}
Expand Down Expand Up @@ -56,7 +56,9 @@ where
}

/// Deserializes the given hex string with optional `0x` prefix.
pub fn deserialize_from_byte_str_array<'de, D>(deserializer: D) -> Result<[u8; 32], D::Error>
pub fn deserialize_from_byte_str_array<'de, D>(
deserializer: D,
) -> Result<[u8; 32], D::Error>
where
D: serde::Deserializer<'de>,
{
Expand Down
36 changes: 27 additions & 9 deletions metadata/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,22 @@
mod byte_str;

use semver::Version;
use serde::{de, Deserialize, Serialize, Serializer};
use serde_json::{Map, Value};
use serde::{
de,
Deserialize,
Serialize,
Serializer,
};
use serde_json::{
Map,
Value,
};
use std::{
fmt::{Display, Formatter, Result as DisplayResult},
fmt::{
Display,
Formatter,
Result as DisplayResult,
},
str::FromStr,
};
use url::Url;
Expand Down Expand Up @@ -627,8 +639,10 @@ mod tests {
#[test]
fn json_with_optional_fields() {
let language = SourceLanguage::new(Language::Ink, Version::new(2, 1, 0));
let compiler =
SourceCompiler::new(Compiler::RustC, Version::parse("1.46.0-nightly").unwrap());
let compiler = SourceCompiler::new(
Compiler::RustC,
Version::parse("1.46.0-nightly").unwrap(),
);
let wasm = SourceWasm::new(vec![0u8, 1u8, 2u8]);
let source = Source::new(Some(wasm), CodeHash([0u8; 32]), language, compiler);
let contract = Contract::builder()
Expand Down Expand Up @@ -709,8 +723,10 @@ mod tests {
#[test]
fn json_excludes_optional_fields() {
let language = SourceLanguage::new(Language::Ink, Version::new(2, 1, 0));
let compiler =
SourceCompiler::new(Compiler::RustC, Version::parse("1.46.0-nightly").unwrap());
let compiler = SourceCompiler::new(
Compiler::RustC,
Version::parse("1.46.0-nightly").unwrap(),
);
let source = Source::new(None, CodeHash([0u8; 32]), language, compiler);
let contract = Contract::builder()
.name("incrementer".to_string())
Expand Down Expand Up @@ -759,8 +775,10 @@ mod tests {
#[test]
fn decoding_works() {
let language = SourceLanguage::new(Language::Ink, Version::new(2, 1, 0));
let compiler =
SourceCompiler::new(Compiler::RustC, Version::parse("1.46.0-nightly").unwrap());
let compiler = SourceCompiler::new(
Compiler::RustC,
Version::parse("1.46.0-nightly").unwrap(),
);
let wasm = SourceWasm::new(vec![0u8, 1u8, 2u8]);
let source = Source::new(Some(wasm), CodeHash([0u8; 32]), language, compiler);
let contract = Contract::builder()
Expand Down
Loading

0 comments on commit cfd55bd

Please sign in to comment.