-
Notifications
You must be signed in to change notification settings - Fork 5k
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
Kondo linter tests for :metabase/validate-logging
#43104
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a487e2b
PoC Kondo linter test
camsaul 8bf55d6
Log linter tests
camsaul 5c0b723
Remove fail-test
camsaul bce6510
Test fixes :wrench:
camsaul b9afba4
Test fixes :wrench:
camsaul 623b3ab
Merge branch 'master' into kondo-
camsaul File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
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,79 @@ | ||
(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])) | ||
|
||
(deftest ^:parallel fail-test | ||
(is (= 1 0))) | ||
|
||
(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 [])}] | ||
(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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed reflection warning introduced by #42316