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

Chore/format and lint #53

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Chore/format and lint #53

wants to merge 9 commits into from

Conversation

Angra974
Copy link
Collaborator

@Angra974 Angra974 commented Mar 25, 2024

solve #34

chore: format the application with prettier and lint

Description

Briefly explain the purpose of this pull request

Format files and use linters to have a coding convention for everyone to use for readability / code quality and easier debugging time.

What has been done

Added scripts:
"format:check" to check folder apps / docs / and tests folder ( can be changed later if used a different folder for testing the application

"format": will fix the formatting in files from the folders apps / docs / tests only
"format:all" will fix the formatting in files from all the application with exception from .gitignore as prettierignore is not existant.

"format:check": will check and give information about the formatting in files from the folders apps / docs / tests only
"format:checkall" will check and give information about the formatting in files from all the application with exception from .gitignore as prettierignore is not existant.

"lint": will fix ( as much as it can ) files from the folders apps / docs / tests only ( markdown files too )
"lint:all": will fix ( as much as it can ) files from the entire application ( markdown files too )

"lint:check": will give information about problems found in files from the folders apps / docs / tests only
"lint:checkall": will give information about problems found in files from the entire application

Added a pre-commit hook with husky using prettier-quick who will format files according to prettier preference while commiting files. Only staged files will be formatted.

Target files

js,jsx,ts,tsx,mjs,cjs,md

Solves #34

Are there any specific user stories or issues addressed by this PR?

No specific stories
issue resolve #34

As eslint use prettier too, both as been resolved in the same time.
module that need to be updated are done to not have conflict between them for the current build.

...

Testing

Run each command to test the result of each of them.
lint:check =>
image

lint:checkall
image

lint:
image

lint:all =>
image

format:check =>
image

format:checkall =>
image

format =>
image

format:all =>
image

Test of precommit hook =>
image
While adding a component in the apps folder,
we have a new line added "✍️ Fixing up app/components/falseComponent.tsx."
that we didn't have in the precedent commit.
So the formating was done at this time.

For the last commit, I resolved the error shown in the lint:all command.
So, we have now an application that give only warning and no error and only one will be definitively ignored by the linter.

image

Breaking Changes (optional)

No breaking change

Checklist

  • I have added unit tests for my changes. (If applicable)
  • I have manually tested the changes and verified they work as expected.
  • I have followed the coding style guide.
  • I have updated the documentation to reflect the changes, including any breaking changes.
  • I have created regression tests for the feature I am adding.

Reviewer Checklist

  • Automated test coverage is satisfactory. (If applicable)
  • PR is fully functional.
  • PR regressions tested.
  • [] Documentation regarding the PR has been properly updated.

Copy link

render bot commented Mar 25, 2024

.eslintrc.cjs Outdated
"prettier",
],

plugins: ["prettier"],
Copy link
Owner

Choose a reason for hiding this comment

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

There is already a Prettier configuration (see L28 after your changes), no need to add the plugin. This was the old way to do that before the configuration.

This is following the official docs.

Copy link
Collaborator Author

@Angra974 Angra974 Mar 25, 2024

Choose a reason for hiding this comment

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

The plugin here is for the md part.
It's use at line 52 "prettier/prettier".
If we take of this like, the tules for md/remark will try to find this plugin.
It's from the repo of eslint-plugin-md i'm using here.
eslint-plugin-md

Can be remove if using another plugin that didn't depend on it or later if we implement remark,
it's what i've done a little later but will be in a separate branch as remark itself will be a new feature and will have it's own way of been handle ( not a perfect one :( ).

server.ts Outdated
@@ -21,7 +21,9 @@ const remixHandler = createRequestHandler({
viteDevServer.ssrLoadModule(
"virtual:remix/server-build",
) as unknown as Promise<ServerBuild>
: await import("./build/server/index.js"),
: /* eslint-disable */
Copy link
Owner

Choose a reason for hiding this comment

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

If you build the project once and keep build/ folder, you'll never have the linting issue.

I suggest adding a comment to run the build once instead of disabling the line.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok to delete it.

"rollup": "^4.13.0",
"storybook": "^8.0.0",
"tailwindcss": "^3.4.1",
"tsx": "^4.7.1",
"typescript": "^5.1.6",
"typescript": "^5.4.0",
Copy link
Owner

Choose a reason for hiding this comment

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

Please avoid bumping packages out of the scope of the PR.

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's necessary for not having warning with eslint.
Even if you have typescript 5.1.6 in package.json, it's version 5.4.3 that is used in the application and seems like you didn't see it ^^.
It's the reason we have to use the overrides parameters in package.json sometimes to help up fix the version.
For some people who are using yarn, this can block you from linting and if you use lint with hook, you can push your comment.

It's not the case but in another application they were linting the application in an intermediate state when starting, so it was not starting.

This is a fresh install with typescript 5.1.6 as you can see, pnpm install the version 5.4.3 that is not totally supported for the moment with the version of eslint use.
image

image

@@ -50,7 +56,7 @@
"@types/react": "^18.2.20",
"@types/react-dom": "^18.2.7",
"@typescript-eslint/eslint-plugin": "^6.7.4",
"@typescript-eslint/parser": "^6.7.4",
"@typescript-eslint/parser": "^7.3.1",
Copy link
Owner

Choose a reason for hiding this comment

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

Non-blocker, just a general advice: Always that you bump to a major version, double check the change log to make sure there is no breaking change that might break the project. I checked and this one is okay, but it might have been a breaking one.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You will have this problem with eslint and this version of the parser.
Use with typescript 5.1.6 in package.json and you see again, the application is using v5.4.3.

image

The path on the lint script in package.json was not good, so eslint was not giving errors / warning because it didn't check something.
And perhaps it will be good to bump @typescript-eslint/eslint-plugin to this version too now that I see it ^^'

package.json Outdated
Comment on lines 9 to 12
"lint": "eslint --cache --fix \"./{app,tests,docs}/**/*.{js,jsx,ts,tsx,mjs,cjs,md}\" ",
"lint:all": "eslint --cache --fix \"./**/*.{js,jsx,ts,tsx,mjs,cjs,md}\"",
"lint:check": "eslint --cache \"./{app,tests,docs}/**/*.{js,jsx,ts,tsx,mjs,cjs,md}\"",
"lint:checkall": "eslint --cache \"./**/*.{js,jsx,ts,tsx,mjs,cjs,md}\"",
Copy link
Owner

Choose a reason for hiding this comment

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

I don't see any benefit in having all those commands.

In most projects you'll only find lint, lint:ci (quiet mode), and lint:fix.

Also, defining a list of files path can be quite dangerous, we probably will miss it when refactoring something. I'd keep the lint:checkall (with removing the md extension) as the default for lint.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok, i'll go for
lint and lint:fix.

@Angra974 Angra974 requested a review from alcpereira March 26, 2024 06:29
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.

Format using Prettier
2 participants