mirror of
https://github.com/crate-ci/typos.git
synced 2024-11-21 16:41:01 -05:00
chore(cli): Allow building without expensive parts
The obvious case is building for docs.rs but this can be helpful for special use cases or faster development iteration.
This commit is contained in:
parent
14f1532bee
commit
2fc1f5468e
5 changed files with 35 additions and 8 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -1558,6 +1558,7 @@ dependencies = [
|
|||
"typos-vars",
|
||||
"unicase",
|
||||
"unicode-segmentation",
|
||||
"varcon-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
13
Cargo.toml
13
Cargo.toml
|
@ -21,6 +21,14 @@ keywords = ["development", "spelling"]
|
|||
license = "MIT"
|
||||
edition = "2018"
|
||||
|
||||
[features]
|
||||
default = ["dict", "vars"]
|
||||
dict = ["typos-dict"]
|
||||
vars = ["typos-vars"]
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
no-default-features = true
|
||||
|
||||
[package.metadata.release]
|
||||
pre-release-replacements = [
|
||||
{file="CHANGELOG.md", search="Unreleased", replace="{{version}}", min=1},
|
||||
|
@ -41,8 +49,9 @@ codecov = { repository = "crate-ci/typos" }
|
|||
|
||||
[dependencies]
|
||||
typos = { version = "^0.4", path = "crates/typos" }
|
||||
typos-dict = { version = "^0.3", path = "crates/typos-dict" }
|
||||
typos-vars = { version = "^0.3", path = "crates/typos-vars" }
|
||||
varcon-core = { version = "1.1.0", path = "crates/varcon-core" }
|
||||
typos-dict = { version = "^0.3", path = "crates/typos-dict", optional = true }
|
||||
typos-vars = { version = "^0.3", path = "crates/typos-vars", optional = true }
|
||||
phf = { version = "0.8", features = ["unicase"] }
|
||||
unicase = "2.5"
|
||||
anyhow = "1.0"
|
||||
|
|
|
@ -41,6 +41,10 @@ stages:
|
|||
displayName: Check that Cargo.lock is satisfiable
|
||||
- script: cargo check --workspace --all-targets
|
||||
displayName: Default features
|
||||
- script: cargo check --all-targets --no-default-features
|
||||
displayName: No features
|
||||
- script: cargo check --all-targets --all-features
|
||||
displayName: All features
|
||||
- stage: test
|
||||
displayName: Test
|
||||
jobs:
|
||||
|
|
|
@ -353,13 +353,13 @@ pub enum Locale {
|
|||
}
|
||||
|
||||
impl Locale {
|
||||
pub const fn category(self) -> Option<typos_vars::Category> {
|
||||
pub const fn category(self) -> Option<varcon_core::Category> {
|
||||
match self {
|
||||
Locale::En => None,
|
||||
Locale::EnUs => Some(typos_vars::Category::American),
|
||||
Locale::EnGb => Some(typos_vars::Category::BritishIse),
|
||||
Locale::EnCa => Some(typos_vars::Category::Canadian),
|
||||
Locale::EnAu => Some(typos_vars::Category::Australian),
|
||||
Locale::EnUs => Some(varcon_core::Category::American),
|
||||
Locale::EnGb => Some(varcon_core::Category::BritishIse),
|
||||
Locale::EnCa => Some(varcon_core::Category::Canadian),
|
||||
Locale::EnAu => Some(varcon_core::Category::Australian),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
15
src/dict.rs
15
src/dict.rs
|
@ -8,7 +8,7 @@ use typos::Status;
|
|||
|
||||
#[derive(Default)]
|
||||
pub struct BuiltIn {
|
||||
locale: Option<typos_vars::Category>,
|
||||
locale: Option<varcon_core::Category>,
|
||||
}
|
||||
|
||||
impl BuiltIn {
|
||||
|
@ -46,6 +46,7 @@ impl BuiltIn {
|
|||
Some(corrections)
|
||||
}
|
||||
|
||||
#[cfg(feature = "dict")]
|
||||
// Not using `Status` to avoid the allocations
|
||||
fn correct_with_dict(&self, word: &str) -> Option<&'static str> {
|
||||
const WORD_RANGE: std::ops::RangeInclusive<usize> =
|
||||
|
@ -57,6 +58,12 @@ impl BuiltIn {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "dict"))]
|
||||
fn correct_with_dict(&self, _word: &str) -> Option<&'static str> {
|
||||
None
|
||||
}
|
||||
|
||||
#[cfg(feature = "vars")]
|
||||
fn correct_with_vars(&self, word: &str) -> Option<Status<'static>> {
|
||||
const WORD_RANGE: std::ops::RangeInclusive<usize> =
|
||||
typos_vars::WORD_MIN..=typos_vars::WORD_MAX;
|
||||
|
@ -68,6 +75,12 @@ impl BuiltIn {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "vars"))]
|
||||
fn correct_with_vars(&self, _word: &str) -> Option<Status<'static>> {
|
||||
None
|
||||
}
|
||||
|
||||
#[cfg(feature = "vars")]
|
||||
fn select_variant(
|
||||
&self,
|
||||
vars: &'static [(u8, &'static typos_vars::VariantsMap)],
|
||||
|
|
Loading…
Reference in a new issue