-
-
Notifications
You must be signed in to change notification settings - Fork 344
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
Added ability to baseline existing violations #873
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Added BaselineRenderer to write the baseline
Added ViolationBaseline Added BaselineSetFactory
mirzazeyrek
approved these changes
Apr 10, 2021
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.
Looks cool! Great work.
mirzazeyrek
approved these changes
Apr 10, 2021
kylekatarnls
approved these changes
Apr 11, 2021
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.
Tested and it works as expected.
Nice work! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Type: Feature
Issue: Resolves #871
Breaking change: no
Added the ability to export existing violations to a (default)
phpmd.baseline.xml
file. When PHPMD notices this file all violations that exist within the baseline will not be added to the violations report. Violations are detected based onfilename
,method
(if present), and the specificrule
.What's been changed?
Command
,CommandLineOptions
andPHPMD
to inject the baseline checks.README.rst
andindex.rst
documentation with the new cli options. This page: https://phpmd.org/documentation/index.htmlSome design decisions:
phpmd.baseline.xml
next to the (first) ruleset given on the cli. Assumed default usage would be aphpmd.xml
in the root of a project--baseline-file /path/to/file
cli option.--generate-baseline
the violations will be exported to the baseline xml instead of the default renderer. By adding this flag, the 2nd cli argument will be ignored.phpmd.baseline.xml
will serve as the base path of the baselined files. All source files should be relative to this file. Eg, the expected location ofphpmd.baseline.xml
should be in the root of your project.Examples
Export:
phpmd /path/to/source text phpmd.xml --generate-baseline
Writes baseline
phpmd.baseline.xml
next tophpmd.xml
Check:
phpmd /path/to/source text phpmd.xml
Tries to find
phpmd.baseline.xml
next tophpmd.xml
phpmd /path/to/source text phpmd.xml --baseline-file /path/to/file
Uses the given baseline filepath. All sources should still be relative to the baseline file.
Discussion A
I tried to stay close to the phpstan behaviour and what felt for me natural in the usages. It could be argued that the 2nd cli argument should be
baseline
. For example for export it could be:phpmd /path/to/source baseline phpmd.xml
I've chosen the extra
--generate-baseline
flag, as the 2nd argument is for output for external purposes, while the baseline is for internal purposes. What are your thoughts?Discussion B
I've chosen to determine the relative path of the violation source paths, to be relative to the baseline file. It felt natural for me to have all the files in the baseline file be relative to the file they are listed in. The downside is that with the
-baseline-line
cli option, you can't randomly choose a file location. Currently it has to be in a parent directory of the sources.Other options would be to calculate the relative path to the
phpmd.xml
. This is kinda awkward as phpmd accepts multiple rulesets as 3rd argument. Would have to pick the location of the first rulesetThird option would be to calculate the relative path based on the current working directory. This felt a little too magic for me, as the working directory could be outside the project.
Future
I read that psalm has an
--update-baseline
option, which will only remove entries from the baseline file, and won't add new ones. I think this will be nice feature for a future PR.