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

Turn on linter (clippy) #12

Merged
merged 3 commits into from
Feb 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ language: rust
rust:
- nightly
script:
- cargo build
- cargo build # Linter is also executed here
- RUST_BACKTRACE=1 cargo test
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "foxbox"
version = "0.1.0"
authors = ["fabrice <fabrice@desre.org>"]
build = "build.rs"

[dependencies]
getopts = "0.2.14"
Expand All @@ -15,3 +16,4 @@ serde = "0.6.11"
serde_json = "0.6.0"
serde_macros = "0.6.11"
uuid = "0.1.18"
clippy = "0.0.37"
15 changes: 15 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use std::env;
use std::fs;
use std::path::Path;

fn update_local_git_hook() {
let p = env::current_dir().unwrap();
let origin_path = Path::new(&p).join("./tools/pre-commit");
let dest_path = Path::new(&p).join(".git/hooks/pre-commit");

fs::copy(&origin_path, &dest_path).unwrap();
}

fn main() {
update_local_git_hook();
}
6 changes: 3 additions & 3 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,16 @@ fn test_should_add_a_service() {
fn get_properties(&self) -> ServiceProperties {
ServiceProperties {
id: '1'.to_string(),
name: "dummy service".to_string(),
description: "really nothing to see".to_string(),
name: "dummy service".to_owned(),
description: "really nothing to see".to_owned(),
http_url: '2'.to_string(),
ws_url: '3'.to_string()
}
}
fn start(&self) {}
fn stop(&self) {}
fn process_request(&self, req: &Request) -> IronResult<Response> {
return Ok(Response::new());
Ok(Response::new())
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
// Needed for IntoIter in context.rs
#![feature(collections)]

// Make linter fail for every warning
#![plugin(clippy)]
#![deny(clippy)]

extern crate core;
extern crate getopts;
#[macro_use]
Expand Down
28 changes: 28 additions & 0 deletions tools/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

CARGO_EXECUTABLE="cargo"
CARGO_COMMAND="build"

hash cargo > /dev/null 2>&1
if [ $? -eq 1 ];
then
echo >&2 "You should install cargo to lint your patch"
echo >&2 "https://crates.io/install"
exit 0
fi

rs_changed_files=`git diff --staged --name-only --diff-filter=ACMRT | grep '\.rs$'`
if [ -n "$rs_changed_files" ]
then

echo "clippy check:"

$CARGO_EXECUTABLE $CARGO_COMMAND
cargot_result=$?

if [ $cargot_result -ne 0 ] ; then
echo "There were errors while linting the files, please see above."
exit 1
fi

fi