From 02842d3b6fcf7ba62705ff10f6c159802e7c9a0b Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Fri, 18 Oct 2024 13:11:57 +0100 Subject: [PATCH] chore(vendor/erb_lint): add work in progress erb_lint package --- vendor/erb-format/erb-format.el | 68 +++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 vendor/erb-format/erb-format.el diff --git a/vendor/erb-format/erb-format.el b/vendor/erb-format/erb-format.el new file mode 100644 index 0000000..01872bf --- /dev/null +++ b/vendor/erb-format/erb-format.el @@ -0,0 +1,68 @@ +;;; erb-format.el --- Format files with erb-format. + +;; Copyright (C) 2024 Jim Myhrberg + +;; Author: Jim Myhrberg +;; 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