Class: Gemfilelint::Linter

Inherits:
Object
  • Object
show all
Defined in:
lib/gemfilelint.rb

Defined Under Namespace

Modules: ANSIColor

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ignore: [], logger: nil) ⇒ Linter

Returns a new instance of Linter.



126
127
128
129
# File 'lib/gemfilelint.rb', line 126

def initialize(ignore: [], logger: nil)
  @ignore = ignore
  @logger = logger || make_logger
end

Instance Attribute Details

#ignoreObject (readonly)

Returns the value of attribute ignore.



124
125
126
# File 'lib/gemfilelint.rb', line 124

def ignore
  @ignore
end

#loggerObject (readonly)

Returns the value of attribute logger.



124
125
126
# File 'lib/gemfilelint.rb', line 124

def logger
  @logger
end

Instance Method Details

#lint(*paths) ⇒ Object

rubocop:disable Metrics/AbcSize, Metrics/MethodLength



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/gemfilelint.rb', line 132

def lint(*paths)
  logger.info("Inspecting gemfiles at #{paths.join(', ')}\n")

  offenses = []

  each_offense_for(paths) do |offense|
    if offense
      offenses << offense
      logger.info("W".colorize(:magenta))
    else
      logger.info(".".colorize(:green))
    end
  end

  logger.info("\n")

  if offenses.empty?
    true
  else
    messages = offenses.map { |offense| offense_to_message(offense) }
    logger.info("\nOffenses:\n\n#{messages.join("\n")}\n")
    false
  end
end