Repository: DevinR528/cargo-sort (language: rust)

Issue:
README.md being discovered as Cargo.toml
I think there might be something slightly off with Cargo.toml discovery.

Based on [this output](https://github.com/ruma/ruma/runs/4597703508?check_suite_focus=true#step:5:502) from Ruma's CI run, it looks like `cargo-sort` is trying to parse `examples/README.md` as a TOML file:

>  thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: TomlError { message: "TOML parse error at line 3, column 7\n  |\n3 | These are example projects showcasing how to use the various crates in this repository. You can use\n  |       ^\nUnexpected `a`\nExpected `=`\n" }', /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/cargo-sort-1.0.6/src/sort.rs:113:46

In this workspace, subdirectories under `examples` (`examples/*`) are set as workspace members. 
I'm not sure, but maybe the `examples` folder is being considered a workspace member instead of the subdirectories of `examples`, and then it's using the only file in that directory as the `Cargo.toml` file?



Discussion / hints:

Fix patch:
diff --git a/Cargo.lock b/Cargo.lock
index f92378c..fe23ae1 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2,28 +2,6 @@
 # It is not intended for manual editing.
 version = 3
 
-[[package]]
-name = "afl"
-version = "0.10.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a5023646d631c14f4b24425600280676437b2c39d58f9cce91a6187e7af929f4"
-dependencies = [
- "cc",
- "clap",
- "libc",
- "rustc_version",
- "xdg",
-]
-
-[[package]]
-name = "ansi_term"
-version = "0.11.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
-dependencies = [
- "winapi",
-]
-
 [[package]]
 name = "ansi_term"
 version = "0.12.1"
@@ -72,7 +50,6 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
 name = "cargo-sort"
 version = "1.0.6"
 dependencies = [
- "afl",
  "chrono",
  "clap",
  "combine",
@@ -83,12 +60,6 @@ dependencies = [
  "termcolor",
 ]
 
-[[package]]
-name = "cc"
-version = "1.0.67"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e3c69b077ad434294d3ce9f1f6143a2a4b89a8a2d54ef813d85003a4fd1137fd"
-
 [[package]]
 name = "chrono"
 version = "0.4.19"
@@ -104,11 +75,11 @@ dependencies = [
 
 [[package]]
 name = "clap"
-version = "2.33.3"
+version = "2.34.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002"
+checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c"
 dependencies = [
- "ansi_term 0.11.0",
+ "ansi_term",
  "atty",
  "bitflags",
  "strsim",
@@ -220,22 +191,13 @@ dependencies = [
  "winapi",
 ]
 
-[[package]]
-name = "pest"
-version = "2.1.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "10f4872ae94d7b90ae48754df22fd42ad52ce740b8f370b03da4835417403e53"
-dependencies = [
- "ucd-trie",
-]
-
 [[package]]
 name = "pretty_assertions"
-version = "0.7.2"
+version = "1.0.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1cab0e7c02cf376875e9335e0ba1da535775beb5450d21e1dffca068818ed98b"
+checksum = "ec0cfe1b2403f172ba0f234e500906ee0a3e493fb81092dac23ebefe129301cc"
 dependencies = [
- "ansi_term 0.12.1",
+ "ansi_term",
  "ctor",
  "diff",
  "output_vt100",
@@ -259,39 +221,12 @@ dependencies = [
  "proc-macro2",
 ]
 
-[[package]]
-name = "rustc_version"
-version = "0.3.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f0dfe2087c51c460008730de8b57e6a320782fbfb312e1f4d520e6c6fae155ee"
-dependencies = [
- "semver",
-]
-
 [[package]]
 name = "ryu"
 version = "1.0.5"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e"
 
-[[package]]
-name = "semver"
-version = "0.11.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6"
-dependencies = [
- "semver-parser",
-]
-
-[[package]]
-name = "semver-parser"
-version = "0.10.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "00b0bef5b7f9e0df16536d3961cfb6e84331c065b4066afb39768d0e319411f7"
-dependencies = [
- "pest",
-]
-
 [[package]]
 name = "serde"
 version = "1.0.125"
@@ -366,12 +301,6 @@ dependencies = [
  "winapi",
 ]
 
-[[package]]
-name = "ucd-trie"
-version = "0.1.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c"
-
 [[package]]
 name = "unicode-width"
 version = "0.1.8"
@@ -441,9 +370,3 @@ name = "winapi-x86_64-pc-windows-gnu"
 version = "0.4.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
-
-[[package]]
-name = "xdg"
-version = "2.2.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d089681aa106a86fade1b0128fb5daf07d5867a509ab036d99988dec80429a57"
diff --git a/Cargo.toml b/Cargo.toml
index 96bf244..54a03cc 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -12,12 +12,12 @@ readme = "README.md"
 exclude = ["examp", "fixtures"]
 default-run = "cargo-sort"
 
-[features]
-fuzz = ["afl"]
+# [features]
+# fuzz = ["afl"]
 
 [dependencies]
-afl = { version = "0.10", optional = true }
-clap = { version = "2.33", features = ["wrap_help"] }
+# afl = { version = "0.10", optional = true }
+clap = { version = "2.34", features = ["wrap_help"] }
 glob = "0.3"
 termcolor = "1.1"
 
@@ -27,18 +27,23 @@ combine = "3.8"
 linked-hash-map = "0.5"
 
 [dev-dependencies]
-pretty_assertions = "0.7"
+pretty_assertions = "1.0.0"
 serde_json = "1"
 
-[[bin]]
-name = "cargo-sort"
-path = "src/main.rs"
+# The following is commented out for releases because of
+# https://github.com/DevinR528/cargo-sort/issues/31
+# see also https://github.com/rust-lang/cargo/issues/8703
+
+# [[bin]]
+# name = "cargo-sort"
+# path = "src/main.rs"
 
 # In order to run fuzz
 # `cargo install afl`
 # `cargo afl build --features=fuzz --bin fuzz`
 # `cargo afl target/debug/fuzz`
-[[bin]]
-name = "fuzz"
-path = "src/fuzz.rs"
-required-features = ["fuzz"]
+
+# [[bin]]
+# name = "fuzz"
+# path = "src/fuzz.rs"
+# required-features = ["fuzz"]
diff --git a/src/main.rs b/src/main.rs
index a7f75fb..679dec1 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -183,6 +183,7 @@ fn _main() -> IoResult<()> {
 
         let raw_toml = read_to_string(&path)
             .map_err(|_| format!("no file found at: {}", path.display()))?;
+
         let toml = raw_toml.parse::<Document>()?;
         let workspace = &toml["workspace"];
         if let Item::Table(ws) = workspace {
@@ -201,6 +202,11 @@ fn _main() -> IoResult<()> {
                         })
                     {
                         let path = entry?;
+                        // The `check_toml` function expects only folders that it appends
+                        // `Cargo.toml` onto
+                        if path.is_file() {
+                            continue;
+                        }
                         filtered_matches.push(Cow::Owned(path.display().to_string()));
                     }
                 } else {
@@ -210,6 +216,8 @@ fn _main() -> IoResult<()> {
         }
     }
 
+    println!("{:?}", filtered_matches);
+
     let mut cwd = cwd.clone();
     cwd.push("tomlfmt.toml");
     let mut config = read_to_string(&cwd)
diff --git a/tomlfmt.toml b/tomlfmt.toml
index 6425609..08ed273 100644
--- a/tomlfmt.toml
+++ b/tomlfmt.toml
@@ -5,7 +5,7 @@ compact_arrays = false
 compact_inline_tables = false
 trailing_newline = true
 key_value_newlines = true
-allowed_blank_lines = 1
+allowed_blank_lines = 2
 crlf = false
 table_order = [
     "package",


Test patch: