flycheck / flycheck-google-cpplint

Google C++ Style checker for Flycheck
GNU General Public License v3.0
42 stars 11 forks source link

Can't Configure it Correctly #1

Closed husainaloos closed 10 years ago

husainaloos commented 10 years ago

Hi, I tried to install the package, and I added the python file in /usr/local/bin/. I added the following in my .emacs

(eval-after-load 'flycheck
    '(progn
       (require 'flycheck-google-cpplint)
       ;; Add Google C++ Style checker.
       ;; In default, syntax checked by Clang and Cppcheck.
       (flycheck-add-next-checker 'c/c++-cppcheck
                                  '(warnings-only . c/c++-googlelint))))
  (custom-set-variables
   '(flycheck-googlelint-verbose "3")
   '(flycheck-google-cpplint-command "/usr/local/bin/cpplint.py")
   '(flycheck-googlelint-filter "-whitespace,+whitespace/braces")
   '(flycheck-googlelint-root "project/src")
   '(flycheck-googlelint-linelength "120"))

and hooked it with my c++-mode-hook. All I get when I activate flycheck-mode is this:

Checker c/c++-googlelint returned non-zero exit code 1, but no errors from output: 
Checker definition probably flawed.

Any idea what's going on?

ghost commented 10 years ago

First: I do not provide flycheck-google-cpplint-command option in flycheck version. That means, you have need to add /usr/local/bin to PATH environment. (see also: EmacsWiki: Exec Path)

Second: If you not use cppcheck. You have need to change flycheck-add-next-checker.

(flycheck-add-next-checker 'c/c++-clang
                           '(warnings-only . c/c++-googlelint))

Please try above two points.

swsnr commented 10 years ago

@senda-akiha flycheck-google-cpplint-command is automatically declared by Flycheck. Changing this variable is sufficient to make Flycheck find cpplint.

Besides, the error message indicates that Flycheck actually runs cpplint, but is unable to parse it's output.

@husainaloos Can you try M-x flycheck-select-checker RET c/c++-googlelint and then C-c ! C-c in a C++ buffer? Flycheck should pop up a buffer which shows the entire output of googlelint. Can you paste that here?

husainaloos commented 10 years ago

@lunaryorn This is what I get

-*- mode: compilation; default-directory: "~/" -*-
Compilation started at Sun Mar 23 12:14:00

cpplint.py --verbose\=3 --filter\=-whitespace\,\+whitespace/braces --root\=project/src --linelength\=120 /home/husainaloos/test.cpp

Compilation exited abnormally with code 1 at Sun Mar 23 12:14:00
swsnr commented 10 years ago

@husainaloos Do you get the same result when your run this command on the terminal?

husainaloos commented 10 years ago

@lunaryorn Yes I do.

husainaloos commented 10 years ago

Hmm. I tried to update PATH, change the path in flycheck-google-cpplint.el file, change my configurations, but with no success. Cppcheck works fine, but google-cpplint doesn't :/ I am still puzzled what's going on.

husainaloos commented 10 years ago

Update:

(1) I noticed that cpplint.py does not work. When I do cpplint.py test.cpp I do get nothing. So I downloaded cpplint from the repository directly instead. Now cpplint test.cpp outputs the error in test.cpp.

(2) I changed my .emacs and instead I added this:

  (flycheck-mode 1)                                                                                                                                           
  (eval-after-load 'flycheck                                                                                                                                  
    '(progn                                                                                                                                                   
       (require 'flycheck-google-cpplint)                                                                                                                     
       (flycheck-add-next-checker 'c/c++-cppcheck                                                                                                             
                                  'c/c++-googlelint 'append))) 

Which is what I found in my flycheck-google-cpplint.el file. I changed the cpplint.py to cpplint in my flycheck-google-cpplint.el as well.

Now when I run flycheck on test.cpp file I get the following error:

Error: (user-error "Configured syntax checker c/c++-googlelint cannot be used") 

Not sure where to go now...

swsnr commented 10 years ago

@husainaloos The value of flycheck-c/c++-cpplint-executable? Use C-h v to find out.

ghost commented 10 years ago
(custom-set-variables
 '(flycheck-c/c++-googlelint-executable "/usr/local/bin/cpplint.py"))

I did not know it would be able this. I will add it to README.

husainaloos commented 10 years ago

@senda-akiha @lunaryorn Finally works! It seems that the value was set to nil for some reason. Thanks!

Q: cpplint is applied to the .cpp file only when I save (it does not update the errors unless I save). is there a way to change that, to make it work as I type just like it does in flymake?

swsnr commented 10 years ago

@husainaloos Flycheck will automatically check the buffer after changes, i.e. work like Flymake. If it doesn't in your case, you've disabled it. Check the value of flycheck-check-syntax-automatically.

husainaloos commented 10 years ago

@lunaryorn The value is (save idle-change new-line mode-enabled), so that is fine.

cppcheck checks fine. It updates the errors and warning while editing the buffer. cpplint doesn't; i have to save the buffer in order for it to update. :/

swsnr commented 10 years ago

@husainaloos Indeed, this syntax checker uses source-original.

@senda-akiha Is there a reason why you use source-original instead of source or source-inplace in this syntax checker?

ghost commented 10 years ago

@lunaryorn Reason that I use a source-original, because depends on the location of the file.

Examples: Assuing that src/.git exists, the header guard CPP variables for src/chrome/browser/ui/browser.h are:

    No flag => CHROME_BROWSER_UI_BROWSER_H_
    --root=chrome => BROWSER_UI_BROWSER_H_
    --root=chrome/browser => UI_BROWSER_H_
swsnr commented 10 years ago

In this case there's no other way, but you should use a predicate checking buffer-modified-p.

husainaloos commented 10 years ago

@lunaryorn @senda-akiha Thank you both for help! Keep it up!

I am assuming that there is no clean fix for this. I will keep using flymake for cpplint and flycheck for cppcheck :)

swsnr commented 10 years ago

@senda-akiha Your Flymake version of this works on a tempfile, though, so wouldn't it work source-inplace instead?

husainaloos commented 10 years ago

Wondering if it is still can be solved.

silgon commented 10 years ago

I'm having a similar problem. Actually when I do M-x flycheck-select-checker RET c/c++-googlelint but it's not working by default. Any ideas?? This is the important part of my configuration

(eval-after-load 'flycheck
  '(progn
       (require 'flycheck-google-cpplint)
       (flycheck-add-next-checker 'c/c++-clang
           '(warnings-only . c/c++-googlelint))))
(custom-set-variables
    '(flycheck-c/c++-googlelint-executable "cpplint")
)
husainaloos commented 9 years ago

@silgon I think you need to change the last part to:

(custom-set-variables
 '(flycheck-c/c++-googlelint-executable "/usr/local/bin/cpplint"))

or depending on where you installed the cpplint.

silgon commented 9 years ago

the excecutable is ok I think, because when I use M-x flycheck-select-checker RET c/c++-googlelint it's working fine. But it's just not the default checker I think

husainaloos commented 9 years ago

@silgon then that means that is is probably not initualized when the c/c++ mode starts. Are you sure that your hook works fine?

silgon commented 9 years ago

sorry for the late response @husainaloos , i'm not sure then that the hook is working fine. I'm still using the code I told you before.

(eval-after-load 'flycheck
  '(progn
       (require 'flycheck-google-cpplint)
       (flycheck-add-next-checker 'c/c++-clang
           '(warnings-only . c/c++-googlelint))))
(custom-set-variables
    '(flycheck-c/c++-googlelint-executable "cpplint")
)

How can I check it???

silgon commented 9 years ago

Any news about this? just checked again and flycheck is not picking by default c/c++-googlelint. Thanks ;)