Fix Clippy lints & GitHub Action improvements (#74)

* ci: improve

- run on all branches to test things
- no cargo color, it destroys actions-rs/cargo features
- update versions

* refactor(lint): fix clippy issues

* refactor(lint): fix more clippy issues
This commit is contained in:
EdJoPaTo 2021-11-14 18:59:56 +01:00 committed by Philip Mueller
parent a6984b0b84
commit dc127ed87a
8 changed files with 17 additions and 24 deletions

View File

@ -2,37 +2,30 @@ name: Rust
on: on:
push: push:
branches: [ master ]
pull_request: pull_request:
branches: [ master ]
env:
CARGO_TERM_COLOR: always
jobs: jobs:
build: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v1 - uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1 - uses: actions-rs/toolchain@v1
with: with:
toolchain: stable toolchain: stable
profile: minimal profile: minimal
override: true override: true
components: rustfmt, clippy components: rustfmt, clippy
- uses: actions-rs/cargo@v1.0.1 - uses: actions-rs/cargo@v1
name: Check format name: Check format
with: with:
command: fmt command: fmt
args: --all -- --check args: --all -- --check
- uses: actions-rs/cargo@v1.0.1 - uses: actions-rs/cargo@v1
name: Run clippy name: Run clippy
with: with:
command: clippy command: clippy
args: --all-targets --locked -- -D warnings args: --all-targets --locked -- -D warnings
- uses: actions-rs/cargo@v1.0.1 - uses: actions-rs/cargo@v1
name: Run tests name: Run tests
with: with:
command: test command: test

View File

@ -12,7 +12,7 @@ impl FromStr for AurHelper {
fn from_str(s: &str) -> anyhow::Result<Self> { fn from_str(s: &str) -> anyhow::Result<Self> {
match s { match s {
"yay" => Ok(AurHelper { "yay" => Ok(Self {
name: String::from("yay"), name: String::from("yay"),
package_name: String::from("yay-bin"), package_name: String::from("yay-bin"),
install_command: vec![ install_command: vec![

View File

@ -186,7 +186,7 @@ fn create(command: args::CreateCommand) -> anyhow::Result<()> {
let root_partition_base = storage_device.get_partition(constants::ROOT_PARTITION_INDEX)?; let root_partition_base = storage_device.get_partition(constants::ROOT_PARTITION_INDEX)?;
let encrypted_root = if let Some(cryptsetup) = &cryptsetup { let encrypted_root = if let Some(cryptsetup) = &cryptsetup {
info!("Encrypting the root filesystem"); info!("Encrypting the root filesystem");
EncryptedDevice::prepare(&cryptsetup, &root_partition_base)?; EncryptedDevice::prepare(cryptsetup, &root_partition_base)?;
Some(EncryptedDevice::open( Some(EncryptedDevice::open(
cryptsetup, cryptsetup,
&root_partition_base, &root_partition_base,

View File

@ -33,7 +33,7 @@ fn visit_dirs(dir: &Path, filevec: &mut Vec<PathBuf>) -> Result<(), io::Error> {
impl Preset { impl Preset {
fn load(path: &Path) -> anyhow::Result<Self> { fn load(path: &Path) -> anyhow::Result<Self> {
let data = fs::read_to_string(path).with_context(|| format!("{}", path.display()))?; let data = fs::read_to_string(path).with_context(|| format!("{}", path.display()))?;
Ok(toml::from_str(&data).with_context(|| format!("{}", path.display()))?) toml::from_str(&data).with_context(|| format!("{}", path.display()))
} }
fn process( fn process(
@ -41,7 +41,7 @@ impl Preset {
packages: &mut HashSet<String>, packages: &mut HashSet<String>,
scripts: &mut Vec<Script>, scripts: &mut Vec<Script>,
environment_variables: &mut HashSet<String>, environment_variables: &mut HashSet<String>,
path: &PathBuf, path: &Path,
aur_packages: &mut HashSet<String>, aur_packages: &mut HashSet<String>,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
if let Some(preset_packages) = &self.packages { if let Some(preset_packages) = &self.packages {
@ -111,7 +111,7 @@ impl PresetsCollection {
// Build vector of paths to files, then sort by path name // Build vector of paths to files, then sort by path name
// Recursively load directories of preset files // Recursively load directories of preset files
let mut dir_paths: Vec<PathBuf> = Vec::new(); let mut dir_paths: Vec<PathBuf> = Vec::new();
visit_dirs(&preset, &mut dir_paths) visit_dirs(preset, &mut dir_paths)
.with_context(|| format!("{}", preset.display()))?; .with_context(|| format!("{}", preset.display()))?;
// Order not guaranteed so we sort // Order not guaranteed so we sort
@ -128,11 +128,11 @@ impl PresetsCollection {
)?; )?;
} }
} else { } else {
Preset::load(&preset)?.process( Preset::load(preset)?.process(
&mut packages, &mut packages,
&mut scripts, &mut scripts,
&mut environment_variables, &mut environment_variables,
&preset, preset,
&mut aur_packages, &mut aur_packages,
)?; )?;
} }
@ -151,8 +151,8 @@ impl PresetsCollection {
Ok(Self { Ok(Self {
packages, packages,
scripts,
aur_packages, aur_packages,
scripts,
}) })
} }
} }

View File

@ -30,7 +30,7 @@ impl LoopDevice {
); );
info!("Mounted {} to {}", file.display(), path.display()); info!("Mounted {} to {}", file.display(), path.display());
Ok(LoopDevice { path, losetup }) Ok(Self { path, losetup })
} }
pub fn path(&self) -> &Path { pub fn path(&self) -> &Path {

View File

@ -68,7 +68,7 @@ pub fn get_storage_devices(allow_non_removable: bool) -> anyhow::Result<Vec<Devi
.context("Could not parse block size to unsigned integer (u128)")? .context("Could not parse block size to unsigned integer (u128)")?
* 512, * 512,
), ),
}) });
} }
Ok(result) Ok(result)

View File

@ -21,7 +21,7 @@ impl<'a> StorageDevice<'a> {
.context("Error querying information about the block device")?; .context("Error querying information about the block device")?;
let device_name = path let device_name = path
.file_name() .file_name()
.and_then(|s| s.to_str()) .and_then(std::ffi::OsStr::to_str)
.map(String::from) .map(String::from)
.ok_or_else(|| anyhow!("Invalid device name: {}", path.display()))?; .ok_or_else(|| anyhow!("Invalid device name: {}", path.display()))?;

View File

@ -20,7 +20,7 @@ pub fn mount<'a>(
info!("Mounting filesystems to {}", mount_path.display()); info!("Mounting filesystems to {}", mount_path.display());
mount_stack mount_stack
.mount(&root_filesystem, mount_path.into(), None) .mount(root_filesystem, mount_path.into(), None)
.with_context(|| format!("Error mounting filesystem to {}", mount_path.display()))?; .with_context(|| format!("Error mounting filesystem to {}", mount_path.display()))?;
let boot_point = mount_path.join("boot"); let boot_point = mount_path.join("boot");
@ -29,7 +29,7 @@ pub fn mount<'a>(
} }
mount_stack mount_stack
.mount(&boot_filesystem, boot_point, None) .mount(boot_filesystem, boot_point, None)
.context("Error mounting the boot point")?; .context("Error mounting the boot point")?;
Ok(mount_stack) Ok(mount_stack)