Sha256: da12c76d51f2cb5612e9fc5a7a73b166fde6612af78f0deb1234987f68cd77c9
Contents?: true
Size: 1.15 KB
Versions: 3
Compression:
Stored size: 1.15 KB
Contents
module Skeptic module Rules class SpacesAroundOperators DESCRIPTION = 'Check for spaces around operators' OPERATORS_WITHOUT_SPACES_AROUND_THEM = ['**'] def initialize(data) @violations = [] end def apply_to(code, tokens, sexp) @violations = tokens.each_cons(3).select do |_, token, _| operator_expecting_spaces? token end.select do |left, operator, right| no_spaces_between?(operator, left) or no_spaces_between?(operator, right) end.map do |_, operator, _| [operator.last, operator.first[0]] end self end def violations @violations.map do |value, line_number| "no spaces around #{value} on line #{line_number}" end end def name 'Spaces around operators' end private def operator_expecting_spaces?(token) token[1] == :on_op and not OPERATORS_WITHOUT_SPACES_AROUND_THEM.include? token.last end def no_spaces_between?(operator, neighbour) neighbour.first[0] == operator.first[0] and neighbour[1] != :on_sp end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
skeptic-0.0.6 | lib/skeptic/rules/spaces_around_operators.rb |
skeptic-0.0.5 | lib/skeptic/rules/spaces_around_operators.rb |
skeptic-0.0.4 | lib/skeptic/rules/spaces_around_operators.rb |