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

Add import and style sorting config + capabilities. #132

Merged
merged 14 commits into from
Mar 13, 2024

Conversation

ultraviolet10
Copy link
Collaborator

Adds auto class sorting with Prettier for tailwind styles and import sorting with ESLint.

Also adds the eslint fix command to the format command in the webapp Makefile, since check will now show an import sort errors.

@ultraviolet10 ultraviolet10 requested a review from norswap March 4, 2024 09:08
plugins: ["@typescript-eslint"],
project: "./tsconfig.json",
"sourceType": "module",
"ecmaVersion": "latest",
Copy link
Member

Choose a reason for hiding this comment

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

What's with the weird indentation here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It doesn't seem to appear on my local repo. 😶

Copy link
Member

Choose a reason for hiding this comment

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

It's because of mixed tabs and spaces. We should add .cjs and .mjs files to the list of those who get formatted by prettier, cand you do that?

"import/no-duplicates": "error",
"simple-import-sort/imports": [
"error",
{
Copy link
Member

Choose a reason for hiding this comment

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

Weird alignment, is this not caught by the formatter?

packages/webapp/package.json Show resolved Hide resolved
// Style imports.
["^.+\\.s?css$"],
// Side effect imports.
["^\\u0000"]
Copy link
Member

Choose a reason for hiding this comment

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

One rule that would be great is to make sure the internal imports, which we prefix with src/ are in their own separate section (after the "internal packages" would be ideal — we should also change that comment to actually say "external packages" (stuff like wagmi etc))

@ultraviolet10 ultraviolet10 requested a review from norswap March 7, 2024 13:40
Copy link
Member

@norswap norswap left a comment

Choose a reason for hiding this comment

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

Added comments to fix some import issues unrelated to sorting + fix the indentation problem by adding cjs/mjs to prettier.

plugins: ["@typescript-eslint"],
project: "./tsconfig.json",
"sourceType": "module",
"ecmaVersion": "latest",
Copy link
Member

Choose a reason for hiding this comment

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

It's because of mixed tabs and spaces. We should add .cjs and .mjs files to the list of those who get formatted by prettier, cand you do that?

import { convertStringToSafeNumber } from "src/utils/js-utils"

import BoardCard from "./boardCard"
import DraggedCard from "./draggedCard"
import HandCard from "./handCard"
Copy link
Member

Choose a reason for hiding this comment

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

These should use the src/ format. I know it's not formatting related, but could you fix it?

I think we could use this type of rule to prevent them, but I wonder if we'd need to be able to make exception to import files form other packages (e.g. deployment addresses) — I think we could get around that by copying files however. Could you look into it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

added this rule, running make check and make format doesn't pop up any errors.

packages/webapp/src/components/hand.tsx Outdated Show resolved Hide resolved
packages/webapp/src/components/modals/globalErrorModal.tsx Outdated Show resolved Hide resolved
packages/webapp/src/components/modals/joinGameModal.tsx Outdated Show resolved Hide resolved
@ultraviolet10 ultraviolet10 requested a review from norswap March 8, 2024 06:16
Copy link
Member

@norswap norswap left a comment

Choose a reason for hiding this comment

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

The import pattern rule uncovered some issues

{
patterns: ["!./*", "!../*"],
},
],
Copy link
Member

Choose a reason for hiding this comment

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

So I was confused why this would work because this is the pattern used in the link I gave to ONLY ALLOW relative links.

Turns out:

  • make check does not actually run the eslint checks, it needs to be pnpm next lint --max-warnings 0 and not pnpm eslint (but let's actually call make lint from make check, that way we avoid duplication)

  • Even so, this should forbid every single one of our imports... turns out it does not work, probably ! is not a thing as an operator.

  • BUT, if you remove the !, then it does exactly what we want, and indeed catches a few relative imports that slipped through the cracks :)

Can you fix make check, this file and eliminate the remaining relative imports? And also add a comment in this file to explain we forbid relative imports and absolute imports starting with src/ should be used instead?

Oh, also you'll need to exclude generated.ts from eslint (ignorePatterns option).

I see we're also excluding src/hooks/useScrollBox.ts from linting, seems to be about React useEffect dependencies, would be good to remove it from the ignore list and either fix or simply add comments to disable eslint on those useEffect statements.

Copy link
Member

@norswap norswap left a 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 good to go?

@ultraviolet10
Copy link
Collaborator Author

I think this is good to go?

tumblr_lyzwwppm5P1qh28hmo1_400

@ultraviolet10 ultraviolet10 merged commit 5080439 into master Mar 13, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants