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
Add an ability to ignore Mutators for source code line(s) by regular expression #1326
Conversation
I'm very happy with the results. I miss only one functionality: a |
eba4b3e
to
0ab9637
Compare
0ab9637
to
0d5e908
Compare
cb789a0
to
bddf72f
Compare
}, | ||
"MethodCallRemoval": { | ||
"ignoreSourceCodeByRegex": [ | ||
"Assert::.*", |
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.
Shouldn't we dog-food this feature already?
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.
As a non-native English speaker, may I ask you what does this mean?
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.
Sure. I'm slightly surprised to find that there's even a Wikipedia article for the term.
Eating your own dog food or dogfooding is the practice of an organization using its own product.
What I meant is that Infection could use exactly this regex to limit removal of these calls.
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.
Shouldn't we dog-food this feature already?
if we need to - we certainly can. I didn't do any analysis for this though
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.
It can certainly wait.
…expression. Fixes #697 Allows to avoid mutating such lines of code as: ```diff - Assert::notNull($variable); ``` or ```diff - $this->logger->error($message, ['user' => $user]); + $this->logger->error($message, []); ``` and so on. Example of new config setting usage: ```json { "mutators": { "MethodCallRemoval": { "ignoreSourceCodeByRegex": [ "Assert::", "\\$this->logger" ] } } } ```
e4d7088
to
ecc0b61
Compare
If we can extend #1327 to allow injecting arbitrary configuration for a plugin, this feature is a great candidate for a standard plugin. Nevertheless I think this idea shouldn't be holding anything up since it should be possible to refactor this ignorer into a plugin without changing the configuration schema in a bit. |
CS Fixer is going nuts 😞 |
yeah, it's because it's downloading v2.15.8 instead of v2.16.4 as the latest PHAR for https://cs.sensiolabs.org/download/php-cs-fixer-v2.phar URL 2.16.4 works as expected locally. I will try to resolve it as a separate issue somewhere later today |
Agree. That was my plan - to release this one ASAP, and then, when we are ready with the plugin system (which can take some time) - we will refactor internal implementation. |
Regarding php-cs-fixer: there is an open issue, let's see how they will resolve it: PHP-CS-Fixer/PHP-CS-Fixer#5099 I think if they wont' fix it today, we can think about downloading particular hardcoded version for the time being |
I did |
Shall we merge this? |
Allows to avoid mutating such lines of code as:
- Assert::notNull($variable);
or
and similar if developers are not interested in them.
Example of new config setting usage:
Also, there is a new setting for
mutators
-global-ignoreSourceCodeByRegex
that will be added to all enabled mutators if present. Works similar toglobal-ignore
From an implementation point of view, it's not possible to use
IgnoreConfig
andIgnoreMutator
to ignore mutators for configured lines of code by regex, because, at the step of applying Mutator, we don't have any information about the source line of code.While we technically can get it (using PrettyPrinter's
prettyPrintExpr($expression)
function or by passing source code to each mutator and finding the needed line), for me it seems like not the right solution.This PR tries to filter out mutants before creating Mutant processes, similar to what is being discussed in
pre-
/post-
hooks here #1323So, before deciding whether we need to ignore mutator or no, we are applying regular expression (if any) to the diff of Mutant. Easy, yet so powerful.
I will continue adding tests/docs after we agree with the implementation.
I see this feature is most requested during the last months, so I would like to release it asap.
Regarding the suggested plugin system - #1323. When we will do it, this implementation can be redeveloped using plugin system/hooks, while for users configuration will be the same, so no BC here.
PS I'm aware of the failed build, it's ok for now since no tests have been updated