Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.ruby-version is ignored if it's not in the working directory #3318

Closed
savef opened this issue Jul 14, 2016 · 1 comment
Closed

.ruby-version is ignored if it's not in the working directory #3318

savef opened this issue Jul 14, 2016 · 1 comment

Comments

@savef
Copy link
Contributor

savef commented Jul 14, 2016

Hey! I was looking forward to removing the TargetRubyVersion from my config with the 0.41 release so that it could just use the existing declaration in my .ruby-version file, however I've had a problem since doing so. Although everything worked fine when using RuboCop from the command line I was getting syntax errors (when my files had keyword arguments) with the linter-rubocop plugin for Atom.

I've now realised the problem is because linter-rubocop executes rubocop from in the directory of the file you're running it on, and when doing so it's not picking up the .ruby-version file as it should. I can now replicate this behaviour from the console, like so:

$ rubocop app/models/user.rb
Inspecting 1 file
.

1 file inspected, no offenses detected
$ cd app/models
$ rubocop user.rb
Inspecting 1 file
E

Offenses:

user.rb:1:1: E: class definition in method body
(Using Ruby 2.0 parser; configure using TargetRubyVersion parameter, under AllCops)
class User < ActiveRecord::Base
^^^^^
user.rb:31:23: E: unexpected token tRPAREN
(Using Ruby 2.0 parser; configure using TargetRubyVersion parameter, under AllCops)
  def self.something(name:)
                      ^

1 file inspected, 2 offenses detected

I think the solution should be that RuboCop looks for the .ruby-version file in more than the current directory. If we don't want it to check every parent directory (like I would assume it does for the config file) then the minimum it should do is look in the same directory that it finds the config file in.

RuboCop version

$ rubocop -V
0.41.2 (using Parser 2.3.1.2, running on ruby 2.3.1 x86_64-linux)

The issue applies from v0.41.0 all the way to master (cd7246f).

@bbatsov
Copy link
Collaborator

bbatsov commented Oct 2, 2016

I think the solution should be that RuboCop looks for the .ruby-version file in more than the current directory. If we don't want it to check every parent directory (like I would assume it does for the config file) then the minimum it should do is look in the same directory that it finds the config file in.

Both solutions seem reasonable to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants