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

Allow override finding level #1344

Merged
merged 1 commit into from Aug 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
56 changes: 22 additions & 34 deletions src/clj_kondo/impl/analyzer.clj
Expand Up @@ -101,7 +101,6 @@
(findings/reg-finding!
ctx
{:message "Keys in :or should be simple symbols."
:level :error
:row (:row m)
:col (:col m)
:end-row (:end-row m)
Expand Down Expand Up @@ -193,7 +192,6 @@
ctx
(node->line (:filename ctx)
expr
:error
:syntax
(str "unsupported binding form " sym)))))))
;; keyword
Expand Down Expand Up @@ -222,15 +220,13 @@
ctx
(node->line (:filename ctx)
expr
:error
:syntax
(str "unsupported binding form " k))))))
:else
(findings/reg-finding!
ctx
(node->line (:filename ctx)
expr
:error
:syntax
(str "unsupported binding form " expr))))
:vector (let [children (:children expr)
Expand Down Expand Up @@ -302,7 +298,6 @@
ctx
(node->line (:filename ctx)
expr
:error
:syntax
(str "unsupported binding form " expr))))))))

Expand Down Expand Up @@ -350,7 +345,6 @@
(findings/reg-finding! ctx
(node->line (:filename ctx)
body
:warning
:syntax
"Function arguments should be wrapped in vector."))
(let [arg-bindings (extract-bindings ctx arg-vec (:fn-body body) {:fn-args? true})
Expand All @@ -368,7 +362,6 @@
(findings/reg-finding! ctx
(node->line (:filename ctx)
body
:warning
:syntax
"Invalid function body."))))

Expand Down Expand Up @@ -415,7 +408,6 @@
(findings/reg-finding! ctx
(node->line (:filename ctx)
first-child
:warning
:misplaced-docstring
"Misplaced docstring."))))
[parsed return-tag]
Expand Down Expand Up @@ -487,7 +479,6 @@
(findings/reg-finding! ctx
(node->line (:filename ctx)
expr
:warning
:syntax
"Invalid function body.")))
;; var is known when making recursive call
Expand Down Expand Up @@ -623,7 +614,7 @@
(when (odd? num-children)
(findings/reg-finding!
ctx
(node->line (:filename ctx) bv :error :syntax
(node->line (:filename ctx) bv :syntax
(format "%s binding vector requires even number of forms" form-name))))))

(defn assert-vector [ctx call expr]
Expand All @@ -632,7 +623,7 @@
(if-not vec?
(do (findings/reg-finding!
ctx
(node->line (:filename ctx) expr :error :syntax
(node->line (:filename ctx) expr :syntax
;; cf. error in clojure
(format "%s requires a vector for its binding" call)))
nil)
Expand All @@ -659,7 +650,7 @@
(and valid-bv-node (empty? (:children valid-bv-node)))))
(findings/reg-finding!
ctx
(node->line filename expr :warning :redundant-let "Redundant let expression.")))
(node->line filename expr :redundant-let "Redundant let expression.")))
(when bv-node
(let [{analyzed-bindings :bindings
arities :arities
Expand Down Expand Up @@ -710,15 +701,15 @@
(when redundant?
(findings/reg-finding!
ctx
(node->line filename expr :warning :redundant-do "redundant do"))))
(node->line filename expr :redundant-do "redundant do"))))
(analyze-children ctx (next (:children expr))))

(defn lint-two-forms-binding-vector! [ctx form-name expr]
(let [num-children (count (:children expr))]
(when (not= 2 num-children)
(findings/reg-finding!
ctx
(node->line (:filename ctx) expr :error :syntax (format "%s binding vector requires exactly 2 forms" form-name))))))
(node->line (:filename ctx) expr :syntax (format "%s binding vector requires exactly 2 forms" form-name))))))

(defn analyze-conditional-let [ctx call expr]
(let [children (next (:children expr))
Expand Down Expand Up @@ -829,15 +820,13 @@
(node->line
filename
expr
:warning
:unexpected-recur "unexpected recur"))
(not= expected-arity arg-count)
(findings/reg-finding!
ctx
(node->line
filename
expr
:error
:invalid-arity
(format "recur argument count mismatch (expected %d, got %d)" expected-arity arg-count)))
:else nil))))
Expand Down Expand Up @@ -885,7 +874,7 @@
(symbol (name var-name))
(do (findings/reg-finding!
ctx
(node->line (:filename ctx) var-name-node :error
(node->line (:filename ctx) var-name-node
:syntax
(str "Invalid var name: " var-name)))
nil)))
Expand Down Expand Up @@ -939,7 +928,7 @@
fn-meta (meta fn-name)]
(when-let [k (types/keyword binding)]
(when-not (types/match? k :ifn)
(findings/reg-finding! ctx (node->line (:filename ctx) expr :error
(findings/reg-finding! ctx (node->line (:filename ctx) expr
:type-mismatch
(format "%s cannot be called as a function."
(str/capitalize (types/label k)))))))
Expand All @@ -960,7 +949,7 @@
(let [arg-count (count (rest children))]
(when-not (arity-match? fixed-arities varargs-min-arity arg-count)
(findings/reg-finding! ctx
(node->line filename expr :error
(node->line filename expr
:invalid-arity
(linters/arity-error nil fn-name arg-count fixed-arities varargs-min-arity)))))))
(analyze-children (update ctx :callstack conj [nil fn-name]) (rest children))))))
Expand All @@ -969,7 +958,7 @@
(when (:in-def ctx)
(findings/reg-finding!
ctx
(node->line (:filename ctx) expr :warning :inline-def "inline def"))))
(node->line (:filename ctx) expr :inline-def "inline def"))))

(defn analyze-declare [ctx expr defined-by]
(let [ns-name (-> ctx :ns :name)
Expand Down Expand Up @@ -1038,7 +1027,6 @@
(node->line
(:filename ctx)
expr
:warning
:missing-clause-in-try
"Missing catch or finally in try")))
analyzed)))))
Expand Down Expand Up @@ -1177,7 +1165,7 @@
(findings/reg-finding!
ctx
(node->line (:filename ctx) not-expr
:warning :not-empty?
:not-empty?
"use the idiom (seq x) rather than (not (empty? x))")))
(analyze-children ctx (rest (:children expr)) false)))

Expand Down Expand Up @@ -1206,7 +1194,7 @@
(findings/reg-finding!
ctx
(node->line (:filename ctx) expr
:warning linter
linter
msg)))
(analyze-children ctx args false)))

Expand Down Expand Up @@ -1277,7 +1265,6 @@
(node->line
(:filename ctx)
expr
:warning
:missing-body-in-when
"Missing body in when"))
(analyze-children ctx body false))))
Expand All @@ -1300,13 +1287,13 @@
(findings/reg-finding!
ctx
(node->line (:filename ctx) (last children)
:warning :type-mismatch
:type-mismatch
"String match arg requires string replacement arg.")))
:char (when (not (identical? matcher-type :char))
(findings/reg-finding!
ctx
(node->line (:filename ctx) (last children)
:warning :type-mismatch
:type-mismatch
"Char match arg requires char replacement arg.")))
:regex (when (not (or (identical? matcher-type :string)
;; we could allow :ifn here, but keywords are
Expand All @@ -1317,7 +1304,7 @@
(findings/reg-finding!
ctx
(node->line (:filename ctx) (last children)
:warning :type-mismatch
:type-mismatch
"Regex match arg requires string or function replacement arg.")))
nil))))))

Expand Down Expand Up @@ -1352,7 +1339,7 @@
arg-count (count args)]
(when-not (= percent-count
arg-count)
(findings/reg-finding! ctx (node->line (:filename ctx) format-str-node :error :format
(findings/reg-finding! ctx (node->line (:filename ctx) format-str-node :format
(format "Format string expects %s arguments instead of %s."
percent-count arg-count))))))

Expand Down Expand Up @@ -1451,7 +1438,7 @@
fn-name (or fsym (:name fst-ana))]
(findings/reg-finding!
ctx
(node->line filename f :error
(node->line filename f
:invalid-arity
(linters/arity-error nil fn-name arg-count fixed-arities varargs-min-arity))))))))))
(concat fana
Expand Down Expand Up @@ -1516,6 +1503,7 @@
:config config
:ns ns-name})
(catch Exception e
;;TODOAQUI
(findings/reg-finding!
ctx
(merge
Expand Down Expand Up @@ -1855,7 +1843,7 @@
(when (or (zero? arg-count)
(> arg-count 2))
(findings/reg-finding! ctx
(node->line (:filename ctx) expr :error :invalid-arity
(node->line (:filename ctx) expr :invalid-arity
(format "keyword :%s is called with %s args but expects 1 or 2"
kw-str
arg-count))))))))
Expand All @@ -1868,7 +1856,7 @@
(when-not (config/skip? config :invalid-arity callstack)
(findings/reg-finding!
ctx
(node->line (:filename ctx) expr :error :invalid-arity
(node->line (:filename ctx) expr :invalid-arity
(format "map is called with %s args but expects 1 or 2"
arg-count)))))))

Expand All @@ -1879,7 +1867,7 @@
(when-not (config/skip? config :invalid-arity callstack)
(findings/reg-finding!
ctx
(node->line (:filename ctx) expr :error :invalid-arity
(node->line (:filename ctx) expr :invalid-arity
(str "Vector can only be called with 1 arg but was called with: "
arg-count)))))))

Expand All @@ -1891,7 +1879,7 @@
(when-not (config/skip? config :invalid-arity callstack)
(findings/reg-finding!
ctx
(node->line (:filename ctx) expr :error :invalid-arity
(node->line (:filename ctx) expr :invalid-arity
(format "symbol is called with %s args but expects 1 or 2"
arg-count)))))))

Expand All @@ -1902,7 +1890,7 @@
(when-not (config/skip? config :not-a-function callstack)
(findings/reg-finding!
ctx
(node->line (:filename ctx) expr :error :not-a-function (str "a " typ " is not a function"))))))
(node->line (:filename ctx) expr :not-a-function (str "a " typ " is not a function"))))))

(defn analyze-reader-macro [ctx expr]
(analyze-children ctx (rest (:children expr))))
Expand Down
2 changes: 1 addition & 1 deletion src/clj_kondo/impl/analyzer/datalog.clj
Expand Up @@ -22,5 +22,5 @@
(catch Exception e
(findings/reg-finding! ctx
(node->line (:filename ctx) query-raw
:error :datalog-syntax
:datalog-syntax
(.getMessage e))))))))
4 changes: 2 additions & 2 deletions src/clj_kondo/impl/analyzer/jdbc.clj
Expand Up @@ -23,12 +23,12 @@
(when-not (<= 2 (count binding-forms) 3)
(findings/reg-finding!
ctx
(node->line filename bindings :error :syntax
(node->line filename bindings :syntax
(format "%s binding form requires exactly 2 or 3 forms" call))))
(when-not (utils/symbol-token? sym)
(findings/reg-finding!
ctx
(node->line filename sym :error :syntax
(node->line filename sym :syntax
(format "%s binding form requires a symbol" call))))
(let [opts-analyzed (analyze-expression** ctx opts)
;; a normal binding vector with just these two forms:
Expand Down
11 changes: 3 additions & 8 deletions src/clj_kondo/impl/analyzer/namespace.clj
Expand Up @@ -44,7 +44,6 @@
(do (when prefix
(findings/reg-finding! ctx (node->line (:filename ctx)
libspec-expr
:error
:syntax
"Prefix lists can only have two levels.")))
(mapcat (fn [f]
Expand All @@ -65,7 +64,6 @@
(findings/reg-finding! ctx
(node->line (:filename ctx)
libspec-expr
:error
:syntax
(format "found lib name '%s' containing period with prefix '%s'. lib names inside prefix lists must not contain periods."
form prefix))))
Expand All @@ -87,7 +85,7 @@
(when-not (= expected-alias alias)
(findings/reg-finding!
ctx
(node->line (:filename ctx) alias :warning
(node->line (:filename ctx) alias
:consistent-alias
(str "Inconsistent alias. Expected " expected-alias " instead of " alias ".")))))))

Expand Down Expand Up @@ -149,7 +147,6 @@
ctx
(node->line (:filename ctx)
child-expr
:warning
:refer
(str "require with " (str child-k))))))
(recur
Expand All @@ -162,7 +159,6 @@
(node->line
filename
(:referred-all m)
:warning
:use
(format "use %srequire with alias or :refer with [%s]"
(if require-sym
Expand Down Expand Up @@ -246,7 +242,7 @@
(meta node))
(findings/reg-finding!
ctx
(node->line (:filename ctx) node :error :syntax "Expected: class symbol"))))
(node->line (:filename ctx) node :syntax "Expected: class symbol"))))

(defn analyze-import [ctx _ns-name libspec-expr]
(utils/handle-ignore ctx libspec-expr)
Expand All @@ -262,7 +258,7 @@
ctx
(node->line
(:filename ctx) java-package-name-node
:error :syntax "Expected: package name followed by classes.")))
:syntax "Expected: package name followed by classes.")))
(into {} (for [i imported]
[i java-package])))
:token (let [package+class (:value libspec-expr)
Expand Down Expand Up @@ -395,7 +391,6 @@
ctx
(node->line (:filename ctx)
ns-name-expr
:error
:syntax
"namespace name expected"))))
'user)
Expand Down