[#103] Specify --parser in Prettier (#107)

Closes #103
This commit is contained in:
Radon Rosborough 2022-09-10 17:24:54 -07:00 committed by GitHub
parent 8ff45766fa
commit 46d373f4bd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
52 changed files with 231 additions and 108 deletions

View file

@ -11,6 +11,10 @@ The format is based on [Keep a Changelog].
* Buffer content is now always passed to formatters using a pipe. This
fixes issues with formatters that behave differently when receiving
input on stdin versus being run on a tty ([#119]).
* Prettier now specifies `--parser` argument explicitly, so it will
work properly even when the name of the file does not match what
Prettier expects (e.g. `.yamllint` will be formatted as YAML by
Prettier as long as it is in `yaml-mode`). See [#103].
### Bugs fixed
* When a formatter has a bug and fails to return anything on stdout
@ -29,10 +33,17 @@ The format is based on [Keep a Changelog].
* [stylua](https://github.com/JohnnyMorganz/StyLua) for Lua ([#105]).
* Native Emacs indentation of Emacs Lisp code as a formatter ([#102]).
### Bugfixes
* Prettier supports SCSS instead of SASS. The original support for
SASS in Apheleia was a bug because Prettier actually never had
support for SASS in the first place, so Apheleia would have failed
anyway on trying to format a SASS file.
[#43]: https://github.com/radian-software/apheleia/issues/43
[#100]: https://github.com/radian-software/apheleia/pull/100
[#101]: https://github.com/radian-software/apheleia/pull/101
[#102]: https://github.com/radian-software/apheleia/pull/102
[#103]: https://github.com/radian-software/apheleia/issues/103
[#105]: https://github.com/radian-software/apheleia/pull/105
[#109]: https://github.com/radian-software/apheleia/issues/109
[#110]: https://github.com/radian-software/apheleia/pull/110

View file

@ -940,6 +940,26 @@ being run, for diagnostic purposes."
"--enable-outside-detected-project"))
(phpcs . ("apheleia-phpcs"))
(prettier . (npx "prettier" "--stdin-filepath" filepath))
(prettier-css
. (npx "prettier" "--stdin-filepath" filepath "--parser=css"))
(prettier-html
. (npx "prettier" "--stdin-filepath" filepath "--parser=html"))
(prettier-graphql
. (npx "prettier" "--stdin-filepath" filepath "--parser=graphql"))
(prettier-javascript
. (npx "prettier" "--stdin-filepath" filepath "--parser=babel-flow"))
(prettier-json
. (npx "prettier" "--stdin-filepath" filepath "--parser=json"))
(prettier-markdown
. (npx "prettier" "--stdin-filepath" filepath "--parser=markdown"))
(prettier-ruby
. (npx "prettier" "--stdin-filepath" filepath "--parser=ruby"))
(prettier-scss
. (npx "prettier" "--stdin-filepath" filepath "--parser=scss"))
(prettier-typescript
. (npx "prettier" "--stdin-filepath" filepath "--parser=typescript"))
(prettier-yaml
. (npx "prettier" "--stdin-filepath" filepath "--parser=yaml"))
(shfmt . ("shfmt" "-i" "4"))
(stylua . ("stylua" "-"))
(rustfmt . ("rustfmt" "--quiet" "--emit" "stdout"))
@ -1073,25 +1093,27 @@ function: %s" command)))
(defcustom apheleia-mode-alist
'(;; php-mode has to come before cc-mode
(php-mode . phpcs)
;; rest are alphabetical
(beancount-mode . bean-format)
(cc-mode . clang-format)
(c-mode . clang-format)
(c++-mode . clang-format)
(caml-mode . ocamlformat)
(common-lisp-mode . lisp-indent)
(css-mode . prettier)
(css-mode . prettier-css)
(dart-mode . dart-format)
(emacs-lisp-mode . lisp-indent)
(elixir-mode . mix-format)
(elm-mode . elm-format)
(fish-mode . fish-indent)
(go-mode . gofmt)
(graphql-mode . prettier-graphql)
(haskell-mode . brittany)
(html-mode . prettier)
(html-mode . prettier-html)
(java-mode . google-java-format)
(js3-mode . prettier)
(js-mode . prettier)
(json-mode . prettier)
(js3-mode . prettier-javascript)
(js-mode . prettier-javascript)
(json-mode . prettier-json)
(kotlin-mode . ktlint)
(latex-mode . latexindent)
(LaTeX-mode . latexindent)
@ -1099,18 +1121,18 @@ function: %s" command)))
(lisp-mode . lisp-indent)
(nix-mode . nixfmt)
(python-mode . black)
(ruby-mode . prettier)
(ruby-mode . prettier-ruby)
(rustic-mode . rustfmt)
(rust-mode . rustfmt)
(sass-mode . prettier)
(scss-mode . prettier-scss)
(sh-mode . shfmt)
(terraform-mode . terraform)
(TeX-latex-mode . latexindent)
(TeX-mode . latexindent)
(tuareg-mode . ocamlformat)
(typescript-mode . prettier)
(typescript-mode . prettier-typescript)
(web-mode . prettier)
(yaml-mode . prettier))
(yaml-mode . prettier-yaml))
"Alist mapping major mode names to formatters to use in those modes.
This determines what formatter to use in buffers without a
setting for `apheleia-formatter'. The keys are major mode

View file

@ -0,0 +1 @@
prettier.bash

View file

@ -0,0 +1 @@
prettier.bash

View file

@ -0,0 +1 @@
prettier.bash

View file

@ -0,0 +1 @@
prettier.bash

View file

@ -0,0 +1 @@
prettier.bash

View file

@ -0,0 +1 @@
prettier.bash

View file

@ -0,0 +1,15 @@
# Need ruby for gem, need gcc and ruby headers for native gem deps
apt-get install -y ruby ruby-dev gcc
# Install the plugin
npm install -g prettier @prettier/plugin-ruby
# Have to install from source because release not tagged yet
# https://github.com/ruby-syntax-tree/syntax_tree-rbs/pull/34
# https://stackoverflow.com/a/11767563
gem install specific_install
gem specific_install -l https://github.com/ruby-syntax-tree/syntax_tree-rbs.git
# These are required dependencies documented at
# https://www.npmjs.com/package/@prettier/plugin-ruby
gem install prettier_print syntax_tree syntax_tree-haml syntax_tree-rbs

View file

@ -0,0 +1 @@
prettier.bash

View file

@ -0,0 +1 @@
prettier.bash

View file

@ -0,0 +1 @@
prettier.bash

View file

@ -0,0 +1,13 @@
body
{
padding-left : 11em;
font-family
: Georgia,
"Times New Roman",
Times, serif;
color: purple;
background-color:
#d8da3d
}

View file

@ -0,0 +1,6 @@
body {
padding-left: 11em;
font-family: Georgia, "Times New Roman", Times, serif;
color: purple;
background-color: #d8da3d;
}

View file

@ -0,0 +1 @@
{human(id: "1000") {name height(unit: FOOT)}}

View file

@ -0,0 +1,6 @@
{
human(id: "1000") {
name
height(unit: FOOT)
}
}

View file

@ -0,0 +1 @@
<h2>Minify <abbr title="HyperText Markup Language">HTML</abbr> and any <abbr title="Cascading Style Sheets">CSS</abbr> or <abbr title="JavaScript">JS</abbr> included in your markup</h2>

View file

@ -0,0 +1,5 @@
<h2>
Minify <abbr title="HyperText Markup Language">HTML</abbr> and any
<abbr title="Cascading Style Sheets">CSS</abbr> or
<abbr title="JavaScript">JS</abbr> included in your markup
</h2>

View file

@ -0,0 +1,4 @@
function HelloWorld({greeting = "hello", greeted = '"World"', silent = false, onMouseOver,}) {
if(!greeting){return null};
}

View file

@ -0,0 +1,10 @@
function HelloWorld({
greeting = "hello",
greeted = '"World"',
silent = false,
onMouseOver,
}) {
if (!greeting) {
return null;
}
}

View file

@ -0,0 +1 @@
{"arrowParens":"always","bracketSpacing":true,"embeddedLanguageFormatting":"auto","htmlWhitespaceSensitivity":"css","insertPragma":false,"jsxBracketSameLine":false,"jsxSingleQuote":false,"printWidth":80,"proseWrap":"preserve","quoteProps":"as-needed","requirePragma":false,"semi":true,"singleQuote":false,"tabWidth":2,"trailingComma":"es5","useTabs":false,"vueIndentScriptAndStyle":false}

View file

@ -0,0 +1,19 @@
{
"arrowParens": "always",
"bracketSpacing": true,
"embeddedLanguageFormatting": "auto",
"htmlWhitespaceSensitivity": "css",
"insertPragma": false,
"jsxBracketSameLine": false,
"jsxSingleQuote": false,
"printWidth": 80,
"proseWrap": "preserve",
"quoteProps": "as-needed",
"requirePragma": false,
"semi": true,
"singleQuote": false,
"tabWidth": 2,
"trailingComma": "es5",
"useTabs": false,
"vueIndentScriptAndStyle": false
}

View file

@ -0,0 +1,4 @@
|col1|col 2|
|-|-|
|nice|fits|
|oh no!|it's ugly!|

View file

@ -0,0 +1,4 @@
| col1 | col 2 |
| ------ | ---------- |
| nice | fits |
| oh no! | it's ugly! |

View file

@ -0,0 +1,13 @@
d=[30644250780,9003106878,
30636278846,66641217692,4501790980,
671_24_603036,131_61973916,66_606629_920,
30642677916,30643069058];a,s=[],$*[0]
s.each_byte{|b|a<<("%036b"%d[b.
chr.to_i]).scan(/\d{6}/)}
a.transpose.each{ |a|
a.join.each_byte{\
|i|print i==49?\
($*[1]||"#")\
:32.chr}
puts
}

View file

@ -0,0 +1,18 @@
d = [
30_644_250_780,
9_003_106_878,
30_636_278_846,
66_641_217_692,
4_501_790_980,
671_24_603036,
131_61973916,
66_606629_920,
30_642_677_916,
30_643_069_058
]
a, s = [], $*[0]
s.each_byte { |b| a << ("%036b" % d[b.chr.to_i]).scan(/\d{6}/) }
a.transpose.each do |a|
a.join.each_byte { |i| print i == 49 ? ($*[1] || "#") : 32.chr }
puts
end

View file

@ -0,0 +1 @@
/* Define standard variables and values for website */$bgcolor: lightblue;$textcolor: darkblue;$fontsize: 18px;/* Use the variables */body{background-color: $bgcolor; color: $textcolor; font-size: $fontsize;}

View file

@ -0,0 +1,9 @@
/* Define standard variables and values for website */
$bgcolor: lightblue;
$textcolor: darkblue;
$fontsize: 18px; /* Use the variables */
body {
background-color: $bgcolor;
color: $textcolor;
font-size: $fontsize;
}

View file

@ -0,0 +1 @@
interface GreetingSettings{greeting: string; duration?: number; color?: string;}declare function greet(setting: GreetingSettings): void;

View file

@ -0,0 +1,6 @@
interface GreetingSettings {
greeting: string;
duration?: number;
color?: string;
}
declare function greet(setting: GreetingSettings): void;

View file

@ -0,0 +1 @@
in.yml

View file

@ -0,0 +1,13 @@
---
- hosts:
all
tasks:
- name:
Get software for apt repository management.
apt:
state: present
name:
- python3-pycurl

View file

@ -0,0 +1 @@
out.yml

View file

@ -0,0 +1,10 @@
---
- hosts: all
tasks:
- name: Get software for apt repository management.
apt:
state: present
name:
- python3-pycurl

View file

@ -1,13 +0,0 @@
body
{
padding-left : 11em;
font-family
: Georgia,
"Times New Roman",
Times, serif;
color: purple;
background-color:
#d8da3d
}

View file

@ -0,0 +1 @@
../prettier-css/in.css

View file

@ -0,0 +1 @@
../prettier-graphql/in.graphql

View file

@ -1 +0,0 @@
<h2>Minify <abbr title="HyperText Markup Language">HTML</abbr> and any <abbr title="Cascading Style Sheets">CSS</abbr> or <abbr title="JavaScript">JS</abbr> included in your markup</h2>

View file

@ -0,0 +1 @@
../prettier-html/in.html

View file

@ -1,4 +0,0 @@
function HelloWorld({greeting = "hello", greeted = '"World"', silent = false, onMouseOver,}) {
if(!greeting){return null};
}

View file

@ -0,0 +1 @@
../prettier-javascript/in.js

View file

@ -1 +0,0 @@
{"arrowParens":"always","bracketSpacing":true,"embeddedLanguageFormatting":"auto","htmlWhitespaceSensitivity":"css","insertPragma":false,"jsxBracketSameLine":false,"jsxSingleQuote":false,"printWidth":80,"proseWrap":"preserve","quoteProps":"as-needed","requirePragma":false,"semi":true,"singleQuote":false,"tabWidth":2,"trailingComma":"es5","useTabs":false,"vueIndentScriptAndStyle":false}

View file

@ -0,0 +1 @@
../prettier-json/in.json

View file

@ -0,0 +1 @@
../prettier-markdown/in.md

View file

@ -1 +0,0 @@
/* Define standard variables and values for website */$bgcolor: lightblue;$textcolor: darkblue;$fontsize: 18px;/* Use the variables */body{background-color: $bgcolor; color: $textcolor; font-size: $fontsize;}

View file

@ -0,0 +1 @@
../prettier-scss/in.scss

View file

@ -1 +0,0 @@
interface GreetingSettings{greeting: string; duration?: number; color?: string;}declare function greet(setting: GreetingSettings): void;

View file

@ -0,0 +1 @@
../prettier-typescript/in.ts

View file

@ -1,13 +0,0 @@
---
- hosts:
all
tasks:
- name:
Get software for apt repository management.
apt:
state: present
name:
- python3-pycurl

View file

@ -0,0 +1 @@
../prettier-yaml/in.yml

View file

@ -1,6 +0,0 @@
body {
padding-left: 11em;
font-family: Georgia, "Times New Roman", Times, serif;
color: purple;
background-color: #d8da3d;
}

View file

@ -0,0 +1 @@
../prettier-css/out.css

View file

@ -0,0 +1 @@
../prettier-graphql/out.graphql

View file

@ -1,5 +0,0 @@
<h2>
Minify <abbr title="HyperText Markup Language">HTML</abbr> and any
<abbr title="Cascading Style Sheets">CSS</abbr> or
<abbr title="JavaScript">JS</abbr> included in your markup
</h2>

View file

@ -0,0 +1 @@
../prettier-html/out.html

View file

@ -1,10 +0,0 @@
function HelloWorld({
greeting = "hello",
greeted = '"World"',
silent = false,
onMouseOver,
}) {
if (!greeting) {
return null;
}
}

View file

@ -0,0 +1 @@
../prettier-javascript/out.js

View file

@ -1,19 +0,0 @@
{
"arrowParens": "always",
"bracketSpacing": true,
"embeddedLanguageFormatting": "auto",
"htmlWhitespaceSensitivity": "css",
"insertPragma": false,
"jsxBracketSameLine": false,
"jsxSingleQuote": false,
"printWidth": 80,
"proseWrap": "preserve",
"quoteProps": "as-needed",
"requirePragma": false,
"semi": true,
"singleQuote": false,
"tabWidth": 2,
"trailingComma": "es5",
"useTabs": false,
"vueIndentScriptAndStyle": false
}

View file

@ -0,0 +1 @@
../prettier-json/out.json

View file

@ -0,0 +1 @@
../prettier-markdown/out.md

View file

@ -1,9 +0,0 @@
/* Define standard variables and values for website */
$bgcolor: lightblue;
$textcolor: darkblue;
$fontsize: 18px; /* Use the variables */
body {
background-color: $bgcolor;
color: $textcolor;
font-size: $fontsize;
}

View file

@ -0,0 +1 @@
../prettier-scss/out.scss

View file

@ -1,6 +0,0 @@
interface GreetingSettings {
greeting: string;
duration?: number;
color?: string;
}
declare function greet(setting: GreetingSettings): void;

View file

@ -0,0 +1 @@
../prettier-typescript/out.ts

View file

@ -1,10 +0,0 @@
---
- hosts: all
tasks:
- name: Get software for apt repository management.
apt:
state: present
name:
- python3-pycurl

View file

@ -0,0 +1 @@
../prettier-yaml/out.yml