Browse Source

org-lint: Add checker for spurious colons in tags

* lisp/org-lint.el (org-lint--checkers): Add checker.
(org-lint-spurious-colons): New function.
* testing/lisp/test-org-lint.el (test-org/spurious-colons): New test.
Nicolas Goaziou 2 years ago
parent
commit
c46fcd9874
2 changed files with 24 additions and 1 deletions
  1. 12 1
      lisp/org-lint.el
  2. 12 0
      testing/lisp/test-org-lint.el

+ 12 - 1
lisp/org-lint.el

@@ -100,6 +100,7 @@
 ;;   - indented diary-sexps
 ;;   - obsolete QUOTE section
 ;;   - obsolete "file+application" link
+;;   - spurious colons in tags
 
 
 ;;; Code:
@@ -285,7 +286,10 @@
    (make-org-lint-checker
     :name 'file-application
     :description "Report obsolete \"file+application\" link"
-    :categories '(link obsolete)))
+    :categories '(link obsolete))
+   (make-org-lint-checker
+    :name 'spurious-colons
+    :description "Report spurious colons in tags"))
   "List of all available checkers.")
 
 (defun org-lint--collect-duplicates
@@ -1031,6 +1035,13 @@ Use \"export %s\" instead"
 			   reports))))))))))))
     reports))
 
+(defun org-lint-spurious-colons (ast)
+  (org-element-map ast '(headline inlinetask)
+    (lambda (h)
+      (when (member "" (org-element-property :tags h))
+	(list (org-element-property :begin h)
+	      "Tags contain a spurious colon")))))
+
 
 
 ;;; Reports UI

+ 12 - 0
testing/lisp/test-org-lint.el

@@ -487,6 +487,18 @@ SCHEDULED: <2012-03-29 thu.>"
 #+end_src"
      (org-lint '(wrong-header-value)))))
 
+(ert-deftest test-org/spurious-colons ()
+  "Test `org-list-spurious-colons' checker."
+  (should-not
+   (org-test-with-temp-text "* H :tag:tag2:"
+     (org-lint '(spurious-colons))))
+  (should
+   (org-test-with-temp-text "* H :tag::tag2:"
+     (org-lint '(spurious-colons))))
+  (should
+   (org-test-with-temp-text "* H :tag::"
+     (org-lint '(spurious-colons)))))
+
 
 (provide 'test-org-lint)
 ;;; test-org-lint.el ends here