Class: Gemfilelint::Linter
- Inherits:
-
Object
- Object
- Gemfilelint::Linter
- Defined in:
- lib/gemfilelint.rb
Defined Under Namespace
Modules: ANSIColor
Instance Attribute Summary collapse
-
#ignore ⇒ Object
readonly
Returns the value of attribute ignore.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
-
#initialize(ignore: [], logger: nil) ⇒ Linter
constructor
A new instance of Linter.
-
#lint(*paths) ⇒ Object
rubocop:disable Naming/PredicateMethod.
Constructor Details
#initialize(ignore: [], logger: nil) ⇒ Linter
Returns a new instance of Linter.
118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/gemfilelint.rb', line 118 def initialize(ignore: [], logger: nil) @ignore = ignore @logger = logger || Logger .new($stdout) .tap do |creating| creating.level = :info creating.formatter = ->(*, ) { } end end |
Instance Attribute Details
#ignore ⇒ Object (readonly)
Returns the value of attribute ignore.
116 117 118 |
# File 'lib/gemfilelint.rb', line 116 def ignore @ignore end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
116 117 118 |
# File 'lib/gemfilelint.rb', line 116 def logger @logger end |
Instance Method Details
#lint(*paths) ⇒ Object
rubocop:disable Naming/PredicateMethod
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/gemfilelint.rb', line 130 def lint(*paths) # rubocop:disable Naming/PredicateMethod logger.info("Inspecting gemfiles at #{paths.join(", ")}\n") offenses = [] paths.each do |path| Parser .for(path) .each_offense(ignore: ignore) do |offense| if offense offenses << offense logger.info("W".colorize(:magenta)) else logger.info(".".colorize(:green)) end end end logger.info("\n") if offenses.empty? true else = offenses.map do |offense| "#{offense.path.colorize(:cyan)}: " \ "#{"W".colorize(:magenta)}: #{offense}" end logger.info("\nOffenses:\n\n#{.join("\n")}\n") false end end |