Skip to content

Commit

Permalink
Merge pull request #1066 from epage/template
Browse files Browse the repository at this point in the history
chore: Update from _rust/main template
  • Loading branch information
epage committed Jul 26, 2024
2 parents c7af471 + 9dc8c88 commit ebbe2a1
Show file tree
Hide file tree
Showing 25 changed files with 227 additions and 123 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
name: Test
strategy:
matrix:
os: ["ubuntu-latest", "windows-latest", "macos-14"]
os: ["ubuntu-latest", "windows-latest", "macos-latest"]
rust: ["stable"]
continue-on-error: ${{ matrix.rust != 'stable' }}
runs-on: ${{ matrix.os }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rust-next.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
name: Test
strategy:
matrix:
os: ["ubuntu-latest", "windows-latest", "macos-latest", "macos-14"]
os: ["ubuntu-latest", "windows-latest", "macos-latest"]
rust: ["stable", "beta"]
include:
- os: ubuntu-latest
Expand Down
43 changes: 30 additions & 13 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,25 +62,42 @@ Auto-cleans up your change according to some rules we have like:

### Process

When you first post a PR, we request that the commit history get cleaned
up. We recommend avoiding this during the PR to make it easier to review how
feedback was handled. Once the commit is ready, we'll ask you to clean up the
commit history. Once you let us know this is done, we can move forward with
merging! If you are uncomfortable with these parts of git, let us know and we
can help.

We ask that all new files have the copyright header. Please update the
copyright year for files you are modifying.

As a heads up, we'll be running your PR through the following gauntlet:
- warnings turned to compile errors
- `cargo test`
- `rustfmt`
- `clippy`
- `rustdoc`
- [`committed`](https://github.com/crate-ci/committed) to enforce [conventional commits](https://www.conventionalcommits.org)

Check out our [CI][CI] for more information.
- [`committed`](https://github.com/crate-ci/committed) as we use [Conventional](https://www.conventionalcommits.org) commit style
- [`typos`](https://github.com/crate-ci/typos) to check spelling

Not everything can be checked automatically though.

We request that the commit history gets cleaned up.
We ask that commits are atomic, meaning they are complete and have a single responsibility.
PRs should tell a cohesive story, with test and refactor commits that keep the
fix or feature commits simple and clear.

Specifically, we would encouage
- File renames be isolated into their own commit
- Add tests in a commit before their feature or fix, showing the current behavior.
The diff for the feature/fix commit will then show how the behavior changed,
making it clearer to reviewrs and the community and showing people that the
test is verifying the expected state.
- e.g. [clap#5520](https://github.com/clap-rs/clap/pull/5520)

Note that we are talking about ideals.
We understand having a clean history requires more advanced git skills;
feel free to ask us for help!
We might even suggest where it would work to be lax.
We also understand that editing some early commits may cause a lot of churn
with merge conflicts which can make it not worth editing all of the history.

For code organization, we recommend
- Grouping `impl` blocks next to their type (or trait)
- Grouping private items after the `pub` item that uses them.
- The intent is to help people quickly find the "relevant" details, allowing them to "dig deeper" as needed. Or put another way, the `pub` items serve as a table-of-contents.
- The exact order is fuzzy; do what makes sense

## Releasing

Expand Down
7 changes: 3 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ default-members = ["crates/typos-cli"]
resolver = "2"

[workspace.package]
license = "MIT OR Apache-2.0"
repository = "https://github.com/crate-ci/typos"
license = "MIT OR Apache-2.0"
edition = "2021"
rust-version = "1.75" # MSRV
include = [
Expand All @@ -22,7 +22,7 @@ include = [
]

[workspace.lints.rust]
rust_2018_idioms = "warn"
rust_2018_idioms = { level = "warn", priority = -1 }
unreachable_pub = "warn"
unsafe_op_in_unsafe_fn = "warn"
unused_lifetimes = "warn"
Expand Down Expand Up @@ -63,7 +63,6 @@ let_and_return = "allow" # sometimes good to name what you are returning
linkedlist = "warn"
lossy_float_literal = "warn"
macro_use_imports = "warn"
match_wildcard_for_single_variants = "warn"
mem_forget = "warn"
mutex_integer = "warn"
needless_for_each = "warn"
Expand All @@ -77,14 +76,14 @@ rest_pat_in_fully_bound_structs = "warn"
same_functions_in_if_condition = "warn"
self_named_module_files = "warn"
semicolon_if_nothing_returned = "warn"
single_match_else = "warn"
str_to_string = "warn"
string_add = "warn"
string_add_assign = "warn"
string_lit_as_bytes = "warn"
string_to_string = "warn"
todo = "warn"
trait_duplication_in_bounds = "warn"
uninlined_format_args = "warn"
verbose_file_reads = "warn"
wildcard_imports = "warn"
zero_sized_map_values = "warn"
Expand Down
2 changes: 1 addition & 1 deletion crates/dictgen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ version = "0.2.8"
description = "Compile-time case-insensitive map"
categories = ["development-tools", "text-processing"]
keywords = ["development", "spelling", "no_std"]
license.workspace = true
repository.workspace = true
license.workspace = true
edition.workspace = true
rust-version.workspace = true
include.workspace = true
Expand Down
13 changes: 6 additions & 7 deletions crates/dictgen/src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,31 @@ pub fn generate_map<'d, W: std::io::Write, V: std::fmt::Display>(

writeln!(
file,
"pub static {}: dictgen::DictTable<{}> = dictgen::DictTable {{",
name, value_type
"pub static {name}: dictgen::DictTable<{value_type}> = dictgen::DictTable {{"
)?;
writeln!(file, " keys: &[")?;
for (key, _value) in data.iter() {
smallest = std::cmp::min(smallest, key.len());
largest = std::cmp::max(largest, key.len());

let key = if key.is_ascii() {
format!("dictgen::InsensitiveStr::Ascii({:?})", key)
format!("dictgen::InsensitiveStr::Ascii({key:?})")
} else {
format!("dictgen::InsensitiveStr::Unicode({:?})", key)
format!("dictgen::InsensitiveStr::Unicode({key:?})")
};

writeln!(file, " {},", key)?;
writeln!(file, " {key},")?;
}
if largest == 0 {
smallest = 0;
}
writeln!(file, " ],")?;
writeln!(file, " values: &[")?;
for (_key, value) in data.iter() {
writeln!(file, " {},", value)?;
writeln!(file, " {value},")?;
}
writeln!(file, " ],")?;
writeln!(file, " range: {}..={},", smallest, largest)?;
writeln!(file, " range: {smallest}..={largest},")?;
writeln!(file, "}};")?;

Ok(())
Expand Down
13 changes: 6 additions & 7 deletions crates/dictgen/src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,31 @@ pub fn generate_table<'d, W: std::io::Write, V: std::fmt::Display>(

writeln!(
file,
"pub static {}: dictgen::DictTable<{}> = dictgen::DictTable {{",
name, value_type
"pub static {name}: dictgen::DictTable<{value_type}> = dictgen::DictTable {{"
)?;
writeln!(file, " keys: &[")?;
for (key, _value) in data.iter() {
smallest = std::cmp::min(smallest, key.len());
largest = std::cmp::max(largest, key.len());

let key = if key.is_ascii() {
format!("dictgen::InsensitiveStr::Ascii({:?})", key)
format!("dictgen::InsensitiveStr::Ascii({key:?})")
} else {
format!("dictgen::InsensitiveStr::Unicode({:?})", key)
format!("dictgen::InsensitiveStr::Unicode({key:?})")
};

writeln!(file, " {},", key)?;
writeln!(file, " {key},")?;
}
if largest == 0 {
smallest = 0;
}
writeln!(file, " ],")?;
writeln!(file, " values: &[")?;
for (_key, value) in data.iter() {
writeln!(file, " {},", value)?;
writeln!(file, " {value},")?;
}
writeln!(file, " ],")?;
writeln!(file, " range: {}..={},", smallest, largest)?;
writeln!(file, " range: {smallest}..={largest},")?;
writeln!(file, "}};")?;

Ok(())
Expand Down
25 changes: 11 additions & 14 deletions crates/dictgen/src/trie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,11 @@ mod codegen {
let mut root = DynRoot::new(data);
root.burst(limit);

let unicode_table_name = format!("{}_UNICODE_TABLE", prefix);
let unicode_table_name = format!("{prefix}_UNICODE_TABLE");

writeln!(
file,
"pub static {}_TRIE: dictgen::DictTrie<{}> = dictgen::DictTrie {{",
prefix, value_type
"pub static {prefix}_TRIE: dictgen::DictTrie<{value_type}> = dictgen::DictTrie {{"
)?;
writeln!(file, " root: &{},", gen_node_name(prefix, ""))?;
writeln!(file, " unicode: &{},", &unicode_table_name)?;
Expand All @@ -118,8 +117,7 @@ mod codegen {
let children_name = gen_children_name(prefix, &start);
writeln!(
file,
"static {}: dictgen::DictTrieNode<{}> = dictgen::DictTrieNode {{",
node_name, value_type
"static {node_name}: dictgen::DictTrieNode<{value_type}> = dictgen::DictTrieNode {{"
)?;
writeln!(
file,
Expand All @@ -128,7 +126,7 @@ mod codegen {
children_name
)?;
if let Some(value) = node.value.as_ref() {
writeln!(file, " value: Some({}),", value)?;
writeln!(file, " value: Some({value}),")?;
} else {
writeln!(file, " value: None,")?;
}
Expand All @@ -139,13 +137,12 @@ mod codegen {
DynChild::Nested(n) => {
writeln!(
file,
"static {}: [Option<&dictgen::DictTrieNode<{}>>; 26] = [",
children_name, value_type,
"static {children_name}: [Option<&dictgen::DictTrieNode<{value_type}>>; 26] = [",
)?;
for b in b'a'..=b'z' {
if let Some(child) = n.get(&b) {
let c = b as char;
let next_start = format!("{}{}", start, c);
let next_start = format!("{start}{c}");
writeln!(file, " Some(&{}),", gen_node_name(prefix, &next_start))?;
nodes.push((next_start, child));
} else {
Expand All @@ -171,21 +168,21 @@ mod codegen {

fn gen_node_name(prefix: &str, start: &str) -> String {
if start.is_empty() {
format!("{}_NODE", prefix)
format!("{prefix}_NODE")
} else {
let mut start = start.to_owned();
start.make_ascii_uppercase();
format!("{}_{}_NODE", prefix, start)
format!("{prefix}_{start}_NODE")
}
}

fn gen_children_name(prefix: &str, start: &str) -> String {
if start.is_empty() {
format!("{}_CHILDREN", prefix)
format!("{prefix}_CHILDREN")
} else {
let mut start = start.to_owned();
start.make_ascii_uppercase();
format!("{}_{}_CHILDREN", prefix, start)
format!("{prefix}_{start}_CHILDREN")
}
}

Expand All @@ -212,7 +209,7 @@ mod codegen {
let mut empty = None;
for (key, value) in data {
if existing.contains(key) {
panic!("Duplicate present: {}", key);
panic!("Duplicate present: {key}");
}
existing.insert(key);

Expand Down
2 changes: 1 addition & 1 deletion crates/misspell-dict/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ description = "Source Code Spelling Correction"
readme = "README.md"
categories = ["development-tools", "text-processing"]
keywords = ["development", "spelling"]
license.workspace = true
repository.workspace = true
license.workspace = true
edition.workspace = true
rust-version.workspace = true
include.workspace = true
Expand Down
4 changes: 2 additions & 2 deletions crates/misspell-dict/tests/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ fn parse_dict(raw: &str) -> Words<'_> {
vec![captures.get(2).unwrap().as_str()],
);
} else {
eprintln!("Unknown line: {}", line);
eprintln!("Unknown line: {line}");
}
}
}

if !bad.is_empty() {
panic!("Failed parsing; found extra words: {:#?}", bad);
panic!("Failed parsing; found extra words: {bad:#?}");
}

Words {
Expand Down
2 changes: 1 addition & 1 deletion crates/typos-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ description = "Source Code Spelling Correction"
readme = "../../README.md"
categories = ["development-tools", "text-processing"]
keywords = ["development", "spelling"]
license.workspace = true
repository.workspace = true
license.workspace = true
edition.workspace = true
rust-version.workspace = true
include.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/typos-cli/src/bin/typos-cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ fn run_checks(args: &args::Args) -> proc_exit::ExitResult {
let mut overrides = ignore::overrides::OverrideBuilder::new(".");
for pattern in walk_policy.extend_exclude.iter() {
overrides
.add(&format!("!{}", pattern))
.add(&format!("!{pattern}"))
.with_code(proc_exit::sysexits::CONFIG_ERR)?;
}
let overrides = overrides
Expand Down
12 changes: 6 additions & 6 deletions crates/typos-cli/src/bin/typos-cli/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ fn print_brief_correction(msg: &Typo<'_>) -> Result<(), std::io::Error> {
context_display(&msg.context),
msg.typo,
itertools::join(
corrections.iter().map(|s| format!("`{good}{}{reset}`", s)),
corrections.iter().map(|s| format!("`{good}{s}{reset}`")),
", "
)
)?;
Expand Down Expand Up @@ -192,7 +192,7 @@ fn print_long_correction(msg: &Typo<'_>) -> Result<(), std::io::Error> {
"{error}error{reset}: `{error}{}{reset}` should be {}",
msg.typo,
itertools::join(
corrections.iter().map(|s| format!("`{good}{}{reset}`", s)),
corrections.iter().map(|s| format!("`{good}{s}{reset}`")),
", "
)
)?;
Expand Down Expand Up @@ -305,7 +305,7 @@ mod tests {
];
for (i, ch) in latin_cyrillic_chars.iter().enumerate() {
let width = calculate_visible_column_width(ch);
assert_eq!(1, width, "latin_cyrillic[{}]: {}", i, ch,);
assert_eq!(1, width, "latin_cyrillic[{i}]: {ch}",);
}
}

Expand All @@ -319,7 +319,7 @@ mod tests {
];
for (i, ch) in cjk_chars.iter().enumerate() {
let width = calculate_visible_column_width(ch);
assert_eq!(2, width, "cjk[{}]: {}", i, ch);
assert_eq!(2, width, "cjk[{i}]: {ch}");
}
}

Expand All @@ -340,7 +340,7 @@ mod tests {
];
for (i, ch) in simple_emojis.iter().enumerate() {
let width = calculate_visible_column_width(ch);
assert_eq!(2, width, "emoji[{}]: {}", i, ch);
assert_eq!(2, width, "emoji[{i}]: {ch}");
}
}

Expand All @@ -352,7 +352,7 @@ mod tests {
];
for (i, ch) in zwj_sequences.iter().enumerate() {
let width = calculate_visible_column_width(ch);
assert_eq!(2, width, "zwj[{}]: {}", i, ch);
assert_eq!(2, width, "zwj[{i}]: {ch}");
}
}
}
2 changes: 1 addition & 1 deletion crates/typos-cli/src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ impl FileChecker for DiffTypos {
let stdout = std::io::stdout();
let mut handle = stdout.lock();
for line in diff {
write!(handle, "{}", line)?;
write!(handle, "{line}")?;
}
}

Expand Down
Loading

0 comments on commit ebbe2a1

Please sign in to comment.