From 7639b755c2cace9ff4134dc8d3e58c7912681ee9 Mon Sep 17 00:00:00 2001 From: James Long Date: Mon, 9 Jan 2017 22:48:56 -0500 Subject: [PATCH] More renaming of jscodefmt -> prettier --- README.md | 2 +- .../emacs/{jscodefmt.el => prettier-js.el} | 78 +++++++++---------- editors/jscodefmt-atom/README.md | 65 ---------------- .../CHANGELOG.md | 0 .../LICENSE.md | 0 editors/prettier-atom/README.md | 23 ++++++ .../keymaps/standard-formatter.json | 0 .../lib/jscodefmt.js | 0 .../menus/standard-formatter.json | 0 .../package.json | 0 10 files changed, 63 insertions(+), 105 deletions(-) rename editors/emacs/{jscodefmt.el => prettier-js.el} (77%) delete mode 100644 editors/jscodefmt-atom/README.md rename editors/{jscodefmt-atom => prettier-atom}/CHANGELOG.md (100%) rename editors/{jscodefmt-atom => prettier-atom}/LICENSE.md (100%) create mode 100644 editors/prettier-atom/README.md rename editors/{jscodefmt-atom => prettier-atom}/keymaps/standard-formatter.json (100%) rename editors/{jscodefmt-atom => prettier-atom}/lib/jscodefmt.js (100%) rename editors/{jscodefmt-atom => prettier-atom}/menus/standard-formatter.json (100%) rename editors/{jscodefmt-atom => prettier-atom}/package.json (100%) diff --git a/README.md b/README.md index d25e35cd0..49e069178 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# jscodefmt +# prettier This is a JavaScript pretty-printer that is opinionated. All it takes is a width to format the code to and it does the rest. Zero config: it diff --git a/editors/emacs/jscodefmt.el b/editors/emacs/prettier-js.el similarity index 77% rename from editors/emacs/jscodefmt.el rename to editors/emacs/prettier-js.el index 74a462c3a..811ce4cc8 100644 --- a/editors/emacs/jscodefmt.el +++ b/editors/emacs/prettier-js.el @@ -1,4 +1,4 @@ -;;; jscodefmt.el --- utility functions to format reason code +;;; prettier.el --- utility functions to format reason code ;; Copyright (c) 2014 The go-mode Authors. All rights reserved. ;; Portions Copyright (c) 2015-present, Facebook, Inc. All rights reserved. @@ -34,12 +34,12 @@ ;;; Code: -(defcustom jscodefmt-command "jscodefmt" - "The 'jscodefmt' command." +(defcustom prettier-command "prettier" + "The 'prettier' command." :type 'string - :group 'jscodefmt) + :group 'prettier) -(defcustom jscodefmt-show-errors 'buffer +(defcustom prettier-show-errors 'buffer "Where to display refmt error output. It can either be displayed in its own buffer, in the echo area, or not at all. Please note that Emacs outputs to the echo area when writing @@ -49,28 +49,28 @@ a `before-save-hook'." (const :tag "Own buffer" buffer) (const :tag "Echo area" echo) (const :tag "None" nil)) - :group 'jscodefmt) + :group 'prettier) -(defcustom jscodefmt-width-mode nil +(defcustom prettier-width-mode nil "Specify width when formatting buffer contents." :type '(choice (const :tag "Window width" window) (const :tag "Fill column" fill) (const :tag "None" nil)) - :group 'jscodefmt) + :group 'prettier) ;;;###autoload -(defun jscodefmt-before-save () +(defun prettier-before-save () "Add this to .emacs to run refmt on the current buffer when saving: (add-hook 'before-save-hook 'refmt-before-save)." (interactive) - (when (eq major-mode 'js-mode) (jscodefmt))) + (when (eq major-mode 'js-mode) (prettier))) -(defun jscodefmt--goto-line (line) +(defun prettier--goto-line (line) (goto-char (point-min)) (forward-line (1- line))) -(defun jscodefmt--delete-whole-line (&optional arg) +(defun prettier--delete-whole-line (&optional arg) "Delete the current line without putting it in the `kill-ring'. Derived from function `kill-whole-line'. ARG is defined as for that function." @@ -96,7 +96,7 @@ function." (delete-region (progn (forward-visible-line 0) (point)) (progn (forward-visible-line arg) (point)))))) -(defun jscodefmt--apply-rcs-patch (patch-buffer) +(defun prettier--apply-rcs-patch (patch-buffer) "Apply an RCS-formatted diff from PATCH-BUFFER to the current buffer." (let ((target-buffer (current-buffer)) ;; Relative offset between buffer line numbers and line numbers @@ -115,7 +115,7 @@ function." (goto-char (point-min)) (while (not (eobp)) (unless (looking-at "^\\([ad]\\)\\([0-9]+\\) \\([0-9]+\\)") - (error "invalid rcs patch or internal error in jscodefmt--apply-rcs-patch")) + (error "invalid rcs patch or internal error in prettier--apply-rcs-patch")) (forward-line) (let ((action (match-string 1)) (from (string-to-number (match-string 2))) @@ -132,28 +132,28 @@ function." (insert text))))) ((equal action "d") (with-current-buffer target-buffer - (jscodefmt--goto-line (- from line-offset)) + (prettier--goto-line (- from line-offset)) (incf line-offset len) - (jscodefmt--delete-whole-line len))) + (prettier--delete-whole-line len))) (t - (error "invalid rcs patch or internal error in jscodefmt--apply-rcs-patch"))))))))) + (error "invalid rcs patch or internal error in prettier--apply-rcs-patch"))))))))) -(defun jscodefmt--process-errors (filename tmpfile errorfile errbuf) +(defun prettier--process-errors (filename tmpfile errorfile errbuf) (with-current-buffer errbuf - (if (eq jscodefmt-show-errors 'echo) + (if (eq prettier-show-errors 'echo) (progn (message "%s" (buffer-string)) - (jscodefmt--kill-error-buffer errbuf)) + (prettier--kill-error-buffer errbuf)) (insert-file-contents errorfile nil nil nil) ;; Convert the refmt stderr to something understood by the compilation mode. (goto-char (point-min)) - (insert "jscodefmt errors:\n") + (insert "prettier errors:\n") (while (search-forward-regexp (regexp-quote tmpfile) nil t) (replace-match (file-name-nondirectory filename))) (compilation-mode) (display-buffer errbuf)))) -(defun jscodefmt--kill-error-buffer (errbuf) +(defun prettier--kill-error-buffer (errbuf) (let ((win (get-buffer-window errbuf))) (if win (quit-window t win) @@ -161,22 +161,22 @@ function." (erase-buffer)) (kill-buffer errbuf)))) -(defun jscodefmt () - "Format the current buffer according to the jscodefmt tool." +(defun prettier () + "Format the current buffer according to the prettier tool." (interactive) (let* ((ext (file-name-extension buffer-file-name t)) - (bufferfile (make-temp-file "jscodefmt" nil ext)) - (outputfile (make-temp-file "jscodefmt" nil ext)) - (errorfile (make-temp-file "jscodefmt" nil ext)) - (errbuf (if jscodefmt-show-errors (get-buffer-create "*jscodefmt errors*"))) - (patchbuf (get-buffer-create "*jscodefmt patch*")) + (bufferfile (make-temp-file "prettier" nil ext)) + (outputfile (make-temp-file "prettier" nil ext)) + (errorfile (make-temp-file "prettier" nil ext)) + (errbuf (if prettier-show-errors (get-buffer-create "*prettier errors*"))) + (patchbuf (get-buffer-create "*prettier patch*")) (coding-system-for-read 'utf-8) (coding-system-for-write 'utf-8) (width-args (cond - ((equal jscodefmt-width-mode 'window) + ((equal prettier-width-mode 'window) (list "--width" (number-to-string (window-body-width)))) - ((equal jscodefmt-width-mode 'fill) + ((equal prettier-width-mode 'fill) (list "--width" (number-to-string fill-column))) (t '())))) @@ -191,24 +191,24 @@ function." (with-current-buffer patchbuf (erase-buffer)) (if (zerop (apply 'call-process - jscodefmt-command nil (list (list :file outputfile) errorfile) + prettier-command nil (list (list :file outputfile) errorfile) nil (append width-args (list bufferfile)))) (progn (call-process-region (point-min) (point-max) "diff" nil patchbuf nil "-n" "-" outputfile) - (jscodefmt--apply-rcs-patch patchbuf) - (message "Applied jscodefmt") - (if errbuf (jscodefmt--kill-error-buffer errbuf))) - (message "Could not apply jscodefmt") + (prettier--apply-rcs-patch patchbuf) + (message "Applied prettier") + (if errbuf (prettier--kill-error-buffer errbuf))) + (message "Could not apply prettier") (if errbuf - (jscodefmt--process-errors (buffer-file-name) bufferfile errorfile errbuf)) + (prettier--process-errors (buffer-file-name) bufferfile errorfile errbuf)) ))) (kill-buffer patchbuf) (delete-file errorfile) (delete-file bufferfile) (delete-file outputfile))) -(provide 'jscodefmt) +(provide 'prettier) -;;; jscodefmt.el ends here +;;; prettier.el ends here diff --git a/editors/jscodefmt-atom/README.md b/editors/jscodefmt-atom/README.md deleted file mode 100644 index 0020b7e57..000000000 --- a/editors/jscodefmt-atom/README.md +++ /dev/null @@ -1,65 +0,0 @@ -# atom-standard-formatter - -Atom package to format your Javascript using [Standard Style](https://github.com/feross/standard) -, [Semi-Standard Style](https://github.com/Flet/semistandard) -or [Happiness Style](https://github.com/jedwatson/happiness). - -![](https://cloud.githubusercontent.com/assets/5852428/8020717/adbf10c0-0c51-11e5-8537-2714c9f698e5.gif) - -### Usage - -#### Keybindings - -Use `ctrl-alt-f` to format the current Javascript file. If a text selection is made, only the selected text will be formatted. - -#### Format On Save - -Automatically format your Javascript file on save by enabling the *Format On Save* package setting. This is off by default. - -#### Menu - -*Packages > standard-formatter > Format* - -### Settings - -#### formatOnSave (default: false) - -Format Javascript files when saving. - -#### checkStyleDevDependencies (default: false) - -Check code style in package.json `devDependencies`. If a valid style is not found it won't format. - -| Note: This will use the nearest package.json - -#### style (default: standard) - -Choose the style formatter module you want to use. If `checkStyleDevDependencies` is `true` this setting will be ignored. - -* [standard](https://github.com/feross/standard) - equivalent to running `standard --fix` -* [standard-format](https://github.com/maxogden/standard-format) -* [semistandard-format](https://github.com/ricardofbarros/semistandard-format) -* [happiness-format](https://github.com/martinheidegger/hapiness-format) - -#### honorPackageConfig (default: true) - -Don't auto-format files included in the package.json's `"ignore"` configuration for the detected style. - -| Note: This will use the nearest package.json - -### A note on formatting - -This package relies on the excellent work from the following modules to perform formatting: - -- [standard](https://github.com/feross/standard) -- [standard-format](https://github.com/maxogden/standard-format) -- [semistandard-format](https://github.com/ricardofbarros/semistandard-format) -- [happiness-format](https://github.com/martinheidegger/hapiness-format) - -If parts of your Javascript are not being formatted as you'd expect, is is likely an issue with one of these modules and not this Atom package. To verify this, you can try to format your file directly using the above modules and examine the output. - -For example, to format `my-file.js` and output to stdout: -``` -$ npm install -g standard-format -$ standard-format my-file.js -``` diff --git a/editors/jscodefmt-atom/CHANGELOG.md b/editors/prettier-atom/CHANGELOG.md similarity index 100% rename from editors/jscodefmt-atom/CHANGELOG.md rename to editors/prettier-atom/CHANGELOG.md diff --git a/editors/jscodefmt-atom/LICENSE.md b/editors/prettier-atom/LICENSE.md similarity index 100% rename from editors/jscodefmt-atom/LICENSE.md rename to editors/prettier-atom/LICENSE.md diff --git a/editors/prettier-atom/README.md b/editors/prettier-atom/README.md new file mode 100644 index 000000000..e994bcaa1 --- /dev/null +++ b/editors/prettier-atom/README.md @@ -0,0 +1,23 @@ +# Prettier formatter for Atom + +Atom package to format your Javascript using [Prettier](https://github.com/jlongster/prettier). + +### Usage + +#### Keybindings + +Use `ctrl-alt-f` to format the current Javascript file. If a text selection is made, only the selected text will be formatted. + +#### Format On Save + +Automatically format your Javascript file on save by enabling the *Format On Save* package setting. This is off by default. + +#### Menu + +*Packages > standard-formatter > Format* + +### Settings + +#### formatOnSave (default: false) + +Format Javascript files when saving. diff --git a/editors/jscodefmt-atom/keymaps/standard-formatter.json b/editors/prettier-atom/keymaps/standard-formatter.json similarity index 100% rename from editors/jscodefmt-atom/keymaps/standard-formatter.json rename to editors/prettier-atom/keymaps/standard-formatter.json diff --git a/editors/jscodefmt-atom/lib/jscodefmt.js b/editors/prettier-atom/lib/jscodefmt.js similarity index 100% rename from editors/jscodefmt-atom/lib/jscodefmt.js rename to editors/prettier-atom/lib/jscodefmt.js diff --git a/editors/jscodefmt-atom/menus/standard-formatter.json b/editors/prettier-atom/menus/standard-formatter.json similarity index 100% rename from editors/jscodefmt-atom/menus/standard-formatter.json rename to editors/prettier-atom/menus/standard-formatter.json diff --git a/editors/jscodefmt-atom/package.json b/editors/prettier-atom/package.json similarity index 100% rename from editors/jscodefmt-atom/package.json rename to editors/prettier-atom/package.json