Forráskód Böngészése

org-lint: Report invalid durations in effort properties

* lisp/org-lint.el (org-lint-invalid-effort-property): New checker.
* testing/lisp/test-org-lint.el (test-org-lint/invalid-effort-property):
New test.
Nicolas Goaziou 8 éve
szülő
commit
33b9c42395
2 módosított fájl, 24 hozzáadás és 0 törlés
  1. 15 0
      lisp/org-lint.el
  2. 9 0
      testing/lisp/test-org-lint.el

+ 15 - 0
lisp/org-lint.el

@@ -87,6 +87,7 @@
 ;;   - spurious macro arguments or invalid macro templates
 ;;   - special properties in properties drawer
 ;;   - obsolete syntax for PROPERTIES drawers
+;;   - Invalid EFFORT property value
 ;;   - missing definition for footnote references
 ;;   - missing reference for footnote definitions
 ;;   - non-footnote definitions in footnote section
@@ -239,6 +240,10 @@
     :name 'obsolete-properties-drawer
     :description "Report obsolete syntax for properties drawers"
     :categories '(obsolete properties))
+   (make-org-lint-checker
+    :name 'invalid-effort-property
+    :description "Report invalid duration in EFFORT property"
+    :categories '(properties))
    (make-org-lint-checker
     :name 'undefined-footnote-reference
     :description "Report missing definition for footnote references"
@@ -540,6 +545,16 @@ Use :header-args: instead"
 		      "Incorrect contents for PROPERTIES drawer"
 		    "Incorrect location for PROPERTIES drawer"))))))))
 
+(defun org-lint-invalid-effort-property (ast)
+  (org-element-map ast 'node-property
+    (lambda (p)
+      (when (equal "EFFORT" (org-element-property :key p))
+	(let ((value (org-element-property :value p)))
+	  (and (org-string-nw-p value)
+	       (not (org-duration-p value))
+	       (list (org-element-property :begin p)
+		     (format "Invalid effort duration format: %S" value))))))))
+
 (defun org-lint-link-to-local-file (ast)
   (org-element-map ast 'link
     (lambda (l)

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

@@ -221,6 +221,15 @@ This is not a node property
 :END:"
      (org-lint '(obsolete-properties-drawer)))))
 
+(ert-deftest test-org-lint/invalid-effort-property ()
+  "Test `org-lint-invalid-effort-property' checker."
+  (should
+   (org-test-with-temp-text "* H\n:PROPERTIES:\n:EFFORT: something\n:END:"
+     (org-lint '(invalid-effort-property))))
+  (should-not
+   (org-test-with-temp-text "* H\n:PROPERTIES:\n:EFFORT: 1:23\n:END:"
+     (org-lint '(invalid-effort-property)))))
+
 (ert-deftest test-org-lint/link-to-local-file ()
   "Test `org-lint-link-to-local-file' checker."
   (should