Skip to content
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

Use Prettier for ESLint formatting TypeScript #23631

Merged
merged 3 commits into from May 9, 2023

Conversation

nschonni
Copy link
Contributor

Adds the ESLint prettier configs and removes rules shadowed by that plugin https://github.com/prettier/eslint-config-prettier/blob/main/index.js
Ran the noisy cleanup as part of the second commit

@nschonni
Copy link
Contributor Author

I think the CodeQL failure is because the previously suppressed warnings are popping up because the suppression through the UI are line specific

@ykzts
Copy link
Sponsor Member

ykzts commented Feb 18, 2023

Mastodon aligns the = position of the assignment with a space; Prettier removes this space to one, so we do not use Prettier in JS. We should be able to ignore this formatting in the Prettier options.

@github-actions
Copy link
Contributor

This pull request has merge conflicts that must be resolved before it can be merged.

@nschonni
Copy link
Contributor Author

Mastodon aligns the = position of the assignment with a space; Prettier removes this space to one, so we do not use Prettier in JS. We should be able to ignore this formatting in the Prettier options.

Prettier is an opinionated formatter with few options https://prettier.io/docs/en/options.html
Since it usually aims to minimize diffs, things like having to reflow lines to realign with the equals sign wouldn't likely become an option there

@github-actions
Copy link
Contributor

This pull request has merge conflicts that must be resolved before it can be merged.

@github-actions
Copy link
Contributor

This pull request has merge conflicts that must be resolved before it can be merged.

@github-actions
Copy link
Contributor

This pull request has resolved merge conflicts and is ready for review.

@github-actions
Copy link
Contributor

This pull request has merge conflicts that must be resolved before it can be merged.

@github-actions
Copy link
Contributor

This pull request has resolved merge conflicts and is ready for review.

@github-actions
Copy link
Contributor

This pull request has merge conflicts that must be resolved before it can be merged.

@github-actions
Copy link
Contributor

This pull request has resolved merge conflicts and is ready for review.

@nschonni
Copy link
Contributor Author

I split the commits between the JSX and JS files to see if one or the other might be easier to accept initially

@github-actions
Copy link
Contributor

This pull request has merge conflicts that must be resolved before it can be merged.

.prettierignore Show resolved Hide resolved
app/javascript/mastodon/is_mobile.ts Outdated Show resolved Hide resolved
@renchap
Copy link
Sponsor Member

renchap commented May 4, 2023

Looks good!

Should we update lint-staged so it only runs prettier on known extensions, ignoring (t|j)sx?? Currently, it will run both prettier --write and eslint --fix on JS/TS files, which may both update the file, and I fear this can create issues.

What about this? Could this cause issues?

@nschonni
Copy link
Contributor Author

nschonni commented May 4, 2023

No, you can run yarn prettier -w "**/*.ts" and there is no changes to the files or warnings from ESLint after it did the autofixing

Copy link
Sponsor Member

@renchap renchap left a comment

Choose a reason for hiding this comment

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

👍

Let's merge this!

Comment on lines +21 to +22
const { hovering, handleMouseEnter, handleMouseLeave } =
useHovering(autoPlayGif);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is that way of having the right-hand side entirely on a new line really more readable?

Copy link
Sponsor Member

Choose a reason for hiding this comment

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

The whole line is > 80 char, so Prettier reformats it to be under this limit by moving the right-hand side to the new line

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I understand this is a result of applying the > 80 chars rule, I just find that less readable. But that's a pretty minor corner-case.

Comment on lines 27 to 32
className='account__avatar-overlay' style={{ width: size, height: size }}
className="account__avatar-overlay"
Copy link
Contributor

Choose a reason for hiding this comment

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

Afaik, this quote style is the opposite of the code style we've been enforcing since the beginning of the project.

Copy link
Sponsor Member

Choose a reason for hiding this comment

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

This can be changed using the jsxSingleQuote option if needed, but I think double quotes are the standard nowadays in JSX, as they are in HTML.

Comment on lines -175 to +246
const { timestamp } = props;
const delta = (new Date(timestamp)).getTime() - state.now;
const unitDelay = getUnitDelay(selectUnits(delta));
const unitRemainder = Math.abs(delta % unitDelay);
const { timestamp } = props;
const delta = new Date(timestamp).getTime() - state.now;
const unitDelay = getUnitDelay(selectUnits(delta));
const unitRemainder = Math.abs(delta % unitDelay);
Copy link
Contributor

Choose a reason for hiding this comment

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

Afaik this is another change from a coding style we were leaning towards. I don't have a strong opinion either way, but I'm wary of changing existing rules, especially if we end up applying this to JS files as well.

Copy link
Contributor Author

@nschonni nschonni May 4, 2023

Choose a reason for hiding this comment

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

I think one of the goals that prettier seems to aim for is to minimize the git noise. Since if the longest variable changes length, the rest of the lines would need to be re-written, so there is no option to use this style with prettier.

Copy link
Contributor

Choose a reason for hiding this comment

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

That does make sense. I'd just want to have @Gargron to ack on this has he has explicitly asked for the current code style in the past (when our toolchain did not enforce either code style).

@renchap
Copy link
Sponsor Member

renchap commented May 8, 2023

I would really like this to be merged soon as more Typescript is appearing in the codebase.

@nschonni could you enable jsxSingleQuote as this is the current style in the codebase, rebase it, and reformat the newly-added TS files (if needed)?

Do you have any other remarks we need to act on @ClearlyClaire?

@github-actions
Copy link
Contributor

github-actions bot commented May 9, 2023

This pull request has merge conflicts that must be resolved before it can be merged.

@ClearlyClaire
Copy link
Contributor

With my glitch-soc maintainer hat, in addition to my earlier comment, I'd like to avoid bundling automatic changes with manual changes (e.g. removing the iOS detection thing).

The reason is glitch-soc works by maintaining a copy of the front-end files with local modifications, and trying to apply a large-scale change like automatic linting is most likely going to not work, but if I know this is just automatic linting, I can run the linter separately. However, if the commit contains both automatic changes and manual changes, I cannot do that (and Mastodon PRs end up squashed in a single commit, so that would end up as a single commit).

renchap added a commit to renchap/mastodon that referenced this pull request May 9, 2023
Extracted from @nshonni's work here: mastodon#23631
@github-actions
Copy link
Contributor

github-actions bot commented May 9, 2023

This pull request has resolved merge conflicts and is ready for review.

@Gargron Gargron merged commit 51b83ed into mastodon:main May 9, 2023
29 checks passed
@nschonni nschonni deleted the eslint-prettier branch May 9, 2023 17:03
@renchap
Copy link
Sponsor Member

renchap commented May 9, 2023

Thanks a lot for your work on this @nschonni ❤️

taichi221228 pushed a commit to taichi221228/mastodon that referenced this pull request May 16, 2023
skerit pushed a commit to 11ways/mastodon that referenced this pull request Jul 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
javascript Pull requests that update Javascript code lint fix 💅 typescript
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants