Skip to content

Conversation

@sirbrillig
Copy link
Owner

@sirbrillig sirbrillig commented Feb 4, 2022

This is a follow-up to #51, which modifies the automatic mode workflows so that they do not run phpcs on the previous version of a file if the current version has no phpcs messages; in this PR we modify them further to also not generate a VCS diff of the file in that case.

Fixes #53

To do:

  • Change git workflow
  • Change svn workflow
  • Clean up docs.

@sirbrillig sirbrillig marked this pull request as ready for review February 8, 2022 00:13
if ($isNewFile) {
$debug('Skipping the linting of the orig file version as it is a new file.');
} else {
$debug('Skipping the linting of the orig file version as the new version of the file contains no lint errors.');
Copy link
Owner Author

Choose a reason for hiding this comment

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

This logging is handled by the above throw and the below catch.

if ($isNewFile) {
$debug('Skipping the linting of the orig file version as it is a new file.');
} else {
$debug('Skipping the linting of the orig file version as the new version of the file contains no lint errors.');
Copy link
Owner Author

Choose a reason for hiding this comment

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

This logging is handled by the above throw and the below catch.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Very elegant solution, which allowed a code serving the mere purpose of debugging messaging to be removed. Nice!

$debug('git status output:', $gitStatusOutput);
if (! $gitStatusOutput || false === strpos($gitStatusOutput, $gitFile)) {
throw new ShellException("Cannot get git status for file '{$gitFile}'");
return false;
Copy link
Owner Author

Choose a reason for hiding this comment

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

I'm not sure how this worked before, since git status file.php will be an empty string for an already existing file.

$shell->registerCommand("cat 'foobar.php' | phpcs", $this->phpcs->getEmptyResults()->toPhpcsJson());

$options = [
'no-cache-git-root' => 1,
Copy link
Owner Author

Choose a reason for hiding this comment

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

This allows us to test without the static variable caching operating.

$hasNewPhpcsMessages = !empty($newFilePhpcsMessages->getMessages());

if (! $hasNewPhpcsMessages) {
throw new NoChangesException("New file '{$svnFile}' has no PHPCS messages; skipping");
Copy link
Collaborator

@david-binda david-binda Feb 8, 2022

Choose a reason for hiding this comment

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

It's not an issue of this PR, but we seem to be using "new file" in multiple meanings across the codebase, which might be confusing when reading the output.

Perhaps we should be using "new version of the {$svnFile}" here, similarly to line 272 where "old file version" is used. And limit the usage of "new file" to newly added file? Or perhaps even better, use "newly added file" instead of "new file"?

Edit: The same goes for "old file", where "old version of" might be more appropriate. And while nitpicking about the messaging, perhaps "previous version" might be better. Not sure, tho, if "new" should be replaced by something like "current/working"

Copy link
Owner Author

Choose a reason for hiding this comment

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

Yeah, I agree! I realized this same issue when working on this PR and I wanted to go through and rename everything, but I decided it would be better for a different PR. I'll get that next.

Copy link
Collaborator

@david-binda david-binda left a comment

Choose a reason for hiding this comment

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

Good job at refactoring the diff generation to situations where it's really necesary.

I also love all the minor touches to the code readability.

I have also manually tested the code, and it seems to work well.

$fileName = $shell->getFileNameFromPath($gitFile);
$newFilePhpcsMessages = PhpcsMessages::fromPhpcsJson($newFilePhpcsOutput, $fileName);
$hasNewFilePhpcsIssues = !empty($newFilePhpcsMessages->getMessages());
$hasNewPhpcsMessages = !empty($newFilePhpcsMessages->getMessages());
Copy link
Collaborator

Choose a reason for hiding this comment

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

I like the new variable name way better than the old one, makes the code more readable.

if ($isNewFile) {
$debug('Skipping the linting of the orig file version as it is a new file.');
} else {
$debug('Skipping the linting of the orig file version as the new version of the file contains no lint errors.');
Copy link
Collaborator

Choose a reason for hiding this comment

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

Very elegant solution, which allowed a code serving the mere purpose of debugging messaging to be removed. Nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Do not generate diff in case new version of the file include no lint issues

3 participants