yujinakayama / atom-lint

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

Fix a bug that couldn't find HOME environment using rubocop #80

Closed rochefort closed 10 years ago

rochefort commented 10 years ago

I saw LinterError using rubocop on atom console.

LinterError: Failed parsing RuboCop's JSON output ""
    command: ["rubocop","--format","json","/Users/trsw/github/git-trend/lib/git_trend/cli.rb"]
    PATH: /Users/trsw/.composer/vendor/bin:/usr/local/sbin:/usr/local/bin:/Users/trsw/.rbenv/shims:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/opt/go/libexec/bin:/Users/trsw/.go/bin
    exit code: 1
    stdout:

    stderr:
        couldn't find HOME environment -- expanding `~'
        /Users/trsw/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rubocop-0.24.1/lib/rubocop/config_loader.rb:138:in `home'
        /Users/trsw/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rubocop-0.24.1/lib/rubocop/config_loader.rb:138:in `dirs_to_search'
        /Users/trsw/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rubocop-0.24.1/lib/rubocop/config_loader.rb:126:in `config_files_in_path'
        /Users/trsw/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rubocop-0.24.1/lib/rubocop/config_loader.rb:89:in `configuration_file_for'
        /Users/trsw/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rubocop-0.24.1/lib/rubocop/config_store.rb:36:in `for'
        /Users/trsw/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rubocop-0.24.1/lib/rubocop/runner.rb:85:in `inspect_file'
        /Users/trsw/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rubocop-0.24.1/lib/rubocop/runner.rb:69:in `block in process_file'
        /Users/trsw/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rubocop-0.24.1/lib/rubocop/runner.rb:64:in `loop'
        /Users/trsw/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rubocop-0.24.1/lib/rubocop/runner.rb:64:in `process_file'
        /Users/trsw/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rubocop-0.24.1/lib/rubocop/runner.rb:27:in `block in run'
        /Users/trsw/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rubocop-0.24.1/lib/rubocop/runner.rb:25:in `each'
        /Users/trsw/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rubocop-0.24.1/lib/rubocop/runner.rb:25:in `run'
        /Users/trsw/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rubocop-0.24.1/lib/rubocop/cli.rb:24:in `run'
        /Users/trsw/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rubocop-0.24.1/bin/rubocop:14:in `block in <top (required)>'
        /Users/trsw/.rbenv/versions/2.1.2/lib/ruby/2.1.0/benchmark.rb:294:in `realtime'
        /Users/trsw/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rubocop-0.24.1/bin/rubocop:13:in `<top (required)>'
        /Users/trsw/.rbenv/versions/2.1.2/bin/rubocop:23:in `load'
        /Users/trsw/.rbenv/versions/2.1.2/bin/rubocop:23:in `<main>'

It is due to using Dir.home in rubocop(lib/rubocop/config_loader.rb:138). It works like this.

yujinakayama commented 10 years ago

Thanks!

yujinakayama commented 10 years ago

By the way, there seems to be something wrong with fetching your login shell's environement variables. Could you try it again on atom-lint 0.14.3 (released just now) and check if there's any error output in the Developer Console?

rochefort commented 10 years ago

Thank you for merging.

Is my environment something wrong?

MacOSX 10.9.4 rbenv 0.4.0 ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-darwin13.0] rubocop 0.24.1 zsh 5.0.5 (x86_64-apple-darwin13.0.0) (by prezto)


command-runner.coffee:69

Error: Command failed: zsh:1: file exists: /var/folders/56/tt94wwzs0cg0z4lwpq8qc6wr0000gn/T/CommandRunner_fetchEnvOfLoginShell.txt

  at ChildProcess.exithandler (child_process.js:709:12)
  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)

cat /var/folders/56/tt94wwzs0cg0z4lwpq8qc6wr0000gn/T/CommandRunner_fetchEnvOfLoginShell.txt
GREP_COLOR=37;45
LESS_TERMCAP_mb=
TERM_PROGRAM=iTerm.app
LESS_TERMCAP_md=
LESS_TERMCAP_me=
TERM=xterm
SHELL=/usr/local/bin/zsh
TMPDIR=/var/folders/56/tt94wwzs0cg0z4lwpq8qc6wr0000gn/T/
Apple_PubSub_Socket_Render=/tmp/launch-R4Pqo7/Render
LESS_TERMCAP_ue=
NVM_DIR=/Users/trsw/.nvm
USER=trsw
LS_COLORS=di=34:ln=35:so=32:pi=33:ex=31:bd=36;01:cd=33;01:su=31;40;07:sg=36;40;07:tw=32;40;07:ow=33;40;07:
SSH_AUTH_SOCK=/tmp/launch-xtV57m/Listeners
__CF_USER_TEXT_ENCODING=0x1F5:1:14
PAGER=less
LESS_TERMCAP_us=
LSCOLORS=exfxcxdxbxGxDxabagacad
__CHECKFIX1436934=1
PATH=/Users/trsw/.composer/vendor/bin:/usr/local/sbin:/usr/local/bin:/Users/trsw/.rbenv/shims:/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/trsw/.composer/vendor/bin:/Users/trsw/.rbenv/shims:/usr/local/opt/go/libexec/bin:/Users/trsw/.go/bin:/usr/local/opt/go/libexec/bin:/Users/trsw/.go/bin
_=/usr/bin/printenv
NVM_NODEJS_ORG_MIRROR=http://nodejs.org/dist
PWD=/
EDITOR=atom
LANG=ja_JP.UTF-8
ITERM_PROFILE=Default
NODE_PATH=/Applications/Atom.app/Contents/Resources/app/exports
NODE_ENV=production
SHLVL=3
COLORFGBG=7;0
HOME=/Users/trsw
GOROOT=/usr/local/opt/go/libexec
ITERM_SESSION_ID=w0t1p0
LESS=-F -g -i -M -R -S -w -X -z-4
LOGNAME=trsw
VISUAL=vim
LESS_TERMCAP_so=
GOPATH=/Users/trsw/.go
BROWSER=open
SECURITYSESSIONID=186a4
LESS_TERMCAP_se=
OLDPWD=/
GREP_OPTIONS=--color=auto
yujinakayama commented 10 years ago

Thanks for the checking.

Hmm, the error is similar to #76 but it's already fixed in version 0.14.2. Could you provide your zsh configuration options in your .zshrc?

rochefort commented 10 years ago

I understand what the issue is. As you expected, it is related to clobber.

I'm using Prezto(https://github.com/sorin-ionescu/prezto). Prezto call directory submodule that is a default module. (*: https://github.com/sorin-ionescu/prezto/blob/master/modules/directory/init.zsh#L22) unsetopt CLOBBER is called in this.

rochefort commented 10 years ago

It works. How does that sound?

$ git diff
diff --git a/lib/command-runner.coffee b/lib/command-runner.coffee
index 9b86cd9..84e4a46 100644
--- a/lib/command-runner.coffee
+++ b/lib/command-runner.coffee
@@ -22,11 +22,11 @@ class CommandRunner
       return callback(new Error("#{process.env.SHELL} is not supported."))

     outputPath = path.join(os.tmpdir(), 'CommandRunner_fetchEnvOfLoginShell.txt')
-    fs.unlinkSync(outputPath) if fs.existsSync(outputPath)
+    # fs.unlinkSync(outputPath) if fs.existsSync(outputPath)

     # Running non-shell-builtin command with -i (interactive) option causes shell to freeze with
     # CPU 100%. So we run it in subshell to make it non-interactive.
-    command = "#{process.env.SHELL} -l -i -c '$(printenv > #{outputPath})'"
+    command = "#{process.env.SHELL} -l -i -c '$(rm -f #{outputPath} && printenv > #{outputPath})'"

     child_process.exec command, (execError, stdout, stderr) =>
       return callback(execError) if execError?
yujinakayama commented 10 years ago

Hmm, I think we need to find out why the fs.unlinkSync(outputPath) doesn't fix your issue...

rochefort commented 10 years ago

CommandRunner.run is called 2times.

I think: First fs.unlinkSync(outputPath) is called in fetchEnvOfLoginShell if outputPath is existed. Other process start by child_process (: this is called child1), and printenv is not called. Second CommandRunner.run is called and fs.unlinkSync(outputPath) is not called, because printenv is not called by child1. child1 call printenv, and outputPath is created. Another process start by child_process(: this is called child2). And then child2 call printenv, and this error is occurred.

yujinakayama commented 10 years ago

It seems you are right. A linter is wastefully run twice on launch of Atom. I've added further fixes and released 0.14.4. It's much appreciated if you would try it.

Finally, thanks for the patient and detailed reports! You helped me fix the obscure bugs a lot.

rochefort commented 10 years ago

0.14.4 works!! :+1:

Thank you, too. I am happy to involve in this project and learn a lot.