-
-
Notifications
You must be signed in to change notification settings - Fork 166
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
Lint changed files by default in pre-push hook #4261
base: main
Are you sure you want to change the base?
Conversation
@@ -127,5 +128,8 @@ module.exports = { | |||
'import/resolver': { | |||
typescript: {}, | |||
}, | |||
jsdoc: { |
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.
Added because .prettierrc.js
is now being linted (it was being ignored before, for some reason) and ESLint doesn't know what to do with TypeScript syntax in JSDoc by default.
@@ -2,6 +2,7 @@ | |||
* @type {import('prettier').Options} | |||
*/ | |||
module.exports = { | |||
plugins: ['prettier-plugin-packagejson'], |
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.
Prettier does not seem to autodetect plugins in version 3. I couldn't find any mention of this in the release notes, but I found this necessary.
@@ -0,0 +1,4 @@ | |||
!.* |
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.
Prettier seems to ignore dotfiles by default.
f6072a8
to
2775ada
Compare
New and removed dependencies detected. Learn more about Socket for GitHub ↗︎
🚮 Removed packages: npm/@pkgr/utils@2.4.2, npm/apg-js@4.1.3, npm/big-integer@1.6.52, npm/bplist-parser@0.2.0, npm/bundle-name@3.0.0, npm/default-browser-id@3.0.0, npm/default-browser@4.0.0, npm/define-lazy-prop@3.0.0, npm/is-docker@3.0.0, npm/is-inside-container@1.0.0, npm/is-wsl@2.2.0, npm/open@9.1.0, npm/run-applescript@5.0.0, npm/titleize@3.0.0, npm/untildify@4.0.0 |
Currently if you install the pre-push hook by running `yarn setup-git-hooks`, then each time you push, every file that can be linted will be. This is incredibly time-consuming if you want to push a branch and you've only changed a handful of files on your branch. To address this, this commit adds a shell script which replaces the existing `lint` and `lint:fix` package scripts. This new script not only runs in "check" and "fix" modes (that is, either check and exit without fixes, or check and automatically make fixes), it also has the ability to detect which files have changed within the branch that you're on and only run ESLint and Prettier on those files. To accomplish this, the argument to `eslint` and `prettier` have been simplified so that instead of excluding non-lintable files when these commands are called, ignore files are used instead. This required updating to Prettier 3, which reads from both `.prettierignore` and `.gitignore`, a useful task Prettier 2 did not do. Of course, you don't need to install the Git hook to take advantage of the changes in this commit. The `lint` and `lint:fix` package scripts now take advantage of the new shell script, and there are also two new package scripts that delegate to the script, namely, `lint:only-branch` and `lint:fix:only-branch`. Finally, CI will still run `yarn lint` to ensure that all files in the repo still pass lint.
Lint violations will be fixed in #4264. |
Putting back in draft due to Prettier 3 upgrade. Perhaps I will roll that back since that doesn't seem feasible right now without first upgrading Jest. |
Explanation
Currently if you install the pre-push hook by running
yarn setup-git-hooks
, then each time you push, every file that can be linted will be linted. This is incredibly time-consuming if you want to push a branch and you've only changed a handful of files on your branch.To address this, this commit adds a shell script which replaces the existing
lint
andlint:fix
package scripts. This new script not only runs in "check" and "fix" modes (that is, either check and exit without fixes, or check and automatically make fixes), it also has the ability to detect which files have changed within the branch that you're on and only run ESLint and Prettier on those files.To accomplish this, the argument to
eslint
andprettier
have been simplified so that instead of excluding non-lintable files when these commands are called, ignore files are used instead. This required updating to Prettier 3, which reads from both.prettierignore
and.gitignore
, a useful task Prettier 2 did not do.Of course, you don't need to install the Git hook to take advantage of the changes in this commit. The
lint
andlint:fix
package scripts now take advantage of the new shell script, and there are also two new package scripts that delegate to the script, namely,lint:only-branch
andlint:fix:only-branch
.Finally, CI will still run
yarn lint
to ensure that all files in the repo still pass lint.References
Fixes #1333.
Testing
You can test this script by checking out this branch, making a change to a file that would violate an ESLint rule or violate Prettier format and then running
yarn lint:only-branch
. This should work regardless of whether or not you commit the change.You can also test that the script only considers the changes to the current branch by cutting a new branch off of this branch and running
yarn lint:only-branch
. ESLint and Prettier shouldn't do anything since no changes have occurred on this branch relative to its parent.Finally, if you want to know what happens on
main
, you can merge this branch intomain
(but don't push) and then runyarn lint:only-branch
. You should get the same results as the first test.Changelog
(No functional changes)
Checklist