-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(vendor/erb_lint): add work in progress erb_lint package
- Loading branch information
Showing
1 changed file
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |