Module: PackageProtections::RubocopProtectionInterface
Defined Under Namespace
Classes: CopConfig
Instance Method Summary
collapse
#default_behavior, #get_offenses, #humanized_protection_description, #humanized_protection_name, #identifier, #supports_violation_behavior?
Instance Method Details
#cop_configs(packages) ⇒ Object
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
# File 'lib/package_protections/rubocop_protection_interface.rb', line 119
def cop_configs(packages)
include_paths = T.let([], T::Array[String])
packages.each do |p|
next unless p.violation_behavior_for(identifier).enabled?
included_globs_for_pack.each do |glob|
include_paths << p.original_package.directory.join(glob).to_s
end
end
[
CopConfig.new(
name: cop_name,
enabled: include_paths.any?,
include_paths: include_paths,
metadata: custom_cop_config
)
]
end
|
#cop_name ⇒ Object
45
|
# File 'lib/package_protections/rubocop_protection_interface.rb', line 45
def cop_name; end
|
#custom_cop_config ⇒ Object
62
63
64
|
# File 'lib/package_protections/rubocop_protection_interface.rb', line 62
def custom_cop_config
{}
end
|
#get_offenses_for_existing_violations(protected_packages) ⇒ Object
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
# File 'lib/package_protections/rubocop_protection_interface.rb', line 83
def get_offenses_for_existing_violations(protected_packages)
exclude_list = RuboCop::Packs.exclude_for_rule(cop_name)
offenses = []
protected_packages.each do |package|
violation_behavior = package.violation_behavior_for(identifier)
case violation_behavior
when ViolationBehavior::FailNever, ViolationBehavior::FailOnNew
next
when ViolationBehavior::FailOnAny
else
T.absurd(violation_behavior)
end
package.original_package.directory.glob(included_globs_for_pack).each do |relative_path_to_file|
next unless exclude_list.include?(relative_path_to_file.to_s)
file = relative_path_to_file.to_s
offenses << Offense.new(
file: file,
message: message_for_fail_on_any(file),
violation_type: identifier,
package: package.original_package
)
end
end
offenses
end
|
#get_offenses_for_new_violations(new_violations) ⇒ Object
74
75
76
|
# File 'lib/package_protections/rubocop_protection_interface.rb', line 74
def get_offenses_for_new_violations(new_violations)
[]
end
|
#included_globs_for_pack ⇒ Object
53
|
# File 'lib/package_protections/rubocop_protection_interface.rb', line 53
def included_globs_for_pack; end
|
#message_for_fail_on_any(file) ⇒ Object
50
|
# File 'lib/package_protections/rubocop_protection_interface.rb', line 50
def message_for_fail_on_any(file); end
|
#unmet_preconditions_for_behavior(behavior, package) ⇒ Object
67
|
# File 'lib/package_protections/rubocop_protection_interface.rb', line 67
def unmet_preconditions_for_behavior(behavior, package); end
|