-1

Recently I tried integrating husky on my application for pre-commit formatting. I am only using rubocop to test the commit but it gives out an error when I try to commit.

My package.json

{
  "name": "asdf",
  "private": true,
  "husky": {
    "hooks": {
      "pre-commit": "lint-staged"
    }
  },
  "lint-staged": {
    "{app,spec}/**/*.rb": [
      "bin/rubocop --require rubocop-rspec --safe-auto-correct",
      "git add"
    ]
  },
  "devDependencies": {
    "husky": "^1.3.1",
    "lint-staged": "^8.1.5"
  }
}

The error it gives

husky > pre-commit (node v8.15.1)
↓ Stashing changes... [skipped]
  → No partially staged files found...
   ❯ Running linters...
     ❯ Running tasks for {app,spec}/**/*.rb
       ✖ bin/rubocop --require rubocop-rspec --safe-auto-correct
        git add

       ✖ bin/rubocop --require rubocop-rspec --safe-auto-correct found some errors. Please fix them and try committing again.

       /usr/lib/ruby/vendor_ruby/bundler/definition.rb:489:in `validate_ruby!': Your Ruby version is 2.5.1, but your Gemfile specified 2.5.0 (Bundler::RubyVersionMismatch)

My rvm

=* ruby-2.5.0 [ x86_64 ]
   ruby-2.5.3 [ x86_64 ]
   ruby-2.6.1 [ x86_64 ]

NOTE: rails server runs just fine and so does every other commands.

tk421
  • 5,775
  • 6
  • 23
  • 34
meerkat
  • 361
  • 1
  • 3
  • 11

1 Answers1

0

Update ruby version in your Gemfile:

ruby "2.5.1"

It runs on occasion (because there are not so many differences between 2.5.0 and 2.5.1) and “runs successfully” basically proves nothing.

Aleksei Matiushkin
  • 119,336
  • 10
  • 100
  • 160
  • Are you sure that won't change my applications drastically? @Aleksei – meerkat Mar 15 '19 at 10:53
  • Absolutely sure. You just confirmed it runs perfectly on `2.5.1`, also it’s a minor update that is nevertheless to be applied. Another option would be to downgrade rails version, but I strongly discourage to do that. – Aleksei Matiushkin Mar 15 '19 at 11:03
  • It solved the error but now I'm getting `Incompatible version ` error. – meerkat Mar 15 '19 at 11:34
  • ``` /home/meerkat/.rvm/gems/ruby-2.5.1/gems/jaro_winkler-1.5.2/lib/jaro_winkler.rb:6:in `require': incompatible library version - /home/meerkat/.rvm/gems/ruby-2.5.1/gems/jaro_winkler-1.5.2/lib/jaro_winkler/jaro_winkler_ext.so (LoadError) from /home/meerkat/.rvm/gems/ruby-2.5.1/gems/jaro_winkler-1.5.2/lib/jaro_winkler.rb:6:in ``` – meerkat Mar 15 '19 at 11:35
  • You have to install the respective ruby version locally `rvm 2.5.1` and re-run `bundle install`. – Aleksei Matiushkin Mar 15 '19 at 11:57
  • I tried `bundle update jaro_winkler` too but it still doesn't work – meerkat Mar 15 '19 at 12:15
  • You need to rebuild native exceptions of this gem. I have no idea how to achieve it and frankly, I do not see how is it connected to the OP. – Aleksei Matiushkin Mar 15 '19 at 12:23