diff --git a/git-checks-core/src/check.rs b/git-checks-core/src/check.rs index 2cbca4273b87f0b61f8456979783eae31465eaa0..162791da6cd15814e3b9cda25b3af847949a1884 100644 --- a/git-checks-core/src/check.rs +++ b/git-checks-core/src/check.rs @@ -13,8 +13,8 @@ use crates::git_workarea::CommitId; use commit::{Commit, Content, Topic}; use context::CheckGitContext; -#[derive(Debug, Default)] /// The results of a check. +#[derive(Debug, Default)] pub struct CheckResult { /// The warnings from running checks. warnings: Vec, diff --git a/git-checks-core/src/commit.rs b/git-checks-core/src/commit.rs index bf99d9fb7002db74cb15b8b64e615fc3db57fae3..53fd35483da29f8aa9f7db8761bfc0184066633f 100644 --- a/git-checks-core/src/commit.rs +++ b/git-checks-core/src/commit.rs @@ -195,8 +195,8 @@ impl CommitError { } } -#[derive(Debug, Clone, Copy, PartialEq, Eq)] /// Ways a file can be changed in a commit. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum StatusChange { /// The file was added in this commit. Added, @@ -248,7 +248,6 @@ pub enum FileNameError { MissingOnesDigit, } -#[derive(Debug, Clone, Eq)] /// A representation of filenames as given by Git. /// /// Git supports filenames with control characters and other non-Unicode byte sequence which are @@ -256,6 +255,7 @@ pub enum FileNameError { /// differences and offers accessors to the file name in different representations. /// /// Generally, the `as_` methods should be preferred to pattern matching on this enumeration. +#[derive(Debug, Clone, Eq)] pub enum FileName { #[doc(hidden)] Normal(String), @@ -403,8 +403,8 @@ impl AsRef for FileName { } } -#[derive(Debug)] /// Information about a file that changed in a commit. +#[derive(Debug)] pub struct DiffInfo { /// The mode of the file in the parent commit. pub old_mode: String, @@ -446,8 +446,8 @@ pub trait Content { fn path_diff(&self, path: &FileName) -> Result; } -#[derive(Debug)] /// Representation of a commit with information useful for commit checks. +#[derive(Debug)] pub struct Commit { /// The SHA1 of the commit. pub sha1: CommitId, @@ -569,8 +569,8 @@ impl Content for Commit { } } -#[derive(Debug)] /// Representation of a topic with information useful for commit checks. +#[derive(Debug)] pub struct Topic { /// The SHA1 of the base commit. pub base: CommitId, diff --git a/git-checks-core/src/context.rs b/git-checks-core/src/context.rs index 97aaf6867866937ac03544990aa1ee0ae5197812..1480e3d5fff78e60e7074f39f0875f4be8ab7e2d 100644 --- a/git-checks-core/src/context.rs +++ b/git-checks-core/src/context.rs @@ -83,8 +83,8 @@ pub enum AttributeState { Value(String), } -#[derive(Debug)] /// Git context for use in checks. +#[derive(Debug)] pub struct CheckGitContext { /// The workarea for the check. workarea: GitWorkArea, diff --git a/git-checks-core/src/run.rs b/git-checks-core/src/run.rs index 5d9283d65c94f7e3c4994194b1543b73a5370c0e..509125c0ab36d28318e0923cddad77b5c539d77f 100644 --- a/git-checks-core/src/run.rs +++ b/git-checks-core/src/run.rs @@ -83,8 +83,8 @@ impl RunError { } } -#[derive(Default, Clone)] /// Configuration for checks to run against a repository. +#[derive(Default, Clone)] pub struct GitCheckConfiguration<'a> { /// Checks to run on each commit. checks: Vec<&'a dyn Check>, @@ -94,8 +94,8 @@ pub struct GitCheckConfiguration<'a> { checks_topic: Vec<&'a dyn TopicCheck>, } -#[derive(Debug)] /// Results from checking a topic. +#[derive(Debug)] pub struct TopicCheckResult { /// The results for each commit in the topic. commit_results: Vec<(CommitId, CheckResult)>, diff --git a/git-checks-core/src/utils.rs b/git-checks-core/src/utils.rs index 4945e71a6d69bfbc3df2d99e9fad00001d409dc8..20049453cb3779822330de20b780a7c4862c0a8c 100644 --- a/git-checks-core/src/utils.rs +++ b/git-checks-core/src/utils.rs @@ -10,11 +10,11 @@ use crates::git_workarea::GitContext; use context::CheckGitContext; -#[derive(Debug)] /// A git context for a submodule for use within checks. /// /// Checks which need to inspect submodules should use this to obtain a `GitContext` for the /// submodule. +#[derive(Debug)] pub struct SubmoduleContext<'a> { /// The name of the submodule (usually the same as `path`). pub name: &'a str, diff --git a/git-checks/CHANGELOG.md b/git-checks/CHANGELOG.md index c7e6fb56320659b6ae7f832252fc63b2e534e26a..85b14034ea86d5d1b9fcbe7dbd5021cd18257ab4 100644 --- a/git-checks/CHANGELOG.md +++ b/git-checks/CHANGELOG.md @@ -13,6 +13,12 @@ ## Changes * The core functionality has been split into the `git-checks-core` crate. + * Various checks have gained `Clone` or `Copy` implementations as available. + +## Fixes + + * The `RejectConflictPaths` check's `Default` implementation now matches its + `::new()` method. ## Updated checks diff --git a/git-checks/src/allow_robot.rs b/git-checks/src/allow_robot.rs index 874ffc73a9715756430bac5d3bc85d2b8dd2f16c..1026c42c6f3d9fd3c57489dd308484c9ffdd6fa5 100644 --- a/git-checks/src/allow_robot.rs +++ b/git-checks/src/allow_robot.rs @@ -8,8 +8,8 @@ use crates::git_checks_core::impl_prelude::*; -#[derive(Debug)] /// A check to allow robots to skip all checks. +#[derive(Debug, Clone)] pub struct AllowRobot { /// The identity of the robot. identity: Identity, diff --git a/git-checks/src/bad_commits.rs b/git-checks/src/bad_commits.rs index 07d8f6c74d389069b4c657b41bd394d81eddf6a1..aa52f1152d2312555f076295266ae9155e3a41da 100644 --- a/git-checks/src/bad_commits.rs +++ b/git-checks/src/bad_commits.rs @@ -29,8 +29,8 @@ impl BadCommitsError { } } -#[derive(Debug)] /// Check for commits which should not be in the history. +#[derive(Debug, Clone)] pub struct BadCommits { /// The set of bad commits to deny. bad_commits: Vec, @@ -38,6 +38,8 @@ pub struct BadCommits { impl BadCommits { /// Create a new check which checks for and denies branches with the given bad commits. + /// + /// Full commit hashes should be used. These are not passed through `git rev-parse`. pub fn new(bad_commits: I) -> Self where I: IntoIterator, @@ -122,6 +124,7 @@ mod tests { use test::*; use BadCommits; + const NO_EXIST_COMMIT: &str = "0000000000000000000000000000000000000000"; const GOOD_COMMIT: &str = "7b0c51ed98a23a32718ed7014d6d4a813423f1bd"; const BAD_COMMIT: &str = "029a00428913ee915ce5ee7250c023abfbc2aca3"; const BAD_TOPIC: &str = "3d535904b40868dcba6465cf2c3ce4358501880a"; @@ -137,7 +140,7 @@ mod tests { let check = BadCommits::new( [ // This commit should never exist. - "0000000000000000000000000000000000000000", + NO_EXIST_COMMIT, ] .iter() .cloned(), diff --git a/git-checks/src/changelog.rs b/git-checks/src/changelog.rs index 602a830bfe637aa70a2cc95e3d6d0eb5ce59f132..e75929ae43a769d1d06cd9cf59d7f76180a73c65 100644 --- a/git-checks/src/changelog.rs +++ b/git-checks/src/changelog.rs @@ -12,8 +12,8 @@ use crates::git_checks_core::impl_prelude::*; use crates::itertools::Itertools; use crates::rayon::prelude::*; -#[derive(Debug)] /// The style of changelog management in use. +#[derive(Debug, Clone)] pub enum ChangelogStyle { /// A directory stores a file per changelog entry. Directory { @@ -154,11 +154,11 @@ impl ChangelogStyle { } } -#[derive(Debug)] /// Check for changelog modifications. /// /// This checks to make sure that a changelog entry has been added (or modified) in every commit or /// topic. +#[derive(Debug, Clone)] pub struct Changelog { /// The changelog management style in use. style: ChangelogStyle, diff --git a/git-checks/src/check_end_of_line.rs b/git-checks/src/check_end_of_line.rs index a13b432310404487fb8043ef28efa74db04e27e6..7a57e6d9474ce3fde64b5348248189f096d76d68 100644 --- a/git-checks/src/check_end_of_line.rs +++ b/git-checks/src/check_end_of_line.rs @@ -8,8 +8,8 @@ use crates::git_checks_core::impl_prelude::*; -#[derive(Debug, Default, Clone, Copy)] /// Check for files which lack an end-of-line at the end of the file. +#[derive(Debug, Default, Clone, Copy)] pub struct CheckEndOfLine; impl CheckEndOfLine { @@ -88,7 +88,7 @@ mod tests { #[test] fn test_check_end_of_line() { - let check = CheckEndOfLine::new(); + let check = CheckEndOfLine::default(); let result = run_check("test_check_end_of_line", BAD_COMMIT, check); test_result_errors(result, &[ "commit 829cdf8cb069b8f8a634a034d3f85089271601cf is not allowed; missing newline at \ @@ -98,7 +98,7 @@ mod tests { #[test] fn test_check_end_of_line_topic() { - let check = CheckEndOfLine::new(); + let check = CheckEndOfLine::default(); let result = run_topic_check("test_check_end_of_line_topic", BAD_COMMIT, check); test_result_errors( result, @@ -108,7 +108,7 @@ mod tests { #[test] fn test_check_end_of_line_removal() { - let check = CheckEndOfLine::new(); + let check = CheckEndOfLine::default(); let conf = make_check_conf(&check); let result = test_check_base( @@ -122,7 +122,7 @@ mod tests { #[test] fn test_check_end_of_line_topic_fixed() { - let check = CheckEndOfLine::new(); + let check = CheckEndOfLine::default(); run_topic_check_ok("test_check_end_of_line_topic_fixed", FIX_COMMIT, check); } } diff --git a/git-checks/src/check_executable_permissions.rs b/git-checks/src/check_executable_permissions.rs index e3e5b03859d969c372ba8892aa0546d5e32fd71d..58fd737c729955eb5e17af4cc779a2dbde92ce21 100644 --- a/git-checks/src/check_executable_permissions.rs +++ b/git-checks/src/check_executable_permissions.rs @@ -10,10 +10,10 @@ use crates::git_checks_core::impl_prelude::*; use binary_format; -#[derive(Debug)] /// Checks whether a file's executable permissions matches its contents. /// /// Files which look executable but are not marked as such or vice versa are rejected. +#[derive(Debug, Default, Clone)] pub struct CheckExecutablePermissions { /// Extensions considered to indicate an executable file. /// @@ -134,9 +134,13 @@ mod tests { const BINARY_FIX_TOPIC: &str = "02487305b25d5ef3ea3fbf77813f5fbc189ef27f"; const LFS_TOPIC: &str = "58b4868402bf3f2e6160af345052c812f4cbe36f"; + fn check_executable_permissions_check(ext: &str) -> CheckExecutablePermissions { + CheckExecutablePermissions::new([ext].iter().cloned()) + } + #[test] fn test_check_executable_permissions() { - let check = CheckExecutablePermissions::new([".exe"].iter().cloned()); + let check = check_executable_permissions_check(".exe"); let result = run_check("test_check_executable_permissions", BAD_TOPIC, check); test_result_errors( result, @@ -153,7 +157,7 @@ mod tests { #[test] fn test_check_executable_permissions_binary() { - let check = CheckExecutablePermissions::new([".exe"].iter().cloned()); + let check = check_executable_permissions_check(".exe"); let result = run_check( "test_check_executable_permissions_binary", BINARY_TOPIC, @@ -177,7 +181,7 @@ mod tests { #[test] fn test_check_executable_permissions_topic() { - let check = CheckExecutablePermissions::new([".exe"].iter().cloned()); + let check = check_executable_permissions_check(".exe"); let result = run_topic_check("test_check_executable_permissions_topic", BAD_TOPIC, check); test_result_errors( result, @@ -194,7 +198,7 @@ mod tests { #[test] fn test_check_executable_permissions_topic_fixed() { - let check = CheckExecutablePermissions::new([".exe"].iter().cloned()); + let check = check_executable_permissions_check(".exe"); run_topic_check_ok( "test_check_executable_permissions_topic_fixed", FIX_TOPIC, @@ -204,7 +208,7 @@ mod tests { #[test] fn test_check_executable_permissions_topic_binary_fixed() { - let check = CheckExecutablePermissions::new([".exe"].iter().cloned()); + let check = check_executable_permissions_check(".exe"); run_topic_check_ok( "test_check_executable_permissions_topic_binary_fixed", BINARY_FIX_TOPIC, @@ -214,7 +218,7 @@ mod tests { #[test] fn test_check_executable_permissions_lfs() { - let check = CheckExecutablePermissions::new([".lfs"].iter().cloned()); + let check = check_executable_permissions_check(".lfs"); let conf = make_check_conf(&check); let result = test_check_base( "test_check_executable_permissions_lfs", diff --git a/git-checks/src/check_size.rs b/git-checks/src/check_size.rs index 7845ea100de9a35e9d3926554ec6b89ceab4c5b2..57cba568204c16d35ba745aea9b0fca0233206ba 100644 --- a/git-checks/src/check_size.rs +++ b/git-checks/src/check_size.rs @@ -24,8 +24,8 @@ impl CheckSizeError { } } -#[derive(Debug, Clone, Copy)] /// Checks that files committed to the tree do not exceed a specified size. +#[derive(Debug, Clone, Copy)] pub struct CheckSize { /// The maximum size of blobs allowed in the repository. max_size: usize, diff --git a/git-checks/src/check_whitespace.rs b/git-checks/src/check_whitespace.rs index d6b22555e3f2161c6fc61e0afdd0efc71256882f..2e264cbbbe770dd618f5cc652b4a588605b4534a 100644 --- a/git-checks/src/check_whitespace.rs +++ b/git-checks/src/check_whitespace.rs @@ -14,9 +14,11 @@ const CR_LF_ENDING: &str = "\r\n"; /// A symbol to replace `\r` characters so that they appear in the error message. const CARRIAGE_RETURN_SYMBOL: &str = "\u{23ce}"; +/// Checks for bad whitespace using Git's built-in checks. +/// +/// This is attribute-driven, so any `gitattributes(5)` files may be used to suppress spirious +/// errors from this check. #[derive(Debug, Default, Clone, Copy)] -/// Checks for bad whitespace using Git's built-in checks. This is attribute-driven, so any -/// `gitattributes(5)` files may be used to suppress spirious errors from this check. pub struct CheckWhitespace; impl CheckWhitespace { @@ -115,7 +117,7 @@ mod tests { #[test] fn test_check_whitespace_defaults() { - let check = CheckWhitespace::new(); + let check = CheckWhitespace::default(); let result = run_check("test_check_whitespace_defaults", DEFAULT_TOPIC, check); test_result_errors( result, @@ -146,7 +148,7 @@ mod tests { #[test] fn test_check_whitespace_all_ignored() { - let check = CheckWhitespace::new(); + let check = CheckWhitespace::default(); run_check_ok( "test_check_whitespace_all_ignored", ALL_IGNORED_TOPIC, @@ -156,7 +158,7 @@ mod tests { #[test] fn test_check_whitespace_all_ignored_blanket() { - let check = CheckWhitespace::new(); + let check = CheckWhitespace::default(); run_check_ok( "test_check_whitespace_all_ignored_blanket", ALL_IGNORED_BLANKET_TOPIC, diff --git a/git-checks/src/commit_subject.rs b/git-checks/src/commit_subject.rs index 39c8e610add2a914bddb30ca0312d0c8650c3e08..034918e9b399428387353c581caee98351a2e550 100644 --- a/git-checks/src/commit_subject.rs +++ b/git-checks/src/commit_subject.rs @@ -11,8 +11,8 @@ use crates::regex::Regex; use crates::git_checks_core::impl_prelude::*; -#[derive(Debug, Default, Clone)] /// Check commit message subjects for invalid patterns. +#[derive(Debug, Clone)] pub struct CommitSubject { /// The minimum length allowed for the summary line. min_summary: usize, @@ -136,6 +136,12 @@ impl CommitSubject { } } +impl Default for CommitSubject { + fn default() -> Self { + CommitSubject::new() + } +} + impl Check for CommitSubject { fn name(&self) -> &str { "commit-subject" @@ -267,9 +273,9 @@ mod tests { const BAD_TOPIC: &str = "5f7284fe1599265c90550b681a4bf0763bc1de21"; #[test] - fn test_check_subject() { - let check = CommitSubject::new(); - let result = run_check("test_check_subject", BAD_TOPIC, check); + fn test_commit_subject() { + let check = CommitSubject::default(); + let result = run_check("test_commit_subject", BAD_TOPIC, check); test_result_errors(result, &[ "commit 234de3c3f17ab29f0b7644ae96242e31a3dd634c has an invalid commit subject; the \ first line must be at least 8 characters.", @@ -297,13 +303,13 @@ mod tests { } #[test] - fn test_check_subject_allowed_prefixes() { - let mut check = CommitSubject::new(); + fn test_commit_subject_allowed_prefixes() { + let mut check = CommitSubject::default(); check .check_work_in_progress(false) .check_rebase_commands(false) .with_allowed_prefixes(vec!["commit message "]); - let result = run_check("test_check_subject_allowed_prefixes", BAD_TOPIC, check); + let result = run_check("test_commit_subject_allowed_prefixes", BAD_TOPIC, check); test_result_errors(result, &[ "commit 234de3c3f17ab29f0b7644ae96242e31a3dd634c has an invalid commit subject; the \ first line must be at least 8 characters.", @@ -332,13 +338,13 @@ mod tests { } #[test] - fn test_check_subject_disallowed_prefixes() { + fn test_commit_subject_disallowed_prefixes() { let mut check = CommitSubject::new(); check .check_work_in_progress(false) .check_rebase_commands(false) .with_disallowed_prefixes(vec!["commit message "]); - let result = run_check("test_check_subject_disallowed_prefixes", BAD_TOPIC, check); + let result = run_check("test_commit_subject_disallowed_prefixes", BAD_TOPIC, check); test_result_errors(result, &[ "commit 234de3c3f17ab29f0b7644ae96242e31a3dd634c has an invalid commit subject; the \ first line must be at least 8 characters.", @@ -362,8 +368,8 @@ mod tests { } #[test] - fn test_check_subject_tolerated_prefixes() { - let mut check = CommitSubject::new(); + fn test_commit_subject_tolerated_prefixes() { + let mut check = CommitSubject::default(); check .check_work_in_progress(false) .check_rebase_commands(false) @@ -380,7 +386,7 @@ mod tests { ) .with_allowed_prefixes(vec!["allowed prefix "]) .with_disallowed_prefixes(vec!["commit message "]); - let result = run_check("test_check_subject_tolerated_prefixes", BAD_TOPIC, check); + let result = run_check("test_commit_subject_tolerated_prefixes", BAD_TOPIC, check); test_result_errors( result, &[ diff --git a/git-checks/src/formatting.rs b/git-checks/src/formatting.rs index b8054ad006a9ee182dad9d1a87f570fed41e176c..21002f0d987f60c8641b3d0d006173d238dc22d1 100644 --- a/git-checks/src/formatting.rs +++ b/git-checks/src/formatting.rs @@ -98,7 +98,6 @@ impl FormattingError { } } -#[derive(Debug, Clone)] /// Run a formatter in the repository to check commits for formatting. /// /// The formatter is passed a single argument: the path to the file which should be checked. @@ -114,6 +113,7 @@ impl FormattingError { /// guaranteed to have the files which have changed in the commit being checked on disk, so /// additional files which should be available for the command to run must be specified with /// `Formatting::add_config_files`. +#[derive(Debug, Clone)] pub struct Formatting { /// The "name" of the formatter. /// diff --git a/git-checks/src/invalid_paths.rs b/git-checks/src/invalid_paths.rs index a1e1d1b779ce3b4ea1397bef3b4cdd79e94fc08b..1c313e80a992e404a940369197a8f77e1564619e 100644 --- a/git-checks/src/invalid_paths.rs +++ b/git-checks/src/invalid_paths.rs @@ -8,8 +8,8 @@ use crates::git_checks_core::impl_prelude::*; -#[derive(Debug, Default)] /// A check which denies commits which adds files containing special characters in their paths. +#[derive(Debug, Clone)] pub struct InvalidPaths { /// Characters not allowed within a filename. invalid_characters: String, @@ -88,6 +88,12 @@ impl InvalidPaths { } } +impl Default for InvalidPaths { + fn default() -> Self { + InvalidPaths::new("") + } +} + impl ContentCheck for InvalidPaths { fn name(&self) -> &str { "invalid-paths" diff --git a/git-checks/src/invalid_utf8.rs b/git-checks/src/invalid_utf8.rs index f83df4b0f69c486eff784ddb6290e54516dc388d..b8b09997caf2bed105fbb3f11e4084fdef20ee45 100644 --- a/git-checks/src/invalid_utf8.rs +++ b/git-checks/src/invalid_utf8.rs @@ -10,8 +10,8 @@ use crates::git_checks_core::impl_prelude::*; use std::char::REPLACEMENT_CHARACTER; -#[derive(Debug, Default, Clone, Copy)] /// A check which denies commits which modify files containing special characters. +#[derive(Debug, Default, Clone, Copy)] pub struct InvalidUtf8; impl InvalidUtf8 { @@ -93,7 +93,7 @@ mod tests { #[test] fn test_invalid_utf8() { - let check = InvalidUtf8; + let check = InvalidUtf8::default(); let result = run_check("test_invalid_utf8", BAD_TOPIC, check); test_result_errors(result, &[ "commit cf16b71a21023320ffab7b3f7673dc62f33e5022 not allowed; invalid utf-8 sequence \ @@ -102,9 +102,11 @@ mod tests { ]); } + // TODO: Add tests for -diff files. + #[test] fn test_invalid_utf8_topic() { - let check = InvalidUtf8; + let check = InvalidUtf8::default(); let result = run_topic_check("test_invalid_utf8_topic", BAD_TOPIC, check); test_result_errors(result, &[ "invalid utf-8 sequence added in `invalid-utf8`: `This file contains an invalid utf-8 \ @@ -114,7 +116,7 @@ mod tests { #[test] fn test_invalid_utf8_topic_fixed() { - let check = InvalidUtf8; + let check = InvalidUtf8::default(); run_topic_check_ok("test_invalid_utf8_topic_fixed", FIX_TOPIC, check); } } diff --git a/git-checks/src/lfs_pointer.rs b/git-checks/src/lfs_pointer.rs index 0794a7a8f1d98bd1f438cc8c8b1c87cf7ce4bffa..9009b1e3745ac7cccdea5deac072c465cd3f3054 100644 --- a/git-checks/src/lfs_pointer.rs +++ b/git-checks/src/lfs_pointer.rs @@ -9,8 +9,8 @@ use crates::git_checks_core::impl_prelude::*; use crates::regex::Regex; -#[derive(Debug, Default, Clone, Copy)] /// A check which verifies that files meant to be under LFS control are valid LFS pointers. +#[derive(Debug, Default, Clone, Copy)] pub struct LfsPointer; impl LfsPointer { @@ -270,7 +270,7 @@ mod tests { #[test] fn test_lfs_invalid_utf8() { - let check = LfsPointer; + let check = LfsPointer::default(); let result = run_check("test_lfs_invalid_utf8", LFS_INVALID_UTF8, check); test_result_errors(result, &[ "commit c413d8954d903557de00be9d96b4daa264bd4b22 not allowed; invalid utf-8 sequence \ @@ -280,7 +280,7 @@ mod tests { #[test] fn test_lfs_invalid_utf8_topic() { - let check = LfsPointer; + let check = LfsPointer::default(); let result = run_topic_check("test_lfs_invalid_utf8_topic", LFS_INVALID_UTF8, check); test_result_errors( result, @@ -290,7 +290,7 @@ mod tests { #[test] fn test_lfs_invalid_utf8_topic_fixed() { - let check = LfsPointer; + let check = LfsPointer::default(); run_topic_check_ok( "test_lfs_invalid_utf8_topic_fixed", LFS_INVALID_UTF8_FIXED, @@ -300,7 +300,7 @@ mod tests { #[test] fn test_lfs_invalid_line_format() { - let check = LfsPointer; + let check = LfsPointer::default(); let result = run_check( "test_lfs_invalid_line_format", LFS_INVALID_LINE_FORMAT, @@ -320,7 +320,7 @@ mod tests { #[test] fn test_lfs_invalid_line_format_topic() { - let check = LfsPointer; + let check = LfsPointer::default(); let result = run_topic_check( "test_lfs_invalid_line_format_topic", LFS_INVALID_LINE_FORMAT, @@ -339,7 +339,7 @@ mod tests { #[test] fn test_lfs_invalid_line_format_topic_fixed() { - let check = LfsPointer; + let check = LfsPointer::default(); run_topic_check_ok( "test_lfs_invalid_line_format_topic_fixed", LFS_INVALID_LINE_FORMAT_FIXED, @@ -349,7 +349,7 @@ mod tests { #[test] fn test_lfs_missing_version() { - let check = LfsPointer; + let check = LfsPointer::default(); let result = run_check("test_lfs_missing_version", LFS_MISSING_VERSION, check); test_result_errors(result, &[ "commit 0ec2ab0e229fdcbff18a8bfd55774e4f71b04bbb not allowed; the first key in LFS \ @@ -359,7 +359,7 @@ mod tests { #[test] fn test_lfs_missing_version_topic() { - let check = LfsPointer; + let check = LfsPointer::default(); let result = run_topic_check("test_lfs_missing_version_topic", LFS_MISSING_VERSION, check); test_result_errors(result, &[ "the first key in LFS pointer `missing-version.lfs` must be `version`; found `oid`.", @@ -368,7 +368,7 @@ mod tests { #[test] fn test_lfs_missing_version_topic_fixed() { - let check = LfsPointer; + let check = LfsPointer::default(); run_topic_check_ok( "test_lfs_missing_version_topic_fixed", LFS_MISSING_VERSION_FIXED, @@ -378,7 +378,7 @@ mod tests { #[test] fn test_lfs_misplaced_version() { - let check = LfsPointer; + let check = LfsPointer::default(); let result = run_check("test_lfs_misplaced_version", LFS_MISPLACED_VERSION, check); test_result_errors(result, &[ "commit c86f7b78fd6ca471d97f3861addf3a35c25f3504 not allowed; the first key in LFS \ @@ -388,7 +388,7 @@ mod tests { #[test] fn test_lfs_misplaced_version_topic() { - let check = LfsPointer; + let check = LfsPointer::default(); let result = run_topic_check( "test_lfs_misplaced_version_topic", LFS_MISPLACED_VERSION, @@ -401,7 +401,7 @@ mod tests { #[test] fn test_lfs_misplaced_version_topic_fixed() { - let check = LfsPointer; + let check = LfsPointer::default(); run_topic_check_ok( "test_lfs_misplaced_version_topic_fixed", LFS_MISPLACED_VERSION_FIXED, @@ -411,7 +411,7 @@ mod tests { #[test] fn test_lfs_invalid_version() { - let check = LfsPointer; + let check = LfsPointer::default(); let result = run_check("test_lfs_invalid_version", LFS_INVALID_VERSION, check); test_result_warnings( result, @@ -424,7 +424,7 @@ mod tests { #[test] fn test_lfs_invalid_version_topic() { - let check = LfsPointer; + let check = LfsPointer::default(); let result = run_topic_check("test_lfs_invalid_version_topic", LFS_INVALID_VERSION, check); test_result_warnings( result, @@ -437,7 +437,7 @@ mod tests { #[test] fn test_lfs_invalid_version_topic_fixed() { - let check = LfsPointer; + let check = LfsPointer::default(); run_topic_check_ok( "test_lfs_invalid_version_topic_fixed", LFS_INVALID_VERSION_FIXED, @@ -447,7 +447,7 @@ mod tests { #[test] fn test_lfs_duplicate_key() { - let check = LfsPointer; + let check = LfsPointer::default(); let result = run_check("test_lfs_duplicate_key", LFS_DUPLICATE_KEY, check); test_result_errors( result, @@ -460,7 +460,7 @@ mod tests { #[test] fn test_lfs_duplicate_key_topic() { - let check = LfsPointer; + let check = LfsPointer::default(); let result = run_topic_check("test_lfs_duplicate_key_topic", LFS_DUPLICATE_KEY, check); test_result_errors( result, @@ -470,7 +470,7 @@ mod tests { #[test] fn test_lfs_duplicate_key_topic_fixed() { - let check = LfsPointer; + let check = LfsPointer::default(); run_topic_check_ok( "test_lfs_duplicate_key_topic_fixed", LFS_DUPLICATE_KEY_FIXED, @@ -480,7 +480,7 @@ mod tests { #[test] fn test_lfs_missing_size() { - let check = LfsPointer; + let check = LfsPointer::default(); let result = run_check("test_lfs_missing_size", LFS_MISSING_SIZE, check); test_result_errors( result, @@ -493,7 +493,7 @@ mod tests { #[test] fn test_lfs_missing_size_topic() { - let check = LfsPointer; + let check = LfsPointer::default(); let result = run_topic_check("test_lfs_missing_size_topic", LFS_MISSING_SIZE, check); test_result_errors( result, @@ -503,7 +503,7 @@ mod tests { #[test] fn test_lfs_missing_size_topic_fixed() { - let check = LfsPointer; + let check = LfsPointer::default(); run_topic_check_ok( "test_lfs_missing_size_topic_fixed", LFS_MISSING_SIZE_FIXED, @@ -513,7 +513,7 @@ mod tests { #[test] fn test_lfs_missing_oid() { - let check = LfsPointer; + let check = LfsPointer::default(); let result = run_check("test_lfs_missing_oid", LFS_MISSING_OID, check); test_result_errors( result, @@ -526,7 +526,7 @@ mod tests { #[test] fn test_lfs_missing_oid_topic() { - let check = LfsPointer; + let check = LfsPointer::default(); let result = run_topic_check("test_lfs_missing_oid_topic", LFS_MISSING_OID, check); test_result_errors( result, @@ -536,7 +536,7 @@ mod tests { #[test] fn test_lfs_missing_oid_topic_fixed() { - let check = LfsPointer; + let check = LfsPointer::default(); run_topic_check_ok( "test_lfs_missing_oid_topic_fixed", LFS_MISSING_OID_FIXED, @@ -546,7 +546,7 @@ mod tests { #[test] fn test_lfs_unrecognized_hash() { - let check = LfsPointer; + let check = LfsPointer::default(); let result = run_check("test_lfs_unrecognized_hash", LFS_UNRECOGNIZED_HASH, check); test_result_warnings( result, @@ -559,7 +559,7 @@ mod tests { #[test] fn test_lfs_unrecognized_hash_topic() { - let check = LfsPointer; + let check = LfsPointer::default(); let result = run_topic_check( "test_lfs_unrecognized_hash_topic", LFS_UNRECOGNIZED_HASH, @@ -573,7 +573,7 @@ mod tests { #[test] fn test_lfs_unrecognized_hash_topic_fixed() { - let check = LfsPointer; + let check = LfsPointer::default(); run_topic_check_ok( "test_lfs_unrecognized_hash_topic_fixed", LFS_UNRECOGNIZED_HASH_FIXED, @@ -583,7 +583,7 @@ mod tests { #[test] fn test_lfs_missing_hash() { - let check = LfsPointer; + let check = LfsPointer::default(); let result = run_check("test_lfs_missing_hash", LFS_MISSING_HASH, check); test_result_errors(result, &[ "commit 109806f98fd036cba88d07f94df162aad5086d0b not allowed; missing hash algorithm \ @@ -593,7 +593,7 @@ mod tests { #[test] fn test_lfs_missing_hash_topic() { - let check = LfsPointer; + let check = LfsPointer::default(); let result = run_topic_check("test_lfs_missing_hash_topic", LFS_MISSING_HASH, check); test_result_errors( result, @@ -603,7 +603,7 @@ mod tests { #[test] fn test_lfs_missing_hash_topic_fixed() { - let check = LfsPointer; + let check = LfsPointer::default(); run_topic_check_ok( "test_lfs_missing_hash_topic_fixed", LFS_MISSING_HASH_FIXED, @@ -613,7 +613,7 @@ mod tests { #[test] fn test_lfs_unsorted_keys() { - let check = LfsPointer; + let check = LfsPointer::default(); let result = run_check("test_lfs_unsorted_keys", LFS_UNSORTED_KEYS, check); test_result_errors( result, @@ -626,7 +626,7 @@ mod tests { #[test] fn test_lfs_unsorted_keys_topic() { - let check = LfsPointer; + let check = LfsPointer::default(); let result = run_topic_check("test_lfs_unsorted_keys_topic", LFS_UNSORTED_KEYS, check); test_result_errors( result, @@ -636,7 +636,7 @@ mod tests { #[test] fn test_lfs_unsorted_keys_topic_fixed() { - let check = LfsPointer; + let check = LfsPointer::default(); run_topic_check_ok( "test_lfs_unsorted_keys_topic_fixed", LFS_UNSORTED_KEYS_FIXED, @@ -646,25 +646,25 @@ mod tests { #[test] fn test_lfs_empty_pointer() { - let check = LfsPointer; + let check = LfsPointer::default(); run_check_ok("test_lfs_empty_pointer", LFS_EMPTY_POINTER, check); } #[test] fn test_lfs_empty_pointer_topic() { - let check = LfsPointer; + let check = LfsPointer::default(); run_topic_check_ok("test_lfs_empty_pointer_topic", LFS_EMPTY_POINTER, check) } #[test] fn test_lfs_valid_pointer() { - let check = LfsPointer; + let check = LfsPointer::default(); run_check_ok("test_lfs_valid_pointer", LFS_VALID_POINTER, check); } #[test] fn test_lfs_valid_pointer_topic() { - let check = LfsPointer; + let check = LfsPointer::default(); run_topic_check_ok("test_lfs_valid_pointer_topic", LFS_VALID_POINTER, check) } } diff --git a/git-checks/src/lib.rs b/git-checks/src/lib.rs index faabb0d466f60feb3ae5d54197e5ab6225fee5e6..9a0bfc4b9cb562f1e80c9222fec67afb828f50fb 100644 --- a/git-checks/src/lib.rs +++ b/git-checks/src/lib.rs @@ -47,9 +47,6 @@ mod changelog; pub use self::changelog::Changelog; pub use self::changelog::ChangelogStyle; -mod commit_subject; -pub use self::commit_subject::CommitSubject; - mod check_end_of_line; pub use self::check_end_of_line::CheckEndOfLine; @@ -62,6 +59,9 @@ pub use self::check_size::CheckSize; mod check_whitespace; pub use self::check_whitespace::CheckWhitespace; +mod commit_subject; +pub use self::commit_subject::CommitSubject; + mod formatting; pub use self::formatting::Formatting; diff --git a/git-checks/src/reject_binaries.rs b/git-checks/src/reject_binaries.rs index d062ee598755f8cbbf0134ced43d392e2cedd440..5f83790b8138849ddfb7eb32793bbb9a83f02c70 100644 --- a/git-checks/src/reject_binaries.rs +++ b/git-checks/src/reject_binaries.rs @@ -105,7 +105,7 @@ mod tests { #[test] fn test_reject_binaries() { - let check = RejectBinaries::new(); + let check = RejectBinaries::default(); let result = run_check("test_reject_binaries", BAD_COMMIT, check); test_result_errors(result, &[ "commit e5e1e2c8db62ac8f50f249d3cf3f334ddf158936 adds the ELF binary `elf-header`.", @@ -119,7 +119,7 @@ mod tests { #[test] fn test_reject_binaries_plus_x() { - let check = RejectBinaries::new(); + let check = RejectBinaries::default(); let result = run_check("test_reject_binaries_plus_x", BAD_COMMIT_EXE, check); test_result_errors(result, &[ "commit e5e1e2c8db62ac8f50f249d3cf3f334ddf158936 adds the ELF binary `elf-header`.", @@ -138,13 +138,13 @@ mod tests { #[test] fn test_reject_binaries_attr_ok() { - let check = RejectBinaries::new(); + let check = RejectBinaries::default(); run_check_ok("test_reject_binaries_attr_ok", ATTR_COMMIT, check) } #[test] fn test_reject_binaries_attr_bad() { - let check = RejectBinaries::new(); + let check = RejectBinaries::default(); let result = run_check("test_reject_binaries_attr_bad", ATTR_COMMIT_BAD, check); test_result_errors(result, &[ "commit 71fa463c4bedeb40807b6c73b08ce207b0fe0309 adds the ELF (not Mach-O) binary `elf-header`.", @@ -158,7 +158,7 @@ mod tests { #[test] fn test_reject_binaries_topic() { - let check = RejectBinaries::new(); + let check = RejectBinaries::default(); let result = run_topic_check("test_reject_binaries_topic", BAD_COMMIT, check); test_result_errors( result, @@ -175,13 +175,13 @@ mod tests { #[test] fn test_reject_binaries_topic_attr_ok() { - let check = RejectBinaries::new(); + let check = RejectBinaries::default(); run_topic_check_ok("test_reject_binaries_topic_attr_ok", ATTR_COMMIT, check) } #[test] fn test_reject_binaries_topic_attr_bad() { - let check = RejectBinaries::new(); + let check = RejectBinaries::default(); let result = run_topic_check( "test_reject_binaries_topic_attr_bad", ATTR_COMMIT_BAD, @@ -202,7 +202,7 @@ mod tests { #[test] fn test_reject_binaries_topic_plus_x() { - let check = RejectBinaries::new(); + let check = RejectBinaries::default(); let result = run_topic_check("test_reject_binaries_topic_plus_x", BAD_COMMIT_EXE, check); test_result_errors( result, @@ -219,13 +219,13 @@ mod tests { #[test] fn test_reject_binaries_topic_fixed() { - let check = RejectBinaries::new(); + let check = RejectBinaries::default(); run_topic_check_ok("test_reject_binaries_topic_fixed", FIX_COMMIT, check); } #[test] fn test_reject_binaries_topic_attr_fixed() { - let check = RejectBinaries::new(); + let check = RejectBinaries::default(); run_topic_check_ok( "test_reject_binaries_topic_attr_fixed", FIX_ATTR_COMMIT, diff --git a/git-checks/src/reject_conflict_paths.rs b/git-checks/src/reject_conflict_paths.rs index d4b8c09160647555ee7517fa077569f97f28dff1..46507c1d5092607a9a8b814da07f788a610cbd7f 100644 --- a/git-checks/src/reject_conflict_paths.rs +++ b/git-checks/src/reject_conflict_paths.rs @@ -9,11 +9,11 @@ use crates::git_checks_core::impl_prelude::*; use crates::regex::Regex; -#[derive(Debug, Default, Clone, Copy)] /// A check which denies paths which look like merge conflict resolution paths. /// /// Sometimes after a merge, the files written to assist in resolving the conflict will be added /// accidentally. +#[derive(Debug, Clone, Copy)] pub struct RejectConflictPaths { require_base_exist: bool, } @@ -96,6 +96,12 @@ impl RejectConflictPaths { } } +impl Default for RejectConflictPaths { + fn default() -> Self { + RejectConflictPaths::new() + } +} + impl ContentCheck for RejectConflictPaths { fn name(&self) -> &str { "reject-conflict-paths" @@ -157,7 +163,7 @@ mod tests { #[test] fn test_reject_conflict_paths_no_base() { - let check = RejectConflictPaths::new(); + let check = RejectConflictPaths::default(); run_check_ok( "test_reject_conflict_paths_no_base", MERGE_CONFLICT_NO_BASE, @@ -167,7 +173,7 @@ mod tests { #[test] fn test_reject_conflict_paths_no_base_topic() { - let check = RejectConflictPaths::new(); + let check = RejectConflictPaths::default(); run_topic_check_ok( "test_reject_conflict_paths_no_base_topic", MERGE_CONFLICT_NO_BASE, @@ -177,7 +183,7 @@ mod tests { #[test] fn test_reject_conflict_paths_no_base_require() { - let mut check = RejectConflictPaths::new(); + let mut check = RejectConflictPaths::default(); check.require_base_exist(false); let result = run_check( "test_reject_conflict_paths_no_base_require", @@ -198,7 +204,7 @@ mod tests { #[test] fn test_reject_conflict_paths_no_base_require_topic() { - let mut check = RejectConflictPaths::new(); + let mut check = RejectConflictPaths::default(); check.require_base_exist(false); let result = run_topic_check( "test_reject_conflict_paths_no_base_require_topic", @@ -219,7 +225,7 @@ mod tests { #[test] fn test_reject_conflict_paths_orig_no_base() { - let check = RejectConflictPaths::new(); + let check = RejectConflictPaths::default(); run_check_ok( "test_reject_conflict_paths_orig_no_base", MERGE_CONFLICT_ORIG_NO_BASE, @@ -229,7 +235,7 @@ mod tests { #[test] fn test_reject_conflict_paths_orig_no_base_topic() { - let check = RejectConflictPaths::new(); + let check = RejectConflictPaths::default(); run_topic_check_ok( "test_reject_conflict_paths_orig_no_base_topic", MERGE_CONFLICT_ORIG_NO_BASE, @@ -239,7 +245,7 @@ mod tests { #[test] fn test_reject_conflict_paths_orig_no_base_require() { - let mut check = RejectConflictPaths::new(); + let mut check = RejectConflictPaths::default(); check.require_base_exist(false); let result = run_check( "test_reject_conflict_paths_orig_no_base_require", @@ -254,7 +260,7 @@ mod tests { #[test] fn test_reject_conflict_paths_orig_no_base_require_topic() { - let mut check = RejectConflictPaths::new(); + let mut check = RejectConflictPaths::default(); check.require_base_exist(false); let result = run_topic_check( "test_reject_conflict_paths_orig_no_base_require_topic", @@ -272,7 +278,7 @@ mod tests { #[test] fn test_reject_conflict_paths_no_ext() { - let check = RejectConflictPaths::new(); + let check = RejectConflictPaths::default(); let result = run_check( "test_reject_conflict_paths_no_ext", MERGE_CONFLICT_NO_EXT, @@ -292,7 +298,7 @@ mod tests { #[test] fn test_reject_conflict_paths_no_ext_topic() { - let check = RejectConflictPaths::new(); + let check = RejectConflictPaths::default(); let result = run_topic_check( "test_reject_conflict_paths_no_ext_topic", MERGE_CONFLICT_NO_EXT, @@ -312,7 +318,7 @@ mod tests { #[test] fn test_reject_conflict_paths_no_ext_topic_fixed() { - let check = RejectConflictPaths::new(); + let check = RejectConflictPaths::default(); run_topic_check_ok( "test_reject_conflict_paths_no_ext_topic_fixed", MERGE_CONFLICT_NO_EXT_FIXED, @@ -322,7 +328,7 @@ mod tests { #[test] fn test_reject_conflict_paths_with_ext() { - let check = RejectConflictPaths::new(); + let check = RejectConflictPaths::default(); let result = run_check( "test_reject_conflict_paths_with_ext", MERGE_CONFLICT_WITH_EXT, @@ -346,7 +352,7 @@ mod tests { #[test] fn test_reject_conflict_paths_with_ext_topic() { - let check = RejectConflictPaths::new(); + let check = RejectConflictPaths::default(); let result = run_topic_check( "test_reject_conflict_paths_with_ext_topic", MERGE_CONFLICT_WITH_EXT, @@ -366,7 +372,7 @@ mod tests { #[test] fn test_reject_conflict_paths_with_ext_topic_fixed() { - let check = RejectConflictPaths::new(); + let check = RejectConflictPaths::default(); run_topic_check_ok( "test_reject_conflict_paths_with_ext_topic_fixed", MERGE_CONFLICT_WITH_EXT_FIXED, @@ -376,7 +382,7 @@ mod tests { #[test] fn test_reject_conflict_paths_two_ext() { - let check = RejectConflictPaths::new(); + let check = RejectConflictPaths::default(); let result = run_check( "test_reject_conflict_paths_two_ext", MERGE_CONFLICT_TWO_EXT, @@ -400,7 +406,7 @@ mod tests { #[test] fn test_reject_conflict_paths_two_ext_topic() { - let check = RejectConflictPaths::new(); + let check = RejectConflictPaths::default(); let result = run_topic_check( "test_reject_conflict_paths_two_ext_topic", MERGE_CONFLICT_TWO_EXT, @@ -423,7 +429,7 @@ mod tests { #[test] fn test_reject_conflict_paths_two_ext_topic_fixed() { - let check = RejectConflictPaths::new(); + let check = RejectConflictPaths::default(); run_topic_check_ok( "test_reject_conflict_paths_two_ext_topic_fixed", MERGE_CONFLICT_TWO_EXT_FIXED, @@ -433,7 +439,7 @@ mod tests { #[test] fn test_reject_conflict_paths_orig_ext() { - let check = RejectConflictPaths::new(); + let check = RejectConflictPaths::default(); let result = run_check( "test_reject_conflict_paths_orig_ext", MERGE_CONFLICT_ORIG_EXT, @@ -447,7 +453,7 @@ mod tests { #[test] fn test_reject_conflict_paths_orig_ext_topic() { - let check = RejectConflictPaths::new(); + let check = RejectConflictPaths::default(); let result = run_topic_check( "test_reject_conflict_paths_orig_ext_topic", MERGE_CONFLICT_ORIG_EXT, @@ -461,7 +467,7 @@ mod tests { #[test] fn test_reject_conflict_paths_orig_ext_topic_fixed() { - let check = RejectConflictPaths::new(); + let check = RejectConflictPaths::default(); run_topic_check_ok( "test_reject_conflict_paths_orig_ext_topic_fixed", MERGE_CONFLICT_ORIG_EXT_FIXED, diff --git a/git-checks/src/reject_merges.rs b/git-checks/src/reject_merges.rs index e7c273b2c7eddc55483a9fdc282e06e274d1615f..3bd88666cbc4c1a5324df871a5f960cca9198d1a 100644 --- a/git-checks/src/reject_merges.rs +++ b/git-checks/src/reject_merges.rs @@ -8,8 +8,8 @@ use crates::git_checks_core::impl_prelude::*; -#[derive(Debug, Default, Clone, Copy)] /// A check which denies merge commits, including octopus merges. +#[derive(Debug, Default, Clone, Copy)] pub struct RejectMerges; impl RejectMerges { @@ -49,13 +49,13 @@ mod tests { #[test] fn test_reject_merges_no_merges() { - let check = RejectMerges::new(); + let check = RejectMerges::default(); run_check_ok("test_reject_merges_no_merges", NO_MERGES_TOPIC, check); } #[test] fn test_reject_merges_with_merges() { - let check = RejectMerges::new(); + let check = RejectMerges::default(); let result = run_check("test_reject_merges_with_merges", WITH_MERGES_TOPIC, check); test_result_errors(result, &[ "commit 92f545fa6c9326fe11dfb69c3ee01af285b595f4 not allowed; it is a merge commit.", @@ -64,7 +64,7 @@ mod tests { #[test] fn test_reject_merges_octopus_merges() { - let check = RejectMerges::new(); + let check = RejectMerges::default(); let result = run_check("test_reject_merges_no_merges", OCTOPUS_MERGES_TOPIC, check); test_result_errors(result, &[ "commit 4447a8eddbccac61daa6b55642e46156011d36cb not allowed; it is a merge commit.", diff --git a/git-checks/src/reject_separate_root.rs b/git-checks/src/reject_separate_root.rs index f415d08e7906ff53ba2fc4342b1efc88ea6cc761..23c90217ac6a9246d7b54c6ef6589531db76c4cb 100644 --- a/git-checks/src/reject_separate_root.rs +++ b/git-checks/src/reject_separate_root.rs @@ -8,8 +8,8 @@ use crates::git_checks_core::impl_prelude::*; -#[derive(Debug, Default, Clone, Copy)] /// A check which denies root commits. +#[derive(Debug, Default, Clone, Copy)] pub struct RejectSeparateRoot; impl RejectSeparateRoot { @@ -48,13 +48,13 @@ mod tests { #[test] fn test_reject_separate_root_no_root() { - let check = RejectSeparateRoot::new(); + let check = RejectSeparateRoot::default(); run_check_ok("test_reject_separate_root_no_root", NO_ROOT_TOPIC, check); } #[test] fn test_reject_separate_root_with_root() { - let check = RejectSeparateRoot::new(); + let check = RejectSeparateRoot::default(); let result = run_check( "test_reject_separate_root_with_root", WITH_ROOT_TOPIC, diff --git a/git-checks/src/reject_symlinks.rs b/git-checks/src/reject_symlinks.rs index 71a94b0f0c5c5b9b15f3aa2c6077caf5d8989727..2ced8bb05ed04bf37beedda3fa5c3bbabd6e7312 100644 --- a/git-checks/src/reject_symlinks.rs +++ b/git-checks/src/reject_symlinks.rs @@ -8,8 +8,8 @@ use crates::git_checks_core::impl_prelude::*; -#[derive(Debug, Default, Clone, Copy)] /// Rejects the addition of symlinks to a repository. +#[derive(Debug, Default, Clone, Copy)] pub struct RejectSymlinks; impl RejectSymlinks { @@ -60,7 +60,7 @@ mod tests { #[test] fn test_reject_symlinks() { - let check = RejectSymlinks; + let check = RejectSymlinks::default(); let result = run_check("test_reject_symlinks", BAD_TOPIC, check); test_result_errors(result, &[ "commit 00ffdf352196c16a453970de022a8b4343610ccf adds a symlink at `absolute-link` \ @@ -76,7 +76,7 @@ mod tests { #[test] fn test_reject_symlinks_topic() { - let check = RejectSymlinks; + let check = RejectSymlinks::default(); let result = run_topic_check("test_reject_symlinks_topic", BAD_TOPIC, check); test_result_errors( result, @@ -91,7 +91,7 @@ mod tests { #[test] fn test_reject_symlinks_topic_fixed() { - let check = RejectSymlinks; + let check = RejectSymlinks::default(); run_topic_check_ok("test_reject_symlinks_topic_fixed", FIX_TOPIC, check); } } diff --git a/git-checks/src/release_branch.rs b/git-checks/src/release_branch.rs index 4a4219c317d08360989d6c90e63e4461f9389552..0428e17292c4b0acac4100cd5d8b186f95eef2a0 100644 --- a/git-checks/src/release_branch.rs +++ b/git-checks/src/release_branch.rs @@ -34,8 +34,8 @@ impl ReleaseBranchError { } } -#[derive(Debug)] /// A check which checks for release branch eligibility. +#[derive(Debug, Clone)] pub struct ReleaseBranch { /// The branch name of the release being checked for. branch: String, diff --git a/git-checks/src/restricted_path.rs b/git-checks/src/restricted_path.rs index df350bb370a2cb84c3c5590b692e4016cdcb2b9a..a3e8e696341245daa36c94ce17ea9f831609a6d0 100644 --- a/git-checks/src/restricted_path.rs +++ b/git-checks/src/restricted_path.rs @@ -8,8 +8,8 @@ use crates::git_checks_core::impl_prelude::*; -#[derive(Debug)] /// A check which denies commits which modify files underneath certain path. +#[derive(Debug, Clone)] pub struct RestrictedPath { /// The path which may not be edited. path: String, diff --git a/git-checks/src/submodule_available.rs b/git-checks/src/submodule_available.rs index ebb1c18292c24c68fa764e9b672a97e519751acb..7be8fcd2ba5741e634885fa2d443f8c2ca16050f 100644 --- a/git-checks/src/submodule_available.rs +++ b/git-checks/src/submodule_available.rs @@ -49,8 +49,8 @@ impl SubmoduleAvailableError { } } -#[derive(Debug, Default, Clone, Copy)] /// Check that submodules are reachable from a given branch and available. +#[derive(Debug, Clone, Copy)] pub struct SubmoduleAvailable { /// Whether the first-parent history is required to contain commits or not. require_first_parent: bool, @@ -74,6 +74,12 @@ impl SubmoduleAvailable { } } +impl Default for SubmoduleAvailable { + fn default() -> Self { + SubmoduleAvailable::new() + } +} + impl Check for SubmoduleAvailable { fn name(&self) -> &str { "submodule-available" @@ -223,7 +229,7 @@ mod tests { #[test] fn test_submodule_unconfigured() { - let check = SubmoduleAvailable::new(); + let check = SubmoduleAvailable::default(); let result = run_check("test_submodule_unconfigured", BASE_COMMIT, check); assert_eq!(result.warnings().len(), 0); @@ -240,7 +246,7 @@ mod tests { #[test] fn test_submodule_move() { - let check = SubmoduleAvailable::new(); + let check = SubmoduleAvailable::default(); let conf = make_check_conf(&check); let result = test_check_submodule("test_submodule_move", MOVE_TOPIC, &conf); @@ -249,7 +255,7 @@ mod tests { #[test] fn test_submodule_move_not_first_parent() { - let check = SubmoduleAvailable::new(); + let check = SubmoduleAvailable::default(); let conf = make_check_conf(&check); let result = test_check_submodule( @@ -262,7 +268,7 @@ mod tests { #[test] fn test_submodule_move_not_first_parent_reject() { - let mut check = SubmoduleAvailable::new(); + let mut check = SubmoduleAvailable::default(); check.require_first_parent(true); let conf = make_check_conf(&check); @@ -281,7 +287,7 @@ mod tests { #[test] fn test_submodule_unavailable() { - let check = SubmoduleAvailable::new(); + let check = SubmoduleAvailable::default(); let conf = make_check_conf(&check); let result = test_check_submodule("test_submodule_unavailable", UNAVAILABLE_TOPIC, &conf); @@ -303,7 +309,7 @@ mod tests { #[test] fn test_submodule_not_ancestor() { - let check = SubmoduleAvailable::new(); + let check = SubmoduleAvailable::default(); let conf = make_check_conf(&check); let result = test_check_submodule("test_submodule_not_ancestor", NOT_ANCESTOR_TOPIC, &conf); diff --git a/git-checks/src/submodule_rewind.rs b/git-checks/src/submodule_rewind.rs index d40ad5e038d32d969b545e4cac23670a31859722..539138f4289588b4ef24380803ff881dcfeddc14 100644 --- a/git-checks/src/submodule_rewind.rs +++ b/git-checks/src/submodule_rewind.rs @@ -38,8 +38,8 @@ impl SubmoduleRewindError { } } -#[derive(Debug, Default, Clone, Copy)] /// Check that submodules are not rewound to older revisions. +#[derive(Debug, Default, Clone, Copy)] pub struct SubmoduleRewind; impl SubmoduleRewind { @@ -149,7 +149,7 @@ mod tests { #[test] fn test_submodule_rewind_ok() { - let check = SubmoduleRewind::new(); + let check = SubmoduleRewind::default(); let conf = make_check_conf(&check); let result = test_check_submodule("test_submodule_rewind_ok", MOVE_TOPIC, &conf); @@ -158,7 +158,7 @@ mod tests { #[test] fn test_submodule_rewind_to_unavailable() { - let check = SubmoduleRewind::new(); + let check = SubmoduleRewind::default(); let conf = make_check_conf(&check); let result = test_check_submodule( @@ -174,7 +174,7 @@ mod tests { #[test] fn test_submodule_rewind_from_unavailable() { - let check = SubmoduleRewind::new(); + let check = SubmoduleRewind::default(); let conf = make_check_conf(&check); let result = test_check_submodule( @@ -190,7 +190,7 @@ mod tests { #[test] fn test_submodule_rewind_rewind() { - let check = SubmoduleRewind::new(); + let check = SubmoduleRewind::default(); let conf = make_check_conf(&check); let result = test_check_submodule_base( diff --git a/git-checks/src/submodule_watch.rs b/git-checks/src/submodule_watch.rs index eb7780422dc26b021979ad21add0048d48e4cb6a..64ca63bdef33e4562489f2afce9f2e96c25c7666 100644 --- a/git-checks/src/submodule_watch.rs +++ b/git-checks/src/submodule_watch.rs @@ -8,8 +8,8 @@ use crates::git_checks_core::impl_prelude::*; -#[derive(Debug, Default, Clone, Copy)] /// Check that submodules are reachable from a given branch and available. +#[derive(Debug, Clone, Copy)] pub struct SubmoduleWatch { /// Whether to reject new submodules or not. reject_additions: bool, @@ -39,6 +39,12 @@ impl SubmoduleWatch { } } +impl Default for SubmoduleWatch { + fn default() -> Self { + SubmoduleWatch::new() + } +} + impl Check for SubmoduleWatch { fn name(&self) -> &str { "submodule-watch" @@ -124,7 +130,7 @@ mod tests { #[test] fn test_submodule_watch_add() { - let check = SubmoduleWatch::new(); + let check = SubmoduleWatch::default(); let result = run_check("test_submodule_watch_add", ADD_SUBMODULE_TOPIC, check); assert_eq!(result.warnings().len(), 0); @@ -141,7 +147,7 @@ mod tests { #[test] fn test_submodule_watch_add_reject() { - let mut check = SubmoduleWatch::new(); + let mut check = SubmoduleWatch::default(); check.reject_additions(true); let result = run_check( "test_submodule_watch_add_reject", @@ -164,7 +170,7 @@ mod tests { #[test] fn test_submodule_watch_add_configured() { - let check = SubmoduleWatch::new(); + let check = SubmoduleWatch::default(); let conf = make_check_conf(&check); let result = test_check_submodule_configure( @@ -178,7 +184,7 @@ mod tests { #[test] fn test_submodule_watch_add_configured_reject() { - let mut check = SubmoduleWatch::new(); + let mut check = SubmoduleWatch::default(); check.reject_additions(true); let conf = make_check_conf(&check); @@ -193,7 +199,7 @@ mod tests { #[test] fn test_submodule_watch_remove() { - let check = SubmoduleWatch::new(); + let check = SubmoduleWatch::default(); let conf = make_check_conf(&check); let result = test_check_submodule_base( @@ -217,7 +223,7 @@ mod tests { #[test] fn test_submodule_watch_remove_reject() { - let mut check = SubmoduleWatch::new(); + let mut check = SubmoduleWatch::default(); check.reject_removals(true); let conf = make_check_conf(&check); diff --git a/git-checks/src/third_party.rs b/git-checks/src/third_party.rs index 3dc64a6d1eed13564e1c980a4e413e448e54ec36..6d45c90f8c3cef8416cad790a400d177bf7d5367 100644 --- a/git-checks/src/third_party.rs +++ b/git-checks/src/third_party.rs @@ -80,7 +80,6 @@ impl ThirdPartyError { } } -#[derive(Debug)] /// Description of a third party package imported using Kitware's third party import process. /// /// The workflow used at Kitware for third party packages is to keep all changes tracked in @@ -96,6 +95,7 @@ impl ThirdPartyError { /// /// This check checks to make sure that any modifications in the main project's imported location of /// the third party project are made on the tracking branch. +#[derive(Debug, Clone)] pub struct ThirdParty { /// The name of the imported project. pub name: String, diff --git a/git-checks/src/valid_name.rs b/git-checks/src/valid_name.rs index 4e237b8c93c4a3cd4d8446f1e91f5f97b1552da4..005c75b2dee3dca0dbdb6eb5958910dcebfdbc93 100644 --- a/git-checks/src/valid_name.rs +++ b/git-checks/src/valid_name.rs @@ -15,8 +15,8 @@ use std::time::Duration; use crates::git_checks_core::impl_prelude::*; use crates::ttl_cache::TtlCache; -#[derive(Debug, Clone, Copy)] /// Configuration value for `ValidName` policy for use of full names in identities. +#[derive(Debug, Clone, Copy)] pub enum ValidNameFullNamePolicy { /// A full name is required, error when missing. Required, @@ -265,7 +265,7 @@ mod tests { #[test] fn test_valid_name_required() { - let check = ValidName::new(); + let check = ValidName::default(); let result = run_check("test_valid_name_required", BAD_TOPIC, check); test_result_errors(result, &[ "The author name (`Mononym`) for commit edac4e5b3a00eac60280a78ee84b5ef8d4cce97a has \ @@ -294,7 +294,7 @@ mod tests { #[test] fn test_valid_name_whitelist() { - let mut check = ValidName::new(); + let mut check = ValidName::default(); check.whitelist_domains(["baddomain.invalid"].iter().cloned()); let result = run_check("test_valid_name_whitelist", BAD_TOPIC, check); test_result_errors(result, &[ @@ -318,7 +318,7 @@ mod tests { #[test] fn test_valid_name_preferred() { - let mut check = ValidName::new(); + let mut check = ValidName::default(); check.set_full_name_policy(ValidNameFullNamePolicy::Preferred); let result = run_check("test_valid_name_preferred", BAD_AUTHOR_NAME, check); test_result_warnings(result, &[ @@ -330,7 +330,7 @@ mod tests { #[test] fn test_valid_name_optional() { - let mut check = ValidName::new(); + let mut check = ValidName::default(); check.set_full_name_policy(ValidNameFullNamePolicy::Optional); run_check_ok("test_valid_name_optional", BAD_AUTHOR_NAME, check); }