Skip to content
This repository has been archived by the owner on Mar 4, 2024. It is now read-only.

Commit

Permalink
Merge pull request #30 from gtk-rs/bilelmoussaoui/ci-clippy
Browse files Browse the repository at this point in the history
CI: add a clippy job
  • Loading branch information
sdroege authored Nov 19, 2020
2 parents 1126eff + ec7dbdc commit ca08014
Show file tree
Hide file tree
Showing 81 changed files with 244 additions and 274 deletions.
68 changes: 68 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,74 @@ jobs:
command: fmt
args: --all -- --check

clippy:
name: clippy
runs-on: ubuntu-latest
container:
image: ubuntu:20.10
steps:
- run: apt-get update -y
- run: apt-get install -y libgtk-3-dev libglib2.0-dev libgraphene-1.0-dev git xvfb curl libcairo-gobject2 libcairo2-dev
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- run: rustup component add clippy

- working-directory: atk
name: atk
run: cargo clippy --features "v2_34" --all-targets -- -D warnings

- working-directory: cairo
name: cairo
run: cargo clippy --features "png,pdf,svg,ps,use_glib,v1_16,freetype,script,xcb,xlib,win32-surface" --all-targets -- -D warnings

- working-directory: examples
name: examples
run: cargo clippy --all-features --all-targets -- -D warnings

- working-directory: gdk
name: gdk
run: cargo clippy --features "v3_24" --all-targets -- -D warnings

- working-directory: gdk-pixbuf
name: gdk-pixbuf
run: cargo clippy --features "v2_40" --all-targets -- -D warnings

- working-directory: gdkx11
name: gdkx11
run: cargo clippy --features "v3_24" --all-targets -- -D warnings

- working-directory: gio
name: gio
run: cargo clippy --features "v2_66" --all-targets -- -D warnings

- working-directory: glib
name: glib
run: cargo clippy --features "v2_66" --all-targets -- -D warnings

- working-directory: glib-macros
name: glib-macros
run: cargo clippy --all-targets -- -D warnings

- working-directory: graphene
name: graphene
run: cargo clippy --features "v1_10" --all-targets -- -D warnings

- working-directory: gtk
name: gtk
run: cargo clippy --features "v3_24_9" --all-targets -- -D warnings

- working-directory: pango
name: pango
run: cargo clippy --features "v1_46" --all-targets -- -D warnings

- working-directory: pangocairo
name: pangocairo
run: cargo clippy --all-targets -- -D warnings

checker:
name: gtk-rs checker
runs-on: ubuntu-latest
Expand Down
11 changes: 0 additions & 11 deletions atk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,7 @@
//! This library contains safe Rust bindings for [ATK](https://developer.gnome.org/atk/). It's
//! a part of [Gtk-rs](https://gtk-rs.org/).

#![cfg_attr(feature = "cargo-clippy", allow(let_unit_value))]
#![cfg_attr(feature = "cargo-clippy", allow(new_without_default))]
#![cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
#![cfg_attr(feature = "cargo-clippy", allow(trivially_copy_pass_by_ref))]
#![cfg_attr(feature = "cargo-clippy", allow(derive_hash_xor_eq))]
#![cfg_attr(feature = "dox", feature(doc_cfg))]
#![allow(deprecated)]

extern crate libc;
#[macro_use]
Expand All @@ -30,11 +24,6 @@ extern crate glib;
#[macro_use]
mod rt;

#[cfg_attr(feature = "cargo-clippy", allow(too_many_arguments))]
#[cfg_attr(feature = "cargo-clippy", allow(match_same_arms))]
#[cfg_attr(feature = "cargo-clippy", allow(let_and_return))]
#[cfg_attr(feature = "cargo-clippy", allow(many_single_char_names))]
#[cfg_attr(feature = "cargo-clippy", allow(wrong_self_convention))]
#[allow(unused_imports)]
mod auto;

Expand Down
1 change: 1 addition & 0 deletions atk/src/text_rectangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ impl TextRectangle {

#[doc(hidden)]
#[inline]
#[allow(clippy::wrong_self_convention)]
pub fn to_glib_none_mut(&mut self) -> (*mut atk_sys::AtkTextRectangle, i32) {
(self as *mut TextRectangle as usize as *mut _, 0)
}
Expand Down
2 changes: 1 addition & 1 deletion cairo/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ impl Context {
ffi::cairo_show_text_glyphs(
self.0.as_ptr(),
text.as_ptr(),
-1 as c_int, //NULL terminated
-1_i32, //NULL terminated
glyphs.as_ptr(),
glyphs.len() as c_int,
clusters.as_ptr(),
Expand Down
5 changes: 3 additions & 2 deletions cairo/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::fmt::{self, Debug};
use std::i32;
use std::u32;

use error::Error;
use ffi;

#[cfg(feature = "use_glib")]
Expand Down Expand Up @@ -1409,13 +1410,13 @@ impl fmt::Display for Format {
gvalue_impl!(Format, ffi::gobject::cairo_gobject_format_get_type);

impl Format {
pub fn stride_for_width(self, width: u32) -> Result<i32, ()> {
pub fn stride_for_width(self, width: u32) -> Result<i32, Error> {
assert!(width <= i32::MAX as u32);
let width = width as i32;

let stride = unsafe { ffi::cairo_format_stride_for_width(self.into(), width) };
if stride == -1 {
Err(())
Err(Error::InvalidFormat)
} else {
Ok(stride)
}
Expand Down
4 changes: 3 additions & 1 deletion cairo/src/font/font_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ impl FontOptions {
let v = CString::new(*v).unwrap();
ffi::cairo_font_options_set_variations(self.to_raw_none(), v.as_ptr())
}
None => ffi::cairo_font_options_set_variations(self.to_raw_none(), 0 as *const _),
None => {
ffi::cairo_font_options_set_variations(self.to_raw_none(), std::ptr::null())
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions cairo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
//! * **win32-surface** - Microsoft Windows surface support

#![cfg_attr(feature = "dox", feature(doc_cfg))]
#![allow(clippy::missing_safety_doc)]

pub extern crate cairo_sys as ffi;
extern crate libc;
Expand Down
15 changes: 7 additions & 8 deletions cairo/src/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ mod tests {
Context::new(&surface)
}

fn assert_path_equals_segments(expected: &Path, actual: &Vec<PathSegment>) {
fn assert_path_equals_segments(expected: &Path, actual: &[PathSegment]) {
// First ensure the lengths are equal

let expected_iter = expected.iter();
Expand All @@ -151,9 +151,8 @@ mod tests {
let expected_iter = expected.iter();
let actual_iter = actual.iter();

let mut iter = expected_iter.zip(actual_iter);

while let Some((e, a)) = iter.next() {
let iter = expected_iter.zip(actual_iter);
for (e, a) in iter {
assert_eq!(e, *a);
}
}
Expand All @@ -175,7 +174,7 @@ mod tests {

let path = cr.copy_path();

assert_path_equals_segments(&path, &vec![PathSegment::MoveTo((1.0, 2.0))]);
assert_path_equals_segments(&path, &[PathSegment::MoveTo((1.0, 2.0))]);
}

#[test]
Expand All @@ -190,7 +189,7 @@ mod tests {

assert_path_equals_segments(
&path,
&vec![
&[
PathSegment::MoveTo((1.0, 2.0)),
PathSegment::LineTo((3.0, 4.0)),
PathSegment::MoveTo((5.0, 6.0)),
Expand All @@ -212,7 +211,7 @@ mod tests {
// from the extra moveto.
assert_path_equals_segments(
&path,
&vec![
&[
PathSegment::MoveTo((1.0, 2.0)),
PathSegment::ClosePath,
PathSegment::MoveTo((1.0, 2.0)),
Expand All @@ -232,7 +231,7 @@ mod tests {

assert_path_equals_segments(
&path,
&vec![
&[
PathSegment::MoveTo((1.0, 2.0)),
PathSegment::CurveTo((3.0, 4.0), (5.0, 6.0), (7.0, 8.0)),
PathSegment::ClosePath,
Expand Down
2 changes: 1 addition & 1 deletion cairo/src/svg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ mod test {

impl io::Write for CustomWriter {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
self.1.write(buf)?;
self.1.write_all(buf)?;

self.0 += buf.len();
Ok(buf.len())
Expand Down
3 changes: 2 additions & 1 deletion cairo/sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
// Licensed under the MIT license, see the LICENSE file or <https://opensource.org/licenses/MIT>

#![allow(non_camel_case_types)]
#![cfg_attr(feature = "cargo-clippy", allow(unreadable_literal, write_literal))]
#![allow(clippy::unreadable_literal)]
#![allow(clippy::write_literal)]

extern crate libc;

Expand Down
1 change: 1 addition & 0 deletions examples/src/bin/basic_subclass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ glib_wrapper! {
}

impl SimpleApplication {
#[allow(clippy::new_without_default)]
pub fn new() -> Self {
glib::Object::new(
Self::static_type(),
Expand Down
36 changes: 18 additions & 18 deletions examples/src/bin/clipboard_simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ fn build_ui(application: &gtk::Application) {
// Save out UI in thread-local storage so we can use it in callbacks later
GLOBAL.with(move |global| {
*global.borrow_mut() = Some(Ui {
button_a1: button_a1,
button_a2: button_a2,
button_b1: button_b1,
button_b2: button_b2,
button_a1,
button_a2,
button_b1,
button_b2,
})
});

Expand All @@ -82,24 +82,24 @@ fn build_ui(application: &gtk::Application) {
GLOBAL.with(|global| {
if let Some(ref ui) = *global.borrow() {
if ui.button_a1.get_active() {
s.push_str("1");
s.push('1');
} else {
s.push_str("0");
s.push('0');
}
if ui.button_a2.get_active() {
s.push_str("1");
s.push('1');
} else {
s.push_str("0");
s.push('0');
}
if ui.button_b1.get_active() {
s.push_str("1");
s.push('1');
} else {
s.push_str("0");
s.push('0');
}
if ui.button_b2.get_active() {
s.push_str("1");
s.push('1');
} else {
s.push_str("0");
s.push('0');
}
}
});
Expand All @@ -109,15 +109,15 @@ fn build_ui(application: &gtk::Application) {
paste_button.connect_clicked(|_| {
let clipboard = gtk::Clipboard::get(&gdk::SELECTION_CLIPBOARD);
clipboard.request_text(|_, t| {
if t.is_some() {
let t = t.unwrap();
if let Some(t) = t {
let t = t.chars().collect::<Vec<_>>();
if t.len() >= 4 {
GLOBAL.with(|global| {
if let Some(ref ui) = *global.borrow() {
ui.button_a1.set_active(t.chars().nth(0).unwrap() == '1');
ui.button_a2.set_active(t.chars().nth(1).unwrap() == '1');
ui.button_b1.set_active(t.chars().nth(2).unwrap() == '1');
ui.button_b2.set_active(t.chars().nth(3).unwrap() == '1');
ui.button_a1.set_active(t[0] == '1');
ui.button_a2.set_active(t[1] == '1');
ui.button_b1.set_active(t[2] == '1');
ui.button_b2.set_active(t[3] == '1');
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion examples/src/bin/gio_futures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn read_and_print_file(
) -> impl Future<Output = Result<(), String>> + std::marker::Unpin {
file.read_async_future(glib::PRIORITY_DEFAULT)
.map_err(|err| format!("Failed to open file: {}", err))
.and_then(|strm| read_and_print_chunks(strm))
.and_then(read_and_print_chunks)
}

// Read the input stream in chunks of 64 bytes, always into the same buffer
Expand Down
2 changes: 1 addition & 1 deletion examples/src/bin/iconview_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ fn create_list_store_model() -> gtk::ListStore {
}
}

return icon_view_model;
icon_view_model
}

fn build_ui(application: &gtk::Application) {
Expand Down
10 changes: 8 additions & 2 deletions examples/src/bin/list_store.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use gio::prelude::*;
use glib::clone;
use gtk::prelude::*;

use std::env::args;
Expand Down Expand Up @@ -51,8 +52,13 @@ fn build_ui(application: &gtk::Application) {

window.show_all();

let model = model.clone();
glib::timeout_add_local(Duration::from_millis(80), move || spinner_timeout(&model));
glib::timeout_add_local(
Duration::from_millis(80),
clone!(@weak model => @default-return glib::Continue(false), move || {
spinner_timeout(&model);
glib::Continue(false)
}),
);
}

struct Data {
Expand Down
6 changes: 3 additions & 3 deletions examples/src/bin/listbox_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,12 +300,12 @@ mod row_data {
}
}

fn get_property(&self, _obj: &Self::Type, id: usize) -> Result<glib::Value, ()> {
fn get_property(&self, _obj: &Self::Type, id: usize) -> glib::Value {
let prop = &PROPERTIES[id];

match *prop {
subclass::Property("name", ..) => Ok(self.name.borrow().to_value()),
subclass::Property("count", ..) => Ok(self.count.borrow().to_value()),
subclass::Property("name", ..) => self.name.borrow().to_value(),
subclass::Property("count", ..) => self.count.borrow().to_value(),
_ => unimplemented!(),
}
}
Expand Down
1 change: 0 additions & 1 deletion examples/src/bin/notebook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ impl Notebook {
let tab = gtk::Box::new(Orientation::Horizontal, 0);

button.set_relief(ReliefStyle::None);
button.set_focus_on_click(false);
button.add(&close_image);

tab.pack_start(&label, false, false, 0);
Expand Down
Loading

0 comments on commit ca08014

Please sign in to comment.