From b41a5afa43d128e31e9fb27460b8904300f94b0e Mon Sep 17 00:00:00 2001 From: Noah Bogart Date: Wed, 14 Feb 2024 09:03:01 -0500 Subject: [PATCH] Bump version for release --- CHANGELOG.md | 2 ++ docs/rules/lint.md | 31 ++++++++++++++++++++++++++++++- docs/rules/performance.md | 3 +++ resources/SPLINT_VERSION | 2 +- resources/config/default.edn | 10 +++++----- 5 files changed, 41 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 411afabd..ebda6087 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ This changelog is loose. Versions are not semantic, they are incremental. Splint ## Unreleased +## v1.13 - 2024-02-14 + ### New Rules - `lint/prefer-method-values`: Prefer `(^[] String/toUpperCase "noah")` to `(.toUpperCase "noah")`. diff --git a/docs/rules/lint.md b/docs/rules/lint.md index 2179878b..9ecd7bcc 100644 --- a/docs/rules/lint.md +++ b/docs/rules/lint.md @@ -506,6 +506,35 @@ Empty loops with nested when can be `while`. --- +## lint/prefer-method-values + +| Enabled by default | Version Added | Version Updated | +| ------------------ | ------------- | --------------- | +| true | 1.13 | 1.13 | + +**NOTE**: Requires Clojure version 1.12.0. + +Uniform qualified method values are a new syntax for calling into java code. They must resolve to a single static or instance method and to help with that, a new metadata syntax can be used: `^[]` aka `^{:param-tags []}`. Types are specified with classes, each corrosponding to an argument in the target method: `(^[long String] SomeClass/someMethod 1 "Hello world!")`. It compiles to a direct call without any reflection, guaranteeing optimal performance. + +If it doesn't resolve to a single method, then the Clojure compiler throws a syntax error (IllegalArgumentException). Such ahead-of-time compilation checking is a powerful and helpful tool in writing correct and performant code. Given that, it is preferable to exclusively use method values. + +### Examples + +```clojure +; bad +(.toUpperCase "noah") +(. "noah" toUpperCase) + +; good +(^[] String/toUpperCase "noah") +``` + +### Reference + +* + +--- + ## lint/prefer-require-over-use | Enabled by default | Version Added | Version Updated | @@ -587,7 +616,7 @@ x | Enabled by default | Version Added | Version Updated | | ------------------ | ------------- | --------------- | -| true | <> | <> | +| false | 1.13 | 1.13 | **NOTE**: Requires Clojure version 1.12.0. diff --git a/docs/rules/performance.md b/docs/rules/performance.md index b9a1a0b2..b6ae7336 100644 --- a/docs/rules/performance.md +++ b/docs/rules/performance.md @@ -55,6 +55,8 @@ Avoid use of `satisfies?` as it is extremely slow. Restructure your code to rely Currently only checks string literals. +If `lint/prefer-method-values` is enabled, then the suggestion will use that syntax. + ### Examples ```clojure @@ -63,6 +65,7 @@ Currently only checks string literals. ; good (.equals "foo" s) +(String/equals "foo" s) ``` --- diff --git a/resources/SPLINT_VERSION b/resources/SPLINT_VERSION index 809bdcb8..d3456a90 100644 --- a/resources/SPLINT_VERSION +++ b/resources/SPLINT_VERSION @@ -1 +1 @@ -1.12 +1.13 diff --git a/resources/config/default.edn b/resources/config/default.edn index a147f49f..39e2c40e 100644 --- a/resources/config/default.edn +++ b/resources/config/default.edn @@ -152,8 +152,8 @@ lint/prefer-method-values {:description "Use uniform Class/member syntax when writing interop." :enabled true - :added "<>" - :updated "<>" + :added "1.13" + :updated "1.13" :link "https://insideclojure.org/2024/02/12/method-values"} lint/prefer-require-over-use @@ -173,9 +173,9 @@ lint/require-explicit-param-tags {:description "Require explicit :param-tags on method values." - :enabled true - :added "<>" - :updated "<>" + :enabled false + :added "1.13" + :updated "1.13" :chosen-style :wildcard :supported-styles [:both :missing :wildcard] :link "https://insideclojure.org/2024/02/12/method-values"}