-
Notifications
You must be signed in to change notification settings - Fork 22.7k
chore: run Prettier on games #19943
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
chore: run Prettier on games #19943
Conversation
**[Bullet Force](https://www.crazygames.com/game/bullet-force-multiplayer)** | ||
3D multiplayer first-person shooter. | ||
|
||
- [Bullet Force](https://www.crazygames.com/game/bullet-force-multiplayer) |
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 manual intervention
This comment was marked as resolved.
This comment was marked as resolved.
this.borderGroup, | ||
this.wallCollision, | ||
null, | ||
this |
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.
We need to turn on trailingComma: all
.
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.
Yes, the default, isn't it (I mean trailingComma is the default)
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 default is es5
, which removes trailing commas for function calls. They are changing it to all
in v3, along with a few other changes (including using tabs and single quotes I think, which I don't like)
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.
Do you have a link to v3? I have not found it. I'm curious to see what is coming.
@@ -114,7 +110,8 @@ A camera entity can be created by adding an [`<a-camera>`](https://aframe.io/doc | |||
cursor-visible="true" | |||
cursor-scale="2" | |||
cursor-color="#0095DD" | |||
cursor-opacity="0.5"> | |||
cursor-opacity="0.5" | |||
> |
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 think using bracketSameLine true is better but I don't know if you have agreed not to use that setting somewhere else :)
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.
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.
Yeah, I don't like the newline thing either, but I wanted to keep it to the defaults to start so I left it as-is
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.
Yes, I think we should do this. This came up when we were doing the conversion - Prettier's behavior here was breaking the Markdown converter. I [can't remember | never understood] the full details, but see for instance:
- HTML ➡️ Markdown: Web/JavaScript #5193 (comment) (the para "there is a more gnarly one")
- Unexpected HTML for <pre> tag after prettier prettier/prettier#10950
...as a result of which I think Gregor restricted Prettier to formatting only HTML tables inside Markdown, when we did the conversion. Because bracketSameLine
didn't exist then.
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'll try adding the setting and re-running to see if it "fixes" it back or not
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.
Yup, looks like it fixed it by adding the .prettierrc.json
with that config
1, 1, 1, 1, 2, 1, 1, 1, | ||
1, 1, 1, 1, 2, 1, 1, 1, | ||
1, 1, 1, 0, 0, 1, 1, 1 | ||
1, 3, 3, 3, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, |
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 think these should not be changed because it's showing correct row count etc. But it will be hard to prevent change in future.
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.
We could use an alias to js
(jsnolint
) to exclude Prettier from updating these snippets. (I still need to check if it works).
I want to double-check if it would work.
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 can wrap this one in the <!-- prettier-ignore-start -->
/end if you want to keep it as-is
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 think this is not so critical. The critical ones are in matrix examples.
IMO it woulds be good to keep previous styling, it's not that necessary. I wonder would adding trailing comments with row counting also disable the autoformat? That would also clarify why it was formatted like that. But could be that it just makes it harder to read.
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.
Strangely I understood that a tile is a square matrix…
files/en-us/games/tutorials/2d_breakout_game_pure_javascript/build_the_brick_field/index.md
Outdated
Show resolved
Hide resolved
@@ -293,6 +303,7 @@ A separate update and draw method could look like the following example. For the | |||
main(performance.now()); // Start the cycle | |||
})(); | |||
``` | |||
<!-- prettier-ignore-end --> | |||
|
|||
Another alternative is to do certain things less often. If a portion of your update loop is difficult to compute but insensitive to time, you might consider scaling back its frequency and, ideally, spreading it out into chunks throughout that lengthened period. An implicit example of this was found over at The Artillery Blog for Artillery Games, where they [adjust their rate of garbage generation](https://web.archive.org/web/20161021030645/http://blog.artillery.com/2012/10/browser-garbage-collection-and-framerate.html) to optimize garbage collection. Obviously, cleaning up resources is not time sensitive (especially if tidying is more disruptive than the garbage itself). |
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 have a general comment:
I find lines like this hard to read where you have a paragraph on one line, essentially. If there are changes to a word in a sentence in the middle, the entire line is affected in a diff.
Prettier can format these using proseWrap in prettier config:
{
"proseWrap": "always",
}
An alternative is to write one sentence per line, but this is a manual effort.
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.
We don't have a consensus on this:
- Some authors write one (long) sentence per line
- Some authors write one paragraph per line
- Some tooling break anywhere between a word if the line is greater than 80 or 120 chars
- Some authors put every clause on a different line. (There was a blog post about this, but I can't find this.)
I think we are far from a consensus. More, I'm not sure we can find a solution that we agree on, and that is enforceable easily to the long tail of editors.
To be fair, I don't think it is a coincidence that Prettier does nothing about this by default.
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.
My two cents: we're taking the initiative to remove the ambiguity and discussions about code style in example code using Prettier, we could do the same for the .md
prose so that there's consistency there, also. Thanks for the context, though, I appreciate this is not simple 😄
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 think this is a discussion worth having once we have set up Prettier and/or Markdownlint. "Stück für Stück" 🤣 .
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.
Stück für Stück
Sounds good to me 😂
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 think we certainly had a strong consensus on this: #6936 .
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.
we're taking the initiative to remove the ambiguity and discussions about code style in example code using Prettier, we could do the same for the .md prose so that there's consistency there, also. Thanks for the context, though, I appreciate this is not simple 😄
I agree with this though, we should run Prettier on Markdown. When we converted from HTML, we ran it through Prettier as well. There are things markdownlint does that Prettier does not (AFAIK things like italic syntax or heading syntax) so we want both.
(Apparently I'm wrong about this. I don't know whether there are things markdownlint does that Prettier does not.)
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 have a strong preference for not wrapping at all—or at least not wrap by column width. I configured my editor to soft wrap and I encourage everyone to do so (you can also do that on GitHub).
If you wrap by column width, and you add one word on the first line, you would possibly trigger tens of lines of diff due to the reflow.
I'm okay with soft breaking by sentences (in that I won't call it out or change it if others do that), but IMO it makes reading the content from the source a little "bumpy", like reading poetry or one of those poorly structured Twitter threads.
…uild_the_brick_field/index.md Co-authored-by: rubiesonthesky <[email protected]>
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 good to me. Let's merge this.
@@ -0,0 +1,3 @@ | |||
{ |
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.
Just as with .eslintrc.js
, I think it would be better to go with .prettierrc.js
(using module.exports = { ... }
syntax, as this allows adding comments (while JSON) doesn't allow this.
@@ -55,13 +56,14 @@ But do not immediately assume animations require frame-by-frame control. Simple | |||
|
|||
There are two obvious issues with our previous main loop: `main()` pollutes the `{{ domxref("window") }}` object (where all global variables are stored) and the example code did not leave us with a way to _stop_ the loop unless the whole tab is closed or refreshed. For the first issue, if you want the main loop to just run and you do not need easy (direct) access to it, you could create it as an Immediately-Invoked Function Expression (IIFE). | |||
|
|||
<!-- prettier-ignore-start --> |
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.
Curious: When do you add these?
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.
MMmh. When I reviewed this PR, this morning, it happened that GitHub hid some previously-changed files . I would really like to avoid these as much as possible (read maybe 3-4 places on the whole of MDN), but this can be fixed in a follow-up PR. (The way games/ is doing examples is unusual for MDN).
@nschonni FWIW Conventional Commits uses
See: https://github.com/angular/angular/blob/22b96b9/CONTRIBUTING.md#type |
Ran prettier on the games folder to see how it interacts with the Markdownlint setup. Found one definition list issue that needed manual intervention, but the rest looked OK