Class: RuboCop::Cop::PackageProtections::OnlyClassMethods

Inherits:
Packs::ClassMethodsAsPublicApis
  • Object
show all
Extended by:
T::Sig
Includes:
PackageProtections::RubocopProtectionInterface
Defined in:
lib/rubocop/cop/package_protections/only_class_methods.rb

Constant Summary collapse

IDENTIFIER =
'prevent_this_package_from_exposing_instance_method_public_apis'.freeze

Instance Method Summary collapse

Methods included from PackageProtections::RubocopProtectionInterface

#cop_configs, #get_offenses_for_existing_violations, #get_offenses_for_new_violations, #unmet_preconditions_for_behavior

Methods included from PackageProtections::ProtectionInterface

#get_offenses, #get_offenses_for_existing_violations, #get_offenses_for_new_violations, #supports_violation_behavior?, #unmet_preconditions_for_behavior

Instance Method Details

#cop_nameObject



56
57
58
# File 'lib/rubocop/cop/package_protections/only_class_methods.rb', line 56

def cop_name
  'PackageProtections/OnlyClassMethods'
end

#custom_cop_configObject



39
40
41
42
43
# File 'lib/rubocop/cop/package_protections/only_class_methods.rb', line 39

def custom_cop_config
  {
    'AcceptableParentClasses' => ::PackageProtections.config.acceptable_parent_classes
  }
end

#default_behaviorObject



61
62
63
# File 'lib/rubocop/cop/package_protections/only_class_methods.rb', line 61

def default_behavior
  ::PackageProtections::ViolationBehavior::FailNever
end

#humanized_protection_descriptionObject



13
14
15
16
17
18
19
20
# File 'lib/rubocop/cop/package_protections/only_class_methods.rb', line 13

def humanized_protection_description
  <<~MESSAGE
    Public API methods can only be static methods.
    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}`
  MESSAGE
end

#humanized_protection_nameObject



51
52
53
# File 'lib/rubocop/cop/package_protections/only_class_methods.rb', line 51

def humanized_protection_name
  'Class Method Public APIs'
end

#identifierObject



46
47
48
# File 'lib/rubocop/cop/package_protections/only_class_methods.rb', line 46

def identifier
  IDENTIFIER
end

#included_globs_for_packObject



30
31
32
33
34
# File 'lib/rubocop/cop/package_protections/only_class_methods.rb', line 30

def included_globs_for_pack
  [
    'app/public/**/*'
  ]
end

#message_for_fail_on_any(file) ⇒ Object



25
26
27
# File 'lib/rubocop/cop/package_protections/only_class_methods.rb', line 25

def message_for_fail_on_any(file)
  "`#{file}` must only contain static (class or module level) methods"
end