Skip to content

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

Merged
merged 4 commits into from
Aug 26, 2022
Merged

chore: run Prettier on games #19943

merged 4 commits into from
Aug 26, 2022

Conversation

nschonni
Copy link
Contributor

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

@nschonni nschonni requested a review from a team as a code owner August 24, 2022 22:19
@nschonni nschonni requested review from bsmth and removed request for a team August 24, 2022 22:19
@github-actions github-actions bot added the Content:Other Any docs not covered by another "Content:" label label Aug 24, 2022
**[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)
Copy link
Contributor Author

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

@github-actions

This comment was marked as resolved.

this.borderGroup,
this.wallCollision,
null,
this
Copy link
Member

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.

Copy link
Contributor

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)

Copy link
Member

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)

Copy link
Contributor

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"
>
Copy link
Contributor

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 :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wbamberg @Rumyra What do you think? Until now, I think this is the only default value we should change. It is working well with React or Vue.js, but I think, in other cases, it looks weird.

Copy link
Contributor Author

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

Copy link
Collaborator

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:

...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.

Copy link
Contributor Author

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

Copy link
Contributor Author

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,
Copy link
Contributor

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.

Copy link
Contributor

@teoli2003 teoli2003 Aug 25, 2022

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.

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor

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…

@@ -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).
Copy link
Member

@bsmth bsmth Aug 25, 2022

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.

Copy link
Contributor

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.

Copy link
Member

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 😄

Copy link
Contributor

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" 🤣 .

Copy link
Member

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 😂

Copy link
Collaborator

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 .

Copy link
Collaborator

@wbamberg wbamberg Aug 25, 2022

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.)

Copy link
Member

@Josh-Cena Josh-Cena Aug 25, 2022

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.

@nschonni nschonni requested a review from a team as a code owner August 25, 2022 15:13
Copy link
Contributor

@teoli2003 teoli2003 left a 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.

@teoli2003 teoli2003 merged commit e4783c0 into mdn:main Aug 26, 2022
@@ -0,0 +1,3 @@
{
Copy link
Contributor

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 -->
Copy link
Contributor

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?

Copy link
Contributor

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).

@caugner
Copy link
Contributor

caugner commented Aug 26, 2022

@nschonni FWIW Conventional Commits uses style: prefix for

Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)

See: https://github.com/angular/angular/blob/22b96b9/CONTRIBUTING.md#type

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:Other Any docs not covered by another "Content:" label
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants