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
style: add gulp task to only format changed files #24969
Conversation
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.
LGTM 👍
Unfortunately, git diff
will not list untracked files, but I don't think there is a non-intrusive way to fix this.
@gkalpak yes, I'm going implement that idea. |
You might want to hurry. You have competition now: #25847 😛 |
e9a42f3
to
44d795f
Compare
@gkalpak @petebacondarwin this one is ready for another review |
tools/gulp-tasks/format.js
Outdated
let currentMatch; | ||
|
||
while ((currentMatch = RE_STATUS.exec(data)) !== null) { | ||
// This is necessary to avoid infinite loops with zero-width matches |
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.
I don't think there can be zero-width matches with the current RegExp 😕
Can you give an example?
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.
I can't think of an example since the output from git is standardized. I generated this when I was testing the Regex. I'll remove that line.
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.
This is more about the RegExp (the input it runs on does not matter). This problem is true for RegExps that can have a zero match (i.e. do match with the input). For example: /.*/
(since *
can match 0 or more character).
It is one of the weird issue of JS RegExps. If you don't know about this exec()
limitation, it must be quite frustrating figuring it out 😁
gulpfile.js
Outdated
@@ -29,6 +29,9 @@ function loadTask(fileName, taskName) { | |||
|
|||
gulp.task('format:enforce', loadTask('format', 'enforce')); | |||
gulp.task('format', loadTask('format', 'format')); | |||
gulp.task('format:changes', loadTask('format', 'format-changes')); | |||
gulp.task('format:diff', loadTask('format', 'format-diff')); | |||
gulp.task('format:changed', ['format:changes', 'format:diff']); |
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.
AFAICT, format:changes
and format:diff
have a good chance of formatting the same files (i.e. formatting a file twice).
Not a big deal, of course, but if you wanted to avoid that, you could change format:changes
to only format untracked files (and rename to format:untracked
😛).
Then, the combination of format:diff
and format:untracked
would format all files without formatting a file twice \o/
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.
👍
600c5b4
to
f6e9528
Compare
f6e9528
to
0e287cb
Compare
0e287cb
to
7388f87
Compare
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Closes #24904
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: N/A
What is the new behavior?
Does this PR introduce a breaking change?
Other information
This introduces a new gulp task to only format changed files (using git diff) that intersect the whitelist of necessary source files. The diff is compared against the provided branch (default: master). It significantly reduces the time to run formatting when working on docs and source code.