Code Monkey home page Code Monkey logo

sublimelinter-javac's Introduction

SublimeLinter

tests

The code linting framework for Sublime Text. No linters included: get them via Package Control.

Installation

Note

The current stable version of Sublime Text, Build 4169, has a bug and cannot install SublimeLinter without requiring a restart. You're fine if you have a later dev build, e.g. build 4173.

Note

We're in a transition phase to the newer ST4 plugin host. Unless we have more experience for the process, it may be necessary to restart Sublime Text after installing or upgrading helper packages. Just check if everything works or if the console shows permanent errors. On my machine, no restarts were necessary.

Probably don't get fancy and just install SublimeLinter via Package Control. Refer https://www.sublimelinter.com/en/latest/installation.html for further information, but, spoiler!, usually you install SublimeLinter, the plugin you're currently looking at, some command line tools, these are the actual linters (e.g. eslint or flake8), and then some plugins/adapters between both. These are typically named after the linter and should be installed via Package Control as well, examples would be SublimeLinter-eslint or SublimeLinter-flake8.

By default, SublimeLinter will run in the background and most linters support this mode so you should get squiggles immediately.

Note that you find all commands we're installing using the Command Palette (ctrl+shift+p). Just search for SublimeLinter. You may find https://github.com/kaste/SublimeLinter-addon-toggler and/or https://github.com/kaste/SublimeLinter-addon-goto-flash useful.

Settings

Settings are documented in the default settings. Open the settings using the Command Palette (ctrl+shift+p) searching for Preferences: SublimeLinter Settings (mnemonic: sls).

When you open the SublimeLinter settings you'll see the defaults on the left or top. Usually that's all that is needed for end-users but some additional information is in our docs at sublimelinter.com.

Key Bindings

SublimeLinter comes with some pre-defined keyboard shortcuts. You can customize these via the Package Settings menu.

Command Linux & Windows MacOS
Lint this view Ctrl + k, l Ctrl + + l
Open diagnostics panel Ctrl + k, a Ctrl + + a
Goto next error Ctrl + k, n Ctrl + + e
Goto prev error Ctrl + k, p Ctrl + + Shift + e

Take also a look at the default bindings because we document other commands and have usually some tricks in there too.

For example, it is very advisable to bind sublime_linter_quick_actions, e.g.

    // To trigger a quick action
    // { "keys": ["ctrl+k", "ctrl+f"],
    //   "command": "sublime_linter_quick_actions"
    // },

Quick Actions/Fixers

As we do just linting SublimeLinter naturally does not come with fixers and/or code formatters. However, we have a fixer API, see the Command Palette: SublimeLinter: Quick Action, and ship (mostly) "fix by ignoring" actions. These allow you to quickly ignore specific error messages inline and ad hoc.[1]

SublimeLinter currently ships actions for eslint, stylelint, flake8, mypy, shellcheck, codespell and phpcs.

Want to see actions for your favourite linter? Please open a PR with your addition to quick_fix.py. We have tests for them!

[1] Why this limitation though? Well it is usually easy to add a semicolon here and a space there, but the inline ignore rules and syntaxes are very cumbersome to type and to remember. And there is basically no project of any size where you don't have to ignore ad-hoc something somewhere once.

Support & Bugs

Yeah, totally! Often if it doesn't work, Sublime will have something in the console (View -> Show Console). Warnings will go there by default.

You can enable debug mode in the settings to get much more information about what's going on. Especially seeing the exact command and working dir SublimeLinter will use should be noted and helpful.

As some code only runs on startup, it is good practice to restart Sublime Text and to examine the console output for anything odd.

If your issue is specific to a particular linter, please report it on that linter's repository, otherwise open it right here.

Hack on it

Sure, you're welcome! Just clone the repository into your Packages folder (Preferences -> Browse Packages).

> git clone https://github.com/SublimeLinter/SublimeLinter.git
> subl SublimeLinter

This will overrule the installed package straight away. Just delete the folder to reverse the process. The dev requirements can be read in the pyproject.toml file. Just use rye and install them:

> rye sync

Creating a linter plugin

Use the template to get started on your plugin. It contains a how-to with all the information you need. Refer to https://www.sublimelinter.com/en/master/linter_plugin.html for more detailed information. Of course, take a look at a similar linter plugin and let it inspire you.

Also Support ❤️

SublimeLinter is the kind of software that needs active maintenance all the time. If you find SublimeLinter helpful and would like to show your appreciation, you can support its development by buying me a coffee! 😄☕ https://paypal.me/herrkaste

😏

sublimelinter-javac's People

Contributors

25a0 avatar aparajita avatar braver avatar davidaurelio avatar groteworld avatar kaste avatar mokkabonna avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sublimelinter-javac's Issues

Syntax errors

The linter currently does not highlight syntax errors (missing semicolons, invalid assignment, etc.) and actually refuses to show any lints if syntax errors are present in the project.

Report errors from multiple files in one go?

r'^(?P<file>.+?):(?P<line>\d+): '

If we instead of "file" use the capturing group name "filename", SublimeLinter actually recognizes that and could read in errors from multiple files in one go. T.i. 🤞 we could omit the split_match implementation here, maybe.

@davidaurelio Could you test that? You're already know how to hack on SL plugins and could probably easily test.

sourcepath

How do I add a sourcepath?

adding "-sorcepath /path/to/src" to args doesn't seem to work

[QUESTION] How to specify the output directory?

How can I configure SublimeLinter to put the compiled .class files into a separate folder, e.g. ./bin?

I know... it must be pretty easy, but I don't get it right :/

Here is my current config:

{
"user": {
    "linters": {
        "javac": {
            "@disable": false,
            "args": [
                "-d", "./bin/"
            ],
            "excludes": [],
            "lint": ""
        }
    }
}

Question: how to make java in current directory/project visible?

This should be a very straightforward issue, but I can't seem to find a solution. I'd appreciate some help a lot!

In my current project I have two Java files: Point.java and LineSegment.java. The LineSegment class uses the Point class; since they are in the same directory LineSegment doesn't have to import Point. Both Point and LineSegment compile without any issues.

However, when I open LineSegment.java in Sublime, all references to Point are highlighted in red and cannot find symbol error is issued.

Any ideas on how I can fix this?

My project settings:

{
  "folders":
  [
    {
      "path": "/home/anton/calc/algorithms/homework/week3"
    }
  ],
  "SublimeLinter":
  {
    "linters":
    {
      "javac": {
        "lint": "all",
        "args": [
          "-encoding", "UTF8",
          "-cp", "/usr/local/algs4/algs4.jar"
        ]
      }
    }
  }
}

Here's the visual trace:

sublime-javac-issue

Destination breaking linter

"SublimeLinter":
	{
		"linters":
		{
			"javac":
			{
				"args":
				[
					"-cp",
					"${project}/../data/lib/mysql.jar:${project}/../data/lib/xpp.jar:${project}/../data/lib/xstream.jar:${project}/../data/lib/filestore.jar:${project}/../data/lib/object-explorer.jar",
					"-sourcepath",
					"${project}/../src/",
					"-d",
					"${project}/../bin/"
				],
				"lint": "all"
			}
		}
	}

Removing the
"-d", "${project}/../bin/"
Fixes the linter, re-adding it causes no errors to be shown. Turning on debugging also shows no information in the console, with the sublimelinter output showing "No lint results."

These settings used to work. Shortly after ${project} was re-added or fixed is when the linter stopped working, I just never got around to posting the issue.

Reverting to sublimelinter-javac 1.1.8 and sublimelinter 3.9.0 fixes the issue.

"Cannot find symbol" in package classes

When writing a package, the linter marks "cannot find symbol" on declarations of other classes in the package. This matches the behaviour of running javac file.java for some file.java in package pkg. Instead, if there's a package declaration, it should be running cd ..; javac pkg/file.java.

Include libraries in the linting

Hi,

whenever I import another library it is linted as an error, because it cannot resolve the symbol.

How do I either tell the linter to stop linting these things or how can I get the linter to properly lint these things.

Thank you very much :-)

javac not working in linux with java 1.7

Running Ubuntu 12.04 LTS

$ whereis javac
javac: /usr/bin/javac /usr/bin/X11/javac /usr/share/man/man1/javac.1.gz

$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/usr/lib/jvm/java-7-oracle/bin:/usr/lib/jvm/java-7-oracle/db/bin:/usr/lib/jvm/java-7-oracle/jre/bin

$ javac -version
javac 1.7.0_51

sense this does not make

Two Java classes inside two levels of folders cannot access each other according to linter

Setup:
Windows 10, Version 1803
Sublime Text 3.1.1, Build 3176
SublimeLinter 4.6.5
SublimeLinter-javac 1.1.11

Steps to reproduce the problem:

  1. Create a folder (say ParentFolder).
  2. Create a folder inside it (say ChildFolder).
  3. Create two Java source code files inside it.
  4. Invoke a static method of any class inside any method of the other class.

Problem:
The linter shows an error, saying that the class can't be found.
javac - cannot find symbol

Obviously, both files can compile with no errors in the command line.

Screenshot:
image

Additional Notes:
If I put them inside a folder and try it, it works as expected.
If I put them inside a folder that is inside another folder, then this problem arises.

SublimeLinter-javac is Unable to locate a Java Runtime installed through homebrew

Environment

  • OS: MacOS Ventura Version 13.3.1 (a) (22E772610a)
  • Javac Version: 17.0.7 (openjdk 17.0.7 2023-04-18)
  • Sublime Text 4 Build 4143

Where javac returns /usr/bin/javac

Where java returns /usr/bin/java

in my .zhrc i set export JAVA_HOME=/opt/homebrew/Cellar/openjdk@17/17.0.7

SublimeLinter.sublime-settings

// SublimeLinter Settings - User /
{
    "debug": true,
    "show_panel_on_save": "window",
    "paths": {
        "osx": [
            "/usr/bin"
        ]
    }
}

Console Output:

INFO:SublimeLinter.plugin.javac:Running ...
  /Users/myusername/Downloads  (working dir)
  $ /usr/bin/javac -Xlint -encoding UTF8 /Users/myusername/Downloads/t.java
SublimeLinter: #81 linter.py:1233     javac: output:
  The operation couldn’t be completed. Unable to locate a Java Runtime.

running /usr/bin/javac -Xlint -encoding UTF8 /Users/myusername/Downloads/t.java alone in terminal works, but not via SublimeLinter-javac

Am I doing something wrong?

Error: Package <pkg> does not exist; Gradle + JUnit project

I'm quite new to Java, so I apologize in advance if the problem is in my setup rather then the linter.

I use the Gradle build tool to run JUnit tests. The test dependecies are specified in my build.gradle file. The test file shows a bunch of "Package does not exist" errors because it doesn't know where to get the dependencies from. The tests, however, have no problem running with gradle build.

Here's a screenshot:
javac-junit-gradle

To reproduce, please pull the code from https://github.com/exercism/xjava/tree/master/etl and take a look at etl/src/test/java/EtlTest.java.

Thanks!

Directory Not Found

I'm not really sure what's going on, I've been using this package for ages without any issues and haven't changed anything, but today I noticed that errors are no longer being displayed. After trying debug mode, I'm seeing the error "javac: directory not found: ${project}/../bin/" (my bin folder is located one directory higher than the sublime-project file). As I mentioned, up until today this has always worked just fine.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.