From c6c092d7240177b4face850c62c89379ea47fd81 Mon Sep 17 00:00:00 2001 From: schneems Date: Thu, 7 Oct 2021 21:42:13 -0500 Subject: [PATCH] Standardize formatting with standardrb gem --- .circleci/config.yml | 23 +++++++---- .standard.yml | 1 + Gemfile | 1 + Gemfile.lock | 29 ++++++++++++- Rakefile | 2 +- dead_end.gemspec | 24 +++++------ exe/dead_end | 6 +-- lib/dead_end/around_block_scan.rb | 25 +++++------ lib/dead_end/auto.rb | 4 +- lib/dead_end/block_expand.rb | 11 ++--- lib/dead_end/capture_code_context.rb | 9 ++-- lib/dead_end/code_block.rb | 6 +-- lib/dead_end/code_frontier.rb | 8 ++-- lib/dead_end/code_line.rb | 22 +++++----- lib/dead_end/code_search.rb | 41 ++++++++++--------- .../display_code_with_line_numbers.rb | 14 +++---- lib/dead_end/display_invalid_blocks.rb | 11 +++-- lib/dead_end/fyi.rb | 3 +- lib/dead_end/heredoc_block_parse.rb | 8 +++- lib/dead_end/internals.rb | 32 +++++++-------- lib/dead_end/lex_all.rb | 14 +++---- lib/dead_end/parse_blocks_from_indent_line.rb | 5 +-- lib/dead_end/trailing_slash_join.rb | 4 +- lib/dead_end/who_dis_syntax_error.rb | 15 ++++--- .../fixtures/{routes.txt.rb => routes.rb.txt} | 0 spec/integration/exe_cli_spec.rb | 2 +- .../improvement_regression_spec.rb | 28 ++++++------- spec/integration/ruby_command_line_spec.rb | 3 +- spec/perf/perf_spec.rb | 6 +-- spec/spec_helper.rb | 8 ++-- spec/unit/around_block_scan_spec.rb | 6 +-- spec/unit/block_expand_spec.rb | 7 +--- spec/unit/capture_code_context_spec.rb | 6 +-- spec/unit/code_block_spec.rb | 6 +-- spec/unit/code_frontier_spec.rb | 6 +-- spec/unit/code_line_spec.rb | 4 +- spec/unit/code_search_spec.rb | 14 +++---- spec/unit/dead_end_spec.rb | 2 +- spec/unit/display_invalid_blocks_spec.rb | 28 ++++++------- spec/unit/heredoc_block_parse_spec.rb | 3 +- spec/unit/lex_all_spec.rb | 2 +- spec/unit/trailing_slash_join_spec.rb | 19 ++++----- spec/unit/who_dis_syntax_error_spec.rb | 2 +- 43 files changed, 252 insertions(+), 218 deletions(-) create mode 100644 .standard.yml rename spec/fixtures/{routes.txt.rb => routes.rb.txt} (100%) diff --git a/.circleci/config.yml b/.circleci/config.yml index f94c3f2..fe4748f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -7,15 +7,12 @@ references: name: Run test suite command: bundle exec rspec spec/ -jobs: - "ruby-2-5": - docker: - - image: circleci/ruby:2.5 - steps: - - checkout - - ruby/install-deps - - <<: *unit + lint: &lint + run: + name: Run linter, fix with `standardrb --fix` locally + command: bundle exec standardrb +jobs: "ruby-2-6": docker: - image: circleci/ruby:2.6 @@ -40,11 +37,19 @@ jobs: - ruby/install-deps - <<: *unit + "lint": + docker: + - image: circleci/ruby:3.0 + steps: + - checkout + - ruby/install-deps + - <<: *lint + workflows: version: 2 build: jobs: - - "ruby-2-5" - "ruby-2-6" - "ruby-2-7" - "ruby-3-0" + - "lint" diff --git a/.standard.yml b/.standard.yml new file mode 100644 index 0000000..a0db153 --- /dev/null +++ b/.standard.yml @@ -0,0 +1 @@ +ruby_version: 2.6.6 diff --git a/Gemfile b/Gemfile index 89e7644..b0065fe 100644 --- a/Gemfile +++ b/Gemfile @@ -8,3 +8,4 @@ gemspec gem "rake", "~> 12.0" gem "rspec", "~> 3.0" gem "stackprof" +gem "standard" diff --git a/Gemfile.lock b/Gemfile.lock index 3491faf..27d2358 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -6,8 +6,15 @@ PATH GEM remote: https://rubygems.org/ specs: + ast (2.4.2) diff-lcs (1.4.4) + parallel (1.21.0) + parser (3.0.2.0) + ast (~> 2.4.1) + rainbow (3.0.0) rake (12.3.3) + regexp_parser (2.1.1) + rexml (3.2.5) rspec (3.10.0) rspec-core (~> 3.10.0) rspec-expectations (~> 3.10.0) @@ -21,7 +28,26 @@ GEM diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.10.0) rspec-support (3.10.0) + rubocop (1.20.0) + parallel (~> 1.10) + parser (>= 3.0.0.0) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) + rexml + rubocop-ast (>= 1.9.1, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 1.4.0, < 3.0) + rubocop-ast (1.12.0) + parser (>= 3.0.1.1) + rubocop-performance (1.11.5) + rubocop (>= 1.7.0, < 2.0) + rubocop-ast (>= 0.4.0) + ruby-progressbar (1.11.0) stackprof (0.2.16) + standard (1.3.0) + rubocop (= 1.20.0) + rubocop-performance (= 1.11.5) + unicode-display_width (2.1.0) PLATFORMS ruby @@ -31,6 +57,7 @@ DEPENDENCIES rake (~> 12.0) rspec (~> 3.0) stackprof + standard BUNDLED WITH - 2.2.16 + 2.2.27 diff --git a/Rakefile b/Rakefile index ee617bb..b6ae734 100644 --- a/Rakefile +++ b/Rakefile @@ -5,4 +5,4 @@ require "rspec/core/rake_task" RSpec::Core::RakeTask.new(:spec) -task :default => :spec +task default: :spec diff --git a/dead_end.gemspec b/dead_end.gemspec index bd49656..06bc030 100644 --- a/dead_end.gemspec +++ b/dead_end.gemspec @@ -1,17 +1,17 @@ # frozen_string_literal: true -require_relative 'lib/dead_end/version' +require_relative "lib/dead_end/version" Gem::Specification.new do |spec| - spec.name = "dead_end" - spec.version = DeadEnd::VERSION - spec.authors = ["schneems"] - spec.email = ["richard.schneeman+foo@gmail.com"] + spec.name = "dead_end" + spec.version = DeadEnd::VERSION + spec.authors = ["schneems"] + spec.email = ["richard.schneeman+foo@gmail.com"] - spec.summary = %q{Find syntax errors in your source in a snap} - spec.description = %q{When you get an "unexpected end" in your syntax this gem helps you find it} - spec.homepage = "https://github.com/zombocom/dead_end.git" - spec.license = "MIT" + spec.summary = "Find syntax errors in your source in a snap" + spec.description = 'When you get an "unexpected end" in your syntax this gem helps you find it' + spec.homepage = "https://github.com/zombocom/dead_end.git" + spec.license = "MIT" spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0") spec.metadata["homepage_uri"] = spec.homepage @@ -19,10 +19,10 @@ Gem::Specification.new do |spec| # Specify which files should be added to the gem when it is released. # The `git ls-files -z` loads the files in the RubyGem that have been added into git. - spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do + spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|assets)/}) } end - spec.bindir = "exe" - spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } + spec.bindir = "exe" + spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] end diff --git a/exe/dead_end b/exe/dead_end index bccb636..f7bb12e 100755 --- a/exe/dead_end +++ b/exe/dead_end @@ -1,8 +1,8 @@ #!/usr/bin/env ruby -require 'pathname' +require "pathname" require "optparse" -require_relative "../lib/dead_end.rb" +require_relative "../lib/dead_end" options = {} options[:terminal] = true @@ -60,7 +60,7 @@ end file = Pathname(file) options[:record_dir] = "tmp" if ENV["DEBUG"] -$stderr.puts "Record dir: #{options[:record_dir]}" if options[:record_dir] +warn "Record dir: #{options[:record_dir]}" if options[:record_dir] DeadEnd.call( source: file.read, diff --git a/lib/dead_end/around_block_scan.rb b/lib/dead_end/around_block_scan.rb index 063b665..b1ef1ee 100644 --- a/lib/dead_end/around_block_scan.rb +++ b/lib/dead_end/around_block_scan.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -# + module DeadEnd # This class is useful for exploring contents before and after # a block @@ -28,7 +28,7 @@ module DeadEnd # # To grab the next surrounding indentation use AroundBlockScan#scan_adjacent_indent class AroundBlockScan - def initialize(code_lines: , block:) + def initialize(code_lines:, block:) @code_lines = code_lines @orig_before_index = block.lines.first.index @orig_after_index = block.lines.last.index @@ -56,7 +56,7 @@ def scan_while(&block) end_count = 0 @before_index = before_lines.reverse_each.take_while do |line| next false if stop_next - next true if @skip_array.detect {|meth| line.send(meth) } + next true if @skip_array.detect { |meth| line.send(meth) } kw_count += 1 if line.is_kw? end_count += 1 if line.is_end? @@ -65,14 +65,14 @@ def scan_while(&block) end block.call(line) - end.reverse.first&.index + end.last&.index stop_next = false kw_count = 0 end_count = 0 @after_index = after_lines.take_while do |line| next false if stop_next - next true if @skip_array.detect {|meth| line.send(meth) } + next true if @skip_array.detect { |meth| line.send(meth) } kw_count += 1 if line.is_kw? end_count += 1 if line.is_end? @@ -89,7 +89,7 @@ def capture_neighbor_context lines = [] kw_count = 0 end_count = 0 - before_lines.reverse.each do |line| + before_lines.reverse_each do |line| next if line.empty? break if line.indent < @orig_indent next if line.indent != @orig_indent @@ -124,14 +124,14 @@ def capture_neighbor_context lines << line end - lines.select! {|line| !line.is_comment? } + lines.select! { |line| !line.is_comment? } lines end def on_falling_indent last_indent = @orig_indent - before_lines.reverse.each do |line| + before_lines.reverse_each do |line| next if line.empty? if line.indent < last_indent yield line @@ -150,7 +150,7 @@ def on_falling_indent end def scan_neighbors - self.scan_while {|line| line.not_empty? && line.indent >= @orig_indent } + scan_while { |line| line.not_empty? && line.indent >= @orig_indent } end def next_up @@ -167,13 +167,14 @@ def scan_adjacent_indent before_after_indent << (next_down&.indent || 0) indent = before_after_indent.min - self.scan_while {|line| line.not_empty? && line.indent >= indent } + scan_while { |line| line.not_empty? && line.indent >= indent } self end def start_at_next_line - before_index; after_index + before_index + after_index @before_index -= 1 @after_index += 1 self @@ -196,7 +197,7 @@ def after_index end private def after_lines - @code_lines[after_index.next..-1] || [] + @code_lines[after_index.next..] || [] end end end diff --git a/lib/dead_end/auto.rb b/lib/dead_end/auto.rb index 4c0b601..00c113c 100644 --- a/lib/dead_end/auto.rb +++ b/lib/dead_end/auto.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -# + require_relative "../dead_end/internals" # Monkey patch kernel to ensure that all `require` calls call the same @@ -40,6 +40,7 @@ def require_relative(file) # am I doing something different? class Object private + def load(path, wrap = false) Kernel.load(path, wrap) rescue SyntaxError => e @@ -52,4 +53,3 @@ def require(path) DeadEnd.handle_error(e) end end - diff --git a/lib/dead_end/block_expand.rb b/lib/dead_end/block_expand.rb index b48c80a..de47e6a 100644 --- a/lib/dead_end/block_expand.rb +++ b/lib/dead_end/block_expand.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module DeadEnd # This class is responsible for taking a code block that exists # at a far indentaion and then iteratively increasing the block @@ -30,7 +31,7 @@ module DeadEnd # end # class BlockExpand - def initialize(code_lines: ) + def initialize(code_lines:) @code_lines = code_lines end @@ -43,7 +44,7 @@ def call(block) end def expand_indent(block) - block = AroundBlockScan.new(code_lines: @code_lines, block: block) + AroundBlockScan.new(code_lines: @code_lines, block: block) .skip(:hidden?) .stop_after_kw .scan_adjacent_indent @@ -59,15 +60,15 @@ def expand_neighbors(block, grab_empty: true) # Slurp up empties if grab_empty scan = AroundBlockScan.new(code_lines: @code_lines, block: scan.code_block) - .scan_while {|line| line.empty? || line.hidden? } + .scan_while { |line| line.empty? || line.hidden? } end new_block = scan.code_block if block.lines == new_block.lines - return nil + nil else - return new_block + new_block end end end diff --git a/lib/dead_end/capture_code_context.rb b/lib/dead_end/capture_code_context.rb index 009dd97..da72a21 100644 --- a/lib/dead_end/capture_code_context.rb +++ b/lib/dead_end/capture_code_context.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true module DeadEnd - # Given a block, this method will capture surrounding # code to give the user more context for the location of # the problem. @@ -26,7 +25,7 @@ module DeadEnd class CaptureCodeContext attr_reader :code_lines - def initialize(blocks: , code_lines:) + def initialize(blocks:, code_lines:) @blocks = Array(blocks) @code_lines = code_lines @visible_lines = @blocks.map(&:visible_lines).flatten @@ -45,13 +44,13 @@ def call @lines_to_output.uniq! @lines_to_output.sort! - return @lines_to_output + @lines_to_output end def capture_falling_indent(block) AroundBlockScan.new( block: block, - code_lines: @code_lines, + code_lines: @code_lines ).on_falling_indent do |line| @lines_to_output << line end @@ -95,7 +94,7 @@ def capture_last_end_same_indent(block) # (this would return line 4) # # end # 4 - matching_end = lines.select {|line| line.indent == block.current_indent && line.is_end? }.first + matching_end = lines.find { |line| line.indent == block.current_indent && line.is_end? } return unless matching_end @lines_to_output << matching_end diff --git a/lib/dead_end/code_block.rb b/lib/dead_end/code_block.rb index ee7df64..1fbefb1 100644 --- a/lib/dead_end/code_block.rb +++ b/lib/dead_end/code_block.rb @@ -54,11 +54,11 @@ def ends_at # populate an array with multiple code blocks then call `sort!` # on it without having to specify the sorting criteria def <=>(other) - out = self.current_indent <=> other.current_indent + out = current_indent <=> other.current_indent return out if out != 0 # Stable sort - self.starts_at <=> other.starts_at + starts_at <=> other.starts_at end def current_indent @@ -71,7 +71,7 @@ def invalid? def valid? return @valid if @valid != UNSET - @valid = DeadEnd.valid?(self.to_s) + @valid = DeadEnd.valid?(to_s) end def to_s diff --git a/lib/dead_end/code_frontier.rb b/lib/dead_end/code_frontier.rb index 4634159..5b1e481 100644 --- a/lib/dead_end/code_frontier.rb +++ b/lib/dead_end/code_frontier.rb @@ -39,7 +39,7 @@ module DeadEnd # # CodeFrontier#detect_invalid_blocks class CodeFrontier - def initialize(code_lines: ) + def initialize(code_lines:) @code_lines = code_lines @frontier = [] @unvisited_lines = @code_lines.sort_by(&:indent_index) @@ -66,7 +66,7 @@ def holds_all_syntax_errors?(block_array = @frontier) # Returns a code block with the largest indentation possible def pop - return @frontier.pop + @frontier.pop end def next_indent_line @@ -78,7 +78,7 @@ def expand? return true if @unvisited_lines.empty? frontier_indent = @frontier.last.current_indent - unvisited_indent= next_indent_line.indent + unvisited_indent = next_indent_line.indent if ENV["DEBUG"] puts "```" @@ -106,7 +106,7 @@ def <<(block) register_indent_block(block) # Make sure we don't double expand, if a code block fully engulfs another code block, keep the bigger one - @frontier.reject! {|b| + @frontier.reject! { |b| b.starts_at >= block.starts_at && b.ends_at <= block.ends_at } @frontier << block diff --git a/lib/dead_end/code_line.rb b/lib/dead_end/code_line.rb index 449b493..83311ff 100644 --- a/lib/dead_end/code_line.rb +++ b/lib/dead_end/code_line.rb @@ -39,7 +39,7 @@ def self.parse(source) attr_reader :line, :index, :indent, :original_line - def initialize(line: , index:) + def initialize(line:, index:) @original_line = line.freeze @line = @original_line if line.strip.empty? @@ -64,25 +64,25 @@ def initialize(line: , index:) next unless lex.type == :on_kw case lex.token - when 'if', 'unless', 'while', 'until' + when "if", "unless", "while", "until" # Only count if/unless when it's not a "trailing" if/unless # https://github.com/ruby/ruby/blob/06b44f819eb7b5ede1ff69cecb25682b56a1d60c/lib/irb/ruby-lex.rb#L374-L375 - kw_count += 1 if !lex.expr_label? - when 'def', 'case', 'for', 'begin', 'class', 'module', 'do' + kw_count += 1 unless lex.expr_label? + when "def", "case", "for", "begin", "class", "module", "do" kw_count += 1 - when 'end' + when "end" end_count += 1 end end - @is_comment = lex_array.detect {|lex| lex.type != :on_sp}&.type == :on_comment + @is_comment = lex_array.detect { |lex| lex.type != :on_sp }&.type == :on_comment return if @is_comment @is_kw = (kw_count - end_count) > 0 @is_end = (end_count - kw_count) > 0 @is_trailing_slash = lex_array.last.token == TRAILING_SLASH end - alias :original :original_line + alias_method :original, :original_line def trailing_slash? @is_trailing_slash @@ -92,8 +92,8 @@ def indent_index @indent_index ||= [indent, index] end - def <=>(b) - self.index <=> b.index + def <=>(other) + index <=> other.index end def is_comment? @@ -133,7 +133,7 @@ def hidden? def line_number index + 1 end - alias :number :line_number + alias_method :number, :line_number def not_empty? !empty? @@ -144,7 +144,7 @@ def empty? end def to_s - self.line + line end end end diff --git a/lib/dead_end/code_search.rb b/lib/dead_end/code_search.rb index 8c357b7..3e73941 100644 --- a/lib/dead_end/code_search.rb +++ b/lib/dead_end/code_search.rb @@ -25,14 +25,21 @@ module DeadEnd # # => ["def lol\n"] # class CodeSearch - private; attr_reader :frontier; public - public; attr_reader :invalid_blocks, :record_dir, :code_lines + private + + attr_reader :frontier + + public + + public + + attr_reader :invalid_blocks, :record_dir, :code_lines def initialize(source, record_dir: ENV["DEAD_END_RECORD_DIR"] || ENV["DEBUG"] ? "tmp" : nil) @source = source if record_dir - @time = Time.now.strftime('%Y-%m-%d-%H-%M-%s-%N') - @record_dir = Pathname(record_dir).join(@time).tap {|p| p.mkpath } + @time = Time.now.strftime("%Y-%m-%d-%H-%M-%s-%N") + @record_dir = Pathname(record_dir).join(@time).tap { |p| p.mkpath } @write_count = 0 end code_lines = source.lines.map.with_index do |line, i| @@ -43,7 +50,7 @@ def initialize(source, record_dir: ENV["DEAD_END_RECORD_DIR"] || ENV["DEBUG"] ? @frontier = CodeFrontier.new(code_lines: @code_lines) @invalid_blocks = [] - @name_tick = Hash.new {|hash, k| hash[k] = 0 } + @name_tick = Hash.new { |hash, k| hash[k] = 0 } @tick = 0 @block_expand = BlockExpand.new(code_lines: code_lines) @parse_blocks_from_indent_line = ParseBlocksFromIndentLine.new(code_lines: @code_lines) @@ -51,13 +58,13 @@ def initialize(source, record_dir: ENV["DEAD_END_RECORD_DIR"] || ENV["DEBUG"] ? # Used for debugging def record(block:, name: "record") - return if !@record_dir + return unless @record_dir @name_tick[name] += 1 filename = "#{@write_count += 1}-#{name}-#{@name_tick[name]}.txt" if ENV["DEBUG"] puts "\n\n==== #{filename} ====" puts "\n```#{block.starts_at}:#{block.ends_at}" - puts "#{block.to_s}" + puts block.to_s puts "```" puts " block indent: #{block.current_indent}" end @@ -65,25 +72,21 @@ def record(block:, name: "record") display = DisplayInvalidBlocks.new( blocks: block, terminal: false, - code_lines: @code_lines, + code_lines: @code_lines ) - f.write(display.indent display.code_with_lines) + f.write(display.indent(display.code_with_lines)) end end - def push(block, name: ) + def push(block, name:) record(block: block, name: name) - if block.valid? - block.mark_invisible - frontier << block - else - frontier << block - end + block.mark_invisible if block.valid? + frontier << block end # Removes the block without putting it back in the frontier - def sweep(block:, name: ) + def sweep(block:, name:) record(block: block, name: name) block.lines.each(&:mark_invisible) @@ -149,8 +152,8 @@ def call end end - @invalid_blocks.concat(frontier.detect_invalid_blocks ) - @invalid_blocks.sort_by! {|block| block.starts_at } + @invalid_blocks.concat(frontier.detect_invalid_blocks) + @invalid_blocks.sort_by! { |block| block.starts_at } self end end diff --git a/lib/dead_end/display_code_with_line_numbers.rb b/lib/dead_end/display_code_with_line_numbers.rb index dbe3147..52c8880 100644 --- a/lib/dead_end/display_code_with_line_numbers.rb +++ b/lib/dead_end/display_code_with_line_numbers.rb @@ -23,10 +23,10 @@ class DisplayCodeWithLineNumbers TERMINAL_HIGHLIGHT = "\e[1;3m" # Bold, italics TERMINAL_END = "\e[0m" - def initialize(lines: , highlight_lines: [], terminal: false) + def initialize(lines:, highlight_lines: [], terminal: false) @lines = Array(lines).sort @terminal = terminal - @highlight_line_hash = Array(highlight_lines).each_with_object({}) {|line, h| h[line] = true } + @highlight_line_hash = Array(highlight_lines).each_with_object({}) { |line, h| h[line] = true } @digit_count = @lines.last&.line_number.to_s.length end @@ -48,12 +48,12 @@ def call end.join end - private def format(contents: , number: , highlight: false, empty:) - string = String.new("") - if highlight - string << "❯ " + private def format(contents:, number:, empty:, highlight: false) + string = +"" + string << if highlight + "❯ " else - string << " " + " " end string << number.rjust(@digit_count).to_s diff --git a/lib/dead_end/display_invalid_blocks.rb b/lib/dead_end/display_invalid_blocks.rb index 539deda..db2dd0c 100644 --- a/lib/dead_end/display_invalid_blocks.rb +++ b/lib/dead_end/display_invalid_blocks.rb @@ -8,7 +8,7 @@ module DeadEnd class DisplayInvalidBlocks attr_reader :filename - def initialize(code_lines: ,blocks:, io: $stderr, filename: nil, terminal: false, invalid_obj: WhoDisSyntaxError::Null.new) + def initialize(code_lines:, blocks:, io: $stderr, filename: nil, terminal: false, invalid_obj: WhoDisSyntaxError::Null.new) @terminal = terminal @filename = filename @io = io @@ -85,15 +85,14 @@ def banner "DeadEnd: Unmatched `#{@invalid_obj.unmatched_symbol}` detected" end end - end def indent(string, with: " ") - string.each_line.map {|l| with + l }.join + string.each_line.map { |l| with + l }.join end def code_block - string = String.new("") + string = +"" string << code_with_context string end @@ -107,7 +106,7 @@ def code_with_context DisplayCodeWithLineNumbers.new( lines: lines, terminal: @terminal, - highlight_lines: @invalid_lines, + highlight_lines: @invalid_lines ).call end @@ -115,7 +114,7 @@ def code_with_lines DisplayCodeWithLineNumbers.new( lines: @code_lines.select(&:visible?), terminal: @terminal, - highlight_lines: @invalid_lines, + highlight_lines: @invalid_lines ).call end end diff --git a/lib/dead_end/fyi.rb b/lib/dead_end/fyi.rb index 6e37c2a..3645201 100644 --- a/lib/dead_end/fyi.rb +++ b/lib/dead_end/fyi.rb @@ -1,7 +1,6 @@ require_relative "../dead_end/internals" -require_relative "auto.rb" +require_relative "auto" DeadEnd.send(:remove_const, :SEARCH_SOURCE_ON_ERROR_DEFAULT) DeadEnd::SEARCH_SOURCE_ON_ERROR_DEFAULT = false - diff --git a/lib/dead_end/heredoc_block_parse.rb b/lib/dead_end/heredoc_block_parse.rb index 5d48ba3..ff5ff6d 100644 --- a/lib/dead_end/heredoc_block_parse.rb +++ b/lib/dead_end/heredoc_block_parse.rb @@ -3,9 +3,13 @@ module DeadEnd # Takes in a source, and returns blocks containing each heredoc class HeredocBlockParse - private; attr_reader :code_lines, :lex; public + private - def initialize(source:, code_lines: ) + attr_reader :code_lines, :lex + + public + + def initialize(source:, code_lines:) @code_lines = code_lines @lex = LexAll.new(source: source) end diff --git a/lib/dead_end/internals.rb b/lib/dead_end/internals.rb index ddd5023..b38ead7 100644 --- a/lib/dead_end/internals.rb +++ b/lib/dead_end/internals.rb @@ -1,15 +1,16 @@ # frozen_string_literal: true + # # This is the top level file, but is moved to `internals` # so the top level file can instead enable the "automatic" behavior require_relative "version" -require 'tmpdir' -require 'stringio' -require 'pathname' -require 'ripper' -require 'timeout' +require "tmpdir" +require "stringio" +require "pathname" +require "ripper" +require "timeout" module DeadEnd class Error < StandardError; end @@ -17,27 +18,27 @@ class Error < StandardError; end TIMEOUT_DEFAULT = ENV.fetch("DEAD_END_TIMEOUT", 5).to_i def self.handle_error(e, search_source_on_error: SEARCH_SOURCE_ON_ERROR_DEFAULT) - raise e if !e.message.include?("end-of-input") + raise e unless e.message.include?("end-of-input") filename = e.message.split(":").first $stderr.sync = true - $stderr.puts "Run `$ dead_end #{filename}` for more options\n" + warn "Run `$ dead_end #{filename}` for more options\n" if search_source_on_error - self.call( + call( source: Pathname(filename).read, filename: filename, - terminal: true, + terminal: true ) end - $stderr.puts "" - $stderr.puts "" + warn "" + warn "" raise e end - def self.call(source: , filename: , terminal: false, record_dir: nil, timeout: TIMEOUT_DEFAULT, io: $stderr) + def self.call(source:, filename:, terminal: false, record_dir: nil, timeout: TIMEOUT_DEFAULT, io: $stderr) search = nil Timeout.timeout(timeout) do record_dir ||= ENV["DEBUG"] ? "tmp" : nil @@ -82,13 +83,13 @@ def self.indent(string) # ) # => true # # DeadEnd.valid?(code_lines) # => false - def self.valid_without?(without_lines: , code_lines:) + def self.valid_without?(without_lines:, code_lines:) lines = code_lines - Array(without_lines).flatten if lines.empty? - return true + true else - return valid?(lines) + valid?(lines) end end @@ -137,7 +138,6 @@ def self.valid?(source) !invalid?(source) end - def self.invalid_type(source) WhoDisSyntaxError.new(source).call end diff --git a/lib/dead_end/lex_all.rb b/lib/dead_end/lex_all.rb index e7cba5a..73b5993 100644 --- a/lib/dead_end/lex_all.rb +++ b/lib/dead_end/lex_all.rb @@ -8,20 +8,20 @@ module DeadEnd class LexAll include Enumerable - def initialize(source: ) + def initialize(source:) @lex = Ripper.lex(source) - lineno = @lex.last&.first&.first + 1 + lineno = @lex.last.first.first + 1 source_lines = source.lines last_lineno = source_lines.count until lineno >= last_lineno - lines = source_lines[lineno..-1] + lines = source_lines[lineno..] - @lex.concat(Ripper.lex(lines.join, '-', lineno + 1)) - lineno = @lex.last&.first&.first + 1 + @lex.concat(Ripper.lex(lines.join, "-", lineno + 1)) + lineno = @lex.last.first.first + 1 end - @lex.map! {|(line, _), type, token, state| LexValue.new(line, _, type, token, state) } + @lex.map! { |(line, _), type, token, state| LexValue.new(line, type, token, state) } end def each @@ -49,7 +49,7 @@ def last class LexValue attr_reader :line, :type, :token, :state - def initialize(line, _, type, token, state) + def initialize(line, type, token, state) @line = line @type = type @token = token diff --git a/lib/dead_end/parse_blocks_from_indent_line.rb b/lib/dead_end/parse_blocks_from_indent_line.rb index 9c5a4df..83789f8 100644 --- a/lib/dead_end/parse_blocks_from_indent_line.rb +++ b/lib/dead_end/parse_blocks_from_indent_line.rb @@ -29,7 +29,7 @@ module DeadEnd class ParseBlocksFromIndentLine attr_reader :code_lines - def initialize(code_lines: ) + def initialize(code_lines:) @code_lines = code_lines end @@ -38,7 +38,7 @@ def each_neighbor_block(target_line) scan = AroundBlockScan.new(code_lines: code_lines, block: CodeBlock.new(lines: target_line)) .skip(:empty?) .skip(:hidden?) - .scan_while {|line| line.indent >= target_line.indent } + .scan_while { |line| line.indent >= target_line.indent } neighbors = scan.code_block.lines @@ -53,4 +53,3 @@ def each_neighbor_block(target_line) end end end - diff --git a/lib/dead_end/trailing_slash_join.rb b/lib/dead_end/trailing_slash_join.rb index 76c54a8..8011dcb 100644 --- a/lib/dead_end/trailing_slash_join.rb +++ b/lib/dead_end/trailing_slash_join.rb @@ -27,7 +27,7 @@ def call @trailing_lines = [] @code_lines.select(&:trailing_slash?).each do |trailing| stop_next = false - lines = @code_lines[trailing.index..-1].take_while do |line| + lines = @code_lines[trailing.index..].take_while do |line| next false if stop_next if !line.trailing_slash? @@ -47,7 +47,7 @@ def call lines.each(&:mark_invisible) end - return @code_lines_dup + @code_lines_dup end end end diff --git a/lib/dead_end/who_dis_syntax_error.rb b/lib/dead_end/who_dis_syntax_error.rb index 06381ba..cb4c1d1 100644 --- a/lib/dead_end/who_dis_syntax_error.rb +++ b/lib/dead_end/who_dis_syntax_error.rb @@ -9,8 +9,13 @@ module DeadEnd # # => :missing_end class WhoDisSyntaxError < Ripper class Null - def error_symbol; :missing_end; end - def unmatched_symbol; :end ; end + def error_symbol + :missing_end + end + + def unmatched_symbol + :end + end end attr_reader :error, :run_once @@ -56,9 +61,9 @@ def on_parse_error(msg) when /unexpected .* expecting '(?.*)'/ @unmatched_symbol = $1.to_sym if $1 @error_symbol = :unmatched_syntax - when /unexpected `end'/, # Ruby 2.7 and 3.0 - /unexpected end/, # Ruby 2.6 - /unexpected keyword_end/i # Ruby 2.5 + when /unexpected `end'/, # Ruby 2.7 and 3.0 + /unexpected end/, # Ruby 2.6 + /unexpected keyword_end/i # Ruby 2.5 @error_symbol = :unmatched_syntax else diff --git a/spec/fixtures/routes.txt.rb b/spec/fixtures/routes.rb.txt similarity index 100% rename from spec/fixtures/routes.txt.rb rename to spec/fixtures/routes.rb.txt diff --git a/spec/integration/exe_cli_spec.rb b/spec/integration/exe_cli_spec.rb index 120d015..4a2aae0 100644 --- a/spec/integration/exe_cli_spec.rb +++ b/spec/integration/exe_cli_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative "../spec_helper.rb" +require_relative "../spec_helper" module DeadEnd RSpec.describe "exe" do diff --git a/spec/integration/improvement_regression_spec.rb b/spec/integration/improvement_regression_spec.rb index 535ae88..c8906b2 100644 --- a/spec/integration/improvement_regression_spec.rb +++ b/spec/integration/improvement_regression_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative "../spec_helper.rb" +require_relative "../spec_helper" module DeadEnd RSpec.describe "Library only integration to test regressions and improvements" do @@ -11,22 +11,22 @@ module DeadEnd DeadEnd.call( io: io, source: source, - filename: "none", + filename: "none" ) expect(io.string).to include(<<~'EOM'.indent(4)) - 5 module DerailedBenchmarks - 6 class RequireTree - 7 REQUIRED_BY = {} - 9 attr_reader :name - 10 attr_writer :cost - 11 attr_accessor :parent - ❯ 13 def initialize(name) - ❯ 18 def self.reset! - ❯ 25 end - 73 end - 74 end - EOM + 5 module DerailedBenchmarks + 6 class RequireTree + 7 REQUIRED_BY = {} + 9 attr_reader :name + 10 attr_writer :cost + 11 attr_accessor :parent + ❯ 13 def initialize(name) + ❯ 18 def self.reset! + ❯ 25 end + 73 end + 74 end + EOM end end end diff --git a/spec/integration/ruby_command_line_spec.rb b/spec/integration/ruby_command_line_spec.rb index acadfde..429f017 100644 --- a/spec/integration/ruby_command_line_spec.rb +++ b/spec/integration/ruby_command_line_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative "../spec_helper.rb" +require_relative "../spec_helper" module DeadEnd RSpec.describe "Requires with ruby cli" do @@ -17,7 +17,6 @@ module DeadEnd methods = (dead_end_methods_array - kernel_methods_array).sort expect(methods).to eq(["dead_end_original_load", "dead_end_original_require", "dead_end_original_require_relative", "timeout"]) - @script.write <<~'EOM' puts Kernel.private_methods EOM diff --git a/spec/perf/perf_spec.rb b/spec/perf/perf_spec.rb index fe6daf8..449a576 100644 --- a/spec/perf/perf_spec.rb +++ b/spec/perf/perf_spec.rb @@ -1,19 +1,19 @@ # frozen_string_literal: true -require_relative "../spec_helper.rb" +require_relative "../spec_helper" require "benchmark" module DeadEnd RSpec.describe "perf" do it "doesnt timeout" do - source = fixtures_dir.join("routes.txt.rb").read + source = fixtures_dir.join("routes.rb.txt").read io = StringIO.new bench = Benchmark.measure do DeadEnd.call( io: io, source: source, - filename: "none", + filename: "none" ) end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 7cd194e..5adba21 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -3,7 +3,7 @@ require "bundler/setup" require "dead_end/internals" # Don't auto load code to -require 'tempfile' +require "tempfile" RSpec.configure do |config| # Enable flags like --only-failures and --next-failure @@ -52,7 +52,7 @@ def run!(cmd) # sometimes. class String def indent(number) - self.lines.map do |line| + lines.map do |line| if line.chomp.empty? line else @@ -62,8 +62,6 @@ def indent(number) end def strip_control_codes - self.gsub(/\e\[[^\x40-\x7E]*[\x40-\x7E]/, "") + gsub(/\e\[[^\x40-\x7E]*[\x40-\x7E]/, "") end end - - diff --git a/spec/unit/around_block_scan_spec.rb b/spec/unit/around_block_scan_spec.rb index e6390d2..781a4f1 100644 --- a/spec/unit/around_block_scan_spec.rb +++ b/spec/unit/around_block_scan_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative "../spec_helper.rb" +require_relative "../spec_helper" module DeadEnd RSpec.describe AroundBlockScan do @@ -62,7 +62,7 @@ def foo block = CodeBlock.new(lines: code_lines[3]) expand = AroundBlockScan.new(code_lines: code_lines, block: block) expand.stop_after_kw - expand.scan_while {true} + expand.scan_while { true } expect(expand.code_block.to_s).to eq(<<~EOM) def foo @@ -106,7 +106,7 @@ def foo code_lines = code_line_array(source_string) block = CodeBlock.new(lines: code_lines[3]) expand = AroundBlockScan.new(code_lines: code_lines, block: block) - expand.scan_while {|line| line.not_empty? } + expand.scan_while { |line| line.not_empty? } expect(expand.code_block.to_s).to eq(<<~EOM.indent(4)) puts "lol" diff --git a/spec/unit/block_expand_spec.rb b/spec/unit/block_expand_spec.rb index 57e5fb6..dc4dade 100644 --- a/spec/unit/block_expand_spec.rb +++ b/spec/unit/block_expand_spec.rb @@ -1,10 +1,8 @@ # frozen_string_literal: true -require_relative "../spec_helper.rb" - +require_relative "../spec_helper" module DeadEnd - RSpec.describe BlockExpand do it "captures multiple empty and hidden lines" do source_string = <<~EOM @@ -116,8 +114,6 @@ def foo puts "haha" end EOM - - block = expansion.call(block) end it "expand until next boundry (indentation)" do @@ -162,7 +158,6 @@ def foo EOM end - it "expand until next boundry (empty lines)" do source_string = <<~EOM describe "what" do diff --git a/spec/unit/capture_code_context_spec.rb b/spec/unit/capture_code_context_spec.rb index 9a04f77..4dff668 100644 --- a/spec/unit/capture_code_context_spec.rb +++ b/spec/unit/capture_code_context_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative "../spec_helper.rb" +require_relative "../spec_helper" module DeadEnd RSpec.describe CaptureCodeContext do @@ -88,7 +88,7 @@ def bark search = CodeSearch.new(source) search.call - expect(search.invalid_blocks.join.strip).to eq('class Dog') + expect(search.invalid_blocks.join.strip).to eq("class Dog") display = CaptureCodeContext.new( blocks: search.invalid_blocks, code_lines: search.code_lines @@ -176,7 +176,7 @@ class Zerg # expect(lines.select(&:hidden?).map(&:line_number)).to eq([11, 12]) out = DisplayCodeWithLineNumbers.new( - lines: lines, + lines: lines ).call expect(out).to eq(<<~EOM.indent(2)) diff --git a/spec/unit/code_block_spec.rb b/spec/unit/code_block_spec.rb index 086a2df..40aa62c 100644 --- a/spec/unit/code_block_spec.rb +++ b/spec/unit/code_block_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative "../spec_helper.rb" +require_relative "../spec_helper" module DeadEnd RSpec.describe CodeBlock do @@ -26,7 +26,7 @@ def foo block_1 = CodeBlock.new(lines: code_lines[1]) block_2 = CodeBlock.new(lines: code_lines[2]) - expect(block_0 <=> block_0).to eq(0) + expect(block_0 <=> block_0.dup).to eq(0) expect(block_1 <=> block_0).to eq(1) expect(block_1 <=> block_2).to eq(-1) @@ -35,7 +35,7 @@ def foo block = CodeBlock.new(lines: CodeLine.new(line: " " * 8 + "foo", index: 4)) array.prepend(block) - expect(array.sort.last).to eq(block) + expect(array.max).to eq(block) end it "knows it's current indentation level" do diff --git a/spec/unit/code_frontier_spec.rb b/spec/unit/code_frontier_spec.rb index 33358af..d5a8d84 100644 --- a/spec/unit/code_frontier_spec.rb +++ b/spec/unit/code_frontier_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative "../spec_helper.rb" +require_relative "../spec_helper" module DeadEnd RSpec.describe CodeFrontier do @@ -31,7 +31,7 @@ module DeadEnd CodeFrontier.combination([:a, :b, :c, :d]) ).to eq( [ - [:a],[:b],[:c],[:d], + [:a], [:b], [:c], [:d], [:a, :b], [:a, :c], [:a, :d], @@ -60,7 +60,7 @@ def foo frontier << CodeBlock.new(lines: [code_lines[2]]) expect(frontier.count).to eq(1) - frontier << CodeBlock.new(lines: [code_lines[1],code_lines[2],code_lines[3]]) + frontier << CodeBlock.new(lines: [code_lines[1], code_lines[2], code_lines[3]]) expect(frontier.count).to eq(1) expect(frontier.pop.to_s).to eq(<<~EOM.indent(2)) puts "lol" diff --git a/spec/unit/code_line_spec.rb b/spec/unit/code_line_spec.rb index ff7d24c..13cbc80 100644 --- a/spec/unit/code_line_spec.rb +++ b/spec/unit/code_line_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative "../spec_helper.rb" +require_relative "../spec_helper" module DeadEnd RSpec.describe CodeLine do @@ -102,7 +102,7 @@ def foo expect(code_lines.map(&:empty?)).to eq([false, true, false]) expect(code_lines.map(&:not_empty?)).to eq([true, false, true]) - expect(code_lines.map {|l| DeadEnd.valid?(l) }).to eq([true, true, true]) + expect(code_lines.map { |l| DeadEnd.valid?(l) }).to eq([true, true, true]) end it "counts indentations" do diff --git a/spec/unit/code_search_spec.rb b/spec/unit/code_search_spec.rb index 9fec231..4272221 100644 --- a/spec/unit/code_search_spec.rb +++ b/spec/unit/code_search_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative "../spec_helper.rb" +require_relative "../spec_helper" module DeadEnd RSpec.describe CodeSearch do @@ -162,13 +162,13 @@ def hello display = DisplayInvalidBlocks.new( code_lines: search.code_lines, blocks: blocks, - io: io, + io: io ) display.call # puts io.string expect(display.code_with_lines.strip_control_codes).to include(<<~EOM) - ❯ 36 def filename + ❯ 36 def filename EOM end @@ -381,10 +381,10 @@ def foo search.call expect(search.invalid_blocks.join).to eq(<<~EOM.indent(2)) - Foo.call - end - Bar.call - end + Foo.call + end + Bar.call + end EOM end diff --git a/spec/unit/dead_end_spec.rb b/spec/unit/dead_end_spec.rb index 56e2561..09ff0cf 100644 --- a/spec/unit/dead_end_spec.rb +++ b/spec/unit/dead_end_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative "../spec_helper.rb" +require_relative "../spec_helper" module DeadEnd RSpec.describe DeadEnd do diff --git a/spec/unit/display_invalid_blocks_spec.rb b/spec/unit/display_invalid_blocks_spec.rb index e92ed23..85dc035 100644 --- a/spec/unit/display_invalid_blocks_spec.rb +++ b/spec/unit/display_invalid_blocks_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative "../spec_helper.rb" +require_relative "../spec_helper" module DeadEnd RSpec.describe DisplayInvalidBlocks do @@ -14,7 +14,7 @@ module DeadEnd display = DisplayInvalidBlocks.new( code_lines: code_lines, blocks: CodeBlock.new(lines: code_lines), - invalid_obj: WhoDisSyntaxError.new(source), + invalid_obj: WhoDisSyntaxError.new(source) ) expect(display.banner).to include("Unmatched `|` character detected") end @@ -30,7 +30,7 @@ class Cat display = DisplayInvalidBlocks.new( code_lines: code_lines, blocks: CodeBlock.new(lines: code_lines), - invalid_obj: WhoDisSyntaxError.new(source), + invalid_obj: WhoDisSyntaxError.new(source) ) expect(display.banner).to include("Unmatched `}` character detected") end @@ -46,7 +46,7 @@ class Cat display = DisplayInvalidBlocks.new( code_lines: code_lines, blocks: CodeBlock.new(lines: code_lines), - invalid_obj: WhoDisSyntaxError.new(source), + invalid_obj: WhoDisSyntaxError.new(source) ) expect(display.banner).to include("DeadEnd: Unmatched `end` detected") end @@ -64,7 +64,7 @@ def meow display = DisplayInvalidBlocks.new( code_lines: code_lines, blocks: CodeBlock.new(lines: code_lines), - invalid_obj: WhoDisSyntaxError.new(source), + invalid_obj: WhoDisSyntaxError.new(source) ) expect(display.banner).to include("DeadEnd: Unmatched `unknown` detected") end @@ -80,7 +80,7 @@ def meow display = DisplayInvalidBlocks.new( code_lines: code_lines, blocks: CodeBlock.new(lines: code_lines), - invalid_obj: WhoDisSyntaxError.new(source), + invalid_obj: WhoDisSyntaxError.new(source) ) expect(display.banner).to include("DeadEnd: Missing `end` detected") end @@ -102,7 +102,7 @@ def hai io: io, blocks: search.invalid_blocks, terminal: false, - code_lines: search.code_lines, + code_lines: search.code_lines ) display.call expect(io.string).to include("Syntax OK") @@ -123,7 +123,7 @@ def hai io: io, blocks: block, terminal: false, - code_lines: code_lines, + code_lines: code_lines ) display.call expect(io.string).to include("❯ 2 def hello") @@ -147,11 +147,11 @@ def hai code_lines: code_lines ) expect(display.code_block).to eq(<<~EOM) - 1 class OH - ❯ 2 def hello - 4 def hai - 5 end - 6 end + 1 class OH + ❯ 2 def hello + 4 def hai + 5 end + 6 end EOM end @@ -192,7 +192,7 @@ def hai expect(display.code_with_lines).to eq( [ " 1 class OH", - ["❯ 2 ", DisplayCodeWithLineNumbers::TERMINAL_HIGHLIGHT, " def hello"].join, + ["❯ 2 ", DisplayCodeWithLineNumbers::TERMINAL_HIGHLIGHT, " def hello"].join, " 3 def hai", " 4 end", " 5 end", diff --git a/spec/unit/heredoc_block_parse_spec.rb b/spec/unit/heredoc_block_parse_spec.rb index 9c82f98..197be00 100644 --- a/spec/unit/heredoc_block_parse_spec.rb +++ b/spec/unit/heredoc_block_parse_spec.rb @@ -1,9 +1,8 @@ # frozen_string_literal: true -require_relative "../spec_helper.rb" +require_relative "../spec_helper" module DeadEnd - RSpec.describe "HeredocBlockParse" do it "works" do source = fixtures_dir.join("this_project_extra_def.rb.txt").read diff --git a/spec/unit/lex_all_spec.rb b/spec/unit/lex_all_spec.rb index fd40320..ffcf243 100644 --- a/spec/unit/lex_all_spec.rb +++ b/spec/unit/lex_all_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative "../spec_helper.rb" +require_relative "../spec_helper" module DeadEnd RSpec.describe "EndBlockParse" do diff --git a/spec/unit/trailing_slash_join_spec.rb b/spec/unit/trailing_slash_join_spec.rb index 5eb6942..3d7ac4e 100644 --- a/spec/unit/trailing_slash_join_spec.rb +++ b/spec/unit/trailing_slash_join_spec.rb @@ -1,10 +1,9 @@ # frozen_string_literal: true -require_relative "../spec_helper.rb" +require_relative "../spec_helper" module DeadEnd RSpec.describe TrailingSlashJoin do - it "formats output" do code_lines = code_line_array(<<~'EOM') context "timezones workaround" do @@ -23,14 +22,14 @@ module DeadEnd lines: out_code_lines.select(&:visible?) ).call ).to eq(<<~'EOM'.indent(2)) - 1 context "timezones workaround" do - 2 it "should receive a time in UTC format and return the time with the"\ - 3 "office's UTC offset substracted from it" do - 4 travel_to DateTime.new(2020, 10, 1, 10, 0, 0) do - 5 office = build(:office) - 6 end - 7 end - 8 end + 1 context "timezones workaround" do + 2 it "should receive a time in UTC format and return the time with the"\ + 3 "office's UTC offset substracted from it" do + 4 travel_to DateTime.new(2020, 10, 1, 10, 0, 0) do + 5 office = build(:office) + 6 end + 7 end + 8 end EOM expect( diff --git a/spec/unit/who_dis_syntax_error_spec.rb b/spec/unit/who_dis_syntax_error_spec.rb index d65ca1a..e72e611 100644 --- a/spec/unit/who_dis_syntax_error_spec.rb +++ b/spec/unit/who_dis_syntax_error_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative "../spec_helper.rb" +require_relative "../spec_helper" module DeadEnd RSpec.describe WhoDisSyntaxError do