LoginSignup

This article is a Private article. Only a writer and users who know the URL can access it.
Please change open range to public in publish setting if you want to share this article with other users.

More than 3 years have passed since last update.

flycheckをカスタマイズする

Last updated at Posted at 2020-03-05

(defun our-django--get-project-root-directory ()
  "Djangoのprojectのrootディレクトリを取得する"
  (locate-dominating-file (or buffer-file-name default-directory)
              "manage.py"))


(defun our-django--get-project-root-directory-for-flyceck (checker)
  "Djangoのprojectのrootディレクトリを取得する"
  (our-django--get-project-root-directory))



(defun our-flycheck-parse-with-patterns (output checker buffer)
  (with-current-buffer (get-buffer-create "*SYMDON-FLYCHECK*")
    (erase-buffer)
    (insert output))
  (flycheck-parse-with-patterns output checker buffer))



(flycheck-define-checker symdon-django-test-checker
  "By Symdon"
  :command ("python" "manage.py" "test" "--verbosity" "3" "--keepdb" "invoy.api")
  :modes python-mode
  :working-directory our-django--get-project-root-directory-for-flyceck
  :predicate flycheck-buffer-saved-p
  :error-parser our-flycheck-parse-with-patterns
  :error-patterns
  ((error line-start (file-name) ":" line ":" column ": error: " (message)
      line-end)
   (warning line-start (file-name) ":" line ":" column ": warning: " (message)
        line-end)
   (info line-start (file-name) ":" line ":" column ": info: " (message)
     line-end)
   ))


(flycheck-define-checker symdon-django-test-checker
  "By Symdon"
  :command ("python" "manage.py" "test" "--verbosity" "3")
  :modes python-mode
  :working-directory our-django--get-project-root-directory-for-flyceck
  :error-patterns
  ((error line-start (file-name) ":" line ":" column ": error: " (message)
      line-end)
   (warning line-start (file-name) ":" line ":" column ": warning: " (message)
        line-end)
   (info line-start (file-name) ":" line ":" column ": info: " (message)
     line-end)
   ))
(require 'flycheck)


(flycheck-define-checker python-doctest
  "Run python doctest"
  :command ("python"
        "-c"
        (eval (format "import doctest; doctest.testfile('%s.py')" 
              (file-name-base buffer-file-name))))
  :error-patterns
  ((error line-start
      "File \"" (file-name) "\", line " line ", in " (submatch (* nonl)) line-end)
      )
  :modes python-mode)


0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up