Skip to content
Open
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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fnmatch-regex2 = "0.3.0"
strip-ansi-escapes = "0.2.0"

[dev-dependencies]
assert_cmd = "2.0.10" # testing CLI
assert_cmd = "2.1.1" # testing CLI
rusty-hook = "^0.11.2" # git hooks
predicates = "3.0.2" # kind of like rspec assertions
pretty_assertions = "1.3.0" # Shows a more readable diff when comparing objects
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[toolchain]
channel = "1.83.0"
channel = "1.92.0"
components = ["clippy", "rustfmt"]
targets = ["x86_64-apple-darwin", "aarch64-apple-darwin", "x86_64-unknown-linux-gnu"]
6 changes: 2 additions & 4 deletions src/packs/checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,8 +517,7 @@ mod tests {
#[test]
fn test_write_violations() {
let chec_result = CheckAllResult {
reportable_violations: vec![
Violation {
reportable_violations: [Violation {
message: "foo/bar/file1.rb:10:5\nPrivacy violation: `::Foo::PrivateClass` is private to `foo`, but referenced from `bar`".to_string(),
identifier: ViolationIdentifier {
violation_type: "Privacy".to_string(),
Expand All @@ -539,8 +538,7 @@ mod tests {
referencing_pack_name: "foo".to_string(),
defining_pack_name: "bar".to_string(),
}
}
].iter().cloned().collect(),
}].iter().cloned().collect(),
stale_violations: Vec::new(),
strict_mode_violations: HashSet::new(),
};
Expand Down
2 changes: 1 addition & 1 deletion src/packs/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl Configuration {

pub(crate) fn constant_resolver_configuration(
&self,
) -> ConstantResolverConfiguration {
) -> ConstantResolverConfiguration<'_> {
ConstantResolverConfiguration {
absolute_root: &self.absolute_root,
cache_directory: &self.cache_directory,
Expand Down
6 changes: 4 additions & 2 deletions src/packs/creator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ pub fn create(
)?;

write_pack_to_disk(&new_pack)?;
let pack_name =
&name.split('/').last().context("unable to find pack name")?;
let pack_name = &name
.split('/')
.next_back()
.context("unable to find pack name")?;
std::fs::create_dir_all(new_pack_path.join("app/public/").join(pack_name))
.context(format!("failed to create app/public/{}", &name))?;
std::fs::create_dir_all(
Expand Down
4 changes: 2 additions & 2 deletions src/packs/file_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ pub fn get_file_type(path: &Path) -> Option<SupportedFileType> {

let is_ruby_file = ruby_extensions
.into_iter()
.any(|ext| extension.map_or(false, |e| e == ext))
.any(|ext| extension.is_some_and(|e| e == ext))
|| ruby_special_files.iter().any(|file| path.ends_with(file));

let is_erb_file = path.extension().map_or(false, |ext| ext == "erb");
let is_erb_file = path.extension().is_some_and(|ext| ext == "erb");

if is_ruby_file {
Some(SupportedFileType::Ruby)
Expand Down
4 changes: 1 addition & 3 deletions src/packs/parsing/ruby/parse_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,7 @@ pub fn get_reference_from_active_record_association(
.chain(ASSOCIATION_METHOD_NAMES.iter().copied().map(String::from))
.collect();

let is_association = combined_associations
.iter()
.any(|association_method| node.method_name == *association_method);
let is_association = combined_associations.contains(&node.method_name);

if is_association {
let first_arg: Option<&Node> = node.args.first();
Expand Down
2 changes: 1 addition & 1 deletion src/packs/parsing/ruby/rails_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ pub(crate) fn get_acronyms_from_disk(
let inflections_file =
std::fs::read_to_string(inflections_path).unwrap();
let inflections_lines = inflections_file.lines();
let re = Regex::new(r#"['\\"]"#).unwrap();
for line in inflections_lines {
if line.contains(".acronym") {
let re = Regex::new(r#"['\\"]"#).unwrap();
let acronym = re.split(line).nth(1).unwrap();
acronyms.insert(acronym.to_string());
}
Expand Down
6 changes: 3 additions & 3 deletions tests/add_constant_dependencies.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use assert_cmd::Command;
use assert_cmd::cargo::cargo_bin_cmd;
use predicates::prelude::*;
use pretty_assertions::assert_eq;
use serial_test::serial;
Expand All @@ -9,7 +9,7 @@ mod common;
#[test]
#[serial]
fn test_add_constant_dependencies() -> anyhow::Result<()> {
Command::cargo_bin("pks")?
cargo_bin_cmd!("pks")
.arg("--project-root")
.arg("tests/fixtures/app_with_missing_dependencies")
.arg("update-dependencies-for-constant")
Expand Down Expand Up @@ -43,7 +43,7 @@ fn test_add_constant_dependencies() -> anyhow::Result<()> {
#[test]
#[serial]
fn test_add_constant_dependencies_no_dependencies() -> anyhow::Result<()> {
Command::cargo_bin("pks")?
cargo_bin_cmd!("pks")
.arg("--project-root")
.arg("tests/fixtures/app_with_missing_dependencies")
.arg("update-dependencies-for-constant")
Expand Down
8 changes: 4 additions & 4 deletions tests/add_dependency_test.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use assert_cmd::Command;
use assert_cmd::cargo::cargo_bin_cmd;
use predicates::prelude::*;
use pretty_assertions::assert_eq;
use serial_test::serial;
Expand All @@ -9,7 +9,7 @@ mod common;
#[test]
#[serial]
fn test_add_dependency() -> Result<(), Box<dyn Error>> {
Command::cargo_bin("pks")?
cargo_bin_cmd!("pks")
.arg("--project-root")
.arg("tests/fixtures/app_with_missing_dependency")
.arg("add-dependency")
Expand Down Expand Up @@ -41,7 +41,7 @@ fn test_add_dependency() -> Result<(), Box<dyn Error>> {
#[test]
#[serial]
fn test_add_dependency_creating_cycle() -> Result<(), Box<dyn Error>> {
Command::cargo_bin("pks")?
cargo_bin_cmd!("pks")
.arg("--project-root")
.arg("tests/fixtures/app_with_missing_dependency")
.arg("add-dependency")
Expand Down Expand Up @@ -80,7 +80,7 @@ fn test_add_dependency_creating_cycle() -> Result<(), Box<dyn Error>> {

#[test]
fn test_add_dependency_unnecessarily() -> Result<(), Box<dyn Error>> {
Command::cargo_bin("pks")?
cargo_bin_cmd!("pks")
.arg("--project-root")
.arg("tests/fixtures/app_with_missing_dependency")
.arg("add-dependency")
Expand Down
45 changes: 19 additions & 26 deletions tests/check_test.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use assert_cmd::Command;
use assert_cmd::cargo::cargo_bin_cmd;
use predicates::prelude::*;
use std::{error::Error, fs};

Expand All @@ -11,7 +11,7 @@ pub fn stripped_output(output: Vec<u8>) -> String {
#[test]
fn test_check_with_privacy_dependency_error_template_overrides(
) -> Result<(), Box<dyn Error>> {
let output = Command::cargo_bin("pks")?
let output = cargo_bin_cmd!("pks")
.arg("--project-root")
.arg("tests/fixtures/privacy_violation_overrides")
.arg("--debug")
Expand All @@ -33,7 +33,7 @@ fn test_check_with_privacy_dependency_error_template_overrides(
}
#[test]
fn test_check() -> Result<(), Box<dyn Error>> {
let output = Command::cargo_bin("pks")?
let output = cargo_bin_cmd!("pks")
.arg("--project-root")
.arg("tests/fixtures/simple_app")
.arg("--debug")
Expand All @@ -56,7 +56,7 @@ fn test_check() -> Result<(), Box<dyn Error>> {

#[test]
fn test_check_enforce_privacy_disabled() -> Result<(), Box<dyn Error>> {
let output = Command::cargo_bin("pks")?
let output = cargo_bin_cmd!("pks")
.arg("--project-root")
.arg("tests/fixtures/simple_app")
.arg("--debug")
Expand All @@ -79,7 +79,7 @@ fn test_check_enforce_privacy_disabled() -> Result<(), Box<dyn Error>> {

#[test]
fn test_check_enforce_dependency_disabled() -> Result<(), Box<dyn Error>> {
let output = Command::cargo_bin("pks")?
let output = cargo_bin_cmd!("pks")
.arg("--project-root")
.arg("tests/fixtures/simple_app")
.arg("--debug")
Expand All @@ -102,7 +102,7 @@ fn test_check_enforce_dependency_disabled() -> Result<(), Box<dyn Error>> {

#[test]
fn test_check_with_single_file() -> Result<(), Box<dyn Error>> {
let output = Command::cargo_bin("pks")?
let output = cargo_bin_cmd!("pks")
.arg("--project-root")
.arg("tests/fixtures/simple_app")
.arg("--debug")
Expand All @@ -127,7 +127,7 @@ fn test_check_with_single_file() -> Result<(), Box<dyn Error>> {
#[test]
fn test_check_with_single_file_experimental_parser(
) -> Result<(), Box<dyn Error>> {
let output = Command::cargo_bin("pks")?
let output = cargo_bin_cmd!("pks")
.arg("--project-root")
.arg("tests/fixtures/simple_app")
.arg("--debug")
Expand All @@ -152,7 +152,7 @@ fn test_check_with_single_file_experimental_parser(

#[test]
fn test_check_with_package_todo_file() -> Result<(), Box<dyn Error>> {
Command::cargo_bin("pks")?
cargo_bin_cmd!("pks")
.arg("--project-root")
.arg("tests/fixtures/contains_package_todo")
.arg("--debug")
Expand All @@ -168,7 +168,7 @@ fn test_check_with_package_todo_file() -> Result<(), Box<dyn Error>> {

#[test]
fn test_check_with_package_todo_file_csv() -> Result<(), Box<dyn Error>> {
Command::cargo_bin("pks")?
cargo_bin_cmd!("pks")
.arg("--project-root")
.arg("tests/fixtures/contains_package_todo")
.arg("--debug")
Expand All @@ -188,7 +188,7 @@ fn test_check_with_package_todo_file_csv() -> Result<(), Box<dyn Error>> {
#[test]
fn test_check_with_package_todo_file_ignoring_recorded_violations(
) -> Result<(), Box<dyn Error>> {
let output = Command::cargo_bin("pks")?
let output = cargo_bin_cmd!("pks")
.arg("--project-root")
.arg("tests/fixtures/contains_package_todo")
.arg("--debug")
Expand All @@ -212,8 +212,7 @@ fn test_check_with_package_todo_file_ignoring_recorded_violations(

#[test]
fn test_check_with_experimental_parser() -> Result<(), Box<dyn Error>> {
let output = Command::cargo_bin("pks")
.unwrap()
let output = cargo_bin_cmd!("pks")
.arg("--project-root")
.arg("tests/fixtures/simple_app")
.arg("--experimental-parser")
Expand All @@ -237,8 +236,7 @@ fn test_check_with_experimental_parser() -> Result<(), Box<dyn Error>> {

#[test]
fn test_check_with_stale_violations() -> Result<(), Box<dyn Error>> {
Command::cargo_bin("pks")
.unwrap()
cargo_bin_cmd!("pks")
.arg("--project-root")
.arg("tests/fixtures/contains_stale_violations")
.arg("check")
Expand All @@ -255,8 +253,7 @@ fn test_check_with_stale_violations() -> Result<(), Box<dyn Error>> {
#[test]
fn test_check_with_stale_violations_when_file_no_longer_exists(
) -> Result<(), Box<dyn Error>> {
Command::cargo_bin("pks")
.unwrap()
cargo_bin_cmd!("pks")
.arg("--project-root")
.arg("tests/fixtures/contains_stale_violations_no_file")
.arg("check")
Expand All @@ -272,8 +269,7 @@ fn test_check_with_stale_violations_when_file_no_longer_exists(

#[test]
fn test_check_with_relationship_violations() -> Result<(), Box<dyn Error>> {
Command::cargo_bin("pks")
.unwrap()
cargo_bin_cmd!("pks")
.arg("--project-root")
.arg("tests/fixtures/app_with_rails_relationships")
.arg("check")
Expand All @@ -289,8 +285,7 @@ fn test_check_with_relationship_violations() -> Result<(), Box<dyn Error>> {

#[test]
fn test_check_without_stale_violations() -> Result<(), Box<dyn Error>> {
Command::cargo_bin("pks")
.unwrap()
cargo_bin_cmd!("pks")
.arg("--project-root")
.arg("tests/fixtures/contains_package_todo")
.arg("check")
Expand All @@ -309,8 +304,7 @@ fn test_check_without_stale_violations() -> Result<(), Box<dyn Error>> {

#[test]
fn test_check_with_strict_mode() -> Result<(), Box<dyn Error>> {
Command::cargo_bin("pks")
.unwrap()
cargo_bin_cmd!("pks")
.arg("--project-root")
.arg("tests/fixtures/uses_strict_mode")
.arg("check")
Expand All @@ -329,8 +323,7 @@ fn test_check_with_strict_mode() -> Result<(), Box<dyn Error>> {

#[test]
fn test_check_with_strict_mode_output_csv() -> Result<(), Box<dyn Error>> {
Command::cargo_bin("pks")
.unwrap()
cargo_bin_cmd!("pks")
.arg("--project-root")
.arg("tests/fixtures/uses_strict_mode")
.arg("check")
Expand All @@ -354,7 +347,7 @@ fn test_check_contents() -> Result<(), Box<dyn Error>> {
let foo_rb_contents =
fs::read_to_string(format!("{}/{}", project_root, relative_path))?;

let output = Command::cargo_bin("pks")?
let output = cargo_bin_cmd!("pks")
.arg("--project-root")
.arg(project_root)
.arg("--debug")
Expand Down Expand Up @@ -385,7 +378,7 @@ fn test_check_contents_ignoring_recorded_violations(
let foo_rb_contents =
fs::read_to_string(format!("{}/{}", project_root, relative_path))?;

let output = Command::cargo_bin("pks")?
let output = cargo_bin_cmd!("pks")
.arg("--project-root")
.arg(project_root)
.arg("--debug")
Expand Down
10 changes: 5 additions & 5 deletions tests/check_unused_dependencies.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use assert_cmd::prelude::*;
use assert_cmd::cargo::cargo_bin_cmd;
use predicates::prelude::*;
use std::{error::Error, fs, process::Command};
use std::{error::Error, fs};
mod common;

fn assert_check_unused_dependencies(cmd: &str) -> Result<(), Box<dyn Error>> {
Command::cargo_bin("pks")?
cargo_bin_cmd!("pks")
.arg("--project-root")
.arg("tests/fixtures/app_with_dependency_cycles")
.arg("--debug")
Expand Down Expand Up @@ -51,7 +51,7 @@ fn assert_auto_correct_unused_dependencies(
let foo_package_yml = fs::read_to_string("tests/fixtures/app_with_unnecessary_dependencies/packs/foo/package.yml").unwrap();
assert_eq!(foo_package_yml, expected_before_autocorrect);

Command::cargo_bin("pks")?
cargo_bin_cmd!("pks")
.arg("--project-root")
.arg("tests/fixtures/app_with_unnecessary_dependencies")
.arg("--debug")
Expand Down Expand Up @@ -94,7 +94,7 @@ fn test_auto_correct_unnecessary_dependencies() -> Result<(), Box<dyn Error>> {
#[test]
fn test_check_unnecessary_dependencies_no_issue() -> Result<(), Box<dyn Error>>
{
Command::cargo_bin("pks")?
cargo_bin_cmd!("pks")
.arg("--project-root")
.arg("tests/fixtures/simple_app")
.arg("--debug")
Expand Down
4 changes: 2 additions & 2 deletions tests/corrupt_todo_test.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use assert_cmd::Command;
use assert_cmd::cargo::cargo_bin_cmd;
use predicates::prelude::*;
mod common;

#[test]
fn test_check_with_corrupt_todo() -> anyhow::Result<()> {
Command::cargo_bin("pks")?
cargo_bin_cmd!("pks")
.arg("--project-root")
.arg("tests/fixtures/contains_corrupt_todo")
.arg("--debug")
Expand Down
Loading