Sha256: 2a6acb480973568a4dc27b212fa3ee691b73040c70682abb1231f0fa1bdf0781

Contents?: true

Size: 1.17 KB

Versions: 2

Compression:

Stored size: 1.17 KB

Contents

module RuboCop
  module Cop
    module Chromebrew
      # Compatibility value which match all architectures should be replaced with 'all'.
      #
      # @example
      #   # bad
      #   compatibility 'aarch64 armv7l i686 x86_64'
      #
      #   # good
      #   compatibility 'all'
      #
      class CompatibilityAll < Base
        extend AutoCorrector
        MSG = "Compatibility properties which match all architectures should be replaced with 'all'"

        def_node_matcher :compatibility?, <<~PATTERN
          (send nil? :compatibility
            (str $_))
        PATTERN

        def on_send(node)
          # Check that we're operating on the compatibility property.
          value = compatibility?(node)
          return unless value

          architectures = %w[aarch64 armv7l i686 x86_64]
          # Check if the compatibility value includes all four architectures.
          return unless architectures.all? { |arch| value.include?(arch) }

          # If requested, replace the offending line with compatibility 'all'.
          add_offense(node) do |corrector|
            corrector.replace(node, "compatibility 'all'")
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rubocop-chromebrew-0.0.2 lib/rubocop/cop/chromebrew/compatibility_all.rb
rubocop-chromebrew-0.0.1 lib/rubocop/cop/chromebrew/compatibility_all.rb