Sha256: 925d445768524f347fc8a1ab786ae2fa86528ff0f262bf56559d132e21857992

Contents?: true

Size: 1.73 KB

Versions: 17

Compression:

Stored size: 1.73 KB

Contents

module Steep
  class Source
    class IgnoreRanges
      attr_reader :all_ignores, :error_ignores, :ignored_ranges, :ignored_lines

      def initialize(ignores:)
        @all_ignores = ignores.sort_by(&:line)
        @error_ignores = []

        @ignored_lines = {}
        @ignored_ranges = []

        last_start = nil #: AST::Ignore::IgnoreStart?

        all_ignores.each do |ignore|
          case ignore
          when AST::Ignore::IgnoreStart
            if last_start
              error_ignores << last_start
            end
            last_start = ignore
          when AST::Ignore::IgnoreEnd
            if last_start
              ignored_ranges << (last_start.line..ignore.line)
              last_start = nil
            else
              error_ignores << ignore
            end
          when AST::Ignore::IgnoreLine
            if last_start
              error_ignores << ignore
            else
              ignored_lines[ignore.line] = ignore
            end
          end
        end

        if last_start
          error_ignores << last_start
        end
      end

      def ignore?(start_line, end_line, code)
        if ignore = ignored_lines.fetch(start_line, nil)
          ignore_code?(ignore, code) and return true
        end

        if start_line != end_line
          if ignore = ignored_lines.fetch(end_line, nil)
            ignore_code?(ignore, code) and return true
          end
        end

        ignored_ranges.any? do |range|
          range.cover?(start_line) && range.cover?(end_line)
        end
      end

      def ignore_code?(line, code)
        case diags = line.ignored_diagnostics
        when Symbol
          true
        else
          diags.any? {|d| code == "Ruby::#{d}" }
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
steep-1.9.1 lib/steep/source/ignore_ranges.rb
steep-1.9.0 lib/steep/source/ignore_ranges.rb
steep-1.9.0.dev.2 lib/steep/source/ignore_ranges.rb
steep-1.9.0.dev.1 lib/steep/source/ignore_ranges.rb
steep-1.8.3 lib/steep/source/ignore_ranges.rb
steep-1.8.2 lib/steep/source/ignore_ranges.rb
steep-1.8.1 lib/steep/source/ignore_ranges.rb
steep-1.8.0 lib/steep/source/ignore_ranges.rb
steep-1.8.0.pre.2 lib/steep/source/ignore_ranges.rb
steep-1.8.0.pre.1 lib/steep/source/ignore_ranges.rb
steep-1.8.0.dev.2 lib/steep/source/ignore_ranges.rb
steep-1.8.0.dev.1 lib/steep/source/ignore_ranges.rb
steep-1.7.1 lib/steep/source/ignore_ranges.rb
steep-1.7.0 lib/steep/source/ignore_ranges.rb
steep-1.7.0.dev.3 lib/steep/source/ignore_ranges.rb
steep-1.7.0.dev.2 lib/steep/source/ignore_ranges.rb
steep-1.7.0.dev.1 lib/steep/source/ignore_ranges.rb