lib/gemfilelint.rb in gemfilelint-0.3.0 vs lib/gemfilelint.rb in gemfilelint-0.4.0
- old
+ new
@@ -1,14 +1,14 @@
# frozen_string_literal: true
-require 'delegate'
-require 'logger'
+require "delegate"
+require "logger"
-require 'bundler'
-require 'bundler/similarity_detector'
+require "bundler"
+require "bundler/similarity_detector"
-require 'gemfilelint/version'
+require "gemfilelint/version"
module Gemfilelint
class SpellChecker
attr_reader :detector, :haystack
@@ -50,12 +50,14 @@
end
end
module Parser
class Valid < Struct.new(:path, :dsl)
- def each_offense
+ def each_offense(ignore: [])
dependencies.each do |dependency|
+ next if ignore.include?(dependency)
+
yield dependency_offense_for(dependency)
end
remotes.each do |remote|
yield remote_offense_for(remote)
@@ -92,11 +94,11 @@
Offenses::Remote.new(path, uri, corrections)
end
end
class Invalid < Struct.new(:path)
- def each_offense
+ def each_offense(**)
yield Offenses::InvalidGemfile.new(path)
end
end
def self.for(path)
@@ -117,13 +119,14 @@
end
end
using ANSIColor
- attr_reader :logger
+ attr_reader :ignore, :logger
- def initialize(logger: nil)
+ def initialize(ignore: [], logger: nil)
+ @ignore = ignore
@logger = logger || make_logger
end
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
def lint(*paths)
@@ -132,13 +135,13 @@
offenses = []
each_offense_for(paths) do |offense|
if offense
offenses << offense
- logger.info('W'.colorize(:magenta))
+ logger.info("W".colorize(:magenta))
else
- logger.info('.'.colorize(:green))
+ logger.info(".".colorize(:green))
end
end
logger.info("\n")
@@ -154,11 +157,11 @@
private
def each_offense_for(paths)
paths.each do |path|
- Parser.for(path).each_offense do |offense|
+ Parser.for(path).each_offense(ignore: ignore) do |offense|
yield offense
end
end
end
@@ -176,18 +179,18 @@
class << self
def dependencies
@dependencies ||=
SpellChecker.new(
- File.read(File.expand_path('gems.txt', __dir__)).split("\n")
+ File.read(File.expand_path("gems.txt", __dir__)).split("\n")
)
end
def remotes
- @remotes ||= SpellChecker.new(['https://rubygems.org/'])
+ @remotes ||= SpellChecker.new(["https://rubygems.org/"])
end
- def lint(*paths, logger: nil)
- Linter.new(logger: logger).lint(*paths)
+ def lint(*paths, ignore: [], logger: nil)
+ Linter.new(ignore: ignore, logger: logger).lint(*paths)
end
end
end