Skip to content

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

tpadjen
Copy link
Contributor

@tpadjen tpadjen commented Jul 18, 2024

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:

"rules": {
    "@next/next/no-img-element": "off",
    // ...
}

If you absolutely need to make a commit, linting be damned, you can add the --no-verify option to your git 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.

@samholmes
Copy link
Contributor

@tpadjen I didn't notice this PR when I worked on #13

Could you diff this PR with your work to see whether there are any changes you'd recommend in addition? A review of my work so to speak.

Copy link
Contributor

@samholmes samholmes left a 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 .",
Copy link
Contributor

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.

Comment on lines +3 to +14
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!
`
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 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
Comment on lines 3 to 5
"rules": {
"@next/next/no-img-element": "off"
}
Copy link
Contributor

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.

Comment on lines +5 to +10
"import/no-anonymous-default-export": [
"warn",
{
"allowObject": true
}
]
Copy link
Contributor

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.

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