From 2fc1f5468e8997eb28da7edb74e5608b7948c352 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Fri, 30 Apr 2021 21:31:20 -0500 Subject: [PATCH] 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. --- Cargo.lock | 1 + Cargo.toml | 13 +++++++++++-- azure-pipelines.yml | 4 ++++ src/config.rs | 10 +++++----- src/dict.rs | 15 ++++++++++++++- 5 files changed, 35 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dd1c91b..f9b5c53 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1558,6 +1558,7 @@ dependencies = [ "typos-vars", "unicase", "unicode-segmentation", + "varcon-core", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 17643ce..02125a3 100644 --- a/Cargo.toml +++ b/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" diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 0d00182..dfa9da7 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -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: diff --git a/src/config.rs b/src/config.rs index 4e3ef1e..305e794 100644 --- a/src/config.rs +++ b/src/config.rs @@ -353,13 +353,13 @@ pub enum Locale { } impl Locale { - pub const fn category(self) -> Option { + pub const fn category(self) -> Option { 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), } } diff --git a/src/dict.rs b/src/dict.rs index 681716c..9cb054c 100644 --- a/src/dict.rs +++ b/src/dict.rs @@ -8,7 +8,7 @@ use typos::Status; #[derive(Default)] pub struct BuiltIn { - locale: Option, + locale: Option, } 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 = @@ -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> { const WORD_RANGE: std::ops::RangeInclusive = 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> { + None + } + + #[cfg(feature = "vars")] fn select_variant( &self, vars: &'static [(u8, &'static typos_vars::VariantsMap)],