From a18441f86e0b72feacc4e97017f61f0d1460d0c9 Mon Sep 17 00:00:00 2001 From: Adam Leff Date: Thu, 7 Dec 2017 14:22:55 -0500 Subject: [PATCH] Rubocop: disable GuardClause and ClassLength (#2382) Neither of these cops is helping us write good code, and GuardClause specifically is actually contributing to us writing sometimes-unclear code. Disabling both of these cops and removing all unnecessary disable decorators in the codebase. Signed-off-by: Adam Leff --- .rubocop.yml | 4 ++++ lib/bundles/inspec-artifact/cli.rb | 2 -- lib/bundles/inspec-compliance/api.rb | 2 +- lib/bundles/inspec-compliance/cli.rb | 2 +- lib/bundles/inspec-habitat/profile.rb | 2 +- lib/fetchers/url.rb | 2 +- lib/inspec/base_cli.rb | 2 +- lib/inspec/cli.rb | 2 +- lib/inspec/control_eval_context.rb | 2 +- lib/inspec/dependencies/lockfile.rb | 2 -- lib/inspec/metadata.rb | 2 +- lib/inspec/profile.rb | 2 +- lib/inspec/profile_context.rb | 2 +- lib/inspec/rspec_json_formatter.rb | 6 +++--- lib/inspec/rule.rb | 2 +- lib/inspec/runner.rb | 2 +- lib/inspec/schema.rb | 2 +- lib/inspec/shell.rb | 2 +- lib/resources/aide_conf.rb | 2 -- lib/resources/auditd.rb | 1 - lib/resources/auditd_rules.rb | 2 -- lib/resources/crontab.rb | 2 +- lib/resources/docker.rb | 2 +- lib/resources/elasticsearch.rb | 2 +- lib/resources/grub_conf.rb | 2 +- lib/resources/port.rb | 2 +- lib/resources/processes.rb | 2 +- lib/resources/registry_key.rb | 2 +- lib/resources/service.rb | 2 +- lib/resources/virtualization.rb | 2 +- lib/resources/x509_certificate.rb | 2 +- 31 files changed, 31 insertions(+), 36 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index e462f750b..c2e7cf5d1 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -38,6 +38,8 @@ Metrics/AbcSize: Max: 33 Metrics/BlockLength: Max: 50 +Metrics/ClassLength: + Enabled: false Metrics/CyclomaticComplexity: Max: 10 Metrics/PerceivedComplexity: @@ -60,6 +62,8 @@ Style/Encoding: Enabled: false Style/FileName: Enabled: false +Style/GuardClause: + Enabled: false Style/IfUnlessModifier: Enabled: false Style/MethodMissing: diff --git a/lib/bundles/inspec-artifact/cli.rb b/lib/bundles/inspec-artifact/cli.rb index b96b747e4..496b21ec6 100644 --- a/lib/bundles/inspec-artifact/cli.rb +++ b/lib/bundles/inspec-artifact/cli.rb @@ -90,8 +90,6 @@ module Artifact SIGNED_PROFILE_SUFFIX='iaf' SIGNED_REPORT_SUFFIX='iar' - - # rubocop:disable Metrics/ClassLength class CLI < Inspec::BaseCLI namespace 'artifact' diff --git a/lib/bundles/inspec-compliance/api.rb b/lib/bundles/inspec-compliance/api.rb index 91dd29e9a..17e79dd6e 100755 --- a/lib/bundles/inspec-compliance/api.rb +++ b/lib/bundles/inspec-compliance/api.rb @@ -12,7 +12,7 @@ module Compliance # API Implementation does not hold any state by itself, # everything will be stored in local Configuration store - class API # rubocop:disable Metrics/ClassLength + class API extend Compliance::API::Login # return all compliance profiles available for the user diff --git a/lib/bundles/inspec-compliance/cli.rb b/lib/bundles/inspec-compliance/cli.rb index 53a353ec1..4b60a1f85 100644 --- a/lib/bundles/inspec-compliance/cli.rb +++ b/lib/bundles/inspec-compliance/cli.rb @@ -6,7 +6,7 @@ require 'thor' require 'erb' module Compliance - class ComplianceCLI < Inspec::BaseCLI # rubocop:disable Metrics/ClassLength + class ComplianceCLI < Inspec::BaseCLI namespace 'compliance' # TODO: find another solution, once https://github.com/erikhuda/thor/issues/261 is fixed diff --git a/lib/bundles/inspec-habitat/profile.rb b/lib/bundles/inspec-habitat/profile.rb index e72f7bfb9..9fe8fe88d 100644 --- a/lib/bundles/inspec-habitat/profile.rb +++ b/lib/bundles/inspec-habitat/profile.rb @@ -6,7 +6,7 @@ require 'mixlib/shellout' require 'tomlrb' module Habitat - class Profile # rubocop:disable Metrics/ClassLength + class Profile attr_reader :options, :path, :profile def self.create(path, options = {}) diff --git a/lib/fetchers/url.rb b/lib/fetchers/url.rb index b23673d3f..84065eb35 100644 --- a/lib/fetchers/url.rb +++ b/lib/fetchers/url.rb @@ -8,7 +8,7 @@ require 'tempfile' require 'open-uri' module Fetchers - class Url < Inspec.fetcher(1) # rubocop:disable Metrics/ClassLength + class Url < Inspec.fetcher(1) MIME_TYPES = { 'application/x-zip-compressed' => '.zip', 'application/zip' => '.zip', diff --git a/lib/inspec/base_cli.rb b/lib/inspec/base_cli.rb index ddb81e48a..6adaead5c 100644 --- a/lib/inspec/base_cli.rb +++ b/lib/inspec/base_cli.rb @@ -7,7 +7,7 @@ require 'inspec/log' require 'inspec/profile_vendor' module Inspec - class BaseCLI < Thor # rubocop:disable Metrics/ClassLength + class BaseCLI < Thor def self.target_options option :target, aliases: :t, type: :string, desc: 'Simple targeting option using URIs, e.g. ssh://user:pass@host:port' diff --git a/lib/inspec/cli.rb b/lib/inspec/cli.rb index 2cb240a32..7b31b520a 100644 --- a/lib/inspec/cli.rb +++ b/lib/inspec/cli.rb @@ -15,7 +15,7 @@ require 'inspec/runner_mock' require 'inspec/env_printer' require 'inspec/schema' -class Inspec::InspecCLI < Inspec::BaseCLI # rubocop:disable Metrics/ClassLength +class Inspec::InspecCLI < Inspec::BaseCLI class_option :log_level, aliases: :l, type: :string, desc: 'Set the log level: info (default), debug, warn, error' diff --git a/lib/inspec/control_eval_context.rb b/lib/inspec/control_eval_context.rb index 0ed5cfc61..e696627ff 100644 --- a/lib/inspec/control_eval_context.rb +++ b/lib/inspec/control_eval_context.rb @@ -13,7 +13,7 @@ module Inspec # as the basic DSL of the control files (describe, control, title, # etc). # - class ControlEvalContext # rubocop:disable Metrics/ClassLength + class ControlEvalContext # Create the context for controls. This includes all components of the DSL, # including matchers and resources. # diff --git a/lib/inspec/dependencies/lockfile.rb b/lib/inspec/dependencies/lockfile.rb index b997069e4..35c49a33f 100644 --- a/lib/inspec/dependencies/lockfile.rb +++ b/lib/inspec/dependencies/lockfile.rb @@ -28,7 +28,6 @@ module Inspec from_content(content) end - # rubocop:disable Style/GuardClause def self.validate_lockfile_version!(version) if version < MINIMUM_SUPPORTED_VERSION raise <<~EOF @@ -49,7 +48,6 @@ module Inspec EOF end end - # rubocop:enable Style/GuardClause attr_reader :version, :deps def initialize(lockfile_content_hash) diff --git a/lib/inspec/metadata.rb b/lib/inspec/metadata.rb index 36f898d56..ff663b2ac 100644 --- a/lib/inspec/metadata.rb +++ b/lib/inspec/metadata.rb @@ -14,7 +14,7 @@ module Inspec # A Metadata object may be created and finalized with invalid data. # This allows the check CLI command to analyse the issues. # Use valid? to determine if the metadata is coherent. - class Metadata # rubocop:disable Metrics/ClassLength + class Metadata attr_reader :ref attr_accessor :params, :content def initialize(ref, logger = nil) diff --git a/lib/inspec/profile.rb b/lib/inspec/profile.rb index fcb849024..6801d5570 100644 --- a/lib/inspec/profile.rb +++ b/lib/inspec/profile.rb @@ -21,7 +21,7 @@ require 'inspec/dependencies/lockfile' require 'inspec/dependencies/dependency_set' module Inspec - class Profile # rubocop:disable Metrics/ClassLength + class Profile extend Forwardable def self.resolve_target(target, cache) diff --git a/lib/inspec/profile_context.rb b/lib/inspec/profile_context.rb index 511676fac..26d4f59d8 100644 --- a/lib/inspec/profile_context.rb +++ b/lib/inspec/profile_context.rb @@ -11,7 +11,7 @@ require 'securerandom' require 'inspec/objects/attribute' module Inspec - class ProfileContext # rubocop:disable Metrics/ClassLength + class ProfileContext def self.for_profile(profile, backend, attributes) new(profile.name, backend, { 'profile' => profile, 'attributes' => attributes, diff --git a/lib/inspec/rspec_json_formatter.rb b/lib/inspec/rspec_json_formatter.rb index fdbb878d4..f871bdc1f 100644 --- a/lib/inspec/rspec_json_formatter.rb +++ b/lib/inspec/rspec_json_formatter.rb @@ -110,7 +110,7 @@ class InspecRspecMiniJson < RSpec::Core::Formatters::JsonFormatter end end -class InspecRspecJson < InspecRspecMiniJson # rubocop:disable Metrics/ClassLength +class InspecRspecJson < InspecRspecMiniJson RSpec::Core::Formatters.register self, :stop, :dump_summary attr_writer :backend @@ -279,7 +279,7 @@ class InspecRspecJson < InspecRspecMiniJson # rubocop:disable Metrics/ClassLengt end end -class InspecRspecCli < InspecRspecJson # rubocop:disable Metrics/ClassLength +class InspecRspecCli < InspecRspecJson RSpec::Core::Formatters.register self, :close case RUBY_PLATFORM @@ -685,7 +685,7 @@ class InspecRspecCli < InspecRspecJson # rubocop:disable Metrics/ClassLength # This class wraps a control hash object to provide a useful inteface for # maintaining the associated profile, ids, results, title, etc. # - class Control # rubocop:disable Metrics/ClassLength + class Control include Comparable STATUS_TYPES = { diff --git a/lib/inspec/rule.rb b/lib/inspec/rule.rb index 97505abd6..32dda09c7 100644 --- a/lib/inspec/rule.rb +++ b/lib/inspec/rule.rb @@ -8,7 +8,7 @@ require 'inspec/describe' require 'inspec/expect' module Inspec - class Rule # rubocop:disable Metrics/ClassLength + class Rule include ::RSpec::Matchers # diff --git a/lib/inspec/runner.rb b/lib/inspec/runner.rb index 973d9a329..7df8aab2d 100644 --- a/lib/inspec/runner.rb +++ b/lib/inspec/runner.rb @@ -28,7 +28,7 @@ module Inspec # r.run # ``` # - class Runner # rubocop:disable Metrics/ClassLength + class Runner extend Forwardable def_delegator :@test_collector, :report diff --git a/lib/inspec/schema.rb b/lib/inspec/schema.rb index f24c29890..e6aaeadbb 100644 --- a/lib/inspec/schema.rb +++ b/lib/inspec/schema.rb @@ -2,7 +2,7 @@ require 'json' module Inspec - class Schema # rubocop:disable Metrics/ClassLength + class Schema STATISTICS = { 'type' => 'object', 'additionalProperties' => false, diff --git a/lib/inspec/shell.rb b/lib/inspec/shell.rb index 415d3ea84..5a3c4f6d7 100644 --- a/lib/inspec/shell.rb +++ b/lib/inspec/shell.rb @@ -9,7 +9,7 @@ module Inspec # A pry based shell for inspec. Given a runner (with a configured backend and # all that jazz), this shell will produce a pry shell from which you can run # inspec/ruby commands that will be run within the context of the runner. - class Shell # rubocop:disable Metrics/ClassLength + class Shell def initialize(runner) @runner = runner end diff --git a/lib/resources/aide_conf.rb b/lib/resources/aide_conf.rb index 30721ae9e..976ad4725 100644 --- a/lib/resources/aide_conf.rb +++ b/lib/resources/aide_conf.rb @@ -3,8 +3,6 @@ require 'utils/filter' require 'utils/parser' - -# rubocop:disable Metrics/ClassLength module Inspec::Resources class AideConf < Inspec.resource(1) name 'aide_conf' diff --git a/lib/resources/auditd.rb b/lib/resources/auditd.rb index 606026bb9..e6c7b8bee 100644 --- a/lib/resources/auditd.rb +++ b/lib/resources/auditd.rb @@ -9,7 +9,6 @@ require 'utils/filter' require 'utils/parser' module Inspec::Resources - # rubocop:disable Metrics/ClassLength class AuditDaemon < Inspec.resource(1) extend Forwardable attr_accessor :lines diff --git a/lib/resources/auditd_rules.rb b/lib/resources/auditd_rules.rb index 552f96391..a29b6d89d 100644 --- a/lib/resources/auditd_rules.rb +++ b/lib/resources/auditd_rules.rb @@ -43,8 +43,6 @@ module Inspec::Resources 'Audit Daemon Rules (for auditd version < 2.3)' end end - - # rubocop:disable Metrics/ClassLength class AuditDaemonRules < Inspec.resource(1) extend Forwardable attr_accessor :rules, :lines diff --git a/lib/resources/crontab.rb b/lib/resources/crontab.rb index 9484d252c..63acf56b7 100644 --- a/lib/resources/crontab.rb +++ b/lib/resources/crontab.rb @@ -4,7 +4,7 @@ require 'utils/parser' require 'utils/filter' module Inspec::Resources - class Crontab < Inspec.resource(1) # rubocop:disable Metrics/ClassLength + class Crontab < Inspec.resource(1) name 'crontab' desc 'Use the crontab InSpec audit resource to test the contents of the crontab for a given user which contains information about scheduled tasks owned by that user.' example " diff --git a/lib/resources/docker.rb b/lib/resources/docker.rb index 734d6baeb..a085076a7 100644 --- a/lib/resources/docker.rb +++ b/lib/resources/docker.rb @@ -63,7 +63,7 @@ module Inspec::Resources # For compatability with Serverspec we also offer the following resouses: # - docker_container # - docker_image - class Docker < Inspec.resource(1) # rubocop:disable Metrics/ClassLength + class Docker < Inspec.resource(1) name 'docker' desc " diff --git a/lib/resources/elasticsearch.rb b/lib/resources/elasticsearch.rb index 50d337d45..97b9f7d1e 100644 --- a/lib/resources/elasticsearch.rb +++ b/lib/resources/elasticsearch.rb @@ -5,7 +5,7 @@ require 'hashie/mash' require 'resources/package' module Inspec::Resources - class Elasticsearch < Inspec.resource(1) # rubocop:disable Metrics/ClassLength + class Elasticsearch < Inspec.resource(1) name 'elasticsearch' desc "Use the Elasticsearch InSpec audit resource to test the status of nodes in an Elasticsearch cluster." diff --git a/lib/resources/grub_conf.rb b/lib/resources/grub_conf.rb index 709bb9fa5..e4268b231 100644 --- a/lib/resources/grub_conf.rb +++ b/lib/resources/grub_conf.rb @@ -3,7 +3,7 @@ require 'utils/simpleconfig' -class GrubConfig < Inspec.resource(1) # rubocop:disable Metrics/ClassLength +class GrubConfig < Inspec.resource(1) name 'grub_conf' desc 'Use the grub_conf InSpec audit resource to test the boot config of Linux systems that use Grub.' example " diff --git a/lib/resources/port.rb b/lib/resources/port.rb index 201f3321b..44ad5edfa 100644 --- a/lib/resources/port.rb +++ b/lib/resources/port.rb @@ -381,7 +381,7 @@ module Inspec::Resources end # extract port information from netstat - class LinuxPorts < PortsInfo # rubocop:disable Metrics/ClassLength + class LinuxPorts < PortsInfo ALLOWED_PROTOCOLS = %w{tcp tcp6 udp udp6}.freeze def info diff --git a/lib/resources/processes.rb b/lib/resources/processes.rb index feb60ae2a..8e6b8f4e9 100644 --- a/lib/resources/processes.rb +++ b/lib/resources/processes.rb @@ -7,7 +7,7 @@ require 'utils/filter' require 'ostruct' module Inspec::Resources - class Processes < Inspec.resource(1) # rubocop:disable Metrics/ClassLength + class Processes < Inspec.resource(1) name 'processes' desc 'Use the processes InSpec audit resource to test properties for programs that are running on the system.' example " diff --git a/lib/resources/registry_key.rb b/lib/resources/registry_key.rb index 43c0b6759..6d7dc8dc9 100644 --- a/lib/resources/registry_key.rb +++ b/lib/resources/registry_key.rb @@ -47,7 +47,7 @@ require 'json' # end module Inspec::Resources - class RegistryKey < Inspec.resource(1) # rubocop:disable Metrics/ClassLength + class RegistryKey < Inspec.resource(1) name 'registry_key' desc 'Use the registry_key InSpec audit resource to test key values in the Microsoft Windows registry.' example " diff --git a/lib/resources/service.rb b/lib/resources/service.rb index 886acaa1a..c6b7c8c4d 100644 --- a/lib/resources/service.rb +++ b/lib/resources/service.rb @@ -68,7 +68,7 @@ module Inspec::Resources # Ubuntu < 15.04 : upstart # # TODO: extend the logic to detect the running init system, independently of OS - class Service < Inspec.resource(1) # rubocop:disable ClassLength + class Service < Inspec.resource(1) name 'service' desc 'Use the service InSpec audit resource to test if the named service is installed, running and/or enabled.' example " diff --git a/lib/resources/virtualization.rb b/lib/resources/virtualization.rb index 4d01bc6ae..70dd58bfe 100644 --- a/lib/resources/virtualization.rb +++ b/lib/resources/virtualization.rb @@ -4,7 +4,7 @@ require 'hashie/mash' module Inspec::Resources - class Virtualization < Inspec.resource(1) # rubocop:disable Metrics/ClassLength + class Virtualization < Inspec.resource(1) name 'virtualization' desc 'Use the virtualization InSpec audit resource to test the virtualization platform on which the system is running' example " diff --git a/lib/resources/x509_certificate.rb b/lib/resources/x509_certificate.rb index 97e90918d..af85ec0d6 100644 --- a/lib/resources/x509_certificate.rb +++ b/lib/resources/x509_certificate.rb @@ -6,7 +6,7 @@ require 'openssl' require 'hashie/mash' module Inspec::Resources - class X509CertificateResource < Inspec.resource(1) # rubocop:disable Metrics/ClassLength + class X509CertificateResource < Inspec.resource(1) name 'x509_certificate' desc 'Used to test x.509 certificates' example "