Skip to content

Commit

Permalink
Apply clippy lints and enable clippy on CI (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
mominul authored Dec 21, 2023
1 parent 40d941c commit c50f1e2
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 32 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ on: [push, pull_request]

name: Continuous integration

# Make sure CI fails on all warnings, including Clippy lints
env:
RUSTFLAGS: "-Dwarnings"

jobs:
test:
name: Test Suite
Expand All @@ -19,3 +23,13 @@ jobs:
with:
toolchain: ${{ matrix.rust }}
- run: cargo test

lint:
name: Clippy Linting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: "clippy"
- run: cargo clippy
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
The Next Gen Bengali input method library written in Rust. It is used by [OpenBangla Keyboard](https://github.com/OpenBangla/OpenBangla-Keyboard).

[![Build Status](https://github.com/OpenBangla/riti/actions/workflows/main.yml/badge.svg?branch=master)](https://github.com/OpenBangla/riti/actions?query=branch%3Amaster)
[![Rust](https://img.shields.io/badge/rust-1.41.1%2B-blue.svg?maxAge=3600)](https://github.com/OpenBangla/riti)
[![](https://tokei.rs/b1/github/OpenBangla/riti?category=code)](https://github.com/OpenBangla/riti)
[![Rust](https://img.shields.io/badge/rust-1.63.0%2B-blue.svg?maxAge=3600)](https://github.com/OpenBangla/riti)
2 changes: 1 addition & 1 deletion src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ pub extern "C" fn riti_suggestion_is_empty(ptr: *const Suggestion) -> bool {
/// `riti_config_set_*` set of functions.
#[no_mangle]
pub extern "C" fn riti_config_new() -> *mut Config {
Box::into_raw(Box::new(Config::default()))
Box::into_raw(Box::default())
}


Expand Down
36 changes: 18 additions & 18 deletions src/fixed/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use crate::{context::Method, data::Data, keycodes::keycode_to_char};
const MARKS: &str = "`~!@#$%^+*-_=+\\|\"/;:,./?><()[]{}";

enum PendingKar {
IKar,
EKar,
OIKar,
I,
E,
OI,
}

pub(crate) struct FixedMethod {
Expand Down Expand Up @@ -238,9 +238,9 @@ impl FixedMethod {
// Capture left standing kar in pending_kar.
if rmc != B_HASANTA && is_left_standing_kar(character) {
self.pending_kar = match character {
B_I_KAR => Some(PendingKar::IKar),
B_E_KAR => Some(PendingKar::EKar),
B_OI_KAR => Some(PendingKar::OIKar),
B_I_KAR => Some(PendingKar::I),
B_E_KAR => Some(PendingKar::E),
B_OI_KAR => Some(PendingKar::OI),
_ => None,
};
return;
Expand All @@ -258,9 +258,9 @@ impl FixedMethod {
if rmc == B_HASANTA {
self.buffer.pop();
self.buffer.push(match left_standing_kar {
PendingKar::EKar => B_E_KAR,
PendingKar::IKar => B_I_KAR,
PendingKar::OIKar => B_OI_KAR,
PendingKar::E => B_E_KAR,
PendingKar::I => B_I_KAR,
PendingKar::OI => B_OI_KAR,
});
self.pending_kar = None;
self.buffer.push(B_HASANTA);
Expand All @@ -271,9 +271,9 @@ impl FixedMethod {
&& (self.buffer.is_empty() || rmc.is_vowel() || MARKS.contains(rmc))
{
self.buffer.push(match left_standing_kar {
PendingKar::EKar => B_E,
PendingKar::IKar => B_I,
PendingKar::OIKar => B_OI,
PendingKar::E => B_E,
PendingKar::I => B_I,
PendingKar::OI => B_OI,
});
}
self.pending_kar = None;
Expand Down Expand Up @@ -380,9 +380,9 @@ impl FixedMethod {
if character == B_HASANTA && is_left_standing_kar(rmc) {
if value.chars().count() == 1 {
self.pending_kar = match self.buffer.pop() {
Some(B_I_KAR) => Some(PendingKar::IKar),
Some(B_E_KAR) => Some(PendingKar::EKar),
Some(B_OI_KAR) => Some(PendingKar::OIKar),
Some(B_I_KAR) => Some(PendingKar::I),
Some(B_E_KAR) => Some(PendingKar::E),
Some(B_OI_KAR) => Some(PendingKar::OI),
_ => None,
};
self.buffer.push(character);
Expand All @@ -409,9 +409,9 @@ impl FixedMethod {
return;
}
self.buffer.push(match left_standing_kar {
PendingKar::EKar => B_E_KAR,
PendingKar::IKar => B_I_KAR,
PendingKar::OIKar => B_OI_KAR,
PendingKar::E => B_E_KAR,
PendingKar::I => B_I_KAR,
PendingKar::OI => B_OI_KAR,
});
self.pending_kar = None;
return;
Expand Down
4 changes: 2 additions & 2 deletions src/phonetic/regex/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mod patterns;
mod regex;
mod parser;

pub(crate) use self::regex::parse;
pub(crate) use self::parser::parse;
File renamed without changes.
5 changes: 1 addition & 4 deletions src/suggestion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,7 @@ impl Suggestion {
///
/// A *lonely* `Suggestion` struct means that the struct has only one suggestion.
pub fn is_lonely(&self) -> bool {
match &self {
Self::Single { .. } => true,
_ => false,
}
matches!(&self, Self::Single { .. })
}

/// Returns `true` if the `Suggestion` struct is empty.
Expand Down
11 changes: 6 additions & 5 deletions src/utility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ pub(crate) fn smart_quoter(mut splitted: SplittedString) -> SplittedString {
for ch in splitted.preceding().chars() {
match ch {
'\'' => {
preceding.push_str("‘");
preceding.push('‘');
}
'"' => {
preceding.push_str("“");
preceding.push('“');
}
_ => preceding.push(ch),
}
Expand All @@ -179,18 +179,19 @@ pub(crate) fn smart_quoter(mut splitted: SplittedString) -> SplittedString {
for ch in splitted.trailing.chars() {
match ch {
'\'' => {
trailing.push_str("’");
trailing.push('’');
}
'"' => {
trailing.push_str("”");
trailing.push('”');
}
_ => trailing.push(ch),
}
}

splitted.preceding = Cow::Owned(preceding);
splitted.trailing = Cow::Owned(trailing);
return splitted;

splitted
}

#[cfg(test)]
Expand Down

0 comments on commit c50f1e2

Please sign in to comment.