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

error when no files will be processed #4326

Merged
merged 2 commits into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,8 @@ public function addFilesByDirectory(string $directory, array $files): void

$this->filesByDirectory[$directory] = $files;
}

public function isPathsEmpty(): bool {
return $this->filePaths === [] && $this->filesByDirectory === [];
}
}
4 changes: 4 additions & 0 deletions src/Console/Command/ProcessCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int

// 1. add files and directories to static locator
$this->dynamicSourceLocatorDecorator->addPaths($paths);
if ($this->dynamicSourceLocatorDecorator->isPathsEmpty()) {
$this->rectorOutputStyle->error("The given paths do not match any files");
return ExitCode::FAILURE;
Copy link
Member

Choose a reason for hiding this comment

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

while probably rare usecase, I think show warning only is better than return error, to avoid a use case that file already removed via other rector rule.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not sure how files which are deleted from rector itself can affect the configuration-paths?

Copy link
Member

Choose a reason for hiding this comment

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

User may can create a custom FileProcessor, which may delete file on specific use, then on parallel, it called on separate rules.

For DX perspective, I think stop and retry should not happen, and this also doesn't give information which part that empty.

}

// 2. inform user about registering configurable rule without configuration
$this->emptyConfigurableRectorChecker->check();
Expand Down
4 changes: 4 additions & 0 deletions src/StaticReflection/DynamicSourceLocatorDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,8 @@ public function addPaths(array $paths): void
$this->dynamicSourceLocatorProvider->addFilesByDirectory($directory, $filesInDirectory);
}
}

public function isPathsEmpty(): bool {
return $this->dynamicSourceLocatorProvider->isPathsEmpty();
}
}