TIL: Flycheck can explain errorsAlong the usual story arc of programming, I wrote a bunch of code b…
انتشار: 2026/07/01 16:07 UTC
TIL: Flycheck can explain errorsAlong the usual story arc of programming, I wrote a bunch of code before realising someone had already done it in a much nicer way.In this particular case Rubocop, Ruby's favourite linter, has a huge number of cops (rules) but I always need to open a tab, search the error identifier and find the online documentation when I stumble upon an unknown rule that cannot be solely understood with the error message.Turns out that Flycheck checkers can define an :error-explainer function to be ran when flycheck-explain-error-at-point (C-c ! e) is used on a faulty line.Look at this:(defun spm--lookup-rubocop-doc (err) (let ((str (flycheck-error-id err))) (when (string-match "\\]\\s-*\\(.*\\)\\'" str) (let* ((identifiers (split-string (match-string 1 str) "/")) (department (car identifiers)) (identifier (cadr identifiers))) (browse-url (format "docs.rubocop.org/rubocop/latest/cops_%s.h… (downcase department) (downcase department) (downcase identifier)))))))(setf (flycheck-checker-get 'ruby-rubocop 'error-explainer) 'spm--lookup-rubocop-doc)And now I can get exactly there in one keystroke. I'm absoluytely overwhelmed with joy.Have a good day everyoneredd.it/1ukoy32@r_emacs