The SSH host key has changed on 8 April, 2022 to this one: SHA256:573uTBSeh74kvOo0HJXi5ijdzRm8me27suzNEDlGyrQ
My .emacs.d directory
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
3.5 KiB

;;; flycheck-swagger-tools --- Flycheck checker for swagger-tools.
;; Copyright (C) 2017 Marc-André Goyette
;; Author: Marc-André Goyette <>
;; URL:
;; Version: 0.1.0
;; Package-Requires: ((emacs "25"))
;; Keywords: swagger
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; GNU General Public License for more details.
;; For a full copy of the GNU General Public License
;; see <>.
;;; Commentary:
;; flycheck-swagger-tools provides a Flycheck checker for swagger-tools.
;; This allows to validate Swagger YAML and JSON files.
;; The checker can be activating by requiring this package.
;; (require 'flycheck-swagger-tools)
;; By default, only the first 4000 characters of a file are scanned to
;; find the swagger 2.0 element. To avoid stack overflow in Emacs
;; multi-line regex, this value is necessary. The defcustom
;; swagger-tools-predicate-regexp-match-limit can be used to change this
;; limit. That could be necessary for YAML files with long initial comments.
;;; Code:
(require 'flycheck)
(defgroup swagger-tools nil
"Validate swagger files with swagger-tools."
:group 'swagger
:prefix "swagger-tools-")
(defcustom swagger-tools-predicate-regexp-match-limit 4000
"Defines the number of characters that will be scanned at the beginning of a
buffer to find the swagger 2.0 element."
:type 'integer
:group 'swagger-tools)
(flycheck-define-checker swagger-tools
"A checker that uses swagger tools to validate Swagger2 JSON and YAML files.
See URL `'."
:command ("swagger-tools" "validate" source)
(lambda ()
;; Need to avoid stack overflow for multi-line regex
(buffer-substring 1 (min (buffer-size)
((warning line-start " " (message (one-or-more not-newline)
"is not used"
(one-or-more not-newline))
;; js-yaml error with position
(error line-start " error: " (message) " at line " line ", column " column ":" line-end)
;; js-yaml error without position
(error line-start " error: " (message) ": " (one-or-more not-newline) line-end)
;; swagger-tools error (always contain a # symbol in the message)
(error line-start
" "
(message (optional (one-or-more not-newline))
(one-or-more "#")
(one-or-more not-newline))
;; Add line number 1 if the error has no line number
(lambda (errors)
(let ((errors (flycheck-sanitize-errors errors)))
(dolist (err errors)
(unless (flycheck-error-line err)
(setf (flycheck-error-line err) 1)))
:modes (json-mode openapi-yaml-mode yaml-mode))
(add-to-list 'flycheck-checkers 'swagger-tools)
(provide 'flycheck-swagger-tools)
;;; flycheck-swagger-tools.el ends here