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

linter reporting #109

Closed
wants to merge 52 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
371f8b4
Migrate to clj-kondo's JVM API
thumbnail Dec 28, 2019
77d3758
Address various linter warnings
thumbnail Jan 6, 2020
421dd5e
Add configurability for kondo-options
thumbnail Jan 7, 2020
c5b2e24
Split Kondo linters by platform (clj/cljs)
thumbnail Jan 7, 2020
fb1277c
Return report from Kondo
thumbnail Jan 19, 2020
e6d27ba
Return report from loc-per-ns
thumbnail Jan 19, 2020
322a6a5
Replace bikeshed with custom linter
thumbnail Jan 18, 2020
601808a
Return report from ns-aliases
thumbnail Jan 19, 2020
3d7a76b
Return report from Eastwood
thumbnail Jan 18, 2020
8a3c703
Use reporter to print lint-results
thumbnail Jan 19, 2020
9aa519d
Return nil from linter/processors
thumbnail Jan 21, 2020
b31b93f
Add Reporter specs and protocol
thumbnail Jan 21, 2020
325cfc9
Add :level to linter-reports
thumbnail Jan 21, 2020
03405ce
Present exceptions as a regular report
thumbnail Jan 21, 2020
9bd4036
Handle exceptions as reports
thumbnail Jan 27, 2020
3024ee9
Rename :linter to :source
thumbnail Jan 27, 2020
2cc69d2
Fix docs
thumbnail Jan 27, 2020
28f2277
Add functional tests for Linter results
thumbnail Jan 28, 2020
9bcec71
Add reporters.file-writer, clean pretty-printer
thumbnail Jan 30, 2020
d80d282
Fix :strategies for cljfmt/how-to-ns
thumbnail Jan 30, 2020
2b34030
Formatting
thumbnail Feb 4, 2020
b124984
Satisfy pedantic
vemv Feb 7, 2020
4ba418e
Adapt `functional.formatting-stack.component` to `protocols.reporter`
vemv Feb 7, 2020
9b54df4
Draft `formatting-stack.reporters.printer`, default to it
vemv Feb 7, 2020
58101d0
Patch linters.one-resource-per-ns so it satisfies the specs
vemv Feb 7, 2020
a53d565
project.clj: honor exclusions via custom middleware
vemv Feb 8, 2020
1ff8a37
Kondo: skip `:unused-binding` linter
vemv Feb 8, 2020
3f87d5a
Cleanup `formatting-stack.linters.kondo`
vemv Feb 8, 2020
b1a6f3d
Strategies: don't exclude Kondo from JVM files anymore
vemv Feb 8, 2020
01f311b
Cleanup project
vemv Feb 8, 2020
7f7677a
Setup a JDK test matrix
vemv Feb 8, 2020
5a5c332
Upgrade utils.modular
vemv Feb 8, 2020
3259cc5
Kondo: use the classpath cache
vemv Feb 8, 2020
64ef1f7
Expand `linters.kondo/clj-options` with `:invalid-arity`
vemv Feb 8, 2020
a1433c5
v3.0.0-alpha1
vemv Feb 8, 2020
2e674c2
Expand `linters.kondo/default-options` with `:unresolved-symbol`
vemv Feb 8, 2020
7ededc7
v3.0.0-alpha3
vemv Feb 8, 2020
32a2ec7
Rework `reporters.pretty-printer`
vemv Feb 10, 2020
e716a55
kondo-classpath-cache: prefer `future` to `delay`
vemv Feb 10, 2020
21a9935
`kondo-classpath-cache`: use a safer `cache-dir`
vemv Feb 10, 2020
97e4cf5
Adapt `linters.one-resource-per-ns` to the Reporters feature
vemv Feb 10, 2020
03703af
Use :warning-details-url
vemv Feb 10, 2020
f4f3169
Make `line-length`/`loc-per-ns` reports more informative
vemv Feb 10, 2020
f0c8928
v3.0.0-alpha6
vemv Feb 10, 2020
d4ba329
Ensure `process-in-parallel!` workloads are performed eagerly
vemv Feb 10, 2020
95cad72
Rearrange linters order
vemv Feb 11, 2020
e4d04c0
Introduce `ensure-sequential`
vemv Feb 11, 2020
5a0a72d
`reporters.file-writer`: rename the default filename
vemv Feb 11, 2020
27f90e0
Split kondo options per-platform
vemv Feb 11, 2020
ebf52ec
Strengthen `project-parsing/project-namespaces`
vemv Feb 11, 2020
5b9ca38
Tweak some linters' `:msg`s
vemv Feb 11, 2020
b1c488b
Remove a disabled test
vemv Feb 11, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 58 additions & 20 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,43 @@ commands:
- ~/.m2
key: v1-dependencies-{{ checksum "project.clj" }}

executor_defaults: &executor_defaults
working_directory: ~/repo

executors:
lein-executor:
openjdk8:
docker:
- image: circleci/clojure:openjdk-8-lein-2.9.1
working_directory: ~/repo
environment:
LEIN_ROOT: "true"
JVM_OPTS: -Xmx3200m
<<: *executor_defaults
openjdk11:
docker:
- image: circleci/clojure:openjdk-11-lein-2.9.1
environment:
LEIN_ROOT: "true"
JVM_OPTS: -Xmx3200m --illegal-access=deny
<<: *executor_defaults

jobs:
build:
executor: lein-executor
test_code:
description: |
Runs tests against given version of the JDK
parameters:
jdk_version:
description: Version of the JDK to test against
type: string
lein_test_command:
description: A Leiningen command that will run a test suite
type: string
executor: << parameters.jdk_version >>
steps:
- setup-env
- run:
name: 'Run JVM tests, including refactor-nrepl functionality'
command: lein with-profile -dev,+ci,+refactor-nrepl do clean, test
- run:
name: 'Run JVM tests, excluding refactor-nrepl functionality'
command: lein with-profile -dev,+ci do clean, test
command: << parameters.lein_test_command >>
deploy:
executor: lein-executor
executor: openjdk8
steps:
- setup-env
- run:
Expand All @@ -52,21 +67,44 @@ jobs:
name: release to Clojars
command: lein deploy clojars

test_code_filters: &test_code_filters
filters:
branches:
only: /.*/
tags:
only: /^v\d+\.\d+\.\d+(-alpha\d+)?$/

workflows:
version: 2
CircleCI:
version: 2.1
ci-test-matrix:
jobs:
- build:
context: JFrog
filters:
branches:
only: /.*/
tags:
only: /^v\d+\.\d+\.\d+(-alpha\d+)?$/
- test_code:
name: "JDK 8 including refactor-nrepl"
jdk_version: openjdk8
lein_test_command: lein with-profile -dev,+ci,+refactor-nrepl do clean, test
<<: *test_code_filters
- test_code:
name: "JDK 8 excluding refactor-nrepl"
jdk_version: openjdk8
lein_test_command: lein with-profile -dev,+ci do clean, test
<<: *test_code_filters
- test_code:
name: "JDK 11 including refactor-nrepl"
jdk_version: openjdk11
lein_test_command: lein with-profile -dev,+ci,+refactor-nrepl do clean, test
<<: *test_code_filters
- test_code:
name: "JDK 11 excluding refactor-nrepl"
jdk_version: openjdk11
lein_test_command: lein with-profile -dev,+ci do clean, test
<<: *test_code_filters
- deploy:
context: JFrog
requires:
- build
- "JDK 8 including refactor-nrepl"
- "JDK 8 excluding refactor-nrepl"
- "JDK 11 including refactor-nrepl"
- "JDK 11 excluding refactor-nrepl"
filters:
branches:
ignore: /.*/
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*~
.*.swo
.*.swp
.clj-kondo/
.DS_Store
.eastwood
.idea/
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ As of today, it is integrated with:
* Defaults to processing .cljs files only, given the overlap with Eastwood.
* [refactor-nrepl](https://github.com/clojure-emacs/refactor-nrepl)
* Used for "clean unused imports" functionality
* [bikeshed](https://github.com/dakrone/lein-bikeshed)
* Used for checking max column count
* [all-my-files-should-end-with-exactly-one-newline-character](https://github.com/gfredericks/lein-all-my-files-should-end-with-exactly-one-newline-character)
* Configurable, you can ensure either 0 or 1 ending newlines per file.

Expand All @@ -32,6 +30,7 @@ And it also bundles a few tiny linters of its own:
* [loc-per-ns](https://github.com/nedap/formatting-stack/blob/debdab8129dae7779d390216490625a3264c9d2c/src/formatting_stack/linters/loc_per_ns.clj) warns if a given NS surpasses a targeted LOC count.
* [ns-aliases](https://github.com/nedap/formatting-stack/blob/debdab8129dae7779d390216490625a3264c9d2c/src/formatting_stack/linters/ns_aliases.clj) warns if [Sierra's](https://stuartsierra.com/2015/05/10/clojure-namespace-aliases) aliasing guide is disregarded.
* [one-resource-per-ns](https://github.com/nedap/formatting-stack/blob/master/src/formatting_stack/linters/one_resource_per_ns.clj) warns if a Clojure namespace is defined in more than one file.
* [line-length](https://github.com/nedap/formatting-stack/blob/f1cf4206399a77a83fde4140095d4c59c10b1605/src/formatting_stack/linters/line_length.clj) warns if max line length is reached.

It is fully extensible: you can configure the bundled formatters, remove them, and/or add your own.

Expand Down Expand Up @@ -74,7 +73,7 @@ The general intent is to make formatting:
#### Coordinates

```clojure
[formatting-stack "2.0.1-alpha2"]
[formatting-stack "3.0.0-alpha6"]
```

**Also** you might have to add the [refactor-nrepl](https://github.com/clojure-emacs/refactor-nrepl) dependency.
Expand Down
11 changes: 8 additions & 3 deletions dev/dev.clj
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,21 @@
;; the "worker" source-path must be excluded.
(set-refresh-dirs "src" "test" "dev")

(defn prepare-tests []
(clear)
(alter-var-root #'clojure.test/*load-tests* (constantly true))
(refresh))

(defn suite []
(refresh)
(prepare-tests)
(run-all-tests #".*\.formatting-stack.*"))

(defn unit []
(refresh)
(prepare-tests)
(run-all-tests #"unit\.formatting-stack.*"))

(defn slow []
(refresh)
(prepare-tests)
(run-all-tests #"integration\.formatting-stack.*"))

(defn diff [x y]
Expand Down
41 changes: 35 additions & 6 deletions project.clj
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
;; Please don't bump the library version by hand - use ci.release-workflow instead.
(defproject formatting-stack "2.0.1-alpha2"
(defproject formatting-stack "3.0.0-alpha6"
;; Please keep the dependencies sorted a-z.
:dependencies [[clj-kondo "2019.05.19-alpha"]
:dependencies [[clj-kondo "2020.01.13"]
[cljfmt "0.6.5" :exclusions [rewrite-clj]]
[com.gfredericks/how-to-ns "0.2.6"]
[com.gfredericks/lein-all-my-files-should-end-with-exactly-one-newline-character "0.1.1"]
[com.nedap.staffing-solutions/speced.def "2.0.0"]
[com.nedap.staffing-solutions/utils.collections "2.0.0"]
[com.nedap.staffing-solutions/utils.modular "2.0.0"]
[com.nedap.staffing-solutions/utils.modular "2.1.0"]
[com.nedap.staffing-solutions/utils.spec.predicates "1.1.0"]
[com.stuartsierra/component "0.4.0"]
[integrant "0.7.0"]
[jonase/eastwood "0.3.5"]
[lein-bikeshed "0.5.1"]
[medley "1.2.0"]
[org.clojure/clojure "1.10.1"]
[org.clojure/tools.namespace "0.3.1"]
Expand Down Expand Up @@ -73,11 +72,41 @@
[org.clojure/test.check "0.10.0-alpha3"]]
:jvm-opts ["-Dclojure.compiler.disable-locals-clearing=true"]
:source-paths ["dev"]
:repl-options {:init-ns dev}}
:repl-options {:init-ns dev}
:middleware [~(do ;; the following ensures that :exclusions are honored in all cases
(create-ns 'user)
(intern 'user
'nedap-ensure-exclusions
(fn [project]
(let [exclusions (->> project
:exclusions
(map (fn [x]
(str (if (namespace (symbol x))
x
(symbol (str x) (str x))))))
(set))]
(update project :dependencies (fn [deps]
(->> deps
(remove (fn [[dep version]]
(exclusions (str dep))))
vec))))))
'user/nedap-ensure-exclusions)]}

:provided {:dependencies [[org.clojure/clojurescript "1.10.597"
:exclusions [com.cognitect/transit-clj
com.google.code.findbugs/jsr305
com.google.errorprone/error_prone_annotations]]
[com.google.guava/guava "25.1-jre" #_"transitive"]
[com.google.protobuf/protobuf-java "3.4.0" #_"transitive"]
[com.cognitect/transit-clj "0.8.313" #_"transitive"]
[com.google.errorprone/error_prone_annotations "2.1.3" #_"transitive"]
[com.google.code.findbugs/jsr305 "3.0.2" #_"transitive"]]}

;; `dev` in :test is important - a test depends on it:
:test {:source-paths ["dev"]
:dependencies [[com.nedap.staffing-solutions/utils.test "1.6.2"]]
:dependencies [[com.nedap.staffing-solutions/utils.test "1.6.2"]
[nubank/matcher-combinators "1.0.1"
:exclusions [commons-codec]]]
:jvm-opts ["-Dclojure.core.async.go-checking=true"
"-Duser.language=en-US"]
:resource-paths ["test-resources-extra"
Expand Down
41 changes: 24 additions & 17 deletions src/formatting_stack/branch_formatter.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
[formatting-stack.formatters.no-extra-blank-lines :as formatters.no-extra-blank-lines]
[formatting-stack.formatters.trivial-ns-duplicates :as formatters.trivial-ns-duplicates]
[formatting-stack.indent-specs]
[formatting-stack.linters.bikeshed :as linters.bikeshed]
[formatting-stack.linters.eastwood :as linters.eastwood]
[formatting-stack.linters.kondo :as linters.kondo]
[formatting-stack.linters.line-length :as linters.line-length]
[formatting-stack.linters.loc-per-ns :as linters.loc-per-ns]
[formatting-stack.linters.ns-aliases :as linters.ns-aliases]
[formatting-stack.linters.one-resource-per-ns :as linters.one-resource-per-ns]
[formatting-stack.processors.cider :as processors.cider]
[formatting-stack.reporters.pretty-printer :as pretty-printer]
[formatting-stack.strategies :as strategies]
[medley.core :refer [mapply]]))

Expand Down Expand Up @@ -46,56 +47,62 @@
(filterv some?)))

(defn default-linters [default-strategies]
[(-> (linters.ns-aliases/new {})
[(-> (linters.kondo/new {})
(assoc :strategies (conj default-strategies
strategies/exclude-edn)))
(-> (linters.one-resource-per-ns/new {})
(assoc :strategies (conj default-strategies
strategies/files-with-a-namespace)))
(-> (linters.ns-aliases/new {})
(assoc :strategies (conj default-strategies
strategies/files-with-a-namespace
;; reader conditionals may confuse `linters.ns-aliases`
strategies/exclude-cljc
;; string requires may confuse clojure.tools.*
strategies/exclude-cljs)))
(-> (linters.loc-per-ns/new {})
(-> (linters.line-length/new {})
(assoc :strategies (conj default-strategies
strategies/exclude-edn)))
(-> (linters.bikeshed/new {})
(-> (linters.loc-per-ns/new {})
(assoc :strategies (conj default-strategies
strategies/exclude-edn)))
(-> (linters.eastwood/new {})
(assoc :strategies (conj default-strategies
strategies/exclude-cljs
strategies/jvm-requirable-files
strategies/namespaces-within-refresh-dirs-only)))
(-> (linters.kondo/new)
(assoc :strategies (conj default-strategies
strategies/exclude-edn
strategies/exclude-clj
strategies/exclude-cljc)))
(-> (linters.one-resource-per-ns/new {})
(assoc :strategies (conj default-strategies
strategies/files-with-a-namespace)))])
strategies/namespaces-within-refresh-dirs-only)))])

(def default-processors
[(processors.cider/new {:third-party-indent-specs third-party-indent-specs})])

(defn format-and-lint-branch! [& {:keys [target-branch in-background?]
(def default-reporter
(pretty-printer/new {}))

(defn format-and-lint-branch! [& {:keys [target-branch in-background? reporter]
:or {target-branch "master"
in-background? (not (System/getenv "CI"))}}]
in-background? (not (System/getenv "CI"))
reporter default-reporter}}]
(let [default-strategies [(fn [& {:as options}]
(mapply strategies/git-diff-against-default-branch (assoc options :target-branch target-branch)))]
formatters (default-formatters default-strategies)
linters (default-linters default-strategies)]
(formatting-stack.core/format! :strategies default-strategies
:processors default-processors
:formatters formatters
:reporter reporter
:linters linters
:in-background? in-background?)))

(defn lint-branch! [& {:keys [target-branch in-background?]
:or {target-branch "master"}}]
(defn lint-branch! [& {:keys [target-branch in-background? reporter]
:or {target-branch "master"
in-background? false
reporter default-reporter}}]
(let [default-strategies [(fn [& {:as options}]
(mapply strategies/git-diff-against-default-branch (assoc options :target-branch target-branch)))]
linters (default-linters default-strategies)]
(formatting-stack.core/format! :strategies default-strategies
:formatters []
:processors default-processors
:reporter reporter
:linters linters
:in-background? in-background?)))
Loading