Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Port to linter-plus #23

Merged
merged 5 commits into from
Aug 3, 2015
Merged

Port to linter-plus #23

merged 5 commits into from
Aug 3, 2015

Conversation

daw42
Copy link
Contributor

@daw42 daw42 commented Jul 9, 2015

This pull request ports linter javac to the new Linter API.

It also uses a longer regular expression to extract the column number for errors and warnings.

This pull request relates to issue #20.

config:
javaExecutablePath:
type: 'string'
default: ''
title: 'Path to the javac executable'
default: '/usr/bin/javac'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be changed to javac which will auto-resolve to /usr/bin/javac in 90% of cases. In the other 10% it will resolve to something else.

@keplersj
Copy link
Contributor

keplersj commented Jul 9, 2015

Besides that, it looks good to me. It looks like you should be able to expand your Regex to find the file being affected. I've written some code which should work here for another linter: https://github.com/AtomLinter/linter-swiftc/blob/master/lib/provider.coffee#L39

Anything I've missed @steelbrain?

@steelbrain
Copy link
Contributor

@k2b6s9j the spawning part could very much use the helpers module.

@steelbrain
Copy link
Contributor

Also @daw42, does javac support JSON output? It should be a priority to use JSON instead of regex if CLI linter supports it.
Also lintOnFly means that the file will be linted everytime you'll stop writing and I don't see you writing the rest of textEditor.getText() to the stdin of the spawned process, which mean that it'll lint the file on the filesystem everytime.
You can either use the helpers to easily spawn the process and write input to stdin instead of a file, or you can disable lintOnFly.

@keplersj
Copy link
Contributor

keplersj commented Jul 9, 2015

javac definitely doesn't have a JSON output. Java moves very slowly and was created 20 years ago.

@steelbrain
Copy link
Contributor

😆

@daw42
Copy link
Contributor Author

daw42 commented Jul 9, 2015

@steelbrain Good point about the lintOnFly option. I think that I'll just disable it and always lint the file on the filesystem. Later on, it might be good to make this a configuration option and give the user the choice.

@daw42
Copy link
Contributor Author

daw42 commented Jul 9, 2015

Just updated the pull request branch. Thanks for your feedback!

By the way, looks like javac doesn't support compiling from standard input, so lintOnFly needs to be disabled.

@steelbrain
Copy link
Contributor

@daw42 I am so sorry this took so much time. You should've pinged us.
Anyways, can you use the atom-linter npm module for spawning part please?

@daw42
Copy link
Contributor Author

daw42 commented Jul 31, 2015

@steelbrain Ok, I've updated so that it uses atom-linter for spawning javac. Thanks.

messages = []
helpers.exec(@javaExecutablePath, args, {throwOnStdErr: false, stream: 'stderr'})
.then (val) => return @parse(val, textEditor)
.catch (val) =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't actually have to catch it here, the last time I checked, atom-linter throws this and linter catches

@daw42
Copy link
Contributor Author

daw42 commented Jul 31, 2015

Updated, thanks again. :)

@steelbrain
Copy link
Contributor

Beautiful, I'll test it soon.

@steelbrain
Copy link
Contributor

I just tried it and it didn't work for me, here's the javacOutput

javac: invalid flag: /var/web/PublishSpace/Zoom/API/test.Java
Usage: javac <options> <source files>
use -help for a list of possible options

@steelbrain
Copy link
Contributor

Here's the patch that fixes that issue

diff --git a/.eslintrc b/.eslintrc
diff --git a/lib/init.coffee b/lib/init.coffee
index e2432ad..2d3bd64 100755
--- a/lib/init.coffee
+++ b/lib/init.coffee
@@ -24,12 +24,10 @@ module.exports =
     lintOnFly: false       # Only lint on save
     lint: (textEditor) =>
       filePath = textEditor.getPath()
-      wd = path.dirname filePath
       # Use the text editor's working directory as the classpath.
       #  TODO: Make the classpath user configurable.
-      args = ['-Xlint:all', '-cp', wd, filePath]
-      messages = []
-      helpers.exec(@javaExecutablePath, args, {stream: 'stderr'})
+      args = ['-Xlint:all', '-cp', '.', path.basename(filePath)]
+      helpers.exec(@javaExecutablePath, args, {stream: 'stderr', cwd: path.dirname(filePath)})
         .then (val) => return @parse(val, textEditor)

   parse: (javacOutput, textEditor) =>

Also, Your current regex is failing for me as the javacOutput is

error: Class names, 'test.Java', are only accepted if annotation processing is explicitly requested
1 error

@daw42
Copy link
Contributor Author

daw42 commented Jul 31, 2015

Looks like the problem is that javac expects a lower-case 'j' for the file extension. Without that, it seems to think that it is a flag or a class name (depending on the classpath). For example, I just tried this in the working directory:

$ javac test.Java 
error: Class names, 'test.Java', are only accepted if annotation processing is explicitly requested
1 error

$ javac ./test.Java 
javac: invalid flag: ./test.Java
Usage: javac <options> <source files>
use -help for a list of possible options

Try a file that has an extension that's all lower case.

I like the patch. Better to base everything from the working directory.

The regex targets only file syntax type errors, I might need to expand it to handle errors like the one you found.

@daw42
Copy link
Contributor Author

daw42 commented Jul 31, 2015

The cwd option for exec doesn't work for me. The source code of atom-linter doesn't seem to use it.

@keplersj
Copy link
Contributor

cwd is passed directly to child_process. I'll double check later, but
that's how I wrote it initially.

On Fri, Jul 31, 2015, 3:38 PM daw42 [email protected] wrote:

The cwd option for exec doesn't work for me. The source code of
atom-linter doesn't seem to use it.


Reply to this email directly or view it on GitHub
#23 (comment)
.

@steelbrain
Copy link
Contributor

@k2b6s9j You're correct! All of the options, not just cwd are passed directly, some are however interpreted by atom-linter and others by the node core

@daw42
Copy link
Contributor Author

daw42 commented Aug 1, 2015

@k2b6s9j @steelbrain

helpers.exec('pwd', [])
  .then (val) => console.log("Current dir: #{val}")

helpers.exec('pwd', [], {cwd: '/tmp'} )
  .then (val) => console.log("Current dir (cwd): #{val}")

Output:

Current dir (cwd): /
Current dir: /

@steelbrain
Copy link
Contributor

Weird, I'll investigate when I have some time. That is definitely not the expected behavior.

@keplersj
Copy link
Contributor

keplersj commented Aug 1, 2015

Sounds like we need a new unit test too. Mind filing an issue on the repo
so I know to write the regression test when I get home?

On Sat, Aug 1, 2015, 10:59 AM Steel Brain [email protected] wrote:

Weird, I'll investigate when I have some time. That is definitely not the
expected behavior.


Reply to this email directly or view it on GitHub
#23 (comment)
.

@daw42
Copy link
Contributor Author

daw42 commented Aug 3, 2015

javac will not accept a file with .Java extension. Please test with *.java.


parse: (javacOutput, textEditor) =>
# Regex to match the error/warning line
errRegex = /^(.*\.java):(\d+): (error|warning): (.+)/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of (error|warning): I recommend using (.+):. This does not limit the type of issue to error and warning. Future-proofing incase some new type of issue is introduced in the future.

@keplersj
Copy link
Contributor

keplersj commented Aug 3, 2015

screen shot 2015-08-03 at 5 24 22 pm
Just tested, and it looks good. I'll merge and make that change to the regex. Thanks @daw42!

keplersj added a commit that referenced this pull request Aug 3, 2015
Port to Linter v1.0.

Fixes #22.
Fixes #24.
@keplersj keplersj merged commit cdfe05a into AtomLinter:master Aug 3, 2015
@daw42 daw42 deleted the linter-plus branch August 7, 2015 21:52
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants