Skip to content
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

[analysis] Support analyze not full parseable code #1146

Closed
ericdallo opened this issue Jan 25, 2021 · 2 comments
Closed

[analysis] Support analyze not full parseable code #1146

ericdallo opened this issue Jan 25, 2021 · 2 comments
Labels
enhancement New feature or request sponsor

Comments

@ericdallo
Copy link
Member

version
2021.01.21-20210122.104321-2

platform

via clj -Sdeps '{:deps {clj-kondo {:mvn/version "2021.01.21-20210122.104321-2"}}}

problem

when the file is not parseable, clj-kondo seems to ignore the lints for that file, it'd be great if tries to fix the code to parse.

repro

repro.zip

Working

clj -Sdeps '{:deps {clj-kondo {:mvn/version "2021.01.21-20210122.104321-2"}}}' -m clj-kondo.main --config '{:output {:analysis true :format :json}}        
' --lint "/tmp/a.clj:/tmp/b_ok.clj" |jq .analysis
output
{
  "namespace-definitions": [
    {
      "filename": "/tmp/a.clj",
      "row": 1,
      "col": 1,
      "name": "a",
      "name-row": 1,
      "name-col": 5,
      "name-end-row": 1,
      "name-end-col": 6
    },
    {
      "filename": "/tmp/b.clj",
      "row": 1,
      "col": 1,
      "name": "b",
      "name-row": 1,
      "name-col": 5,
      "name-end-row": 1,
      "name-end-col": 6
    }
  ],
  "namespace-usages": [
    {
      "name-end-col": 15,
      "name-end-row": 2,
      "name-row": 2,
      "alias-end-row": 2,
      "alias-row": 2,
      "filename": "/tmp/b.clj",
      "alias": "foo",
      "from": "b",
      "col": 14,
      "name-col": 14,
      "alias-col": 20,
      "alias-end-col": 23,
      "row": 2,
      "to": "a"
    }
  ],
  "var-definitions": [
    {
      "name-end-col": 9,
      "name-end-row": 3,
      "name-row": 3,
      "ns": "a",
      "name": "bar",
      "filename": "/tmp/a.clj",
      "col": 1,
      "name-col": 6,
      "row": 3
    }
  ],
  "var-usages": [
    {
      "fixed-arities": [
        1,
        3,
        2
      ],
      "name-end-col": 5,
      "name-end-row": 3,
      "name-row": 3,
      "name": "def",
      "filename": "/tmp/a.clj",
      "from": "a",
      "macro": true,
      "col": 2,
      "name-col": 2,
      "arity": 2,
      "row": 3,
      "to": "clojure.core"
    },
    {
      "name-end-col": 6,
      "name-end-row": 4,
      "name-row": 4,
      "name": "b",
      "filename": "/tmp/b.clj",
      "alias": "foo",
      "from": "b",
      "col": 1,
      "name-col": 1,
      "row": 4,
      "to": "a"
    }
  ]
}

Not working

clj -Sdeps '{:deps {clj-kondo {:mvn/version "2021.01.21-20210122.104321-2"}}}' -m clj-kondo.main --config '{:output {:analysis true :format :json}}        
' --lint "/tmp/a.clj:/tmp/b_bug.clj" |jq .analysis
output
{
  "namespace-definitions": [
    {
      "filename": "/tmp/a.clj",
      "row": 1,
      "col": 1,
      "name": "a",
      "name-row": 1,
      "name-col": 5,
      "name-end-row": 1,
      "name-end-col": 6
    }
  ],
  "namespace-usages": [],
  "var-definitions": [
    {
      "name-end-col": 9,
      "name-end-row": 3,
      "name-row": 3,
      "ns": "a",
      "name": "bar",
      "filename": "/tmp/a.clj",
      "col": 1,
      "name-col": 6,
      "row": 3
    }
  ],
  "var-usages": [
    {
      "fixed-arities": [
        1,
        3,
        2
      ],
      "name-end-col": 5,
      "name-end-row": 3,
      "name-row": 3,
      "name": "def",
      "filename": "/tmp/a.clj",
      "from": "a",
      "macro": true,
      "col": 2,
      "name-col": 2,
      "arity": 2,
      "row": 3,
      "to": "clojure.core"
    }
  ]
}

config

[ Is your bug related to .clj-kondo/config.edn? Paste your entire
configuration here. Also check if the bug still occurs without using a
configuration, as the bug may be a result of malformed configuration. ]

expected behavior

Expect to parse at least the parseable code from the file, like the ns, alias requires and other valid functions

@borkdude
Copy link
Member

@ericdallo Fixed with 6dab88f

$ clojure -M:clj-kondo/dev --config '{:output {:analysis true :format :edn}}' --lint "a.clj:b_bug.clj" | jet --query ':analysis' | puget
{:namespace-definitions [{:col 1,
                          :filename "a.clj",
                          :name a,
                          :name-col 5,
                          :name-end-col 6,
                          :name-end-row 1,
                          :name-row 1,
                          :row 1}
                         {:col 1,
                          :filename "b_bug.clj",
                          :name b,
                          :name-col 5,
                          :name-end-col 6,
                          :name-end-row 1,
                          :name-row 1,
                          :row 1}],
 :namespace-usages [{:alias foo,
                     :alias-col 20,
                     :alias-end-col 23,
                     :alias-end-row 2,
                     :alias-row 2,
                     :col 14,
                     :filename "b_bug.clj",
                     :from b,
                     :name-col 14,
                     :name-end-col 15,
                     :name-end-row 2,
                     :name-row 2,
                     :row 2,
                     :to a}],
 :var-definitions [{:col 1,
                    :end-col 14,
                    :end-row 3,
                    :filename "a.clj",
                    :name bar,
                    :name-col 6,
                    :name-end-col 9,
                    :name-end-row 3,
                    :name-row 3,
                    :ns a,
                    :row 3}],
 :var-usages [{:arity 2,
               :col 2,
               :filename "a.clj",
               :fixed-arities #{1 2 3},
               :from a,
               :macro true,
               :name def,
               :name-col 2,
               :name-end-col 5,
               :name-end-row 3,
               :name-row 3,
               :row 3,
               :to clojure.core}]}

@ericdallo
Copy link
Member Author

Thank you @borkdude, I'll try with clojure-lsp soon!

borkdude added a commit that referenced this issue Feb 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request sponsor
Projects
None yet
Development

No branches or pull requests

2 participants