Class: RuboCop::Cop::PackageProtections::RequireDocumentedPublicApis

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

Constant Summary collapse

IDENTIFIER =
'prevent_this_package_from_exposing_undocumented_public_apis'.freeze

Instance Method Summary collapse

Methods included from PackageProtections::RubocopProtectionInterface

#cop_configs, #custom_cop_config, #get_offenses_for_existing_violations, #get_offenses_for_new_violations

Methods included from PackageProtections::ProtectionInterface

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

Instance Method Details

#cop_nameObject



44
45
46
# File 'lib/rubocop/cop/package_protections/require_documented_public_apis.rb', line 44

def cop_name
  'PackageProtections/RequireDocumentedPublicApis'
end

#default_behaviorObject



54
55
56
# File 'lib/rubocop/cop/package_protections/require_documented_public_apis.rb', line 54

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

#humanized_protection_descriptionObject



59
60
61
62
63
64
65
66
# File 'lib/rubocop/cop/package_protections/require_documented_public_apis.rb', line 59

def humanized_protection_description
  <<~MESSAGE
    All public API must have a documentation comment (between the signature and method).
    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



49
50
51
# File 'lib/rubocop/cop/package_protections/require_documented_public_apis.rb', line 49

def humanized_protection_name
  'Documented Public APIs'
end

#identifierObject



15
16
17
# File 'lib/rubocop/cop/package_protections/require_documented_public_apis.rb', line 15

def identifier
  IDENTIFIER
end

#included_globs_for_packObject



20
21
22
23
24
# File 'lib/rubocop/cop/package_protections/require_documented_public_apis.rb', line 20

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

#message_for_fail_on_any(file) ⇒ Object



39
40
41
# File 'lib/rubocop/cop/package_protections/require_documented_public_apis.rb', line 39

def message_for_fail_on_any(file)
  "`#{file}` must contain documentation on every method (between signature and method)"
end

#unmet_preconditions_for_behavior(behavior, package) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/rubocop/cop/package_protections/require_documented_public_apis.rb', line 27

def unmet_preconditions_for_behavior(behavior, package)
  if !behavior.fail_never?
    readme_path = package.directory.join('README.md')
    if !readme_path.exist?
      "This package must have a readme at #{readme_path} to use this protection"
    end
  end
end