From 59c879aedb7e0f2a681e2148bcb9b097771ece95 Mon Sep 17 00:00:00 2001 From: Kevin Amado Date: Sun, 30 Jan 2022 13:26:52 -0500 Subject: [PATCH] feat: format toml --- Cargo.toml | 26 ++++----- flake.lock | 145 +++++++++++++++++++++++++++++++++++++++++++++++++-- flake.nix | 16 ++++-- rustfmt.toml | 18 +++++++ treefmt.toml | 55 ++++--------------- 5 files changed, 194 insertions(+), 66 deletions(-) create mode 100644 rustfmt.toml diff --git a/Cargo.toml b/Cargo.toml index c0201c5..b1b4a18 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,18 +1,18 @@ [dependencies] - clap = "*" - rand = "*" - rayon = "*" - rnix = "*" - rowan = "*" - walkdir = "*" +clap = "*" +rand = "*" +rayon = "*" +rnix = "*" +rowan = "*" +walkdir = "*" [dev-dependencies] - indoc = "*" +indoc = "*" [package] - authors = ["Kevin Amado "] - description = "The uncompromising Nix formatter" - edition = "2021" - name = "alejandra" - repository = "https://github.com/kamadorueda/alejandra" - version = "0.0.0" +authors = ["Kevin Amado "] +description = "The uncompromising Nix formatter" +edition = "2021" +name = "alejandra" +repository = "https://github.com/kamadorueda/alejandra" +version = "0.0.0" diff --git a/flake.lock b/flake.lock index 9f292f6..764c727 100644 --- a/flake.lock +++ b/flake.lock @@ -1,8 +1,31 @@ { "nodes": { + "alejandra": { + "inputs": { + "fenix": "fenix", + "flakeCompat": "flakeCompat", + "flakeUtils": "flakeUtils", + "nixpkgs": "nixpkgs", + "treefmt": "treefmt" + }, + "locked": { + "lastModified": 1643565035, + "narHash": "sha256-RhNRxpW1kYWSIiUdgV5FaPomXXH4Dlrh/5dqtSFkrMc=", + "owner": "kamadorueda", + "repo": "alejandra", + "rev": "c07a964d8ae8d283f4c270bd26bbd391d274f729", + "type": "github" + }, + "original": { + "owner": "kamadorueda", + "repo": "alejandra", + "type": "github" + } + }, "fenix": { "inputs": { "nixpkgs": [ + "alejandra", "nixpkgs" ], "rust-analyzer-src": "rust-analyzer-src" @@ -21,6 +44,29 @@ "type": "github" } }, + "fenix_2": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "rust-analyzer-src": [ + "rustAnalyzerSrc" + ] + }, + "locked": { + "lastModified": 1643523738, + "narHash": "sha256-6XmIEKOtv26tO/wCPg/TQUKXFPfDKPS8pXOBEicSMsw=", + "owner": "nix-community", + "repo": "fenix", + "rev": "08742f341a9bcf35b9ee0092c4e9ab309c860558", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "fenix", + "type": "github" + } + }, "flake-utils": { "locked": { "lastModified": 1610051610, @@ -52,6 +98,22 @@ "type": "github" } }, + "flakeCompat_2": { + "flake": false, + "locked": { + "lastModified": 1641205782, + "narHash": "sha256-4jY7RCWUoZ9cKD8co0/4tFARpWB+57+r1bLLvXNJliY=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "b7547d3eed6f32d06102ead8991ec52ab0a4f1a7", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, "flakeUtils": { "locked": { "lastModified": 1642700792, @@ -67,6 +129,21 @@ "type": "github" } }, + "flakeUtils_2": { + "locked": { + "lastModified": 1642700792, + "narHash": "sha256-XqHrk7hFb+zBvRg6Ghl+AZDq03ov6OshJLiSWOoX5es=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "846b2ae0fc4cc943637d3d1def4454213e203cba", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1643322911, @@ -83,13 +160,31 @@ "type": "github" } }, + "nixpkgs_2": { + "locked": { + "lastModified": 1643381941, + "narHash": "sha256-pHTwvnN4tTsEKkWlXQ8JMY423epos8wUOhthpwJjtpc=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "5efc8ca954272c4376ac929f4c5ffefcc20551d5", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, "root": { "inputs": { - "fenix": "fenix", - "flakeCompat": "flakeCompat", - "flakeUtils": "flakeUtils", - "nixpkgs": "nixpkgs", - "treefmt": "treefmt" + "alejandra": "alejandra", + "fenix": "fenix_2", + "flakeCompat": "flakeCompat_2", + "flakeUtils": "flakeUtils_2", + "nixpkgs": "nixpkgs_2", + "rustAnalyzerSrc": "rustAnalyzerSrc", + "treefmt": "treefmt_2" } }, "rust-analyzer-src": { @@ -109,9 +204,49 @@ "type": "github" } }, + "rustAnalyzerSrc": { + "flake": false, + "locked": { + "lastModified": 1643549027, + "narHash": "sha256-M1+EmMsidaI+ZQCJEV3wVSAS+PaDqZ63OiGDkoRccjg=", + "owner": "rust-analyzer", + "repo": "rust-analyzer", + "rev": "c08df0f1f5e188e2e1e8f1715ff3a6d583cfb9f3", + "type": "github" + }, + "original": { + "owner": "rust-analyzer", + "repo": "rust-analyzer", + "type": "github" + } + }, "treefmt": { "inputs": { "flake-utils": "flake-utils", + "nixpkgs": [ + "alejandra", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1640364438, + "narHash": "sha256-sV1Oa9JVNmpAwZ4cnVs7ovHrKL8EPg3J08jPX/a48LI=", + "owner": "numtide", + "repo": "treefmt", + "rev": "26d7f5f15e5d22d4413ba7c5ae0447fdc0b5cc76", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt", + "type": "github" + } + }, + "treefmt_2": { + "inputs": { + "flake-utils": [ + "flakeUtils" + ], "nixpkgs": [ "nixpkgs" ] diff --git a/flake.nix b/flake.nix index c7b7f53..7090a0f 100644 --- a/flake.nix +++ b/flake.nix @@ -1,12 +1,17 @@ { inputs = { + alejandra.url = "github:kamadorueda/alejandra"; fenix.url = "github:nix-community/fenix"; fenix.inputs.nixpkgs.follows = "nixpkgs"; + fenix.inputs.rust-analyzer-src.follows = "rustAnalyzerSrc"; flakeCompat.url = github:edolstra/flake-compat; flakeCompat.flake = false; flakeUtils.url = "github:numtide/flake-utils"; nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; + rustAnalyzerSrc.url = "github:rust-analyzer/rust-analyzer"; + rustAnalyzerSrc.flake = false; treefmt.url = "github:numtide/treefmt"; + treefmt.inputs.flake-utils.follows = "flakeUtils"; treefmt.inputs.nixpkgs.follows = "nixpkgs"; }; outputs = @@ -57,11 +62,16 @@ fenix.latest.rust-src fenix.latest.rustc fenix.latest.rustfmt - treefmt - nixpkgs.shfmt + inputs.alejandra.outputs.defaultPackage.${ system } + nixpkgs.jq nixpkgs.nodePackages.prettier + nixpkgs.shfmt + treefmt ]; - shellHook = "cargo build"; + shellHook = + '' + export NODE_PATH=${ nixpkgs.nodePackages.prettier-plugin-toml }/lib/node_modules:$NODE_PATH + ''; }; } ); diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..0cee591 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,18 @@ +edition = "2021" +enum_discrim_align_threshold = 999 +format_code_in_doc_comments = true +format_generated_files = true +format_macro_bodies = true +format_macro_matchers = true +format_strings = true +hex_literal_case = "Lower" +imports_granularity = "Crate" +imports_layout = "HorizontalVertical" +max_width = 80 +normalize_comments = true +normalize_doc_attributes = true +reorder_impl_items = true +struct_field_align_threshold = 999 +unstable_features = true +use_small_heuristics = "Max" +version = "Two" diff --git a/treefmt.toml b/treefmt.toml index 816146c..81f4e92 100644 --- a/treefmt.toml +++ b/treefmt.toml @@ -1,59 +1,24 @@ -# One CLI to format the code tree - https://github.com/numtide/treefmt +[formatter] + +[formatter.json] +command = "jq" +includes = ["*.json"] +options = ["-S"] [formatter.nix] -command = "./target/debug/alejandra" +command = "alejandra" includes = ["*.nix"] [formatter.prettier] command = "prettier" -options = ["--write"] -includes = [ - "*.css", - "*.html", - "*.js", - "*.json", - "*.jsx", - "*.md", - "*.mdx", - "*.scss", - "*.ts", - "*.yaml", -] +includes = ["*.md", "*.toml", "*.yaml"] +options = ["--plugin", "prettier-plugin-toml", "--write"] [formatter.rust] command = "rustfmt" -options = [ - "--edition", "2021", - "--config", - """enum_discrim_align_threshold=999,\ - format_code_in_doc_comments=true,\ - format_generated_files=true,\ - format_macro_bodies=true,\ - format_macro_matchers=true,\ - format_strings=true,\ - hex_literal_case=Lower,\ - imports_granularity=Crate,\ - imports_layout=HorizontalVertical,\ - max_width=80,\ - normalize_comments=true,\ - normalize_doc_attributes=true,\ - reorder_impl_items=true,\ - struct_field_align_threshold=999,\ - unstable_features=true,\ - use_small_heuristics=Max,\ - version=Two""", -] includes = ["*.rs"] [formatter.shell] command = "shfmt" -options = [ - "-bn", # binary ops like && and | may start a line - "-ci", # switch cases will be indented - "-sr", # redirect operators will be followed by a space - "-i", "2", # indent 2 - "-s", # simplify the code - "-w", # write back to the file -] includes = ["*.sh"] - +options = ["-bn", "-ci", "-sr", "-i", "2", "-s", "-w"]