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 pre-commit hook to run frontend linters #7075

Closed
wants to merge 7 commits into from

Conversation

timja
Copy link
Member

@timja timja commented Sep 7, 2022

I've noticed a few builds failing from linting related errors.
This should automatically fix those that are auto-fixable.

Lint errors that aren't auto-fixable (some eslint and stylelint ones) will fail the commit.

The git hook will be automatically installed via husky.

It can be bypassed by running git commit --no-verify

Proposed changelog entries

  • (skip)
  • ...

Proposed upgrade guidelines

N/A

Submitter checklist

  • (If applicable) Jira issue is well described
  • Changelog entries and upgrade guidelines are appropriate for the audience affected by the change (users or developer, depending on the change) and are in the imperative mood. Examples
    • Fill-in the Proposed changelog entries section only if there are breaking changes or other changes which may require extra steps from users during the upgrade
  • Appropriate autotests or explanation to why this change has no tests
  • New public classes, fields, and methods are annotated with @Restricted or have @since TODO Javadoc, as appropriate.
  • New deprecations are annotated with @Deprecated(since = "TODO") or @Deprecated(forRemoval = true, since = "TODO") if applicable.
  • New or substantially changed JavaScript is not defined inline and does not call eval to ease future introduction of Content-Security-Policy directives (see documentation on jenkins.io).
  • For dependency updates: links to external changelogs and, if possible, full diffs

Maintainer checklist

Before the changes are marked as ready-for-merge:

  • There are at least 2 approvals for the pull request and no outstanding requests for change
  • Conversations in the pull request are over OR it is explicit that a reviewer does not block the change
  • Changelog entries in the PR title and/or Proposed changelog entries are accurate, human-readable, and in the imperative mood
  • Proper changelog labels are set so that the changelog can be generated automatically
  • If the change needs additional upgrade steps from users, upgrade-guide-needed label is set and there is a Proposed upgrade guidelines section in the PR title. (example)
  • If it would make sense to backport the change to LTS, a Jira issue must exist, be a Bug or Improvement, and be labeled as lts-candidate to be considered (see query).

@timja timja added skip-changelog Should not be shown in the changelog web-ui The PR includes WebUI changes which may need special expertise labels Sep 7, 2022
@timja timja requested review from a team September 7, 2022 08:11
@daniel-beck
Copy link
Member

The git hook will be automatically installed via husky.

How does this interact with existing hooks?

@timja
Copy link
Member Author

timja commented Sep 7, 2022

The git hook will be automatically installed via husky.

How does this interact with existing hooks?

It will override it as it sets the hooks path config option and sets it to war/.husky/

Basically the pre-commit hook will be managed in the project and I'm not sure if there's a way for you to add your own one on top other than getting the project to accept it

@NotMyFault NotMyFault requested a review from a team September 7, 2022 10:04
Copy link
Contributor

@Wadeck Wadeck left a comment

Choose a reason for hiding this comment

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

Last time I worked with this kind of linter at commit time, it was not an ideal experience for the developers. Your code is modified after you have prepared everything, which is surprising sometimes.

With the linters being supported by most of the IDEs, the native "format" shortcut should take that into consideration. ("should" as Jenkins has multiple different linters)


For folks working on their enterprise laptops, do you have any pre-commit hooks policy that could be impacted by this kind of change?


Do you know what is the time it takes to lint a commit ? I expect if you are working on pure Java classes, the impact should be close to 0, but I prefer to ask.
It was a pain in a previous project (badly configured) ;-)

war/package.json Outdated Show resolved Hide resolved
@@ -0,0 +1,5 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
Copy link
Contributor

Choose a reason for hiding this comment

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

Normally despite the shell script, it's supported on Windows (https://typicode.github.io/husky/#/?id=does-it-work-on-windows)
Now, it could be interesting to get some Windows users to ensure it's really working.
On my own system it was working, but perhaps I have too many stuff installed that are necessary for Jenkins development.

@timja
Copy link
Member Author

timja commented Sep 7, 2022

Do you know what is the time it takes to lint a commit ? I expect if you are working on pure Java classes, the impact should be close to 0, but I prefer to ask.

Close to 0, not really noticeable as it only works on staged files rather than doing something like running a whole maven build

@github-actions github-actions bot added the unresolved-merge-conflict There is a merge conflict with the target branch. label Sep 8, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Sep 8, 2022

Please take a moment and address the merge conflicts of your pull request. Thanks!

@basil
Copy link
Member

basil commented Sep 8, 2022

-0 from me, I hate pre-commit hooks and would much rather run a Maven command to fix up formatting when I want rather than at Git commit time. If this is accepted, the first thing I will do will be to disable it on my local machine.

@timja
Copy link
Member Author

timja commented Sep 8, 2022

-0 from me, I hate pre-commit hooks and would much rather run a Maven command to fix up formatting when I want rather than at Git commit time. If this is accepted, the first thing I will do will be to disable it on my local machine.

Could you explain why? / have you tried this out to get a feel for it to see if it would impact your worflow?

The first thing I will do will be to disable it on my local machine.

sure you can just unset the config item it adds if you want to do that

@basil
Copy link
Member

basil commented Sep 8, 2022

This is just personal preference. I am not against others using what works for them, but this does not work for me. I don't like it when my Git operations take anything more than 30 or so milliseconds, and I don't like it when they do anything other than source control operations. When I write code I create a lot of "private" commits that mean nothing to anyone other than me, squashing them together into something logically coherent before publishing the result, so my workflow relies on commits being fast and surprise-free. I appreciate that others have different workflows, which is why I started this comment by stating that it is a matter of personal preference. As long as I can opt-out I am OK.

@github-actions github-actions bot added unresolved-merge-conflict There is a merge conflict with the target branch. and removed unresolved-merge-conflict There is a merge conflict with the target branch. labels Sep 8, 2022
@github-actions
Copy link
Contributor

Please take a moment and address the merge conflicts of your pull request. Thanks!

@github-actions github-actions bot added unresolved-merge-conflict There is a merge conflict with the target branch. and removed unresolved-merge-conflict There is a merge conflict with the target branch. labels Sep 10, 2022
@github-actions
Copy link
Contributor

Please take a moment and address the merge conflicts of your pull request. Thanks!

@github-actions github-actions bot removed the unresolved-merge-conflict There is a merge conflict with the target branch. label Sep 14, 2022
@NotMyFault NotMyFault self-requested a review September 14, 2022 20:55
@timja timja mentioned this pull request Sep 21, 2022
Co-authored-by: Jesse Glick <jglick@cloudbees.com>
@timja timja mentioned this pull request Sep 23, 2022
13 tasks
@github-actions github-actions bot added the unresolved-merge-conflict There is a merge conflict with the target branch. label Oct 10, 2022
@github-actions
Copy link
Contributor

Please take a moment and address the merge conflicts of your pull request. Thanks!

@timja
Copy link
Member Author

timja commented Oct 12, 2022

Seems to be little appetite for this so closing

@timja timja closed this Oct 12, 2022
@timja timja deleted the add-lint-staged-and-husky branch October 12, 2022 21:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
skip-changelog Should not be shown in the changelog unresolved-merge-conflict There is a merge conflict with the target branch. web-ui The PR includes WebUI changes which may need special expertise
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants