-
Notifications
You must be signed in to change notification settings - Fork 453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add prettier beautifier and bracket_spacing option #2047
Conversation
src/beautifiers/prettier.coffee
Outdated
_: | ||
tabWidth: "indent_size" | ||
useTabs: "indent_with_tabs" | ||
JavaScript: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TypeScript is also a Prettier supported language.
src/beautifiers/prettier.coffee
Outdated
options: { | ||
_: | ||
tabWidth: "indent_size" | ||
useTabs: "indent_with_tabs" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend something like https://github.com/Glavin001/atom-beautify/blob/master/src/beautifiers/prettydiff.coffee#L10-L13
useTabs: ["indent_with_tabs", "indent_char", (indent_with_tabs, indent_char) ->
return (indent_with_tabs is true) or (indent_char is "\t")
]
which is the following in JavaScript:
useTabs: [
"indent_with_tabs",
"indent_char",
function(indent_with_tabs,
indent_char) {
return (indent_with_tabs === true) || (indent_char === "\t");
}
]
src/languages/javascript.coffee
Outdated
@@ -108,5 +108,9 @@ module.exports = { | |||
default: "System Default" | |||
enum: ["CRLF","LF","System Default"] | |||
description: "Override EOL from line-ending-selector" | |||
bracket_spacing: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about object_curly_spacing
to align with Unibeautify and ESLint? See https://unibeautify.com/docs/option-object-curly-spacing.html
Or object_bracket_spacing
?
src/options.json
Outdated
"description": "Insert spaces between brackets in object literals (Supported by Coffee Formatter)", | ||
"title": "Bracket spacing", | ||
"beautifiers": [ | ||
"Coffee Formatter" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is strange. Should be Prettier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's under the CoffeeScript language, which falls back to JavaScript.
@Glavin001 made the changes you requested. Let me know what you want to do about the option being included in all of the languages that have The Travis build that fails will be fixed once #2048 is merged, so I'm x'ing that one. |
@szeck87 : Merged #2048. Please update this PR and we can see Travis CI passing. Thanks! |
The build passed, but I just noticed AB is not reading from the configuration file for prettier. Let me fix that. |
@Glavin001 good to go. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation shows beautifiers supporting the new object_curly_spacing
option which I know do not.
docs/options.md
Outdated
|
||
**Type**: `boolean` | ||
|
||
**Supported Beautifiers**: [`TypeScript Formatter`](#typescript-formatter) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not think this beautifier supports this option.
docs/options.md
Outdated
|
||
**Type**: `boolean` | ||
|
||
**Supported Beautifiers**: [`Vue Beautifier`](#vue-beautifier) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not think this beautifier supports this option.
docs/options.md
Outdated
|
||
**Type**: `boolean` | ||
|
||
**Supported Beautifiers**: [`JS Beautify`](#js-beautify) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not think this beautifier supports this option.
docs/options.md
Outdated
|
||
**Type**: `boolean` | ||
|
||
**Supported Beautifiers**: [`JS Beautify`](#js-beautify) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not think this beautifier supports this option.
@szeck87 : For example: https://github.com/Glavin001/atom-beautify/blob/master/src/beautifiers/typescript-formatter.coffee#L8-L9 This is false. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like it would be better to revert the last commit about fixing the beautifier support. We can hold this off until a future PR then since it is more complicated than anticipated.
@@ -7,7 +7,7 @@ module.exports = class CoffeeFormatter extends Beautifier | |||
link: "https://github.com/Glavin001/Coffee-Formatter" | |||
|
|||
options: { | |||
CoffeeScript: true | |||
CoffeeScript: false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good.
@@ -5,7 +5,7 @@ module.exports = class TypeScriptFormatter extends Beautifier | |||
name: "TypeScript Formatter" | |||
link: "https://github.com/vvakame/typescript-formatter" | |||
options: { | |||
TypeScript: true | |||
TypeScript: false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope.
See rest of file:
if options.indent_with_tabs
opts.convertTabsToSpaces = false
else
opts.tabSize = options.tab_width or options.indent_size
opts.indentSize = options.indent_size
Firstly, this beautifier supports indent_with_tabs
, tab_with
, and indent_size
.
Secondly, I expect TypeScript
and TSX
languages to have the same support, unless otherwise specified.
@@ -6,7 +6,7 @@ module.exports = class VueBeautifier extends Beautifier | |||
link: "https://github.com/Glavin001/atom-beautify/blob/master/src/beautifiers/vue-beautifier.coffee" | |||
|
|||
options: | |||
Vue: true | |||
Vue: false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this uses JS Beautify may as well leave as true
.
src/beautifiers/prettier.coffee
Outdated
else | ||
reject(new Error("Unknown language for Prettier")) | ||
|
||
filePath = atom.workspace.getActiveTextEditor().getPath() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use context.filePath
instead.
See
atom-beautify/src/beautifiers/rustfmt.coffee
Lines 20 to 21 in 788d002
beautify: (text, language, options, context) -> | |
cwd = context.filePath and path.dirname context.filePath |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does Prettier resolveConfig
do if filePath = undefined
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It returns null if it can't find anything.
@@ -2,7 +2,7 @@ module.exports = { | |||
|
|||
name: "TSX" | |||
namespace: "tsx" | |||
fallback: ['ts'] | |||
fallback: ['js'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The options defined here https://github.com/szeck87/atom-beautify/blob/add-prettier/src/beautifiers/typescript-formatter.coffee#L12-L15 aren't recognized if the fallback is to ts
.
@@ -18,4 +18,6 @@ module.exports = { | |||
"ts" | |||
] | |||
|
|||
defaultBeautifier: "TypeScript Formatter" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 This was the previous default beautifier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, the build failed originally because it used prettier for the tests.
Despite being an author of #2004 and #2008, I'd vote for making prettier a default beautifier for markdown and ignoring a switch to remark-cli! I've been using Prettier from a command line recently and quite like its design! If I'm not wrong, Prettier uses remark to parse markdown, so we'll still keep remark under the hood 😉 If there is a plan to make prettier a default markdown beautifier, feel free to close my two PRs mentioned above! I can also return to #1990 once Prettier lands atom-beautify. Although prettier already formats some code blocks recursively, it'd be cool to additionally beautify a user-defined set of langauges with atom-beautify. So until prettier supports language XYZ as a plugin, people can enjoy nested code block formatting in their markdowns 👍 |
To be completely fair about prettier, there is one inconvenience in it that could make markdown beautification a bit frustrating for some users. It is to do with how numbered lists are indented, see prettier/prettier#3459 (comment) There is a PR to solve this prettier/prettier#3990, but until it’s discussed and merged it’d be perhaps wise to keep Prettier non-default (at least in markdown). Markdown support in prettier is still pretty new, but I like the pace at which they are improving stuff! |
@kachkaev prettier won't be the default for anything yet. I want to get it out there for people to start using and make sure it doesn't have any serious problems. But certainly open to it once it's been out there for a while. |
] | ||
JavaScript: | ||
bracketSpacing: "object_curly_spacing" | ||
TypeScript: false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be true
?
May be related: #2070 |
I can't find any documentation on the |
What does this implement/fix? Explain your changes.
bracket_spacing
, to print spaces between brackets in object literals for JavaScript...
Does this close any currently open issues?
Closes #1497
Closes #802
...
Any other comments?
...
Checklist
Check all those that are applicable and complete.
master
branchnpm run docs
CHANGELOG.md
under "Next" section