forked from logseq/logseq
-
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.
clj-kondo: check regex error prone double escaping
- Loading branch information
1 parent
dd86856
commit 770fdc5
Showing
4 changed files
with
25 additions
and
3 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
(ns hooks.regex-checks | ||
"This hook try to find out those error-prone double escaping regex expressions" | ||
(:require [clj-kondo.hooks-api :as api])) | ||
|
||
(def double-escaped-checker #"\(re-pattern .*\\\\\\\\[\?\#\|\.\^\$\\\+].*\)") | ||
|
||
(defn double-escaped-regex | ||
[{:keys [node]}] | ||
(let [[_ _content regex & _args] (:children node) | ||
regex-string (str (api/sexpr regex))] | ||
(when (and (= (api/tag regex) :regex) | ||
(re-matches double-escaped-checker regex-string)) | ||
(api/reg-finding! (assoc (meta regex) | ||
:message (str "double slash (\\\\) found in this regular expression followed by a regex special character (, + , * , ? , ^ , $ , | , \\ ), are you mistakenly double escaped a special character? Only escape one-time is required. No escape is required in character class []. (use #_{:clj-kondo/ignore [:regex-checks/double-escaped-regex]} to ignore)") | ||
:type :regex-checks/double-escaped-regex))))) |
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