Skip to content

Commit

Permalink
Extract gem_declaration?
Browse files Browse the repository at this point in the history
  • Loading branch information
timlkelly committed May 4, 2021
1 parent 96299da commit 90db0f7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions lib/rubocop.rb
Expand Up @@ -82,6 +82,7 @@
require_relative 'rubocop/cop/mixin/enforce_superclass'
require_relative 'rubocop/cop/mixin/first_element_line_break'
require_relative 'rubocop/cop/mixin/frozen_string_literal'
require_relative 'rubocop/cop/mixin/gem_declaration'
require_relative 'rubocop/cop/mixin/hash_alignment_styles'
require_relative 'rubocop/cop/mixin/hash_transform_method'
require_relative 'rubocop/cop/mixin/ignored_pattern'
Expand Down
4 changes: 1 addition & 3 deletions lib/rubocop/cop/bundler/gem_comment.rb
Expand Up @@ -82,6 +82,7 @@ module Bundler
#
class GemComment < Base
include DefNode
include GemDeclaration

MSG = 'Missing gem description comment.'
CHECKED_OPTIONS_CONFIG = 'OnlyFor'
Expand All @@ -90,9 +91,6 @@ class GemComment < Base
RESTRICTIVE_VERSION_PATTERN = /<|~>/.freeze
RESTRICT_ON_SEND = %i[gem].freeze

# @!method gem_declaration?(node)
def_node_matcher :gem_declaration?, '(send nil? :gem str ...)'

def on_send(node)
return unless gem_declaration?(node)
return if ignored_gem?(node)
Expand Down
4 changes: 1 addition & 3 deletions lib/rubocop/cop/bundler/gem_version.rb
Expand Up @@ -34,14 +34,12 @@ module Bundler
#
class GemVersion < Base
include ConfigurableEnforcedStyle
include GemDeclaration

REQUIRED_MSG = 'Gem version specification is required.'
FORBIDDEN_MSG = 'Gem version specification is forbidden.'
VERSION_SPECIFICATION_REGEX = /^[~<>=]*\s?[0-9.]+/.freeze

# @!method gem_declaration?(node)
def_node_matcher :gem_declaration?, '(send nil? :gem str ...)'

# @!method includes_version_specification?(node)
def_node_matcher :includes_version_specification?, <<~PATTERN
(send nil? :gem <(str #version_specification?) ...>)
Expand Down
13 changes: 13 additions & 0 deletions lib/rubocop/cop/mixin/gem_declaration.rb
@@ -0,0 +1,13 @@
# frozen_string_literal: true

module RuboCop
module Cop
# Common functionality for checking gem declarations.
module GemDeclaration
extend NodePattern::Macros

# @!method gem_declaration?(node)
def_node_matcher :gem_declaration?, '(send nil? :gem str ...)'
end
end
end

0 comments on commit 90db0f7

Please sign in to comment.