Skip to content

Commit

Permalink
Add clippy linting
Browse files Browse the repository at this point in the history
  • Loading branch information
qdm12 committed Jul 8, 2021
1 parent 04f41b1 commit 5cb5934
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ jobs:
steps:
- uses: actions/checkout@v2.3.4

- name: Lint
run: docker build --target lint

- name: Build test image
run: docker build --target test -t test-container .

Expand Down
123 changes: 123 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ http = "0.2"
tokio = { version = "1.0", features = ["macros", "rt"] }
prometheus_exporter_base = { version = "1.2", features = ["hyper_server"] }
regex = "1.5.4"

[dev-dependencies]
clippy = "*"
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ RUN rm -r \

COPY . .

FROM base AS lint
ENTRYPOINT \
RUSTFLAGS="$(cat /tmp/rustflags)" \
CC="$(cat /tmp/musl)-gcc" \
cargo clippy --target "$(cat /tmp/rusttarget)"

FROM base AS test
ENTRYPOINT \
RUSTFLAGS="$(cat /tmp/rustflags)" \
Expand Down
1 change: 1 addition & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# see https://rust-lang.github.io/rust-clippy/master/index.html
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
info!("using options: {:?}", options);

let bind = matches.value_of("port").unwrap();
let bind = u16::from_str_radix(&bind, 10).expect("port must be a valid number");
let bind = (&bind).parse::<u16>().expect("port must be a valid number");
let ip = matches.value_of("addr").unwrap().parse::<IpAddr>().unwrap();
let addr = (ip, bind).into();

Expand Down
11 changes: 5 additions & 6 deletions src/wireguard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ impl TryFrom<&str> for WireGuard {
if let Some(endpoints) = wg.interfaces.get_mut(v[0]) {
endpoints.push(endpoint);
} else {
let mut new_vec = Vec::new();
new_vec.push(endpoint);
let new_vec = vec![endpoint];
wg.interfaces.insert(v[0].to_owned(), new_vec);
}
}
Expand Down Expand Up @@ -212,10 +211,10 @@ impl WireGuard {
// store in attibutes their references. attributes_owned is onyl
// needed for separate ip+subnet
let mut attributes_owned: Vec<(String, String)> = Vec::new();
let mut attributes: Vec<(&str, &str)> = Vec::new();

attributes.push(("interface", interface));
attributes.push(("public_key", &ep.public_key));
let mut attributes: Vec<(&str, &str)> = vec![
("interface", interface),
("public_key", &ep.public_key),
];

if split_allowed_ips {
let v_ip_and_subnet: Vec<(&str, &str)> = ep
Expand Down

0 comments on commit 5cb5934

Please sign in to comment.