The cop Style/HashSyntax attempts to determine whether a hash has a valid syntax. For complex symbol keys it delegates this to the Ruby parser and calls the parse method on a code snippet with no path context.
By "complex symbol keys" I mean something like this:
{ 'complex_symbol': 0 }
where the key is a symbol but one declared using unusual but valid syntax.
When we run Rubocop, with rubocop-md required, on code like this (in a Ruby script rather than embedded in Markdown) we get the following exception:
An error occurred while Style/HashSyntax cop was inspecting /home/build/Development/dominicsayers/rubocop-hash-syntax-exception/hash_syntax_exception.rb:3:0.
no implicit conversion of nil into String
/home/build/.rvm/gems/ruby-2.6.3/gems/rubocop-md-0.3.2/lib/rubocop/markdown/rubocop_ext.rb:34:in `extname'
/home/build/.rvm/gems/ruby-2.6.3/gems/rubocop-md-0.3.2/lib/rubocop/markdown/rubocop_ext.rb:34:in `markdown_file?'
/home/build/.rvm/gems/ruby-2.6.3/gems/rubocop-md-0.3.2/lib/rubocop/markdown/rubocop_ext.rb:80:in `parse'
This PR fixes that exception.
To get the tests to run I have had to make the following changes, which I have minimised as much as possible:
Drop support for Ruby v2.3 because otherwise core Rubocop complains
Update the .rubocop.yml config to enable new cops by default
Fix a Rubocop offence in this code that is now detected with recent versions of Rubocop
The cop
Style/HashSyntax
attempts to determine whether a hash has a valid syntax. For complex symbol keys it delegates this to the Ruby parser and calls the parse method on a code snippet with no path context.By "complex symbol keys" I mean something like this:
where the key is a symbol but one declared using unusual but valid syntax.
When we run Rubocop, with
rubocop-md
required, on code like this (in a Ruby script rather than embedded in Markdown) we get the following exception:This PR fixes that exception.
To get the tests to run I have had to make the following changes, which I have minimised as much as possible:
.rubocop.yml
config to enable new cops by default