Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup github actions and fix a bunch of clippy warnings #37

Merged
merged 12 commits into from
Oct 14, 2024
17 changes: 17 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
root = true

[*]
charset = utf-8

end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

indent_style = space
indent_size = 4

[*.md]
trim_trailing_whitespace = false

[*.yml]
indent_size = 2
108 changes: 108 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
name: CI

on:
push:
pull_request:
branches: [ main ]

env:
CARGO_TERM_COLOR: always

jobs:
style:
name: Check style
runs-on: ubuntu-latest

steps:
- name: Checkout the repo
uses: actions/checkout@v4

- name: Install rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly
components: rustfmt

- name: Cargo fmt
run: cargo fmt --all -- --check

typos:
name: Spell Check with Typos
runs-on: ubuntu-latest

steps:
- name: Checkout Actions Repository
uses: actions/checkout@v4

- name: Check the spelling of the files in our repo
uses: crate-ci/typos@master

clippy:
name: Run clippy
needs: [style]
runs-on: ubuntu-latest

steps:
- name: Checkout the repo
uses: actions/checkout@v4

- name: Install WeeChat
run: |
sudo mkdir /root/.gnupg
sudo chmod 700 /root/.gnupg
sudo mkdir -p /usr/share/keyrings
sudo gpg --no-default-keyring --keyring /usr/share/keyrings/weechat-archive-keyring.gpg --keyserver hkps://keys.openpgp.org --recv-keys 11E9DE8848F2B65222AA75B8D1820DB22A11534E
echo "deb [signed-by=/usr/share/keyrings/weechat-archive-keyring.gpg] https://weechat.org/ubuntu jammy main" | sudo tee /etc/apt/sources.list.d/weechat.list
echo "deb-src [signed-by=/usr/share/keyrings/weechat-archive-keyring.gpg] https://weechat.org/ubuntu jammy main" | sudo tee -a /etc/apt/sources.list.d/weechat.list
sudo apt-get update
sudo apt-get install weechat-dev

- name: Install rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly
components: clippy

- uses: Swatinem/rust-cache@v2

- name: Clippy
run: cargo clippy --all-targets --all-features -- -D warnings

test:
name: ${{ matrix.target.name }} ${{ matrix.channel }}
needs: [clippy]

runs-on: ${{ matrix.target.os }}
strategy:
matrix:
target: [
{ "os": "ubuntu-latest", "toolchain": "x86_64-unknown-linux-gnu", "name": "Linux GNU" },
# TODO: Add some more OS variants here.
]
channel: [stable, beta, nightly]

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install WeeChat
if: runner.os == 'Linux'
run: |
sudo mkdir /root/.gnupg
sudo chmod 700 /root/.gnupg
sudo mkdir -p /usr/share/keyrings
sudo gpg --no-default-keyring --keyring /usr/share/keyrings/weechat-archive-keyring.gpg --keyserver hkps://keys.openpgp.org --recv-keys 11E9DE8848F2B65222AA75B8D1820DB22A11534E
echo "deb [signed-by=/usr/share/keyrings/weechat-archive-keyring.gpg] https://weechat.org/ubuntu jammy main" | sudo tee /etc/apt/sources.list.d/weechat.list
echo "deb-src [signed-by=/usr/share/keyrings/weechat-archive-keyring.gpg] https://weechat.org/ubuntu jammy main" | sudo tee -a /etc/apt/sources.list.d/weechat.list
sudo apt-get update
sudo apt-get install weechat-dev

- name: Install rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ format('{0}-{1}', matrix.channel, matrix.target.toolchain) }}

- uses: Swatinem/rust-cache@v2

- name: Test
run: cargo test --all-features
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"rust-analyzer.checkOnSave.command": "clippy",
"rust-analyzer.cargo.features": "all",
"rust-analyzer.rustfmt": {
"extraArgs": ["+nightly"]
}
}
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[workspace]

members = [
"crates/*",
]
resolver = "2"

[profile.release]
opt-level = 'z'
opt-level = "z"
codegen-units = 1
lto = true
4 changes: 3 additions & 1 deletion crates/weechat-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ pub fn plugin(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
let weechat = unsafe {
Weechat::init_from_ptr(plugin)
};
let args = Args::new(argc, argv);

let args = unsafe { Args::new(argc, argv) };

match <#plugin as ::weechat::Plugin>::init(&weechat, args) {
Ok(p) => {
unsafe {
Expand Down
2 changes: 1 addition & 1 deletion crates/weechat/src/buffer/lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl<'a> Iterator for BufferLines<'a> {
}
}

impl<'a> DoubleEndedIterator for BufferLines<'a> {
impl DoubleEndedIterator for BufferLines<'_> {
fn next_back(&mut self) -> Option<Self::Item> {
if self.done {
None
Expand Down
29 changes: 13 additions & 16 deletions crates/weechat/src/buffer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub struct Buffer<'a> {
pub(crate) inner: InnerBuffers<'a>,
}

impl<'a> std::fmt::Debug for Buffer<'a> {
impl std::fmt::Debug for Buffer<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Buffer").field("full_name", &self.full_name()).finish()
}
Expand All @@ -50,7 +50,7 @@ pub(crate) enum InnerBuffers<'a> {
OwnedBuffer(InnerOwnedBuffer<'a>),
}

impl<'a> InnerBuffers<'a> {
impl InnerBuffers<'_> {
fn is_closing(&self) -> bool {
match self {
InnerBuffers::BorrowedBuffer(b) => b.closing.get(),
Expand All @@ -66,10 +66,10 @@ impl<'a> InnerBuffers<'a> {
}
}

impl<'a> InnerBuffers<'a> {
impl InnerBuffers<'_> {
pub(crate) fn weechat(&self) -> &Weechat {
match self {
InnerBuffers::BorrowedBuffer(b) => &b.weechat,
InnerBuffers::BorrowedBuffer(b) => b.weechat,
InnerBuffers::OwnedBuffer(b) => &b.weechat,
}
}
Expand All @@ -95,7 +95,7 @@ impl PartialEq for Buffer<'_> {

impl PartialOrd for Buffer<'_> {
fn partial_cmp(&self, other: &Buffer) -> Option<Ordering> {
self.number().partial_cmp(&other.number())
Some(self.number().cmp(&other.number()))
}
}

Expand Down Expand Up @@ -220,7 +220,6 @@ impl<T: FnMut(&Weechat, &Buffer) -> Result<(), ()> + 'static> BufferCloseCallbac
}

#[cfg(feature = "async")]
#[cfg_attr(feature = "docs", doc(cfg(r#async)))]
#[async_trait(?Send)]
/// Trait for the buffer input callback.
///
Expand Down Expand Up @@ -253,7 +252,6 @@ impl<T: FnMut(BufferHandle, String) -> LocalBoxFuture<'static, ()> + 'static>
}

#[cfg(feature = "async")]
#[cfg_attr(feature = "docs", doc(cfg(r#async)))]
/// Builder for the creation of a buffer.
pub struct BufferBuilderAsync {
pub(crate) name: String,
Expand All @@ -276,7 +274,7 @@ impl BufferBuilderAsync {
/// # Arguments
///
/// * `name` - The name of the new buffer. Needs to be unique across a
/// plugin, otherwise the buffer creation will fail.
/// plugin, otherwise the buffer creation will fail.
///
/// Returns a Buffer if one has been created, otherwise an empty Error.
///
Expand Down Expand Up @@ -350,7 +348,7 @@ impl BufferBuilder {
/// # Arguments
///
/// * `name` - The name of the new buffer. Needs to be unique across a
/// plugin, otherwise the buffer creation will fail.
/// plugin, otherwise the buffer creation will fail.
///
/// # Panics
///
Expand Down Expand Up @@ -392,7 +390,7 @@ impl BufferBuilder {
/// # Arguments
///
/// * `callback` - A function or a struct that implements the
/// BufferCloseCallback trait.
/// BufferCloseCallback trait.
pub fn input_callback(mut self, callback: impl BufferInputCallback + 'static) -> Self {
self.input_callback = Some(Box::new(callback));
self
Expand Down Expand Up @@ -478,7 +476,6 @@ impl Weechat {
}

#[cfg(feature = "async")]
#[cfg_attr(feature = "docs", doc(cfg(r#async)))]
fn buffer_new_with_async(builder: BufferBuilderAsync) -> Result<BufferHandle, ()> {
unsafe extern "C" fn c_input_cb(
pointer: *const c_void,
Expand Down Expand Up @@ -582,7 +579,7 @@ impl Weechat {
};

if buf_ptr.is_null() {
unsafe { Box::from_raw(buffer_pointers_ref) };
unsafe { drop(Box::from_raw(buffer_pointers_ref)) };
return Err(());
}

Expand Down Expand Up @@ -697,7 +694,7 @@ impl Weechat {
};

if buf_ptr.is_null() {
unsafe { Box::from_raw(buffer_pointers_ref) };
unsafe { drop(Box::from_raw(buffer_pointers_ref)) };
return Err(());
}

Expand Down Expand Up @@ -728,7 +725,7 @@ pub(crate) type WeechatInputCbT = unsafe extern "C" fn(
impl Buffer<'_> {
fn weechat(&self) -> &Weechat {
match &self.inner {
InnerBuffers::BorrowedBuffer(b) => &b.weechat,
InnerBuffers::BorrowedBuffer(b) => b.weechat,
InnerBuffers::OwnedBuffer(b) => &b.weechat,
}
}
Expand Down Expand Up @@ -830,7 +827,7 @@ impl Buffer<'_> {
/// Returns a `Nick` if one is found, None otherwise.
pub fn search_nick(&self, nick: &str) -> Option<Nick> {
let weechat = self.weechat();
let nick = Buffer::search_nick_helper(&weechat, self.ptr(), nick, None);
let nick = Buffer::search_nick_helper(weechat, self.ptr(), nick, None);

if nick.is_null() {
None
Expand Down Expand Up @@ -871,7 +868,7 @@ impl Buffer<'_> {
/// error otherwise.
pub fn add_nick(&self, nick_settings: NickSettings) -> Result<Nick, ()> {
let weechat = self.weechat();
let nick_ptr = Buffer::add_nick_helper(&weechat, self.ptr(), nick_settings, None);
let nick_ptr = Buffer::add_nick_helper(weechat, self.ptr(), nick_settings, None);

if nick_ptr.is_null() {
return Err(());
Expand Down
2 changes: 1 addition & 1 deletion crates/weechat/src/buffer/nick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub struct Nick<'a> {
pub(crate) buffer: PhantomData<&'a Buffer<'a>>,
}

impl<'a> Nick<'a> {
impl Nick<'_> {
/// Get a Weechat object out of the nick.
fn get_weechat(&self) -> Weechat {
Weechat::from_ptr(self.weechat_ptr)
Expand Down
2 changes: 1 addition & 1 deletion crates/weechat/src/buffer/nickgroup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct NickGroup<'a> {
pub(crate) buffer: PhantomData<&'a Buffer<'a>>,
}

impl<'a> NickGroup<'a> {
impl NickGroup<'_> {
fn get_weechat(&self) -> Weechat {
Weechat::from_ptr(self.weechat_ptr)
}
Expand Down
4 changes: 2 additions & 2 deletions crates/weechat/src/buffer/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct Window<'a> {
pub(crate) phantom: PhantomData<&'a Buffer<'a>>,
}

impl<'a> Window<'a> {
impl Window<'_> {
fn get_integer(&self, property: &str) -> i32 {
let weechat = Weechat::from_ptr(self.weechat);
let get_integer = weechat.get().window_get_integer.unwrap();
Expand Down Expand Up @@ -130,7 +130,7 @@ impl<'a> Window<'a> {
/// # Arguments
///
/// * `title` - The new title that should be set for the terminal, the
/// string is evaluated, so variables like ${info:version} can be used.
/// string is evaluated, so variables like ${info:version} can be used.
pub fn set_title(&self, title: &str) {
self.set_title_helper(Some(title));
}
Expand Down
16 changes: 9 additions & 7 deletions crates/weechat/src/config/boolean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use crate::{
Weechat,
};

type BooleanChangeCallback = Box<dyn FnMut(&Weechat, &BooleanOption)>;

/// Settings for a new boolean option.
#[derive(Default)]
pub struct BooleanOptionSettings {
Expand All @@ -19,7 +21,7 @@ pub struct BooleanOptionSettings {

pub(crate) default_value: bool,

pub(crate) change_cb: Option<Box<dyn FnMut(&Weechat, &BooleanOption)>>,
pub(crate) change_cb: Option<BooleanChangeCallback>,
}

impl BooleanOptionSettings {
Expand Down Expand Up @@ -87,7 +89,7 @@ pub struct BooleanOption<'a> {
pub(crate) _phantom: PhantomData<&'a ConfigSection>,
}

impl<'a> BooleanOption<'a> {
impl BooleanOption<'_> {
/// Get the value of the option.
pub fn value(&self) -> bool {
let weechat = self.get_weechat();
Expand All @@ -97,13 +99,13 @@ impl<'a> BooleanOption<'a> {
}
}

impl<'a> FromPtrs for BooleanOption<'a> {
impl FromPtrs for BooleanOption<'_> {
fn from_ptrs(option_ptr: *mut t_config_option, weechat_ptr: *mut t_weechat_plugin) -> Self {
BooleanOption { ptr: option_ptr, weechat_ptr, _phantom: PhantomData }
}
}

impl<'a> HiddenConfigOptionT for BooleanOption<'a> {
impl HiddenConfigOptionT for BooleanOption<'_> {
fn get_ptr(&self) -> *mut t_config_option {
self.ptr
}
Expand All @@ -113,10 +115,10 @@ impl<'a> HiddenConfigOptionT for BooleanOption<'a> {
}
}

impl<'a> BaseConfigOption for BooleanOption<'a> {}
impl<'a> ConfigOptions for BooleanOption<'_> {}
impl BaseConfigOption for BooleanOption<'_> {}
impl ConfigOptions for BooleanOption<'_> {}

impl<'a> PartialEq<bool> for BooleanOption<'a> {
impl PartialEq<bool> for BooleanOption<'_> {
fn eq(&self, other: &bool) -> bool {
self.value() == *other
}
Expand Down
Loading