branch: externals/relint commit 6a865096791757c0034238f813910b87018a0e31 Author: Mattias Engdegård <matti...@acm.org> Commit: Mattias Engdegård <matti...@acm.org>
Tuned miscape filtering Instead of disabling the useless backslash check for all doc strings, just ignore escaped ()[]' -- round and square brackets and apostrophe. This catches more actual mistakes while avoiding most false positives. --- relint.el | 13 ++++--------- test/13.elisp | 13 +++++++------ test/13.expected | 38 ++++++++++++++++++++++++-------------- 3 files changed, 35 insertions(+), 29 deletions(-) diff --git a/relint.el b/relint.el index 3c6d05a..5124958 100644 --- a/relint.el +++ b/relint.el @@ -2164,20 +2164,15 @@ Return a list of (FORM . STARTING-POSITION)." (and (= steps 4) (looking-at (rx (or "define-derived-mode")))))))) -(defconst relint--miscape-ignore-left-round-bracket nil - "Whether to ignore specifically `\\(' in doc strings.") - -(defconst relint--miscape-ignore-all-doc-strings t - "Whether to ignore all stray backslashes in doc strings.") - (defun relint--suspicious-backslash (string-start) "With point at an ineffective backslash, emit an warning unless filtered out. STRING-START is the start of the string literal (first double quote)." (let ((c (char-after (1+ (point))))) + ;; Filter out escaped round and square brackets and apostrophes + ;; inside doc strings, as well as anything in the leftmost column: + ;; common for historical reasons and less likely to be mistakes. (unless (or (bolp) - (and (or (and relint--miscape-ignore-left-round-bracket - (eq c ?\()) - relint--miscape-ignore-all-doc-strings) + (and (memq c '(?\( ?\) ?\[ ?\] ?\')) (relint--in-doc-string-p string-start))) (relint--warn (point) nil (format-message diff --git a/test/13.elisp b/test/13.elisp index 58c1609..1f8cb58 100644 --- a/test/13.elisp +++ b/test/13.elisp @@ -3,13 +3,14 @@ ;; Test ineffective backslashes in strings (defun f1 () - "doc string with \(silly\) bac\kslashes -\[that we ignore\]" + "doc string: +\! \( \) \[ \] \' all ignored +not ignored: \{ \} \| \` \? \* \. \+ \; \q etc" (list - "\more \(bad things\)" - "long \<string\> -\(with mistakes\) -\{and so on\}" + "\more" + "not ignored: \( \) \[ \] \'" + "long string \; +\; and so on" "valid: \\ \" \x5e \172 \u1234 \u00000041 \C-x \M-e \ \ and \a \b \f \n \r \t \v \d \e \s \^P")) diff --git a/test/13.expected b/test/13.expected index 8c721d5..53a4568 100644 --- a/test/13.expected +++ b/test/13.expected @@ -1,18 +1,28 @@ -13.elisp:9:5: Ineffective string escape `\m' -13.elisp:9:11: Ineffective string escape `\(' -13.elisp:9:23: Ineffective string escape `\)' -13.elisp:10:10: Ineffective string escape `\<' -13.elisp:10:18: Ineffective string escape `\>' -13.elisp:11:16: Ineffective string escape `\)' -13.elisp:12:12: Ineffective string escape `\}' -13.elisp:17:23: In call to re-search-forward: Unescaped literal `$' (pos 0) +13.elisp:8:14: Ineffective string escape `\{' +13.elisp:8:17: Ineffective string escape `\}' +13.elisp:8:20: Ineffective string escape `\|' +13.elisp:8:23: Ineffective string escape `\`' +13.elisp:8:26: Ineffective string escape `\?' +13.elisp:8:29: Ineffective string escape `\*' +13.elisp:8:32: Ineffective string escape `\.' +13.elisp:8:35: Ineffective string escape `\+' +13.elisp:8:38: Ineffective string escape `\;' +13.elisp:8:41: Ineffective string escape `\q' +13.elisp:10:5: Ineffective string escape `\m' +13.elisp:11:18: Ineffective string escape `\(' +13.elisp:11:21: Ineffective string escape `\)' +13.elisp:11:24: Ineffective string escape `\[' +13.elisp:11:27: Ineffective string escape `\]' +13.elisp:11:30: Ineffective string escape `\'' +13.elisp:12:17: Ineffective string escape `\;' +13.elisp:18:23: In call to re-search-forward: Unescaped literal `$' (pos 0) "$.x++" ^ -13.elisp:17:23: Ineffective string escape `\$' -13.elisp:17:25: Ineffective string escape `\.' -13.elisp:17:28: Ineffective string escape `\+' -13.elisp:17:30: In call to re-search-forward: Repetition of repetition (pos 4) +13.elisp:18:23: Ineffective string escape `\$' +13.elisp:18:25: Ineffective string escape `\.' +13.elisp:18:28: Ineffective string escape `\+' +13.elisp:18:30: In call to re-search-forward: Repetition of repetition (pos 4) "$.x++" ....^ -13.elisp:17:30: Ineffective string escape `\+' -13.elisp:18:16: Ineffective string escape `\q' +13.elisp:18:30: Ineffective string escape `\+' +13.elisp:19:16: Ineffective string escape `\q'