Skip to content

feat: add Lint API #220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed

feat: add Lint API #220

wants to merge 8 commits into from

Conversation

aminya
Copy link
Contributor

@aminya aminya commented Oct 11, 2020

Adds convenient API to lint string, file, and module

Issues

Fixes #17
Fixes #37
Fixes #14

Requires:

julia-vscode/SymbolServer.jl#190
julia-vscode/CSTParser.jl#209

TODO

  • Add tests
  • Add print lint function for REPL usage

@aminya aminya mentioned this pull request Dec 9, 2020
@twolodzko
Copy link

@aviatesk @davidanthoff @pfitzseb is there a chance for this to be merged? The ability to run the linter from command line as a part of CI/CD would be great feature.

@pfitzseb
Copy link
Member

Yes.

Copy link
Member

@davidanthoff davidanthoff left a comment

Choose a reason for hiding this comment

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

I took a quick look and left some comments, but I think @ZacLN really needs to weigh in on most of the issues here.

@@ -6,6 +6,8 @@ version = "4.5.1-DEV"
Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
CSTParser = "00ebfdb7-1f24-5e51-bd34-a7502290713f"
SymbolServer = "cf896787-08d5-524d-9de7-132aaa0cb996"
CodeTools = "53a63b46-67e4-5edd-8c66-0af0544a99b9"
Copy link
Member

Choose a reason for hiding this comment

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

We can't take a dependency on that, it pulls in too many other packages.

Copy link
Contributor Author

@aminya aminya Jan 5, 2021

Choose a reason for hiding this comment

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

I can move my PRs to this organization to a different package if you think you can't add a dependency, or the codes make you nervous.

Copy link
Member

Choose a reason for hiding this comment

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

This comment was really narrowly talking about CodeTools.jl: I think that would pull at least five new packages in, and because we ship all packages manually for the VS Code extension that would add just too much extra work to keep all of that updated and maintained.

BUT, having said that: I think maybe having a new package that is user facing and exposes a simple API for LanguageServer, SymbolServer, StaticLint etc. might actually be the best design. Such a package could really primarily target REPL users and make things most convenient for them. It could also easily take on any additional dependencies that are not needed for the VS Code extension. Plus, you wouldn't have to deal with the bottleneck of our snail paced review times ;)

The general idea then would be that packages like StaticLint, SymbolServer, LanguageServer etc. are really targeting IDE integration authors, are low level and not user friendly, with a minimal API surface. And (your) new package would expose things for REPL/end users.

@ZacLN and @aminya does that make sense to you? We could actually host such a package here in the julia-vscode org, or @aminya you could also host it on your account, I'm indifferent on that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's OK. I can host a Lint.jl package on my account.

The old Lint.jl is not registered anymore.

Choose a reason for hiding this comment

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

Sounds like a good idea! @aminya could you ping me when you create it or if you need any help on it? I'd be lively interested in it.

@davidanthoff when there's a separate package for standalone linter, maybe this could be mentioned in Readme here as well so it would be easier for people looking for such functionality to find it?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, we could definitely change the README here to essentially say "This is a low-level package, go to Lint.jl for something that most users would want to use."

# parse
cst = CSTParser.parse_code(str)

# TODO: we should not need to write to a file!
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, that is definitely key :) LS doesn't write any files, so it can be done, but I'm not familiar enough with the API to help out here.

Copy link
Contributor

@ZacLN ZacLN Jan 6, 2021

Choose a reason for hiding this comment

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

From https://github.com/julia-vscode/StaticLint.jl/blob/master/test/runtests.jl:

using SymbolServer, StaticLint
function parse_and_pass(s)
    server = StaticLint.FileServer()
    ssi = SymbolServerInstance("/path/to/julia/depot/")
    _, server.symbolserver = SymbolServer.getstore(ssi, "/path/to/env")
    server.symbol_extends  = SymbolServer.collect_extended_methods(server.symbolserver)

    f = StaticLint.File("", s, CSTParser.parse(s, true), nothing, server)
    StaticLint.setroot(f, f)
    StaticLint.setfile(server, "", f)
    StaticLint.scopepass(f)
    StaticLint.check_all(f.cst, StaticLint.LintOptions(), server)
    return f.cst
end

StaticLint.scopepass(file)

return file
end
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure this lint_file API can work. StaticLint.jl really kind of operates on folders, I think, so not sure how this would fit in.

Copy link
Contributor

Choose a reason for hiding this comment

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

using SymbolServer, StaticLint

function parse_and_pass(path)
    server = StaticLint.FileServer()
    ssi = SymbolServerInstance("/path/to/julia/depot/")
    _, server.symbolserver = SymbolServer.getstore(ssi, "/path/to/env")
    server.symbol_extends  = SymbolServer.collect_extended_methods(server.symbolserver)

    f = StaticLint.loadfile(server, path)
    StaticLint.scopepass(f)
    StaticLint.check_all(f.cst, StaticLint.LintOptions(), server)
    return f.cst
end

export lint_module
"""
lint_module(modul::Module)
lint_module(module_name::String)
Copy link
Member

Choose a reason for hiding this comment

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

I am also not sure whether that API makes sense? I think we should probably limit the API to linting files and folders in some way.

The whole code around modulefiles also makes me nervous, and if we didn't have that API here we wouldn't need that code, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd just use the lint_file function on the Module entry file, so a thin wrapper function.

@davidanthoff
Copy link
Member

So I'm going to close this here, under the assumption that we all are on board with a new package for the public API.

@takbal
Copy link

takbal commented Jan 29, 2021

@aminya does 10ad459 achieve what you wanted? Are you planning to update Lint.jl with this, and add a working linter to juno/atom? It is the only feature missing there badly.

@aminya
Copy link
Contributor Author

aminya commented Jan 29, 2021

Yes, I will make the package over the weekend.

@takbal
Copy link

takbal commented Mar 3, 2021

I have made a linter-julia fork that uses StaticLint:

https://github.com/takbal/linter-julia

PR:

AtomLinter/linter-julia#119

Possibly quite amateurish effort (I know nothing of js or Atom, and learning Julia just for a few months), but it seems to work so far. Please review @aminya

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How StaticLint.jl server is different than Lint.jl Docs? API functions for CLI / REPL usage
6 participants