git-lint 4.6.0 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/README.adoc +235 -30
  4. data/git-lint.gemspec +9 -8
  5. data/lib/git/lint/analyzer.rb +14 -3
  6. data/lib/git/lint/analyzers/abstract.rb +8 -5
  7. data/lib/git/lint/analyzers/commit_author_capitalization.rb +2 -9
  8. data/lib/git/lint/analyzers/commit_author_email.rb +2 -9
  9. data/lib/git/lint/analyzers/commit_author_name.rb +2 -7
  10. data/lib/git/lint/analyzers/commit_body_leading_line.rb +3 -3
  11. data/lib/git/lint/analyzers/commit_body_paragraph_capitalization.rb +9 -6
  12. data/lib/git/lint/analyzers/commit_signature.rb +22 -0
  13. data/lib/git/lint/analyzers/commit_trailer_collaborator_capitalization.rb +9 -17
  14. data/lib/git/lint/analyzers/commit_trailer_collaborator_email.rb +9 -13
  15. data/lib/git/lint/analyzers/commit_trailer_collaborator_key.rb +5 -15
  16. data/lib/git/lint/analyzers/commit_trailer_collaborator_name.rb +9 -15
  17. data/lib/git/lint/analyzers/commit_trailer_duplicate.rb +25 -0
  18. data/lib/git/lint/analyzers/commit_trailer_format_key.rb +33 -0
  19. data/lib/git/lint/analyzers/commit_trailer_format_value.rb +33 -0
  20. data/lib/git/lint/analyzers/commit_trailer_issue_key.rb +33 -0
  21. data/lib/git/lint/analyzers/commit_trailer_issue_value.rb +33 -0
  22. data/lib/git/lint/analyzers/commit_trailer_signer_capitalization.rb +35 -0
  23. data/lib/git/lint/analyzers/commit_trailer_signer_email.rb +39 -0
  24. data/lib/git/lint/analyzers/commit_trailer_signer_key.rb +33 -0
  25. data/lib/git/lint/analyzers/commit_trailer_signer_name.rb +39 -0
  26. data/lib/git/lint/analyzers/commit_trailer_tracker_key.rb +33 -0
  27. data/lib/git/lint/analyzers/commit_trailer_tracker_value.rb +33 -0
  28. data/lib/git/lint/cli/actions/analyze/branch.rb +1 -1
  29. data/lib/git/lint/cli/actions/analyze/commit.rb +8 -11
  30. data/lib/git/lint/cli/actions/hook.rb +4 -2
  31. data/lib/git/lint/commits/loader.rb +2 -2
  32. data/lib/git/lint/commits/systems/circle_ci.rb +5 -3
  33. data/lib/git/lint/commits/systems/git_hub_action.rb +5 -3
  34. data/lib/git/lint/commits/systems/local.rb +5 -3
  35. data/lib/git/lint/commits/systems/netlify_ci.rb +7 -7
  36. data/lib/git/lint/configuration/defaults.yml +58 -15
  37. data/lib/git/lint/container.rb +25 -4
  38. data/lib/git/lint/rake/{tasks.rb → register.rb} +6 -8
  39. data/lib/git/lint/reporters/commit.rb +1 -1
  40. data/lib/git/lint/validators/capitalization.rb +4 -7
  41. data/lib/git/lint/validators/email.rb +3 -4
  42. data/lib/git/lint/validators/name.rb +12 -9
  43. data/lib/git/lint.rb +0 -1
  44. data.tar.gz.sig +0 -0
  45. metadata +44 -21
  46. metadata.gz.sig +0 -0
  47. data/lib/git/lint/analyzers/commit_trailer_collaborator_duplication.rb +0 -46
  48. data/lib/git/lint/parsers/trailers/collaborator.rb +0 -50
  49. data/lib/git/lint/rake/setup.rb +0 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d02f9170b8002b1fec4f4c37602195fe1c097a9fb7a48dd29b7fea2f6d7d2fa8
4
- data.tar.gz: 2d3f96fedecaa53da9f889ea11ee299c72ba6128fb83fa1773341e0140226f57
3
+ metadata.gz: 3955d8d2f1ec24fd3501d952c62d3639f96fa5e417ef56ca0fe48269048c8ba1
4
+ data.tar.gz: b02899b30de349bab2a672de98ab06ce4155c500781fb6274adc512afb3ef9a0
5
5
  SHA512:
6
- metadata.gz: ded52e449c9ff4b05b0327976eec0534964d7b596130221ef14449b8a0b0e7d214d0dfe8c8b2846d7f057d578fae927825228ac1e2a1dbfa6b86dbae3b29495b
7
- data.tar.gz: 6b846bc2625c81485f39ae22a4cb28623dbaf698ea7ff70d191a5ed94e470ab54e5097093ce3fce08cfc06e92094afdef1880d4cd85bf751a9d08c9dfefaf98d
6
+ metadata.gz: 521674b30c53b1ebefa82ed270e685280c69ae9b25ca323cc79658a7b308fb8edf6940d957760bffd7d8a39092e6648b828f12721de2a1ab41477684338fac7e
7
+ data.tar.gz: 422413f4a60e9f3a2079578c4d01f0e8fb6d76f3b4958f10704f5d2f87728251908fbf8a53a82109a899069fe2d446c6d359eb174c35f55057b0a8cea377a16f
checksums.yaml.gz.sig CHANGED
Binary file
data/README.adoc CHANGED
@@ -407,12 +407,10 @@ ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, orn
407
407
  [options="header"]
408
408
  |===
409
409
  | Enabled | Severity | Defaults
410
- | true | error | maximum: 72
410
+ | false | error | maximum: 72
411
411
  |===
412
412
 
413
- Ensures each line of the commit body doesn't force you to scroll horizontally to read the message.
414
- This allows commit messages to remain readable and is especially handy when commit messages are read
415
- via the command line or email clients.
413
+ Ensures each line of the commit body doesn't extend beyond the maximum column limit.
416
414
 
417
415
  ==== Commit Body Paragraph Capitalization
418
416
 
@@ -462,7 +460,7 @@ and provides the missing spec to ensure this doesn't happen again.
462
460
  [options="header"]
463
461
  |===
464
462
  | Enabled | Severity | Defaults
465
- | false | warn | minimum: 1
463
+ | true | warn | minimum: 1
466
464
  |===
467
465
 
468
466
  Ensures a minimum number of lines are present within the commit body. Lines with empty characters
@@ -517,6 +515,27 @@ Instead of using tracker shorthand syntax, take the time to write a short summar
517
515
  commit was made. Doing this will make it easier to understand _why_ the commit was made, keeps the
518
516
  commit self-contained, and makes learning about/debugging the commit faster.
519
517
 
518
+ ==== Commit Signature
519
+
520
+ [options="header"]
521
+ |===
522
+ | Enabled | Severity | Defaults
523
+ | false | error | includes: `["Good"]`
524
+ |===
525
+
526
+ Ensures all commit signatures are properly signed for improved security and validity of code being committed by various authors. By default, only "Good" signatures are allowed but you can expand this list if desired (although not recommended for security reasons). Valid options are:
527
+
528
+ * *Bad* (_B_)
529
+ * *Error* (_E_)
530
+ * *Good* (_G_)
531
+ * *None* (_N_)
532
+ * *Revoked* (_R_)
533
+ * *Unknown* (_U_)
534
+ * *Expired* (_X_)
535
+ * *Expired Key* (_Y_)
536
+
537
+ All of the above obtained when using the pretty formats as provided by link:https://git-scm.com/docs/git-log#Documentation/git-log.txt-emGem[Git Log].
538
+
520
539
  ==== Commit Subject Length
521
540
 
522
541
  [options="header"]
@@ -598,7 +617,7 @@ releases.
598
617
  [options="header"]
599
618
  |===
600
619
  | Enabled | Severity | Defaults
601
- | false | error | none
620
+ | true | error | none
602
621
  |===
603
622
 
604
623
  Ensures collaborator name is properly capitalized. Example:
@@ -611,15 +630,69 @@ shepherd derrial book
611
630
  Shepherd Derrial Book
612
631
  ....
613
632
 
614
- ==== Commit Trailer Collaborator Duplication
633
+ ==== Commit Trailer Collaborator Email
634
+
635
+ [options="header"]
636
+ |===
637
+ | Enabled | Severity | Defaults
638
+ | true | error | none
639
+ |===
640
+
641
+ Ensures collaborator email address is valid for commit trailer.
642
+
643
+ ....
644
+ # Disallowed
645
+ Co-Authored-By: River Tam <invalid>
646
+
647
+ # Allowed
648
+ Co-Authored-By: River Tam <river@firefly.com>
649
+ ....
650
+
651
+ ==== Commit Trailer Collaborator Key
615
652
 
616
653
  [options="header"]
617
654
  |===
618
655
  | Enabled | Severity | Defaults
619
- | false | error | none
656
+ | true | error | includes: `["Co-Authored-By"]`
620
657
  |===
621
658
 
622
- Ensures collaborator trailers are not duplicated. Example:
659
+ Ensures collaborator trailer key is correct format.
660
+
661
+ ....
662
+ # Disallowed
663
+ Co-authored-by: River Tam <river@firefly.com>
664
+
665
+ # Allowed
666
+ Co-Authored-By: River Tam <river@firefly.com>
667
+ ....
668
+
669
+ ==== Commit Trailer Collaborator Name
670
+
671
+ [options="header"]
672
+ |===
673
+ | Enabled | Severity | Defaults
674
+ | true | error | minimum: 2
675
+ |===
676
+
677
+ Ensures collaborator name consists of, at least, a first and last name. Example:
678
+
679
+ ....
680
+ # Disallowed
681
+ Co-Authored-By: River <river@firefly.com>
682
+
683
+ # Allowed
684
+ Co-Authored-By: River Tam <river@firefly.com>
685
+ ....
686
+
687
+ ==== Commit Trailer Duplicate
688
+
689
+ [options="header"]
690
+ |===
691
+ | Enabled | Severity | Defaults
692
+ | true | error | minimum: 2
693
+ |===
694
+
695
+ Ensures commit trailer keys are not duplicated. Example:
623
696
 
624
697
  ....
625
698
  # Disallowed
@@ -631,58 +704,184 @@ Co-Authored-By: Malcolm Reynolds <malcolm@firefly.com>
631
704
  Co-Authored-By: Shepherd Derrial Book <shepherd@firefly.com>
632
705
  ....
633
706
 
634
- ==== Commit Trailer Collaborator Email
707
+ ==== Commit Trailer Format Key
635
708
 
636
709
  [options="header"]
637
710
  |===
638
711
  | Enabled | Severity | Defaults
639
- | false | error | none
712
+ | true | error | includes: `["Format"]`
640
713
  |===
641
714
 
642
- Ensures collaborator email address is valid for commit trailer.
715
+ Ensures format trailer key is correct format.
643
716
 
644
717
  ....
645
718
  # Disallowed
646
- Co-Authored-By: River Tam <invalid>
719
+ format: ASCII
647
720
 
648
721
  # Allowed
649
- Co-Authored-By: River Tam <river@firefly.com>
722
+ Format: ASCII
650
723
  ....
651
724
 
652
- ==== Commit Trailer Collaborator Key
725
+ ==== Commit Trailer Format Value
653
726
 
654
727
  [options="header"]
655
728
  |===
656
729
  | Enabled | Severity | Defaults
657
- | false | error | includes: `["Co-Authored-By"]`
730
+ | true | error | includes: `["ASCII", "Markdown"]`
658
731
  |===
659
732
 
660
- Ensures collaborator trailer key is correct format.
733
+ Ensures format trailer value is a valid value.
661
734
 
662
735
  ....
663
736
  # Disallowed
664
- Co-authored-by: River Tam <river@firefly.com>
737
+ Format: Plain
665
738
 
666
739
  # Allowed
667
- Co-Authored-By: River Tam <river@firefly.com>
740
+ Format: ASCII
668
741
  ....
669
742
 
670
- ==== Commit Trailer Collaborator Name
743
+ ==== Commit Trailer Issue Key
671
744
 
672
745
  [options="header"]
673
746
  |===
674
747
  | Enabled | Severity | Defaults
675
- | false | error | minimum: 2
748
+ | true | error | includes: `["Issue"]`
676
749
  |===
677
750
 
678
- Ensures collaborator name consists of, at least, a first and last name. Example:
751
+ Ensures issue trailer key is correct format.
679
752
 
680
753
  ....
681
754
  # Disallowed
682
- Co-Authored-By: River <river@firefly.com>
755
+ issue: 123
683
756
 
684
757
  # Allowed
685
- Co-Authored-By: River Tam <river@firefly.com>
758
+ Issue: 123
759
+ ....
760
+
761
+ ==== Commit Trailer Issue Value
762
+
763
+ [options="header"]
764
+ |===
765
+ | Enabled | Severity | Defaults
766
+ | true | error | includes: `["[\\w-]+"]`
767
+ |===
768
+
769
+ Ensures issue trailer value is correct format.
770
+
771
+ ....
772
+ # Disallowed
773
+ Issue: 123+45
774
+
775
+ # Allowed
776
+ Issue: 123
777
+ ....
778
+
779
+ ==== Commit Trailer Signer Capitalization
780
+
781
+ [options="header"]
782
+ |===
783
+ | Enabled | Severity | Defaults
784
+ | true | error | none
785
+ |===
786
+
787
+ Ensures commit signer trailer name is properly capitalized.
788
+
789
+ ....
790
+ # Disallowed
791
+ Signed-By: jayne cobb
792
+
793
+ # Allowed
794
+ Signed-By: Jayne Cobb
795
+ ....
796
+
797
+ ==== Commit Trailer Signer Email
798
+
799
+ [options="header"]
800
+ |===
801
+ | Enabled | Severity | Defaults
802
+ | true | error | none
803
+ |===
804
+
805
+ Ensures commit signer trailer email is properly capitalized.
806
+
807
+ ....
808
+ # Disallowed
809
+ Signed-By: Jayne Cobb <invalid>
810
+
811
+ # Allowed
812
+ Signed-By: Jayne Cobb <jcobb@firefly.com>
813
+ ....
814
+
815
+ ==== Commit Trailer Signer Key
816
+
817
+ [options="header"]
818
+ |===
819
+ | Enabled | Severity | Defaults
820
+ | true | error | includes: `["Signed-By"]`
821
+ |===
822
+
823
+ Ensures signer trailer key is correct format.
824
+
825
+ ....
826
+ # Disallowed
827
+ signed-by: Jayne Cobb
828
+
829
+ # Allowed
830
+ Signed-By: Jayne Cobb
831
+ ....
832
+
833
+ ==== Commit Trailer Signer Name
834
+
835
+ [options="header"]
836
+ |===
837
+ | Enabled | Severity | Defaults
838
+ | true | error | minimum: 2
839
+ |===
840
+
841
+ Ensures signer name consists of, at least, a first and last name.
842
+
843
+ ....
844
+ # Disallowed
845
+ Signed-By: Jayne
846
+
847
+ # Allowed
848
+ Signed-By: Jayne Cobb
849
+ ....
850
+
851
+ ==== Commit Trailer Tracker Key
852
+
853
+ [options="header"]
854
+ |===
855
+ | Enabled | Severity | Defaults
856
+ | true | error | includes: `["Tracker"]`
857
+ |===
858
+
859
+ Ensures tracker trailer key is correct format.
860
+
861
+ ....
862
+ # Disallowed
863
+ tracker: Linear
864
+
865
+ # Allowed
866
+ Tracker: Linear
867
+ ....
868
+
869
+ ==== Commit Trailer Tracker Value
870
+
871
+ [options="header"]
872
+ |===
873
+ | Enabled | Severity | Defaults
874
+ | true | error | includes: `["[\\w\\-\\s]+"]`
875
+ |===
876
+
877
+ Ensures tracker trailer key is correct format.
878
+
879
+ ....
880
+ # Disallowed
881
+ Tracker: *ACME$
882
+
883
+ # Allowed
884
+ Tracker: ACME Issues
686
885
  ....
687
886
 
688
887
  === Git
@@ -788,18 +987,24 @@ Whenever a commit has been saved, this script will run Git Lint to check for iss
788
987
 
789
988
  === Rake
790
989
 
791
- This gem provides optional Rake tasks. They can be added to your project by adding the following
792
- requirement to the top of your `Rakefile`:
990
+ You can add Rake support by adding the following to your `Rakefile`:
793
991
 
794
992
  [source,ruby]
795
993
  ----
796
- require "git/lint/rake/setup"
994
+ begin
995
+ require "git/lint/rake/register"
996
+ rescue LoadError => error
997
+ puts error.message
998
+ end
999
+
1000
+ Git::Lint::Rake::Register.call
797
1001
  ----
798
1002
 
799
- Now, when running `bundle exec rake -T`, you'll see `git_lint` included in the list.
1003
+ Once required and registered, the following tasks will be available (i.e. `bundle exec rake -T`):
800
1004
 
801
- If you need a concrete example, check out the
802
- link:https://github.com/bkuhlmann/git-lint/blob/main/Rakefile[Rakefile] of this project for details.
1005
+ ....
1006
+ rake git_lint
1007
+ ....
803
1008
 
804
1009
  === Continuous Integration (CI)
805
1010
 
data/git-lint.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "git-lint"
5
- spec.version = "4.6.0"
5
+ spec.version = "5.0.0"
6
6
  spec.authors = ["Brooke Kuhlmann"]
7
7
  spec.email = ["brooke@alchemists.io"]
8
8
  spec.homepage = "https://www.alchemists.io/projects/git-lint"
@@ -22,15 +22,16 @@ Gem::Specification.new do |spec|
22
22
  spec.signing_key = Gem.default_key_path
23
23
  spec.cert_chain = [Gem.default_cert_path]
24
24
 
25
- spec.required_ruby_version = "~> 3.1"
26
- spec.add_dependency "cogger", "~> 0.4"
25
+ spec.required_ruby_version = "~> 3.2"
26
+ spec.add_dependency "cogger", "~> 0.5"
27
27
  spec.add_dependency "dry-container", "~> 0.11"
28
- spec.add_dependency "git_plus", "~> 1.7"
29
- spec.add_dependency "infusible", "~> 0.2"
28
+ spec.add_dependency "dry-monads", "~> 1.6"
29
+ spec.add_dependency "gitt", "~> 1.0"
30
+ spec.add_dependency "infusible", "~> 1.0"
30
31
  spec.add_dependency "pastel", "~> 0.8"
31
- spec.add_dependency "refinements", "~> 9.7"
32
- spec.add_dependency "runcom", "~> 8.7"
33
- spec.add_dependency "spek", "~> 0.6"
32
+ spec.add_dependency "refinements", "~> 10.0"
33
+ spec.add_dependency "runcom", "~> 9.0"
34
+ spec.add_dependency "spek", "~> 1.0"
34
35
  spec.add_dependency "zeitwerk", "~> 2.6"
35
36
 
36
37
  spec.bindir = "exe"
@@ -20,14 +20,25 @@ module Git
20
20
  Analyzers::CommitBodyPresence,
21
21
  Analyzers::CommitBodySingleBullet,
22
22
  Analyzers::CommitBodyTrackerShorthand,
23
+ Analyzers::CommitSignature,
23
24
  Analyzers::CommitSubjectLength,
24
25
  Analyzers::CommitSubjectPrefix,
25
26
  Analyzers::CommitSubjectSuffix,
26
27
  Analyzers::CommitTrailerCollaboratorCapitalization,
27
- Analyzers::CommitTrailerCollaboratorDuplication,
28
28
  Analyzers::CommitTrailerCollaboratorEmail,
29
29
  Analyzers::CommitTrailerCollaboratorKey,
30
- Analyzers::CommitTrailerCollaboratorName
30
+ Analyzers::CommitTrailerCollaboratorName,
31
+ Analyzers::CommitTrailerDuplicate,
32
+ Analyzers::CommitTrailerFormatKey,
33
+ Analyzers::CommitTrailerFormatValue,
34
+ Analyzers::CommitTrailerIssueKey,
35
+ Analyzers::CommitTrailerIssueValue,
36
+ Analyzers::CommitTrailerSignerCapitalization,
37
+ Analyzers::CommitTrailerSignerEmail,
38
+ Analyzers::CommitTrailerSignerKey,
39
+ Analyzers::CommitTrailerSignerName,
40
+ Analyzers::CommitTrailerTrackerKey,
41
+ Analyzers::CommitTrailerTrackerValue
31
42
  ].freeze
32
43
 
33
44
  # rubocop:disable Metrics/ParameterLists
@@ -54,7 +65,7 @@ module Git
54
65
 
55
66
  def process commits
56
67
  collector.clear
57
- commits.map { |commit| analyze commit }
68
+ commits.value_or([]).map { |commit| analyze commit }
58
69
  end
59
70
 
60
71
  def analyze commit
@@ -12,13 +12,13 @@ module Git
12
12
  using ::Refinements::Strings
13
13
 
14
14
  LEVELS = %i[warn error].freeze
15
- ISSUE_LINE_OFFSET = 2
15
+ BODY_OFFSET = 3
16
16
 
17
17
  def self.id = to_s.delete_prefix("Git::Lint::Analyzers").snakecase.to_sym
18
18
 
19
19
  def self.label = to_s.delete_prefix("Git::Lint::Analyzers").titleize
20
20
 
21
- def self.build_issue_line(index, line) = {number: index + ISSUE_LINE_OFFSET, content: line}
21
+ def self.build_issue_line(index, line) = {number: index + BODY_OFFSET, content: line}
22
22
 
23
23
  attr_reader :commit
24
24
 
@@ -64,9 +64,12 @@ module Git
64
64
 
65
65
  def affected_commit_trailers
66
66
  commit.trailers
67
- .each.with_object([])
68
- .with_index(commit.trailers_index) do |(line, lines), index|
69
- lines << self.class.build_issue_line(index, line) if invalid_line? line
67
+ .each
68
+ .with_object([])
69
+ .with_index(commit.body_lines.size) do |(trailer, trailers), index|
70
+ next unless invalid_line? trailer
71
+
72
+ trailers << self.class.build_issue_line(index, trailer.to_s)
70
73
  end
71
74
  end
72
75
 
@@ -5,22 +5,15 @@ module Git
5
5
  module Analyzers
6
6
  # Analyzes author for proper capitalization of author name.
7
7
  class CommitAuthorCapitalization < Abstract
8
- def initialize commit, validator: Validators::Capitalization, **dependencies
9
- super commit, **dependencies
10
- @validator = validator
11
- end
8
+ include Import[validator: "validators.capitalization"]
12
9
 
13
- def valid? = validator.new(commit.author_name).valid?
10
+ def valid? = validator.call commit.author_name
14
11
 
15
12
  def issue
16
13
  return {} if valid?
17
14
 
18
15
  {hint: %(Capitalize each part of name: "#{commit.author_name}".)}
19
16
  end
20
-
21
- private
22
-
23
- attr_reader :validator
24
17
  end
25
18
  end
26
19
  end
@@ -5,22 +5,15 @@ module Git
5
5
  module Analyzers
6
6
  # Analyzes author email address for proper format.
7
7
  class CommitAuthorEmail < Abstract
8
- def initialize commit, validator: Validators::Email, **dependencies
9
- super commit, **dependencies
10
- @validator = validator
11
- end
8
+ include Import[validator: "validators.email"]
12
9
 
13
- def valid? = validator.new(commit.author_email).valid?
10
+ def valid? = validator.call commit.author_email
14
11
 
15
12
  def issue
16
13
  return {} if valid?
17
14
 
18
15
  {hint: %(Use "<name>@<server>.<domain>" instead of "#{commit.author_email}".)}
19
16
  end
20
-
21
- private
22
-
23
- attr_reader :validator
24
17
  end
25
18
  end
26
19
  end
@@ -5,12 +5,9 @@ module Git
5
5
  module Analyzers
6
6
  # Analyzes author name for minimum parts of name.
7
7
  class CommitAuthorName < Abstract
8
- def initialize commit, validator: Validators::Name, **dependencies
9
- super commit, **dependencies
10
- @validator = validator
11
- end
8
+ include Import[validator: "validators.name"]
12
9
 
13
- def valid? = validator.new(commit.author_name, minimum:).valid?
10
+ def valid? = validator.call(commit.author_name, minimum:)
14
11
 
15
12
  def issue
16
13
  return {} if valid?
@@ -20,8 +17,6 @@ module Git
20
17
 
21
18
  private
22
19
 
23
- attr_reader :validator
24
-
25
20
  def minimum = settings.minimum
26
21
  end
27
22
  end
@@ -6,12 +6,12 @@ module Git
6
6
  # Analyzes leading line between commit subject and start of body.
7
7
  class CommitBodyLeadingLine < Abstract
8
8
  def valid?
9
- message = commit.message
10
- subject, body = message.split "\n", 2
9
+ raw = commit.raw
10
+ subject, body = raw.split "\n", 2
11
11
 
12
12
  return true if !String(subject).empty? && String(body).strip.empty?
13
13
 
14
- message.match?(/\A.+(\n\n|\#).+/m)
14
+ raw.match?(/\A.+(\n\n|\#).+/m)
15
15
  end
16
16
 
17
17
  def issue
@@ -7,7 +7,12 @@ module Git
7
7
  class CommitBodyParagraphCapitalization < Abstract
8
8
  def self.invalid?(line) = line.match?(/\A[[:lower:]].+\Z/m)
9
9
 
10
- def valid? = lowercased_lines.empty?
10
+ def initialize(...)
11
+ super
12
+ @invalids = commit.body_paragraphs.select { |line| self.class.invalid? line }
13
+ end
14
+
15
+ def valid? = invalids.empty?
11
16
 
12
17
  def issue
13
18
  return {} if valid?
@@ -20,13 +25,11 @@ module Git
20
25
 
21
26
  private
22
27
 
23
- def lowercased_lines = commit.body_paragraphs.select { |line| self.class.invalid? line }
28
+ attr_reader :invalids
24
29
 
25
30
  def affected_lines
26
- klass = self.class
27
-
28
- commit.body_paragraphs.each.with_object([]).with_index do |(line, lines), index|
29
- lines << klass.build_issue_line(index, line)
31
+ invalids.each.with_object [] do |line, lines|
32
+ lines << self.class.build_issue_line(commit.body_lines.index(line[/.+/]), line)
30
33
  end
31
34
  end
32
35
  end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Git
4
+ module Lint
5
+ module Analyzers
6
+ # Analyzes commit signature validity.
7
+ class CommitSignature < Abstract
8
+ include Import[sanitizer: "sanitizers.signature"]
9
+
10
+ def valid?
11
+ sanitizer.call(commit.signature).match?(/\A#{Regexp.union filter_list.to_regexp}\Z/)
12
+ end
13
+
14
+ def issue = valid? ? {} : {hint: %(Use: #{filter_list.to_hint}.)}
15
+
16
+ protected
17
+
18
+ def load_filter_list = Kit::FilterList.new(settings.includes)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -5,16 +5,11 @@ module Git
5
5
  module Analyzers
6
6
  # Analyzes commit trailer collaborator name capitalization.
7
7
  class CommitTrailerCollaboratorCapitalization < Abstract
8
- # rubocop:disable Metrics/ParameterLists
9
- def initialize commit,
10
- parser: Parsers::Trailers::Collaborator,
11
- validator: Validators::Capitalization,
12
- **dependencies
13
- super commit, **dependencies
14
- @parser = parser
15
- @validator = validator
16
- end
17
- # rubocop:enable Metrics/ParameterLists
8
+ include Import[
9
+ pattern: "trailers.collaborator",
10
+ parser: "parsers.person",
11
+ validator: "validators.capitalization"
12
+ ]
18
13
 
19
14
  def valid? = affected_commit_trailers.empty?
20
15
 
@@ -29,14 +24,11 @@ module Git
29
24
 
30
25
  protected
31
26
 
32
- def invalid_line? line
33
- collaborator = parser.new line
34
- collaborator.match? && !validator.new(collaborator.name.strip).valid?
27
+ def invalid_line? trailer
28
+ parser.call(trailer.value).then do |person|
29
+ trailer.key.match?(pattern) && !validator.call(person.name)
30
+ end
35
31
  end
36
-
37
- private
38
-
39
- attr_reader :parser, :validator
40
32
  end
41
33
  end
42
34
  end