From e0ccef4781d8c136a71c55db1129a7bccdd4f860 Mon Sep 17 00:00:00 2001 From: pml68 Date: Mon, 13 Jan 2025 00:53:05 +0100 Subject: ci: add lint workflow --- .cargo/config.toml | 3 +++ .github/workflows/lint.yml | 17 +++++++++++++++++ src/lib.rs | 17 +++++++---------- 3 files changed, 27 insertions(+), 10 deletions(-) create mode 100644 .cargo/config.toml create mode 100644 .github/workflows/lint.yml 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 diff --git a/src/lib.rs b/src/lib.rs index 7e55d90..ecbe03d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 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 Highlight { impl Highlight { /// The defalt styling function of a [`Highlight`]. + #[must_use] pub fn default_style(theme: &Theme, scope: &Scope) -> Format { 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, + custom_scopes: &[Self], ) -> Self { let scopes: Vec = if custom_scopes.is_empty() { Self::ALL.to_vec() } else { - let mut hashset: HashSet = - (*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 -- cgit v1.2.3