Skip to content

Commit

Permalink
Omit prettier --parser flag for named files (#175)
Browse files Browse the repository at this point in the history
Let `prettier` itself select the right parser for named files. It can
look at the file name extension to figure out which one to pick.
  • Loading branch information
lassik committed May 10, 2022
1 parent a07bf10 commit 828280e
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions format-all.el
Original file line number Diff line number Diff line change
Expand Up @@ -1027,17 +1027,21 @@ Consult the existing formatters for examples of BODY."
(:format
(format-all--buffer-easy
executable
"--parser" (let ((pair (assoc language
'(("_Angular" . "angular")
("_Flow" . "flow")
("JavaScript" . "babel")
("JSX" . "babel")
("Solidity" . "solidity-parse")
("TSX" . "typescript")))))
(if pair (cdr pair) (downcase language)))
(when (buffer-file-name) (list "--stdin-filepath" (buffer-file-name)))
(unless (buffer-file-name)
(list "--parser"
(let ((pair (assoc language
'(("_Angular" . "angular")
("_Flow" . "flow")
("JavaScript" . "babel")
("JSX" . "babel")
("Solidity" . "solidity-parse")
("TSX" . "typescript")))))
(if pair (cdr pair) (downcase language)))))
(when (buffer-file-name)
(list "--stdin-filepath" (buffer-file-name)))
(let ((ignore-file (format-all--locate-file ".prettierignore")))
(when ignore-file (list "--ignore-path" ignore-file)))
(when ignore-file
(list "--ignore-path" ignore-file)))
(when region
(list "--range-start" (number-to-string (1- (car region)))
"--range-end" (number-to-string (1- (cdr region))))))))
Expand Down

0 comments on commit 828280e

Please sign in to comment.