Skip to content

Commit

Permalink
chore(fmt): group_imports = "One", imports_granularity = "Crate" (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
kyu08 authored Jan 24, 2025
1 parent 929dd2a commit 27b99ca
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 37 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/fmt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup nightly rustfmt
run: |
rustup set profile minimal
rustup install nightly
rustup override set nightly
rustup component add rustfmt
- name: Check formatting
run: |
make fmt
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ curl-test:
ci: # Checks same as CI
@make test-ci; \
make check; \
make fmt; \
make fmt-check; \
make spell-check

.PHONY: tools
Expand Down Expand Up @@ -89,7 +89,11 @@ build:

.PHONY: fmt
fmt:
@cargo fmt -- --check
@cargo +nightly fmt

.PHONY: fmt-check
fmt-check:
@cargo +nightly fmt -- --check

.PHONY: check
check:
Expand Down
2 changes: 2 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
edition = "2021"
max_width = 120
fn_call_width = 120
imports_granularity = "Crate"
group_imports = "One"
6 changes: 2 additions & 4 deletions src/controller/controller_main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use crate::usecase::fzf_make::FzfMake;
use crate::usecase::{fzf_make, help, history, invalid_arg, repeat, usecase_main, version};
use crate::usecase::{fzf_make, fzf_make::FzfMake, help, history, invalid_arg, repeat, usecase_main, version};
use colored::Colorize;
use std::sync::Arc;
use std::{collections::HashMap, env};
use std::{collections::HashMap, env, sync::Arc};

pub async fn run() {
let command_line_args = env::args().collect();
Expand Down
3 changes: 1 addition & 2 deletions src/file/toml_old.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ pub fn parse_history(content: String) -> Result<fzf_make_toml::Histories> {
#[cfg(test)]
mod test {
use super::*;
use crate::file::toml as fzf_make_toml;
use crate::model::runner_type;
use crate::{file::toml as fzf_make_toml, model::runner_type};
use pretty_assertions::assert_eq;

#[test]
Expand Down
7 changes: 2 additions & 5 deletions src/model/js_package_manager/pnpm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,7 @@ impl Pnpm {
// 3. Collect all scripts defined in given `package.json` paths.
fn collect_workspace_scripts(current_dir: PathBuf) -> Option<Vec<command::Command>> {
// Collect scripts defined in package.json in the current directory(which fzf-make is launched)
let mut result = match Self::collect_scripts_in_package_json(current_dir.clone()) {
Some(result) => result,
None => return None,
};
let mut result = Self::collect_scripts_in_package_json(current_dir.clone())?;

// Collect the paths of all `package.json` in the workspace.
let workspace_package_json_paths = match Self::get_workspace_packages() {
Expand Down Expand Up @@ -153,7 +150,7 @@ impl Pnpm {

let output = String::from_utf8(output.stdout)?;
// split by newline to remove unnecessary lines.
let lines = output.split("\n").filter(|l| !l.is_empty()).collect::<Vec<&str>>();
let lines = output.split('\n').filter(|l| !l.is_empty()).collect::<Vec<&str>>();

Ok(lines
.iter()
Expand Down
7 changes: 2 additions & 5 deletions src/model/js_package_manager/yarn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,7 @@ impl Yarn {
// 3. Collect all scripts defined in given `package.json` paths.
fn collect_workspace_scripts(current_dir: PathBuf) -> Option<Vec<command::Command>> {
// Collect scripts defined in package.json in the current directory(which fzf-make is launched)
let mut result = match Self::collect_scripts_in_package_json(current_dir.clone()) {
Some(result) => result,
None => return None,
};
let mut result = Self::collect_scripts_in_package_json(current_dir.clone())?;

// Collect the paths of all `package.json` in the workspace.
let package_json_in_workspace = match Self::get_yarn_version() {
Expand Down Expand Up @@ -238,7 +235,7 @@ impl Yarn {
*/

// split by newline to remove unnecessary lines.
let lines = output.split("\n").collect::<Vec<&str>>();
let lines = output.split('\n').collect::<Vec<&str>>();

// remove the first and last line and the second line from the end.
match lines.get(1..(lines.len() - 2)) {
Expand Down
2 changes: 1 addition & 1 deletion src/model/just/just_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ impl Just {
if recipe_child.kind() == "recipe_header" {
// `recipe_name` has format like: `fmt:`
let recipe_name = &source_code[recipe_child.byte_range()];
let trimmed = recipe_name.split(":").collect::<Vec<&str>>();
let trimmed = recipe_name.split(':').collect::<Vec<&str>>();
if let Some(r) = trimmed.first() {
commands.push(Command::new(
RunnerType::Just,
Expand Down
2 changes: 1 addition & 1 deletion src/model/make/make_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use super::target::*;
use crate::model::{command, file_util};
use anyhow::{anyhow, Result};
use regex::Regex;
use std::process;
use std::{
fs,
path::{Path, PathBuf},
process,
};

/// Make represents a Makefile.
Expand Down
6 changes: 4 additions & 2 deletions src/model/runner_type.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use super::{js_package_manager::js_package_manager_main as js, runner};
use serde::de::{self};
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use serde::{
de::{self},
Deserialize, Deserializer, Serialize, Serializer,
};
use std::fmt;

#[derive(Hash, PartialEq, Debug, Clone, Eq)]
Expand Down
6 changes: 2 additions & 4 deletions src/usecase/fzf_make.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use super::tui::config;
use crate::usecase::tui::app;
use crate::usecase::usecase_main::Usecase;
use crate::usecase::{tui::app, usecase_main::Usecase};
use anyhow::Result;
use futures::future::BoxFuture;
use futures::FutureExt;
use futures::{future::BoxFuture, FutureExt};

pub struct FzfMake;

Expand Down
3 changes: 2 additions & 1 deletion src/usecase/tui/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ use std::{
collections::HashMap,
env,
io::{self, Stderr},
panic::AssertUnwindSafe,
path::PathBuf,
sync::{Arc, Mutex},
time::Duration,
};
use std::{panic::AssertUnwindSafe, time::Duration};
use tokio::task;
use tui_textarea::TextArea;
use update_informer::{registry, Check};
Expand Down
22 changes: 13 additions & 9 deletions src/usecase/tui/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ use ratatui::{
Frame,
};
use rust_embed::RustEmbed;
use std::fs;
use std::fs::File;
use std::io::{BufRead, BufReader};
use std::path::PathBuf;
use syntect::easy::HighlightLines;
use syntect::highlighting::{Color as SColor, ThemeSet};
use syntect::parsing::SyntaxSet;
use std::{
fs,
fs::File,
io::{BufRead, BufReader},
path::PathBuf,
};
use syntect::{
easy::HighlightLines,
highlighting::{Color as SColor, ThemeSet},
parsing::SyntaxSet,
};
use syntect_tui::into_span;

pub fn ui(f: &mut Frame, model: &mut Model) {
Expand Down Expand Up @@ -92,7 +96,7 @@ fn render_preview_block(model: &SelectCommandState, f: &mut Frame, chunk: ratatu
.skip(start_index)
.take(end_index - start_index + 1)
// HACK: workaround for https://github.com/ratatui/ratatui/issues/876
.map(|line| line.unwrap().replace("\t", " "))
.map(|line| line.unwrap().replace('\t', " "))
.collect()
}
_ => vec![],
Expand Down Expand Up @@ -185,7 +189,7 @@ fn load_syntax_highlighting_theme() -> Result<PathBuf> {
let path = temp_dir.join(theme_file_name);
let content = Asset::get(theme_file_name).context("Failed to get embedded asset")?;

fs::write(&path, content.data).context("Failed to write asset file")?;
fs::write(path, content.data).context("Failed to write asset file")?;
fs::write(version_file, current_version).context("Failed to write version file")?;
}

Expand Down

0 comments on commit 27b99ca

Please sign in to comment.