Skip to content

Commit

Permalink
chore(vendor/erb_lint): add work in progress erb_lint package
Browse files Browse the repository at this point in the history
  • Loading branch information
jimehk committed Oct 18, 2024
1 parent 3cae3d9 commit 02842d3
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions vendor/erb-format/erb-format.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
;;; erb-format.el --- Format files with erb-format.

;; Copyright (C) 2024 Jim Myhrberg

;; Author: Jim Myhrberg <[email protected]>
;; Keywords: formatting, tools
;; Package-Requires: ((emacs "25.1") (reformatter "0.6"))
;; Package-Version: 0.0.1

;;; Commentary:

;; This package provides a simple way to format ERB files using erb_lint.

;;; Code:

(require 'reformatter)

(defgroup erb-format nil
"Format buffers with erb-format."
:group 'tools)

(defcustom erb-format-executable "erb_lint"
"Name/path of the erb-format executable."
:group 'erb-format
:type 'string)

(defcustom erb-format-config-filename ".erb-lint.yml"
"Name/path of the erb-format executable."
:group 'erb-format
:type 'string)

(defcustom erb-format-extra-args nil
"Extra arguments to pass to erblint."
:group 'erb-format
:type '(repeat string))
(make-variable-buffer-local 'erb-format-extra-args)


(defun erb-format--config-file-dir ()
"Return the directory where the .erb-lint.yml config file is found, or nil."
(when buffer-file-name
(locate-dominating-file buffer-file-name erb-format-config-filename)))

(defun erb-format--config-file ()
"Return the path of the .erb-lint.yml config file, or nil."
(when buffer-file-name
(let ((dir (erb-format--config-file-dir)))
(if dir
(expand-file-name erb-format-config-filename dir)))))

;;;###autoload (autoload 'erb-format-buffer "erb-format" nil t)
;;;###autoload (autoload 'erb-format-region "erb-format" nil t)
;;;###autoload (autoload 'erb-format-on-save-mode "erb-format" nil t)
(reformatter-define erb-format
:program erb-format-executable
:args (let ((config-file (erb-format--config-file)))
(append
(when config-file `("--config" ,config-file))
`("--autocorrect" ,input-file)
erb-format-extra-args))
:stdin nil
:lighter " fmt"
:group 'erb-format
:working-directory (erb-format--config-file-dir)) ; Use the directory where config is found.

(provide 'erb-format)

;;; erb-format.el ends here

0 comments on commit 02842d3

Please sign in to comment.