-
Notifications
You must be signed in to change notification settings - Fork 5
Enforce eslint and prettier rules with a pre-commit hook #10
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
base: master
Are you sure you want to change the base?
Conversation
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.
Overall, these seem like good additions. Could you rebase this PR on to main (master), and then rename the PR to "Linting additions". Thanks! 🙌
@@ -8,7 +8,8 @@ | |||
"build": "next build", | |||
"start": "next start", | |||
"lint": "next lint", | |||
"format": "prettier --write ." | |||
"format": "prettier --write .", |
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 prefer to use the prettier ESLint plugin for formatting so that way eslint --fix
applies the linting fixes in addition to the formatting errors all in one go. A dev can use an eslint IDE integration to get auto formatting and linting fixes on file save.
const communityDescription = ` | ||
We're a community of developers of all skill levels, dedicated to fostering a fun and | ||
educational environment. Hosted by Sam Holmes and a team of passionate organizers, our | ||
monthly meetups offer an opportunity to network, learn, and showcase your projects. At | ||
each event, you'll enjoy complimentary food and drinks during our networking lunch, | ||
followed by a series of engaging presentations on various developer and engineering | ||
topics. After the talks, we break into groups for casual networking, project showcases, | ||
and coding help. Whether you're a seasoned developer or just starting out, there's | ||
something for everyone. Be sure to bring your laptop if you'd like to share your latest | ||
project or give a presentation. We look forward to meeting you and seeing what you're | ||
excited about! | ||
` |
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 I resolved this same issue in my PR, but instead of factoring out the string, I kept it inline. That'd be preferable since this consts is single-use.
.eslintrc.json
Outdated
"rules": { | ||
"@next/next/no-img-element": "off" | ||
} |
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 is useful to remove the warnings.
"import/no-anonymous-default-export": [ | ||
"warn", | ||
{ | ||
"allowObject": true | ||
} | ||
] |
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'm unsure what this fixes.
Dsecription
Adds a pre-commit hook using husky that auto-fixes eslint errors and prettifies staged files in case a contributer does not have their IDE configured to run those actions on save.
When Commits Fail
This may occasionally cause a commit to fail when the eslint problem is not auto-fixable.
Usually this is because of an important web standard violation, such as a missing
alt
description on an<img />
tag. In these cases, simply clean up the problem, add the change to staging, and re-commit.If the error is more involved or less useful, consider turning off the associated eslint rule in
.eslintrc.json
, like so:If you absolutely need to make a commit, linting be damned, you can add the
--no-verify
option to yourgit commit
command. Because this is possible, linting enforcement can possibly be moved to CI once a deployment pipeline has been established.Other Changes
This also cleans up some eslint errors/warnings concerning missing alt tags and unescaped html entities.