emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/typescript-mode e0b4a6cb31 055/222: Merge pull request #36


From: ELPA Syncer
Subject: [nongnu] elpa/typescript-mode e0b4a6cb31 055/222: Merge pull request #36 from lddubeau/feature/improved-tslint-regex
Date: Sun, 6 Feb 2022 16:59:14 -0500 (EST)

branch: elpa/typescript-mode
commit e0b4a6cb31750314e827bbc57de9a35558b34fd9
Merge: f25f4751fe 46e032e932
Author: Jostein Kjønigsen <jostein@kjonigsen.net>
Commit: GitHub <noreply@github.com>

    Merge pull request #36 from lddubeau/feature/improved-tslint-regex
    
    Support rule names and severity in tslint reports.
---
 typescript-mode-tests.el | 70 ++++++++++++++++++++++++++++++++++++++++++++++++
 typescript-mode.el       | 38 +++++++++++++++++++-------
 2 files changed, 99 insertions(+), 9 deletions(-)

diff --git a/typescript-mode-tests.el b/typescript-mode-tests.el
index fb40785094..0c8fec5076 100644
--- a/typescript-mode-tests.el
+++ b/typescript-mode-tests.el
@@ -29,6 +29,76 @@
 
     (kill-buffer buffer)))
 
+(defun get-all-matched-strings (to-match)
+  (let (result)
+    (dotimes (x (/ (length (match-data)) 2))
+      (setq result (nconc result (list (match-string x to-match)))))
+    result))
+
+(ert-deftest typescript-tslint-report-regexp-matches ()
+  "typescript-tslint-report-regexp matches a line that does not
+have a rule name or a severity."
+  (let* ((to-match
+          "src/modules/authenticator.ts[1, 83]: ' should be \"")
+         (match (string-match typescript-tslint-report-regexp
+                              to-match))
+         (matches (and match (get-all-matched-strings to-match))))
+    (should match)
+    (should (not (nth 1 matches)))
+    (should (not (nth 2 matches)))
+    (should (string-equal (nth 3 matches)
+                          "src/modules/authenticator.ts"))
+    (should (string-equal (nth 4 matches) "1"))
+    (should (string-equal (nth 5 matches) "83"))))
+
+(ert-deftest typescript-tslint-report-regexp-matches-with-name ()
+  "typescript-tslint-report-regexp matches a line that has
+a rule name, no severity."
+  (let* ((to-match
+          "(quotemark) src/modules/authenticator.ts[1, 83]: ' should be \"")
+         (match (string-match typescript-tslint-report-regexp
+                              to-match))
+         (matches (and match (get-all-matched-strings to-match))))
+    (should match)
+    (should (not (nth 1 matches)))
+    (should (string-equal (nth 2 matches) "(quotemark) "))
+    (should (string-equal (nth 3 matches)
+                          "src/modules/authenticator.ts"))
+    (should (string-equal (nth 4 matches) "1"))
+    (should (string-equal (nth 5 matches) "83"))))
+
+(ert-deftest typescript-tslint-report-regexp-matches-with-error ()
+  "typescript-tslint-report-regexp matches a line that has
+a severity set to ERROR, no rule name."
+  (let* ((to-match
+          "ERROR: src/modules/authenticator.ts[1, 83]: ' should be \"")
+         (match (string-match typescript-tslint-report-regexp
+                              to-match))
+         (matches (and match (get-all-matched-strings to-match))))
+    (should match)
+    (should (not (nth 1 matches)))
+    (should (not (nth 2 matches)))
+    (should (string-equal (nth 3 matches)
+                          "src/modules/authenticator.ts"))
+    (should (string-equal (nth 4 matches) "1"))
+    (should (string-equal (nth 5 matches) "83"))))
+
+(ert-deftest typescript-tslint-report-regexp-matches-with-warning ()
+  "typescript-tslint-report-regexp matches a line that has
+a severity set to WARNING, no rule name."
+  (let* ((to-match
+          "WARNING: src/modules/authenticator.ts[1, 83]: ' should be \"")
+         (match (string-match typescript-tslint-report-regexp
+                              to-match))
+         (matches (and match (get-all-matched-strings to-match))))
+    (should match)
+    (should (string-equal (nth 1 matches) "WARNING"))
+    (should (not (nth 2 matches)))
+    (should (string-equal (nth 3 matches)
+                          "src/modules/authenticator.ts"))
+    (should (string-equal (nth 4 matches) "1"))
+    (should (string-equal (nth 5 matches) "83"))))
+
 (provide 'typescript-mode-tests)
 
 ;;; typescript-mode-tests.el ends here
diff --git a/typescript-mode.el b/typescript-mode.el
index 5de10fb9a6..12c71a9897 100644
--- a/typescript-mode.el
+++ b/typescript-mode.el
@@ -2027,21 +2027,41 @@ the broken-down class name of the item to insert."
    "error [[:alnum:]]+: [^\r\n]+$")
   "Regexp to match errors generated by tsc.")
 
+;;
 ;; Should handle output like:
 ;; src/modules/authenticator.ts[1, 83]: ' should be "
-;; src/modules/authenticator.ts[2, 26]: ' should be "
-(defconst typescript-tslint-warning-regexp
+;; (quotemarks) src/modules/authenticator.ts[2, 26]: ' should be "
+;; ERROR: (quotemarks) src/modules/authenticator.ts[2, 26]: ' should be "
+;; WARNING: src/modules/authenticator.ts[2, 26]: ' should be "
+;;
+;; "(quotemarks)" it the rule name. It is produced when using the
+;; "verbose" formatter. The "verbose" formatter is identical to the
+;; default ("prose") formatter, except for the additional rule name.
+;;
+;; "ERROR:" and "WARNING:" are the severity. This was added in tslint
+;; 5.0. Prior versions have no notion of severity and simply omit this
+;; part.
+;;
+(defconst typescript-tslint-report-regexp
   (concat
    "^[[:blank:]]*"
-   "\\([^(\r\n)]+\\)" ;; filename
+   ;; severity ("type" in Emacs' parlance)
+   "\\(?:\\(?:ERROR\\|\\(WARNING\\)\\):[[:blank:]]+\\)?"
+   ;; rule name
+   "\\((.*)[[:blank:]]+\\)?"
+   ;; filename
+   "\\([^(\r\n)]+\\)"
    "\\["
-   "\\([[:digit:]]+\\)" ; line
+   ;; line
+   "\\([[:digit:]]+\\)"
    ", "
-   "\\([[:digit:]]+\\)" ; column
+   ;; column
+   "\\([[:digit:]]+\\)"
    "\\]: "
-   ".*$"    ;; type of warnings
+   ;; message
+   ".*$"
    )
-  "Regexp to match warnings generated by tslint.")
+  "Regexp to match reports generated by tslint.")
 
 (dolist
     (regexp
@@ -2050,8 +2070,8 @@ the broken-down class name of the item to insert."
         1 2 3 2)
 
        (typescript-tslint
-        ,typescript-tslint-warning-regexp
-        1 2 3 1)))
+        ,typescript-tslint-report-regexp
+        3 4 5 (1))))
   (add-to-list 'compilation-error-regexp-alist-alist regexp)
   (add-to-list 'compilation-error-regexp-alist (car regexp)))
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]