Skip to content

Commit

Permalink
Setup rustfmt.
Browse files Browse the repository at this point in the history
Included .rustfmt.toml allows `cargo fmt` to be run on `uom`.
Additionally the Travis CI build includes an additional job to validate
that any changes do not break formatting conventions. Resolves #80.
  • Loading branch information
iliekturtles committed May 29, 2018
1 parent e7d272e commit 80ef52c
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 21 deletions.
7 changes: 7 additions & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#comment_width = 100
#error_on_unformatted = true
#format_strings = true
#imports_indent = "Block"
#match_block_trailing_comma = true
newline_style = "Native"
#reorder_imports = true
9 changes: 8 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,18 @@ rust:
matrix:
allow_failures:
- rust: nightly
include:
- env: RUSTFMT
rust: 1.26.1
install:
- rustup component add rustfmt-preview
script:
- cargo fmt -- --write-mode=diff

before_script: |
test "${TRAVIS_RUST_VERSION//./_}" != "stable" ||
(test -x /home/travis/.cargo/bin/cargo-coveralls || cargo install cargo-travis) ||
(test $(grep "cargo-travis" /home/travis/.cargo/.crates.toml | sed -r "s/\"cargo-travis ([^\ ]+).+/\1/") = $(cargo search cargo-travis --limit 1 | sed -r "s/cargo-travis \(([^\)]+)\).+/\1/") || cargoo install cargo-travis --force)
(test $(grep "cargo-travis" /home/travis/.cargo/.crates.toml | sed -r "s/\"cargo-travis ([^\ ]+).+/\1/") = $(cargo search cargo-travis --limit 1 | sed -r "s/cargo-travis \(([^\)]+)\).+/\1/") || cargo install cargo-travis --force)
script: |
cargo build --verbose --no-default-features --features "autoconvert usize u8 u16 u32 u64 isize i8 i16 i32 i64 bigint biguint rational rational32 rational64 bigrational f32 f64 si std use_serde" &&
Expand Down
6 changes: 5 additions & 1 deletion examples/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ use uom::si::length::{centimeter, meter};
use uom::si::time::second;

mod cgs {
ISQ!(uom::si, f32, (centimeter, gram, second, ampere, kelvin, mole, candela));
ISQ!(
uom::si,
f32,
(centimeter, gram, second, ampere, kelvin, mole, candela)
);
}

fn main() {
Expand Down
2 changes: 1 addition & 1 deletion examples/mks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ system! {

mod f32 {
mod s {
pub use ::*;
pub use *;
}

Q!(f32::s, f32);
Expand Down
2 changes: 1 addition & 1 deletion examples/si.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
extern crate uom;

use uom::si::Unit;
use uom::si::f32::*;
use uom::si::length::{centimeter, kilometer, meter};
use uom::si::time::second;
use uom::si::velocity::{kilometer_per_second, meter_per_second};
use uom::si::Unit;

fn main() {
let l1 = Length::new::<meter>(15.0);
Expand Down
25 changes: 12 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
//! * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
//! <http://www.apache.org/licenses/LICENSE-2.0>)
//! * MIT license ([LICENSE-MIT](LICENSE-MIT) or <http://opensource.org/licenses/MIT>)
//!
//!
//! at your option.
//!
//! [BIPM]: http://www.bipm.org/en/about-us/
Expand All @@ -146,23 +146,21 @@
// Compile with `no_std` when the `std` feature is not specified.
#![cfg_attr(not(feature = "std"), no_std)]

// Default rustc lints.
#![warn(
missing_copy_implementations,
missing_debug_implementations,
missing_docs,
trivial_casts,
trivial_numeric_casts,
unused_extern_crates,
unused_import_braces,
unused_qualifications,
unused_results)]

#![warn(missing_copy_implementations)]
#![warn(missing_debug_implementations)]
#![warn(missing_docs)]
#![warn(trivial_casts)]
#![warn(trivial_numeric_casts)]
#![warn(unused_extern_crates)]
#![warn(unused_import_braces)]
#![warn(unused_qualifications)]
#![warn(unused_results)]
// Clippy lints.
#![cfg_attr(feature = "cargo-clippy", allow(inline_always))]

// Fail to compile if no underlying storage type features are specified.
#[cfg_attr(rustfmt, rustfmt_skip)]
#[cfg(not(any(
feature = "usize", feature = "u8", feature = "u16", feature = "u32", feature = "u64",
feature = "isize", feature = "i8", feature = "i16", feature = "i32", feature = "i64",
Expand Down Expand Up @@ -266,6 +264,7 @@ pub trait Conversion<V> {
/// Trait representing a [conversion factor][factor].
///
/// [factor]: https://jcgm.bipm.org/vim/en/1.24.html
#[cfg_attr(rustfmt, rustfmt_skip)]
pub trait ConversionFactor<V>
: lib::ops::Div<Self, Output = Self>
+ lib::ops::Mul<Self, Output = Self>
Expand Down
1 change: 1 addition & 0 deletions src/si/prefix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
/// [si]: http://jcgm.bipm.org/vim/en/1.16.html
/// [mult]: http://jcgm.bipm.org/vim/en/1.17.html
/// [submult]: http://jcgm.bipm.org/vim/en/1.18.html
#[cfg_attr(rustfmt, rustfmt_skip)]
#[macro_export]
macro_rules! prefix {
(yotta) => { 1.0E24 };
Expand Down
9 changes: 5 additions & 4 deletions src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use self::length::{kilometer, meter};
use self::mass::kilogram;
#[allow(unused_imports)]
use {Conversion, ConversionFactor};
use lib::fmt::Debug;
use lib::marker::PhantomData;
#[allow(unused_imports)]
use num::{Float, FromPrimitive, One, Saturating, Signed, Zero};
use quickcheck::TestResult;
use lib::fmt::Debug;
use lib::marker::PhantomData;
#[cfg(feature = "serde")]
use serde_json;
#[allow(unused_imports)]
use typenum::{N1, P1, P2, P3, Z0};
#[allow(unused_imports)]
use {Conversion, ConversionFactor};

#[macro_use]
mod length {
Expand Down Expand Up @@ -47,6 +47,7 @@ system! {
}

/// Test trait to allow tests to perform storage-type sensitive comparisons.
#[cfg_attr(rustfmt, rustfmt_skip)]
pub trait Test
: Debug
+ Sized
Expand Down

0 comments on commit 80ef52c

Please sign in to comment.