Code Monkey home page Code Monkey logo

Comments (15)

tkelman avatar tkelman commented on May 18, 2024

Ooh yeah I've been thinking about how to accomplish exactly this, but am not too familiar with how this/CSTParser/Tokenize/Lint all work. As a (separate?) check, maybe doing the same thing for methods extended from other packages too.

from languageserver.jl.

ZacLN avatar ZacLN commented on May 18, 2024

Well what I'm going to do today is do a pass over all package/workspace code so that at any step you'll apply some arbitrary lint_xxx(x::EXPR, scope, importedmodules) function to an expression (a CSTParser.EXPR which is pretty much the same as Expr in structure) where scope lists all available symbols both from Base/imported modules and those defined in the current context.

So the above would be something along the lines of pseudocode :

if x.head == :call && x.args[1] in Base && isimported(x.args[1])
    argtypes =  collect(typesof(x.args[2:end]))
    if !any(argstypes in scope)
        return lintmessage("this is bad form")
    end
end

from languageserver.jl.

tkelman avatar tkelman commented on May 18, 2024

don't we want :function, or :(=) with lhs a :call, head? guess the other-packages version would just check other imported packages instead of Base

does this work strictly on the text content of a file? does it walk imports or recognize when code is dead (never included or behind some conditional?) or would you run it in catch-all mode on all .jl files and hope no one is including julia files under different extensions that would be missed?

another one for package linting is checking that all directly imported/used packages are listed in REQUIRE, or test/REQUIRE for test-only deps. I get the impression there's already infrastructure here for detecting imports?

from languageserver.jl.

ZacLN avatar ZacLN commented on May 18, 2024

Yeah that's just my sloppiness on the first point, there's a isfuncdef function floating somewhere in CSTParser.

The LS first builds an tree structure following includes of files in the project so if you lint somefileA the scope is built by first checking which other files include somefileA and starting from there ( #19). There's naive recognition of deadcode sections (i.e. if false) and it traverses expressions maintaining the same scoping rules of evaluation so that an include call inside a function will be followed while traversing the rest of the function body but has no impact on the enclosing scope.

If you include something that doesn't exist you're warned.

from languageserver.jl.

tkelman avatar tkelman commented on May 18, 2024

Very cool. Does it attempt to resolve programmatic includes with some heuristic?

from languageserver.jl.

ZacLN avatar ZacLN commented on May 18, 2024

Not yet, I'm going to add an implementation for joinpath and maybe the simplest of loops

from languageserver.jl.

tkelman avatar tkelman commented on May 18, 2024

Hm okay, is there a warning at the moment about possibly-missed includes? Or fall back to "all .jl files" as a next-best guess?

from languageserver.jl.

ZacLN avatar ZacLN commented on May 18, 2024

No, at the moment it just ignores

from languageserver.jl.

tkelman avatar tkelman commented on May 18, 2024

I don't think the code in this package helps me with this one, but while we're writing down things I'd like to lint for - checking that supported Julia versions are all running on Travis.

from languageserver.jl.

ZacLN avatar ZacLN commented on May 18, 2024

Yeah I don't think that'll fit into general linting but I think it may be worth adding a special tkelman/publish package lint command checking these things. Also: check REQUIRE packages with specified versions against Pkg.available(pkg)?

from languageserver.jl.

oxinabox avatar oxinabox commented on May 18, 2024

Also maybe check REQUIRE ing Compat.jl, without any min-version?

from languageserver.jl.

ZacLN avatar ZacLN commented on May 18, 2024

Makes sense

from languageserver.jl.

ZacLN avatar ZacLN commented on May 18, 2024

@tkelman, available versions for Travis are listed at https://s3.amazonaws.com/julialang right? Which parts am I checking against is it checksums or exe/dmg/tar.gz ?

from languageserver.jl.

tkelman avatar tkelman commented on May 18, 2024

we added a new caching layer, I think julialang-s3.julialang.org or something like that. probably unlikely that different platforms' available versions would get out of sync unless I screw something up in uploading

from languageserver.jl.

ZacLN avatar ZacLN commented on May 18, 2024

Cheers

from languageserver.jl.

Related Issues (20)

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.