diff options
| author | pml68 <contact@pml68.dev> | 2025-01-13 00:53:05 +0100 |
|---|---|---|
| committer | pml68 <contact@pml68.dev> | 2025-01-13 00:53:41 +0100 |
| commit | e0ccef4781d8c136a71c55db1129a7bccdd4f860 (patch) | |
| tree | a41b2bb48fe1cba56756a7ea50dd3396775f51de | |
| parent | refactor: apply clippy suggestions (diff) | |
| download | iced_custom_highlighter-e0ccef4781d8c136a71c55db1129a7bccdd4f860.tar.gz | |
ci: add lint workflow
| -rw-r--r-- | .cargo/config.toml | 3 | ||||
| -rw-r--r-- | .github/workflows/lint.yml | 17 | ||||
| -rw-r--r-- | src/lib.rs | 17 |
3 files changed, 27 insertions, 10 deletions
diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..feb6aad --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,3 @@ +[alias] +lint = "clippy --no-deps -- -D warnings" +lint-all = "clippy --no-deps -- -D clippy::pedantic" diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..76bc0c3 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,17 @@ +name: Lint +on: [push, pull_request] +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: hecrj/setup-rust-action@v2 + with: + components: clippy + - uses: actions/checkout@master + - name: Install dependencies + run: | + export DEBIAN_FRONTED=noninteractive + sudo apt-get -qq update + sudo apt-get install -y libxkbcommon-dev + - name: Check lints + run: cargo lint @@ -6,7 +6,6 @@ use iced_widget::core::text::highlighter::{self, Format}; use iced_widget::text_editor::Catalog; use iced_widget::Theme; -use std::collections::HashSet; use std::ops::Range; use std::str::FromStr; use std::sync::LazyLock; @@ -134,10 +133,7 @@ impl<T: Catalog + 'static + Clone + PartialEq> highlighter::Highlighter Some(( range, Highlight { - scope: Scope::from_scopestack( - stack, - custom_scopes.clone(), - ), + scope: Scope::from_scopestack(stack, custom_scopes), style: *style, }, )) @@ -211,6 +207,7 @@ impl<T: Catalog> Highlight<T> { impl Highlight<Theme> { /// The defalt styling function of a [`Highlight`]. + #[must_use] pub fn default_style(theme: &Theme, scope: &Scope) -> Format<Font> { let color = match scope { Scope::Comment | Scope::TagStart => { @@ -362,6 +359,7 @@ impl Scope { } /// Retuns the scope string of the [`Scope`]. + #[must_use] pub fn scope_str(&self) -> &str { match self { Self::Comment => "comment, meta.documentation", @@ -405,15 +403,14 @@ impl Scope { fn from_scopestack( stack: &parsing::ScopeStack, - custom_scopes: Vec<Self>, + custom_scopes: &[Self], ) -> Self { let scopes: Vec<Self> = if custom_scopes.is_empty() { Self::ALL.to_vec() } else { - let mut hashset: HashSet<Self> = - (*Self::ALL).iter().cloned().collect(); - hashset.extend(custom_scopes); - hashset.into_iter().collect() + let mut all = Self::ALL.to_vec(); + all.extend_from_slice(custom_scopes); + all }; let selectors: Vec<(Self, highlighting::ScopeSelectors)> = scopes |
