forked from metabase/metabase
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Kondo linter tests for
:metabase/validate-logging
(metabase#43104)
* PoC Kondo linter test * Log linter tests * Remove fail-test
- Loading branch information
Showing
28 changed files
with
120 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
(ns ^:mb/once hooks.common-test | ||
(:require | ||
[clj-kondo.hooks-api :as api] | ||
[clj-kondo.impl.utils] | ||
[clojure.test :refer :all] | ||
[hooks.common])) | ||
|
||
(deftest ^:parallel node->qualified-symbol-test | ||
(binding [clj-kondo.impl.utils/*ctx* {:namespaces (atom nil)}] | ||
(is (= 'metabase.util.i18n/tru | ||
(hooks.common/node->qualified-symbol (api/parse-string "metabase.util.i18n/tru")))))) | ||
|
||
(deftest ^:parallel node->qualified-symbol-test-2 | ||
(binding [clj-kondo.impl.utils/*ctx* {:namespaces (atom {:clj {:clj '{hooks.common-test {:qualify-ns {i18n metabase.util.i18n}}}}}) | ||
:lang :clj | ||
:base-lang :clj | ||
:ns {:name 'hooks.common-test}}] | ||
(is (= 'metabase.util.i18n/tru | ||
(hooks.common/node->qualified-symbol (api/parse-string "i18n/tru")))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
(ns ^:mb/once hooks.metabase.util.log-test | ||
(:require | ||
[clj-kondo.hooks-api :as api] | ||
[clj-kondo.impl.utils] | ||
[clojure.string :as str] | ||
[clojure.test :refer :all] | ||
[hooks.metabase.util.log])) | ||
|
||
(defn- warnings | ||
[form] | ||
(let [f (if (str/ends-with? (name (first form)) "f") | ||
hooks.metabase.util.log/infof | ||
hooks.metabase.util.log/info)] | ||
(binding [clj-kondo.impl.utils/*ctx* {:config {:linters {:metabase/validate-logging {:level :warning}}} | ||
:ignores (atom nil) | ||
:findings (atom []) | ||
:namespaces (atom {})}] | ||
(f {:node (api/parse-string (pr-str form))}) | ||
(mapv :message @(:findings clj-kondo.impl.utils/*ctx*))))) | ||
|
||
(deftest ^:parallel warn-on-missing-format-args-test | ||
(testing "should fail, missing a format arg" | ||
(are [form] (= ["log format string expects 1 arguments instead of 0."] | ||
(warnings (quote form))) | ||
(metabase.util.log/warnf "Migration lock was acquired after %d retries.") | ||
(metabase.util.log/warnf e "Migration lock was acquired after %d retries.")))) | ||
|
||
(deftest ^:parallel warn-on-too-many-format-args-test-1 | ||
(testing "should fail, too many format args" | ||
(are [form] (= ["log format string expects 1 arguments instead of 2."] | ||
(warnings (quote form))) | ||
(metabase.util.log/warnf "Migration lock was acquired after %d retries." 1 2) | ||
(metabase.util.log/warnf e "Migration lock was acquired after %d retries." 1 2)))) | ||
|
||
(deftest ^:parallel warn-on-too-many-format-args-test-2 | ||
(testing "should fail, too many format args" | ||
(are [form] (= ["this looks like an i18n format string. Don't use identifiers like {0} in logging." | ||
"Don't use metabase.util.log/warnf with no format string arguments, use metabase.util.log/warn instead." | ||
"log format string expects 0 arguments instead of 1."] | ||
(warnings (quote form))) | ||
(metabase.util.log/warnf "Migration lock was acquired after {0} retries." 1) | ||
(metabase.util.log/warnf e "Migration lock was acquired after {0} retries." 1)))) | ||
|
||
(deftest ^:parallel warn-on-format-args-without-logf-test | ||
(testing "should fail, has format args but is warn rather than warnf" | ||
(are [form] (= ["metabase.util.log/warn used with a format string, use metabase.util.log/warnf instead."] | ||
(warnings (quote form))) | ||
(metabase.util.log/warn "Migration lock was acquired after %d retries." 1) | ||
(metabase.util.log/warn e "Migration lock was acquired after %d retries." 1)))) | ||
|
||
(deftest ^:parallel warn-on-format-without-logf-test | ||
(testing "should fail, has format args but is warn rather than warnf" | ||
(are [form] (= ["Use metabase.util.log/warnf instead of metabase.util.log/warn + format"] | ||
(warnings (quote form))) | ||
(metabase.util.log/warn (format "Migration lock was acquired after %d retries." 1)) | ||
(metabase.util.log/warn e (format "Migration lock was acquired after %d retries." 1))))) | ||
|
||
(deftest ^:parallel warn-on-logf-with-no-format-args-test | ||
(testing "should fail, has format args but is warn rather than warnf" | ||
(are [form] (= ["Don't use metabase.util.log/warnf with no format string arguments, use metabase.util.log/warn instead."] | ||
(warnings (quote form))) | ||
(metabase.util.log/warnf "Migration lock cleared.") | ||
(metabase.util.log/warnf e "Migration lock cleared.")))) | ||
|
||
(deftest ^:parallel warn-on-i18n-test-1 | ||
(testing "should fail -- should not use i18n/tru or i18n/trs" | ||
(are [form] (= ["do not i18n the logs!"] | ||
(warnings (quote form))) | ||
(metabase.util.log/warnf (metabase.util.i18n/tru "Migration lock was acquired after {0} retries." 1)) | ||
(metabase.util.log/warnf e (metabase.util.i18n/tru "Migration lock was acquired after {0} retries." 1))))) | ||
|
||
(deftest ^:parallel warn-on-i18n-test-2 | ||
(testing "should fail -- should not use i18n/tru or i18n/trs" | ||
(are [form] (= ["do not i18n the logs!"] | ||
(warnings (quote form))) | ||
(metabase.util.log/warn (metabase.util.i18n/trs "Migration lock was acquired after {0} retries." 1)) | ||
(metabase.util.log/warn e (metabase.util.i18n/trs "Migration lock was acquired after {0} retries." 1))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters