feat: Add Pre-Commit Copyright Date Check & Fix Automation#583
feat: Add Pre-Commit Copyright Date Check & Fix Automation#583SteinGabriel wants to merge 4 commits intodevelopfrom
Conversation
|
|
View your CI Pipeline Execution ↗ for commit b780c49
☁️ Nx Cloud last updated this comment at |
commit: |
ancheetah
left a comment
There was a problem hiding this comment.
This is amazing. Thank you for doing this Gabriel! Will save us a lot of time. Just left a comment on the tests.
| const input = '/* Copyright 2020 - 2026 Ping Identity. All Rights Reserved */'; | ||
| const actual = updateCopyrightYears(input, 2026); | ||
| assert.equal(actual, '/* Copyright 2020 - 2026 Ping Identity. All Rights Reserved */'); |
There was a problem hiding this comment.
In a lot of these tests the input looks identical to the value being asserted. For example, in this test shouldn't the input have something like years 2020 - 2025 before it is updated?
There was a problem hiding this comment.
I could swear I had this right and I was loosing my mind wondering why my input date updates weren't showing up, until I realized that the pre-commit script was actually "fixing" the input date header in the test files, making it the same as the value being asserted. lol
Anyways, I added a check to prevent it from running on specific paths, such as test files. Thanks for pointing it out!
57fc8b5 to
2c7f8b3
Compare
ryanbas21
left a comment
There was a problem hiding this comment.
This is cool. I'd like us to weigh this approach versus https://www.npmjs.com/package/eslint-plugin-license-header as an eslint rule with auto fixing.
Could you, when available to, maybe present the differences / overlap / benefits to each approach? Maybe theres a better eslint rule out there also, I just happened to find this one and it seems up to date / maintained.
The main limitation I can see is that ESLint rules enforce a fixed template. They are great at spotting missing headers, but they cannot keep the start year and only bump the end year. If we used a standard rule, I think we would lose our start years (e.g., 2020–2025 would become 2026). The pre-commit script is much more flexible for those range updates. Also, we have some pattern variation in the headers (such as That being said, ESLint rules could add value in enforcing header presence on new files. We could have an ESLint rule scoped to detecting missing headers only (with auto-fix disabled for year ranges), while keeping this pre-commit script for year updates. |
I think this is actually okay. I'm not 100% sure if the year range is a hard requirement. I think adding both could be valuable though, even if we don't allow the eslint rule to autofix. |
Summary
Automates Ping-owned copyright year updates so developers no longer need
to hand-edit headers. A pre-commit hook fixes and re-stages any staged
files with stale Ping copyright years before lint and build checks run.
Adds a pre-commit hook that automatically keeps Ping-owned copyright
year headers up-to-date in staged files, removing the need for manual
year updates on every change.
Changes
tools/copyright/sync-header-years.mjstools/copyright/sync-header-years.test.mjs.husky/pre-commitpackage.jsoncopyright:syncandcopyright:checkscriptsHow it works
git commit, the pre-commit hook reads the list of staged files.header in place and re-stages the file.
year at all, the commit is aborted with an error listing the incorrect files.
Supported formats updated automatically:
Copyright 2020 Ping Identity.→Copyright 2020 - 2026 Ping Identity.Copyright 2020-2024 Ping Identity.→Copyright 2020 - 2026 Ping Identity.Copyright 2020-2026 Ping Identity.→Copyright 2020 - 2026 Ping Identity.© Copyright 2020 - 2024 PingIdentity.→© Copyright 2020 - 2026 Ping Identity.Copyright (c) 2023 - 2024 Ping Identity Corporation.→Copyright (c) 2023 - 2026 Ping Identity Corporation.Testing
Known gaps / follow-ups
copyright:checkon PRs) deferred to a follow-up.Rollout notes