Skip to content

Commit

Permalink
Implement :ignored-faults configuration option
Browse files Browse the repository at this point in the history
Fixes jonase#21
  • Loading branch information
vemv committed Mar 27, 2021
1 parent ee7ebc4 commit 242619a
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 5 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2346,6 +2346,28 @@ remains the same throughout the file. This is a common convention
followed by most Clojure source code, and required by several other
Clojure development tools.

## Ignored faults

If there are specific instances of linter faults that you need to supress
(e.g. for making a CI build pass), you can use the `:ignored-faults` option.

It has the following shape:

```clj
;;linter-name ns-name target
;;--- --- ---
{:implicit-dependencies {'example.namespace {:line 3 :column 2}}
:unused-ret-vals {'another.namespace true}}
```

`{:line 3 :column 2}` matches a given linter (within a specific ns)
if and only if the linter triggers that fault in that exact line/column.
Accordingly, you might have to update the configured line/column from time to time.

If you wish to ban a ignore a linter for an entire namespace, pass `true` instead, as shown in the example above.

> Please, if encountering an issue in Eastwood, consider reporting it in addition to (or instead of) silencing it.
> This way Eastwood can continue to be a precise linter, having as few false positives as possible.

## Change log

Expand Down
4 changes: 4 additions & 0 deletions cases/testcases/ignored_faults_example.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(ns testcases.ignored-faults-example
"A sample namespace for the 'ignored-faults' feature")

clojure.set/difference
15 changes: 14 additions & 1 deletion changes.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
# Change log for Eastwood

## Changes from 0.3.13 to
## Changes from 0.3.14 to 0.4.0

* Introduce `:ignored-faults` option
* See: https://github.com/jonase/eastwood#ignored-faults
* Fixes https://github.com/jonase/eastwood/issues/21
* Support require+import pattern for defrecords, without triggering "Namespace is never used"
* Fixes https://github.com/jonase/eastwood/issues/210
* Remove a noisy println, on certain cases that would be already caught by the reflection warnings mechanism.
* Fixes https://github.com/jonase/eastwood/issues/355
* Restore accidentally-dropped support for Clojure < 1.10
* Fixes https://github.com/jonase/eastwood/issues/356
* Drop support for Clojure 1.6

## Changes from 0.3.13 to 0.3.14

* Improve `:implicit-dependencies` to support potemkin/import-vars

Expand Down
16 changes: 13 additions & 3 deletions src/eastwood/lint.clj
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,20 @@
(when-let [url (:url linter)]
{"warning-details-url" url}))})

(defn ignore-fault? [ignored-faults {{:keys [namespace-sym column line linter]} :warn-data
:as linter-result}]
(let [match (get-in ignored-faults [linter namespace-sym])]
(or (true? match)
(= match
{:line line :column column}))))

(defn- run-linter [linter analyze-results ns-sym opts]
(let [ns-info (namespace-info ns-sym (:cwd opts))]
(try
(doall (->> ((:fn linter) analyze-results opts)
(map (partial handle-lint-result linter ns-info))))
(->> ((:fn linter) analyze-results opts)
(map (partial handle-lint-result linter ns-info))
(remove (partial ignore-fault? (:ignored-faults opts)))
doall)
(catch Throwable e
[{:kind :lint-error
:warn-data (format "Exception thrown by linter %s on namespace %s" (:name linter) ns-sym)
Expand Down Expand Up @@ -457,7 +466,8 @@ Return value:
:exclude-namespaces #{}
:config-files #{}
:builtin-config-files default-builtin-config-files
:rethrow-exceptions? false})
:rethrow-exceptions? false
:ignored-faults {}})

(defn last-options-map-adjustments [opts reporter]
(let [{:keys [namespaces] :as opts} (merge default-opts opts)
Expand Down
35 changes: 34 additions & 1 deletion test/eastwood/lint_test.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns eastwood.lint-test
(:use [clojure.test ])
(:require [eastwood.lint :refer :all]
(:require [eastwood.lint :as sut :refer :all]
[eastwood.copieddeps.dep11.clojure.java.classpath :as classpath]
[eastwood.util :as util]
[eastwood.copieddeps.dep9.clojure.tools.namespace.dir :as dir]
Expand Down Expand Up @@ -94,3 +94,36 @@
invalid-namespaces true false
valid-namespaces true true
valid-namespaces false true)))

(deftest ignore-fault?-test
(are [input expected] (= expected
(sut/ignore-fault? input
{:warn-data {:namespace-sym 'some-ns
:line 1
:column 2
:linter :some-linter}}))
nil false
{} false
{:some-linter {'some-ns true}} true
{:different-linter {'some-ns true}} false
{:some-linter {'different-ns true}} false
{:some-linter {'some-ns {:line 1 :column 2}}} true
{:some-linter {'some-ns {:line 999 :column 2}}} false
{:some-linter {'some-ns {:line 1 :column 999}}} false
{:some-linter {'different-ns {:line 1 :column 2}}} false
{:some-linter {'different-ns {:line 999 :column 2}}} false
{:some-linter {'different-ns {:line 1 :column 999}}} false))

(deftest ignored-faults-test
(testing "A ignored-faults can remove warnings.
The ignored-faults must match ns (exactly) and file/column (exactly, but only if provided)"
(are [input expected] (= expected
(-> eastwood.lint/default-opts
(assoc :namespaces #{'testcases.ignored-faults-example}
:ignored-faults input)
(eastwood.lint/eastwood)))
{} {:some-warnings true}
{:implicit-dependencies {'testcases.ignored-faults-example true}} {:some-warnings false}
{:implicit-dependencies {'testcases.ignored-faults-example {:line 4 :column 1}}} {:some-warnings false}
{:implicit-dependencies {'testcases.ignored-faults-example {:line 4 :column 99}}} {:some-warnings true}
{:implicit-dependencies {'testcases.ignored-faults-example {:line 99 :column 1}}} {:some-warnings true})))

0 comments on commit 242619a

Please sign in to comment.