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

Adding pre-commit hook for linting #453

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

Conversation

GeorgeCodes19
Copy link
Contributor

Ticket

Resolves FFS-2488.

Changes

  • Updated pre-commit hook to utilize the package.json lint command e.g. npm run lint
  • Improved error handling for commit message formatting with ticket number
  • Swapped out Ruby standard library in favor of rubocop for linting

Context for reviewers

Acceptance testing

  • No acceptance testing needed
    • This change will not affect the user experience (bugfix, dependency updates, etc.)
  • Acceptance testing prior to merge
    • This change can be verified visually via screenshots attached below or by sending a link to a local development environment to the acceptance tester
    • Acceptance testing should be done by design for visual changes, product for behavior/logic changes, or both for changes that impact both.
  • Acceptance testing after merge
    • This change is hard to test locally, so we'll test it in the demo environment (deployed automatically after merge.)
    • Make sure to notify the team once this PR is merged so we don't inadvertently deploy the unaccepted change to production. (e.g. :alert: Deploy block! @ffs-eng I just merged PR [#123] and will be doing acceptance testing in demo - please don't deploy until I'm finished!)

Copy link
Contributor

@tdooner tdooner left a comment

Choose a reason for hiding this comment

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

Seems fine to me, in principle, since people have to opt into it by symlinking the git hook script.

Personally I like the pre-commit framework which has a lot of wrapping logic to this stuff which makes it faster and easier to deal with. So I'll probably keep https://jiraent.cms.gov/browse/FFS-2488 open to track that work.

exit 1
fi

# Stage the files that were auto-corrected by RuboCop
git add app/**/*.rb
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 unexpected to me, and I'd guess will cause people to inadvertently commit files. Also, this script should really make sure it's running in the right directory, ideally by doing something like:

cd "$(git rev-parse --show-toplevel)"

at the top of the script. (This will cd to the top-level of the git repo.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch

document.addEventListener("turbo:frame-render", () => {
initialLoad = true;
});
document.addEventListener('turbo:frame-render', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, can we just standardize on double-quotes in JS for consistency with Ruby? Is there a technical reason to use single quotes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No technical reason. By convention I'm used to single quotes and only using double quotes for strings that require interpolation. It's simply a practice that I've used for years now.

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 string interpolation in JS uses tildes, right?

Copy link
Contributor Author

@GeorgeCodes19 GeorgeCodes19 Feb 18, 2025

Choose a reason for hiding this comment

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

JS uses backticks. In other languages that differs (PHP for example uses double quotes)- it's just convention that I'm used to, but not married to. I don't mind setting "singleQuote": false. Double quotes do allow us to avoid escaping apostrophes though.

Copy link
Contributor

@allthesignals allthesignals left a comment

Choose a reason for hiding this comment

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

I kind of wish that was broken out a little more. There are a few things going on:

  1. first run of lint rules against JS files which makes a lot of changes
  2. introduction of linter tooling (prettier)
  3. introduction of pre-commit hook

i would first get it to lint as part of the CI pipeline over this pre-commit thing. Oh it already does, duh! Eh, I'd definitely split the pre-commit thing out so we can have some more discussion on it because the linted-up javascript is valuable.

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.

3 participants