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

style: add gulp task to only format changed files #24969

Closed
wants to merge 3 commits into from

Conversation

brandonroberts
Copy link
Contributor

Closes #24904

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] angular.io application / infrastructure changes
[x] Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

[ ] Yes
[x] No

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.

@brandonroberts brandonroberts added target: major This PR is targeted for the next major release comp: misc labels Jul 18, 2018
Copy link
Member

@gkalpak gkalpak left a 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.

@brandonroberts
Copy link
Contributor Author

@gkalpak yes, I'm going implement that idea.

@gkalpak
Copy link
Member

gkalpak commented Sep 7, 2018

You might want to hurry. You have competition now: #25847 😛

@brandonroberts
Copy link
Contributor Author

@gkalpak @petebacondarwin this one is ready for another review

@brandonroberts brandonroberts added action: review The PR is still awaiting reviews from at least one requested reviewer and removed state: WIP labels Sep 10, 2018
let currentMatch;

while ((currentMatch = RE_STATUS.exec(data)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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']);
Copy link
Member

@gkalpak gkalpak Sep 10, 2018

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/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@brandonroberts brandonroberts force-pushed the format-changed branch 2 times, most recently from 600c5b4 to f6e9528 Compare September 17, 2018 18:25
@IgorMinar IgorMinar added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Sep 27, 2018
@alxhub alxhub closed this in ac3252a Sep 27, 2018
@brandonroberts brandonroberts deleted the format-changed branch September 27, 2018 19:15
FrederikSchlemmer pushed a commit to FrederikSchlemmer/angular that referenced this pull request Jan 3, 2019
FrederikSchlemmer pushed a commit to FrederikSchlemmer/angular that referenced this pull request Jan 3, 2019
FrederikSchlemmer pushed a commit to FrederikSchlemmer/angular that referenced this pull request Jan 3, 2019
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add filter to source code formatting (gulp format)
5 participants