mirror of
https://github.com/italicsjenga/valence.git
synced 2024-12-23 22:41:30 +11:00
Add clippy lints and format checks (#46)
The nightly rust toolchain is used because we are currently using unstable rustfmt settings.
This commit is contained in:
parent
4920defe3e
commit
fdedf74d29
12
.github/workflows/rust.yml
vendored
12
.github/workflows/rust.yml
vendored
|
@ -20,7 +20,13 @@ jobs:
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- name: Build on ${{ matrix.os }}
|
- uses: dtolnay/rust-toolchain@nightly
|
||||||
run: cargo build --verbose
|
with:
|
||||||
|
components: clippy, rustfmt
|
||||||
|
|
||||||
|
- name: Validate formatting on ${{ matrix.os }}
|
||||||
|
run: cargo fmt --all -- --check
|
||||||
|
- name: Run clippy lints on ${{ matrix.os }}
|
||||||
|
run: cargo +stable clippy --verbose --no-deps --all-features
|
||||||
- name: Run tests on ${{ matrix.os }}
|
- name: Run tests on ${{ matrix.os }}
|
||||||
run: cargo test --verbose
|
run: cargo +stable test --verbose --all-features
|
||||||
|
|
|
@ -547,7 +547,8 @@ impl<C: Config> Client<C> {
|
||||||
/// Sets the XP bar visible above hotbar and total experience.
|
/// Sets the XP bar visible above hotbar and total experience.
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
/// * `bar` - Floating value in the range `0.0..=1.0` indicating progress on the XP bar.
|
/// * `bar` - Floating value in the range `0.0..=1.0` indicating progress on
|
||||||
|
/// the XP bar.
|
||||||
/// * `level` - Number above the XP bar.
|
/// * `level` - Number above the XP bar.
|
||||||
/// * `total_xp` - TODO.
|
/// * `total_xp` - TODO.
|
||||||
pub fn set_level(&mut self, bar: f32, level: i32, total_xp: i32) {
|
pub fn set_level(&mut self, bar: f32, level: i32, total_xp: i32) {
|
||||||
|
@ -562,7 +563,8 @@ impl<C: Config> Client<C> {
|
||||||
/// You can read more about hunger and saturation [here](https://minecraft.fandom.com/wiki/Food#Hunger_vs._Saturation).
|
/// You can read more about hunger and saturation [here](https://minecraft.fandom.com/wiki/Food#Hunger_vs._Saturation).
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
/// * `health` - Float in range `0.0..=20.0`. Value `<=0` is legal and will kill the player.
|
/// * `health` - Float in range `0.0..=20.0`. Value `<=0` is legal and will
|
||||||
|
/// kill the player.
|
||||||
/// * `food` - Integer in range `0..=20`.
|
/// * `food` - Integer in range `0..=20`.
|
||||||
/// * `food_saturation` - Float in range `0.0..=5.0`.
|
/// * `food_saturation` - Float in range `0.0..=5.0`.
|
||||||
pub fn set_health_and_food(&mut self, health: f32, food: i32, food_saturation: f32) {
|
pub fn set_health_and_food(&mut self, health: f32, food: i32, food_saturation: f32) {
|
||||||
|
|
|
@ -652,13 +652,13 @@ impl From<EntitySpawnPacket> for S2cPlayPacket {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::num::NonZeroU32;
|
use std::num::NonZeroU32;
|
||||||
|
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use super::{Entities, EntityId, EntityKind};
|
use super::{Entities, EntityId, EntityKind};
|
||||||
use crate::{
|
use crate::config::Config;
|
||||||
config::Config,
|
use crate::server::Server;
|
||||||
slab_versioned::Key,
|
use crate::slab_versioned::Key;
|
||||||
server::Server
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Created for the sole purpose of use during unit tests.
|
/// Created for the sole purpose of use during unit tests.
|
||||||
struct MockConfig;
|
struct MockConfig;
|
||||||
|
@ -670,8 +670,10 @@ mod tests {
|
||||||
type ChunkState = ();
|
type ChunkState = ();
|
||||||
type PlayerListState = ();
|
type PlayerListState = ();
|
||||||
|
|
||||||
fn max_connections(&self) -> usize { 10 }
|
fn max_connections(&self) -> usize {
|
||||||
fn update(&self, _server: &mut Server<Self>) { }
|
10
|
||||||
|
}
|
||||||
|
fn update(&self, _server: &mut Server<Self>) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -680,7 +682,7 @@ mod tests {
|
||||||
let network_id: i32 = 8675309;
|
let network_id: i32 = 8675309;
|
||||||
let entity_id = EntityId(Key::new(
|
let entity_id = EntityId(Key::new(
|
||||||
202298,
|
202298,
|
||||||
NonZeroU32::new(network_id as u32).expect("Value given should never be zero!")
|
NonZeroU32::new(network_id as u32).expect("Value given should never be zero!"),
|
||||||
));
|
));
|
||||||
let uuid = Uuid::from_bytes([2; 16]);
|
let uuid = Uuid::from_bytes([2; 16]);
|
||||||
assert!(entities.is_empty());
|
assert!(entities.is_empty());
|
||||||
|
@ -697,7 +699,8 @@ mod tests {
|
||||||
let (player_id, player_entity) = entities.insert(EntityKind::Player, 1);
|
let (player_id, player_entity) = entities.insert(EntityKind::Player, 1);
|
||||||
assert_eq!(player_entity.state, 1);
|
assert_eq!(player_entity.state, 1);
|
||||||
assert_eq!(entities.get(player_id).unwrap().state, 1);
|
assert_eq!(entities.get(player_id).unwrap().state, 1);
|
||||||
let mut_player_entity = entities.get_mut(player_id)
|
let mut_player_entity = entities
|
||||||
|
.get_mut(player_id)
|
||||||
.expect("Failed to get mutable reference");
|
.expect("Failed to get mutable reference");
|
||||||
mut_player_entity.state = 100;
|
mut_player_entity.state = 100;
|
||||||
assert_eq!(entities.get(player_id).unwrap().state, 100);
|
assert_eq!(entities.get(player_id).unwrap().state, 100);
|
||||||
|
@ -709,10 +712,12 @@ mod tests {
|
||||||
let mut entities: Entities<MockConfig> = Entities::new();
|
let mut entities: Entities<MockConfig> = Entities::new();
|
||||||
let uuid = Uuid::from_bytes([2; 16]);
|
let uuid = Uuid::from_bytes([2; 16]);
|
||||||
assert!(entities.is_empty());
|
assert!(entities.is_empty());
|
||||||
let (zombie_id, zombie_entity) = entities.insert_with_uuid(EntityKind::Zombie, uuid, 1)
|
let (zombie_id, zombie_entity) = entities
|
||||||
|
.insert_with_uuid(EntityKind::Zombie, uuid, 1)
|
||||||
.expect("Unexpected Uuid collision when inserting to an empty collection");
|
.expect("Unexpected Uuid collision when inserting to an empty collection");
|
||||||
assert_eq!(zombie_entity.state, 1);
|
assert_eq!(zombie_entity.state, 1);
|
||||||
let maybe_zombie = entities.get_with_uuid(uuid)
|
let maybe_zombie = entities
|
||||||
|
.get_with_uuid(uuid)
|
||||||
.expect("Uuid lookup failed on item already added to this collection");
|
.expect("Uuid lookup failed on item already added to this collection");
|
||||||
assert_eq!(zombie_id, maybe_zombie);
|
assert_eq!(zombie_id, maybe_zombie);
|
||||||
assert_eq!(entities.len(), 1);
|
assert_eq!(entities.len(), 1);
|
||||||
|
@ -726,14 +731,18 @@ mod tests {
|
||||||
assert_eq!(boat_entity.state, 12);
|
assert_eq!(boat_entity.state, 12);
|
||||||
let (cat_id, cat_entity) = entities.insert(EntityKind::Cat, 75);
|
let (cat_id, cat_entity) = entities.insert(EntityKind::Cat, 75);
|
||||||
assert_eq!(cat_entity.state, 75);
|
assert_eq!(cat_entity.state, 75);
|
||||||
let maybe_boat_id = entities.get_with_network_id(boat_id.0.version.get() as i32)
|
let maybe_boat_id = entities
|
||||||
|
.get_with_network_id(boat_id.0.version.get() as i32)
|
||||||
.expect("Network id lookup failed on item already added to this collection");
|
.expect("Network id lookup failed on item already added to this collection");
|
||||||
let maybe_boat = entities.get(maybe_boat_id)
|
let maybe_boat = entities
|
||||||
|
.get(maybe_boat_id)
|
||||||
.expect("Failed to look up item already added to collection");
|
.expect("Failed to look up item already added to collection");
|
||||||
assert_eq!(maybe_boat.state, 12);
|
assert_eq!(maybe_boat.state, 12);
|
||||||
let maybe_cat_id = entities.get_with_network_id(cat_id.0.version.get() as i32)
|
let maybe_cat_id = entities
|
||||||
|
.get_with_network_id(cat_id.0.version.get() as i32)
|
||||||
.expect("Network id lookup failed on item already added to this collection");
|
.expect("Network id lookup failed on item already added to this collection");
|
||||||
let maybe_cat = entities.get(maybe_cat_id)
|
let maybe_cat = entities
|
||||||
|
.get(maybe_cat_id)
|
||||||
.expect("Failed to look up item already added to collection");
|
.expect("Failed to look up item already added to collection");
|
||||||
assert_eq!(maybe_cat.state, 75);
|
assert_eq!(maybe_cat.state, 75);
|
||||||
assert_eq!(entities.len(), 2);
|
assert_eq!(entities.len(), 2);
|
||||||
|
@ -744,7 +753,8 @@ mod tests {
|
||||||
let mut entities: Entities<MockConfig> = Entities::new();
|
let mut entities: Entities<MockConfig> = Entities::new();
|
||||||
assert!(entities.is_empty());
|
assert!(entities.is_empty());
|
||||||
let (player_id, _) = entities.insert(EntityKind::Player, 1);
|
let (player_id, _) = entities.insert(EntityKind::Player, 1);
|
||||||
let player_state = entities.remove(player_id)
|
let player_state = entities
|
||||||
|
.remove(player_id)
|
||||||
.expect("Failed to remove an item from the collection");
|
.expect("Failed to remove an item from the collection");
|
||||||
assert_eq!(player_state, 1);
|
assert_eq!(player_state, 1);
|
||||||
}
|
}
|
||||||
|
@ -759,7 +769,7 @@ mod tests {
|
||||||
let (goat_id, _) = entities.insert(EntityKind::Goat, 120);
|
let (goat_id, _) = entities.insert(EntityKind::Goat, 120);
|
||||||
let (horse_id, _) = entities.insert(EntityKind::Horse, 30);
|
let (horse_id, _) = entities.insert(EntityKind::Horse, 30);
|
||||||
assert_eq!(entities.len(), 5);
|
assert_eq!(entities.len(), 5);
|
||||||
entities.retain(|_id, entity| entity.state > 100 );
|
entities.retain(|_id, entity| entity.state > 100);
|
||||||
assert_eq!(entities.len(), 2);
|
assert_eq!(entities.len(), 2);
|
||||||
assert!(entities.get(fox_id).is_some());
|
assert!(entities.get(fox_id).is_some());
|
||||||
assert!(entities.get(goat_id).is_some());
|
assert!(entities.get(goat_id).is_some());
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
//! Namespaced identifiers.
|
//! Namespaced identifiers.
|
||||||
//!
|
|
||||||
//!
|
|
||||||
|
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use byteorder::ReadBytesExt;
|
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
|
||||||
|
use byteorder::ReadBytesExt;
|
||||||
|
|
||||||
use crate::nbt::Compound;
|
use crate::nbt::Compound;
|
||||||
use crate::protocol::{Decode, Encode, VarInt};
|
use crate::protocol::{Decode, Encode, VarInt};
|
||||||
|
|
||||||
|
@ -58,9 +59,10 @@ impl Decode for Slot {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
|
||||||
use serde_nbt::Value;
|
use serde_nbt::Value;
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn slot_with_nbt() {
|
fn slot_with_nbt() {
|
||||||
let mut buf: Vec<u8> = Vec::new();
|
let mut buf: Vec<u8> = Vec::new();
|
||||||
|
|
Loading…
Reference in a new issue