yujinakayama / atom-lint

Obsolete: Generic code linting support for Atom
https://atom.io/packages/atom-lint
MIT License
111 stars 33 forks source link

Rubocop not found if not in global PATH variable #30

Closed cschneid closed 10 years ago

cschneid commented 10 years ago

I am launching atom from a terminal that has RVM installed, in a gemset with Rubocop available.

$ which rubocop
/Users/cschneid/Developer/.rvm/gems/ruby-2.1.1@advanced-apps/bin/rubocop

$ atom .

The atom-lint package cannot find the rubocop executable, probably due to some of the PATH hackery done in this commit: https://github.com/yujinakayama/atom-lint/commit/7702e76f124ccbf1289577262d9441b7e246ce11

I like the goal of that commit, and I can work around this issue by manually configuring the path to rubocop, but I had expected that it would load the path that I had when I launched the editor.

Maybe support both?

Thanks for the otherwise awesome tool! Once I had the workaround to set the path, the rest is looking really cool.

yujinakayama commented 10 years ago

I'll tackle this. Could you provide the following infomations?

cschneid commented 10 years ago

Path:

"/Users/cschneid/Developer/.rvm/gems/ruby-2.1.1@advanced-apps/bin:/Users/cschneid/Developer/.rvm/gems/ruby-2.1.1@global/bin:/Users/cschneid/Developer/.rvm/rubies/ruby-2.1.1/bin:/Users/cschneid/.rvm/bin::/usr/local/heroku/bin:/Users/cschneid/Developer/bin:/Users/cschneid/.cabal/bin:/usr/local/bin:::/usr/local/heroku/bin:/Users/cschneid/Developer/bin:/Users/cschneid/.cabal/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/local/MacGPG2/bin:/usr/texbin:/Applications/MacVim.app/Contents/MacOS:/usr/local/sbin:/Users/cschneid/bin:/Users/cschneid/Projects/comv/bin:/usr/bin:/usr/sbin:/bin:/sbin:/opt/X11/bin:/Users/cschneid/Library/Python/2.7/bin:/Applications/MacVim.app/Contents/MacOS:/usr/local/sbin:/Users/cschneid/bin:/Users/cschneid/Projects/comv/bin:/usr/bin:/usr/sbin:/bin:/sbin:/opt/X11/bin:/Users/cschneid/Library/Python/2.7/bin"

ZSH Setup is standard RVM.

#################
# RVM
#################
export rvm_path=/Users/cschneid/Developer/.rvm
if [[ -s /Users/cschneid/Developer/.rvm/scripts/rvm ]] ; then
  source /Users/cschneid/Developer/.rvm/scripts/rvm
  export rvm_pretty_print_flag=1
fi

And the rubocop app is in /Users/cschneid/Developer/.rvm/gems/ruby-2.1.1@advanced-apps/bin

yujinakayama commented 10 years ago

Hmm, I'm wondering why rubocop isn't found despite the PATH including /Users/cschneid/Developer/.rvm/gems/ruby-2.1.1@advanced-apps/bin.

atomweekly commented 10 years ago

No idea - but hardcoding this snippet in my config does fix things:

'atom-lint':
  'rubocop':
    'path': '/Users/cschneid/Developer/.rvm/gems/ruby-2.1.1@advanced-apps/bin/rubocop'
atomweekly commented 10 years ago

Sorry - that is cschneid above - doing work on a new account...

yujinakayama commented 10 years ago

I was a bit confused but now I understood the reason.

yujinakayama commented 10 years ago

I think the issue is fixed in version 0.8.1.

Please note that if you've launched Atom from Finder/Dock first and then opened another project by running atom command in your shell, the Atom process always uses the environment variables of Finder/Dock even in the project window launched from shell. This is unavoidable and cannot be handled in atom-lint.

If you still have the issue, please reopen.

JeanMertz commented 10 years ago

@yujinakayama I ran into this issue myself.

using 0.11.3:

$ which rubocop
> /Users/Jean/.gem/ruby/2.1.1/bin/rubocop

$ atom .
$ cmd + alt + i # developer console
$ process.env.PATH
> *:/Users/Jean/.gem/ruby/2.1.1/bin:* # stripped line of non-essentials

As you can see, the path is included, but I get the following error in the console when running the rubocop linter:

# lint-view.coffee:57

SyntaxError
message: "Unexpected end of input"
stack: "SyntaxError: Unexpected end of input
  at Object.parse (native)
  at /Users/Jean/.atom/packages/atom-lint/lib/linter/rubocop.coffee:46:31
  at ChildProcess.<anonymous> (/Users/Jean/.atom/packages/atom-lint/lib/command-runner.coffee:99:7)
  at ChildProcess.EventEmitter.emit (events.js:104:17)
  at maybeClose (child_process.js:821:16)
  at Socket.<anonymous> (child_process.js:1038:11)
  at Socket.EventEmitter.emit (events.js:101:17)
  at Pipe.close (net.js:459:12)
"

and no errors are shown in the editor (even though running rubocop from the terminal on the same file shows errors.

EDIT: Having said that, hard-coding the path like @cschneid suggested doesn't work in my case, so seems like a different error.

JeanMertz commented 10 years ago

Okay, looked a bit further, adding some log statements, I found the following:

  runRubocop: (callback) ->
    runner = new CommandRunner(@buildCommand())

    runner.run (error, result) ->
      console.log(error)
      console.log(result)
null
"couldn't find HOME environment -- expanding `~'
/Users/Jean/.gem/ruby/2.1.1/gems/rubocop-0.20.1/lib/rubocop/config_loader.rb:157:in `home'
/Users/Jean/.gem/ruby/2.1.1/gems/rubocop-0.20.1/lib/rubocop/config_loader.rb:157:in `dirs_to_search'
/Users/Jean/.gem/ruby/2.1.1/gems/rubocop-0.20.1/lib/rubocop/config_loader.rb:145:in `config_files_in_path'
/Users/Jean/.gem/ruby/2.1.1/gems/rubocop-0.20.1/lib/rubocop/config_loader.rb:95:in `configuration_file_for'
/Users/Jean/.gem/ruby/2.1.1/gems/rubocop-0.20.1/lib/rubocop/config_store.rb:37:in `for'
/Users/Jean/.gem/ruby/2.1.1/gems/rubocop-0.20.1/lib/rubocop/file_inspector.rb:99:in `inspect_file'
/Users/Jean/.gem/ruby/2.1.1/gems/rubocop-0.20.1/lib/rubocop/file_inspector.rb:69:in `block in process_file'
/Users/Jean/.gem/ruby/2.1.1/gems/rubocop-0.20.1/lib/rubocop/file_inspector.rb:67:in `loop'
/Users/Jean/.gem/ruby/2.1.1/gems/rubocop-0.20.1/lib/rubocop/file_inspector.rb:67:in `process_file'
/Users/Jean/.gem/ruby/2.1.1/gems/rubocop-0.20.1/lib/rubocop/file_inspector.rb:23:in `block in process_files'
/Users/Jean/.gem/ruby/2.1.1/gems/rubocop-0.20.1/lib/rubocop/file_inspector.rb:21:in `each'
/Users/Jean/.gem/ruby/2.1.1/gems/rubocop-0.20.1/lib/rubocop/file_inspector.rb:21:in `process_files'
/Users/Jean/.gem/ruby/2.1.1/gems/rubocop-0.20.1/lib/rubocop/cli.rb:31:in `run'
/Users/Jean/.gem/ruby/2.1.1/gems/rubocop-0.20.1/bin/rubocop:14:in `block in <top (required)>'
/Users/Jean/.rubies/ruby-2.1.1/lib/ruby/2.1.0/benchmark.rb:294:in `realtime'
/Users/Jean/.gem/ruby/2.1.1/gems/rubocop-0.20.1/bin/rubocop:13:in `<top (required)>'
/Users/Jean/.gem/ruby/2.1.1/bin/rubocop:23:in `load'
/Users/Jean/.gem/ruby/2.1.1/bin/rubocop:23:in `<main>'
"
kemelzaidan commented 9 years ago

I'm having the same problem with rbenv:

$ which rubocop
/Users/kemelzaidan/.rbenv/shims/rubocop
process.env.PATH
"/usr/bin:/bin:/usr/sbin:/sbin"

rbenv config in bash:

export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"

Error: The linter binary 'rubocop' cannot be found. Linting has been halted. Please install the linter binary or disable the linter plugin depending on it. Make sure to reload Atom to detect changes Close All Failed to spawn command rubocop. Make sure rubocop is installed and on your PATH

mmahalwy commented 8 years ago

I have the same problem @kemelzaidan but with fish shell. Any luck?

kWhittington commented 8 years ago

Same for me. Atom's actually brining up the developer console too and I can't close it.

bbrock25 commented 8 years ago

I am having similar issues. The best I've found is to specify bundle exec rubocop as the custom command. However it still chokes when I specify the full path for bundler.

ilyakatz commented 8 years ago

Having the same issue, anyone has any ideas?

sergiotapia commented 7 years ago

This is still happening :(

andretf commented 7 years ago

I'm using rbenv, using shims path does not work. Set path to ~/.rbenv/versions/2.3.1/bin/rubocop and it should work.

graciano commented 7 years ago

In case anyone ran into this issue with the same problem that I had: The project I'm working on uses a legacy version of ruby: 1.9, and this is not compatible with the current version of the gem rubocop. So installing a compatible version worked for me

gem install rubocop -v 0.41.2
merefield commented 6 years ago

thanks @graciano!

gem install rubocop

Was enough for me to fix this.

wbotelhos commented 6 years ago

Thank you @yujinakayama ,

After months not using this plugin, even trying a lot of thing, now I know the differents env depending of the way you open the app (Atom in my case).

clockworkpc commented 5 years ago

I think the issue is fixed in version 0.8.1.

Please note that if you've launched Atom from Finder/Dock first and then opened another project by running atom command in your shell, the Atom process always uses the environment variables of Finder/Dock even in the project window launched from shell. This is unavoidable and cannot be handled in atom-lint.

If you still have the issue, please reopen.

HALLELUJAH. This fixed it for me.