Splint v1.9.0 and v1.10.0

Forgot to post after releasing v1.9.0 back in May, so this is gonna be fuckin huge.

In short: v1.9 added a new rule (style/prefer-clj-string) and a new cli flag (--[no-]summary). v1.10 added reading available deps.edn and project.clj files to determine the directories to check, changing the pattern DSL to use a variation of pangloss/pattern's DSL, and to add 5 new rules, 4 of which are performance rules (style/redundant-regex-constructor, performance/assoc-many, performance/avoid-satisfies, performance/get-in-literals, performance/get-keyword).

The change in v1.10 means that you can run bb splint or clojure -M:splint and it'll "just work": it'll check the primary directories and the directories under and :test alias without any extra fiddling. This makes it much easier to use quickly. I've always been annoyed at clj-kondo's insistence on forcing the --lint flag for choosing files, and loved Rubocop's "just run it" mentality.

The performance rules are disabled by default cuz they might make code more wordy or annoying to work with, and they're highly opinionated. I like them but I get it.

Full release docs/change logs under the fold.


v1.9.0

New Rules

  • style/prefer-clj-string: Prefer clojure.string functions over raw interop. Defaults to true.

Added

  • --[no]summary cli flag to print or not print the summary line.

Changed

  • :filename in Diagnostic is now a java.io.File object, not a string. This is propogated through everything. I suspect no one is using these so I think I could change the Diagnostic as well, but maybe I'll wait a min.
  • make-edamame-opts now accepts both features and ns-state, and parse-string and parse-string-all take in features instead of ns-state.
  • The runner tracks the filetype of each file and runs over cljc files twice, both clj and cljs, with their respective sides of the reader conditionals applied.
  • Diagnostics are deduped before printing.
  • lint/warn-on-reflection only runs in clj files.
  • Remove farolero. Didn't provide any benefits over judicious try/catch use. :(
  • Extend the matcher-combinators.core/Matcher protocol to java.io.File, making match? work nicely with both strings and file objects.
  • Performance improvements by converting rules-by-type from a map of simple-type -> map of rule name -> rule to simple-type -> vec of rule.

Fixed

  • Correctly print special characters/clojure.core vars (@, not splint/deref, etc).

v1.10.0

The big feature here is adding support to run splint without specifying paths. Now Splint will read the deps.edn or project.clj file in the current directory and check the paths in the base definition as well as :dev and :test aliases/profiles if no path argument is given. Splint still doesn't support specifying paths in .splint.edn, nor does it allow for using paths from a project file as well as additional paths when called, but those are planned.

The second big change is moving from the old DSL to the new pangloss/pattern inspired DSL. More flexible, more usable, overall better.

The third is adding performance rules. These are off by default and are designed for those who want to pinch their cycles. Some affect common code (get-in) and some are much more rare (satisfies), but they're all designed to help you be mindful of slower paths.

Breaking

  • Moved spat.parser to splint.parser.
  • Moved spat.pattern to splint.pattern. RIP spat, you treated me well for 9 months, but keeping spat and splint separate is no longer helpful.
  • Switched to the new pattern system, updated all rules.

New Rules

  • performance/assoc-many: Prefer (-> m (assoc :k1 1) (assoc :k2 2)) over (assoc m :k1 1 :k2 2).
  • performance/avoid-satisfies: Do not use clojure.core/satisfies?, full stop.
  • performance/get-in-literals: Prefer (-> m :k1 :k2 :k3) over (get-in m [:k1 :k2 :k3]).
  • performance/get-keyword: Prefer (:k m) over (get m :k).
  • style/redundant-regex-constructor: Prefer #"abc" over (re-pattern #"abc").

Added

  • Implemented faster/more efficient versions of Clojure standard library functions:
    • ->list: concrete list building instead of apply . Useful anywhere a lazy-seq might be returned otherwise. seq/vec input: 40/43 us -> 28/15 us
    • mapv*: mapv but short-circuits empty input and uses object-array. Still unsure of this one. 36 us -> 36 us
    • run!*: run! but short-circuits empty input and uses .iterator to perform the side-effects. Does not support reduced. 7 us -> 950 ns
    • pmap*: Avoids lazy-seq overhead and relies on Java's built-in Executors. 3.34 s -> 202 ms
    • walk* and postwalk*: Primarily useful in replace, but may prove useful otherwise. Only supports simple-type defined types. 72 us -> 25 us
  • splint.config/read-project-file returns a map of :clojure-version and :paths, taken from the project file (deps.edn or project.clj) in the current directory. If no file is found, :paths is nil and :clojure-version is pulled from *clojure-version*.
  • :min-clojure-version in defrule, allowing for rules to specify the minimum version of clojure they require. Rules that are below the supported version are disabled at preparation time and can't be enabled during a run. Acceptable shape is a map of at least one of :major, :minor, and :incremental.
    • Include this in rule documentation.
  • test-helpers/with-temp-file and test-helpers/print-to-file! to test file contents.

Changed

  • Move spat.parser/parse-string and spat.parser/parse-string-all into the test-helper namespace, and replace with parse-file which accepts the file-obj map.
  • Parse data reader/tagged literals as maps instead of lists, and put the extension (dialect) into the symbol's metadata.
  • Defer building cli summary until needed.
  • Use new splint.config/slurp-edn to read config files, parsed with [edamame][edamame].
  • Changed :spat/lit metadata to :splint/lit. :spat/lit still works for the time being, but no promises.
  • splint.printer/print-results now accepts only the results object, which should additionally have :checked-files and :total-time.
  • Output formats simple, full, and clj-kondo now print the number of files checked as well: "Linting took 1ms, checked 3 files, 3 style warnings"
  • Moved splint.replace/revert-splint-reader-macros into splint.printer where it belongs.
  • Rely on undefined behavior in symbol to correctly print unprintable special characters by converting sexprs to strings and then converting those to symbols.
  • Move simple-type and drop-quote to splint.utils.
Liked the post? Hated the post? Felt nothing whatsoever about the post? Email me, and let me know!


Copyright © 2024 Noah Bogart
Website credits