I'm trying to run my Emacs Lisp code on Code Coverage from jest with TypeScript and it fails because the file (/coverage/coverage-final.json) that I use to read coverage that has an invalid (according to my code) data.
This is my code to be complete:
(defun jc/mark-buffer-jest ()
(interactive)
(message "jc/mark-buffer-jest")
(let* ((dir (jc/root-git-repo))
(json-object-type 'hash-table)
(json-array-type 'list)
(json-key-type 'string)
(coverage-fname (concat dir "/coverage/coverage-final.json")))
(if (not (file-exists-p coverage-fname))
(message "file coverage not found")
(let* ((json (json-read-file coverage-fname))
(filename (jc/real-filename (buffer-file-name (current-buffer))))
(coverage (gethash filename json)))
(if (not (hash-table-p coverage))
(message "No coverage found for this file")
(let ((statments (gethash "statementMap" coverage)))
(save-excursion
(let ((coverage-list (gethash "s" coverage))
(covered 0)
(not-covered 0))
(maphash (lambda (key value)
(if (not (and jc/statements (= (gethash key jc/statements) value)))
(let* ((statment (gethash key statments))
(start (gethash "start" statment))
(end (gethash "end" statment))
(start-line-pos (jc/line-pos-at-line (gethash "line" start)))
(start-pos (+ start-line-pos (gethash "column" start)))
(end-line-pos (jc/line-pos-at-line (gethash "line" end)))
(end-pos (+ end-line-pos (gethash "column" end)))
(face (if (= value 0)
'jc/not-covered
'jc/covered)))
(message "[%s:%s] %s:%s -> [%s:%s] %s:%s"
(gethash "line" start)
(gethash "column" start)
start-line-pos start-pos
(gethash "line" end)
(gethash "column" end)
end-line-pos end-pos)
(hlt-highlight-region start-pos end-pos face)))
(if (= value 0)
(setq not-covered (+ 1 not-covered))
(setq covered (+ 1 covered))))
coverage-list)
(message "%3.2f%% coverage" (* (/ (float covered) (+ covered not-covered)) 100))
(setq jc/statements coverage-list)))))))))
It throw an error:
(wrong-type-argument number-or-marker-p nil)
In this line:
(end-pos (+ end-line-pos (gethash "column" end)))
The reason for this is that some of the statements look like this:
"24":{"start":{"line":70,"column":4},"end":{"line":72,"column":null}}
What does it mean that column is null? Is the content of this JSON documented somewhere? I run my code on a TypeScript file with ts-jest.