lib/danger-packwerk/danger_packwerk.rb in danger-packwerk-0.9.0 vs lib/danger-packwerk/danger_packwerk.rb in danger-packwerk-0.10.0

- old
+ new

@@ -19,10 +19,14 @@ DEFAULT_MAX_COMMENTS = 15 OnFailure = T.type_alias { T.proc.params(offenses: T::Array[Packwerk::ReferenceOffense]).void } DEFAULT_ON_FAILURE = T.let(->(offenses) {}, OnFailure) DEFAULT_FAIL = false DEFAULT_FAILURE_MESSAGE = 'Packwerk violations were detected! Please resolve them to unblock the build.' + DEFAULT_VIOLATION_TYPES = T.let([ + DEPENDENCY_VIOLATION_TYPE, + PRIVACY_VIOLATION_TYPE + ], T::Array[String]) class CommentGroupingStrategy < ::T::Enum enums do PerConstantPerLocation = new PerConstantPerPack = new @@ -36,19 +40,21 @@ offenses_formatter: T.nilable(Check::OffensesFormatter), max_comments: Integer, fail_build: T::Boolean, failure_message: String, on_failure: OnFailure, + violation_types: T::Array[String], grouping_strategy: CommentGroupingStrategy ).void end def check( offenses_formatter: nil, max_comments: DEFAULT_MAX_COMMENTS, fail_build: DEFAULT_FAIL, failure_message: DEFAULT_FAILURE_MESSAGE, on_failure: DEFAULT_ON_FAILURE, + violation_types: DEFAULT_VIOLATION_TYPES, grouping_strategy: CommentGroupingStrategy::PerConstantPerLocation ) offenses_formatter ||= Check::DefaultFormatter.new repo_link = github.pr_json[:base][:repo][:html_url] org_name = github.pr_json[:base][:repo][:owner][:login] @@ -86,14 +92,16 @@ packwerk_reference_offenses = PackwerkWrapper.get_offenses_for_files(targeted_files.to_a).compact renamed_files = git.renamed_files.map { |before_after_file| before_after_file[:after] } - # Ignore references that have been renamed packwerk_reference_offenses_to_care_about = packwerk_reference_offenses.reject do |packwerk_reference_offense| constant_name = packwerk_reference_offense.reference.constant.name filepath_that_defines_this_constant = Private.constant_resolver.resolve(constant_name)&.location - renamed_files.include?(filepath_that_defines_this_constant) + # Ignore references that have been renamed + renamed_files.include?(filepath_that_defines_this_constant) || + # Ignore violations that are not in the allow-list of violation types to leave comments for + !violation_types.include?(packwerk_reference_offense.violation_type) end # We group by the constant name, line number, and reference path. Any offenses with these same values should only differ on what type of violation # they are (privacy or dependency). We put privacy and dependency violation messages in the same comment since they would occur on the same line. packwerk_reference_offenses_to_care_about.group_by do |packwerk_reference_offense|