mattlqx / pre-commit-search-and-replace

Plugin for pre-commit for arbitrary search and replace on committed files.
MIT License
12 stars 7 forks source link

Search and replace fails with a syntax error #20

Closed matthew-limbinar closed 3 hours ago

matthew-limbinar commented 2 months ago

Running bundle2.7 exec rspec spec/unit/search_and_replace_spec.rb on 1.1.3 tag results in failures:

....FF................

Failures:

  1) SearchAndReplace when loading a config has correct number of occurrences for bad regexp config
     Failure/Error: match.match_length(:sar_all)

     NoMethodError:
       undefined method `match_length' for #<MatchData "Bad     Regexp" sar_all:"Bad     Regexp">
     # ./lib/search-and-replace.rb:89:in `length_from_match'
     # ./lib/search-and-replace.rb:80:in `search_line'
     # ./lib/search-and-replace.rb:43:in `parse_file'
     # ./lib/search-and-replace.rb:32:in `block in parse_files'
     # ./lib/search-and-replace.rb:32:in `map'
     # ./lib/search-and-replace.rb:32:in `parse_files'
     # ./spec/unit/search_and_replace_spec.rb:70:in `block (3 levels) in <top (required)>'

  2) SearchAndReplace when loading a config has correct number of occurrences for insensitive config
     Failure/Error: match.match_length(:sar_all)

     NoMethodError:
       undefined method `match_length' for #<MatchData "InsensitiveRegexp" sar_all:"InsensitiveRegexp">
     # ./lib/search-and-replace.rb:89:in `length_from_match'
     # ./lib/search-and-replace.rb:80:in `search_line'
     # ./lib/search-and-replace.rb:43:in `parse_file'
     # ./lib/search-and-replace.rb:32:in `block in parse_files'
     # ./lib/search-and-replace.rb:32:in `map'
     # ./lib/search-and-replace.rb:32:in `parse_files'
     # ./spec/unit/search_and_replace_spec.rb:77:in `block (3 levels) in <top (required)>'

Finished in 1.17 seconds (files took 0.08439 seconds to load)
22 examples, 2 failures

Failed examples:

rspec ./spec/unit/search_and_replace_spec.rb:69 # SearchAndReplace when loading a config has correct number of occurrences for bad regexp config
rspec ./spec/unit/search_and_replace_spec.rb:76 # SearchAndReplace when loading a config has correct number of occurrences for insensitive config

Coverage report generated for RSpec to /home/mtl/proj/pre-commit-search-and-replace/coverage. 91 / 91 LOC (100.0%) covered.
Stopped processing SimpleCov as a previous error not related to SimpleCov has been detected

This appears to be due to a syntax error and search/replace not being tested.

Killusions commented 1 day ago

Since the fix to this wasn't accepted so far I released v1.1.4 under https://github.com/Killusions/pre-commit-search-and-replace.git