Class: RuboCop::Cop::PackageProtections::TypedPublicApi
Overview
This inherits from ‘Sorbet::StrictSigil` and doesn’t change any behavior of it. The only reason we do this is so that configuration for this cop can live under a different cop namespace. This prevents this cop’s configuration from clashing with other configurations for the same cop. A concrete example of this would be if a user is using this package protection to make sure public APIs are typed, and separately the application as a whole requiring strict typing in certain parts of the application.
To prevent problems associated with needing to manage identical configurations for the same cop, we simply call it something else in the context of this protection.
We can apply this same pattern if we want to use other cops in the context of package protections and prevent clashing.
Constant Summary
collapse
- IDENTIFIER =
T.let('prevent_this_package_from_exposing_an_untyped_api'.freeze, String)
Instance Method Summary
collapse
#cop_configs, #custom_cop_config, #get_offenses_for_existing_violations, #get_offenses_for_new_violations
#default_behavior, #get_offenses, #get_offenses_for_existing_violations, #get_offenses_for_new_violations, #supports_violation_behavior?
Instance Method Details
#cop_name ⇒ Object
40
41
42
|
# File 'lib/rubocop/cop/package_protections/typed_public_api.rb', line 40
def cop_name
'PackageProtections/TypedPublicApi'
end
|
#humanized_protection_description ⇒ Object
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/rubocop/cop/package_protections/typed_public_api.rb', line 64
def humanized_protection_description
<<~MESSAGE
These files cannot have ANY Ruby files in the public API that are not typed strict or higher.
This is failing because these files are in `.rubocop_todo.yml` under `#{cop_name}`.
If you want to be able to ignore these files, you'll need to open the file's package's `package.yml` file and
change `#{IDENTIFIER}` to `#{::PackageProtections::ViolationBehavior::FailOnNew.serialize}`
See https://go/packwerk_cheatsheet_typed_api for more info.
MESSAGE
end
|
#humanized_protection_name ⇒ Object
59
60
61
|
# File 'lib/rubocop/cop/package_protections/typed_public_api.rb', line 59
def humanized_protection_name
'Typed API Violations'
end
|
#identifier ⇒ Object
27
28
29
|
# File 'lib/rubocop/cop/package_protections/typed_public_api.rb', line 27
def identifier
IDENTIFIER
end
|
#included_globs_for_pack ⇒ Object
45
46
47
48
49
|
# File 'lib/rubocop/cop/package_protections/typed_public_api.rb', line 45
def included_globs_for_pack
[
'app/public/**/*'
]
end
|
#message_for_fail_on_any(file) ⇒ Object
54
55
56
|
# File 'lib/rubocop/cop/package_protections/typed_public_api.rb', line 54
def message_for_fail_on_any(file)
"#{file} should be `typed: strict`"
end
|
#unmet_preconditions_for_behavior(behavior, package) ⇒ Object
32
33
34
35
36
37
|
# File 'lib/rubocop/cop/package_protections/typed_public_api.rb', line 32
def unmet_preconditions_for_behavior(behavior, package)
nil
end
|