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

Allow unused function arguments as regexp #22

Merged
merged 11 commits into from
Apr 27, 2018

Conversation

sirbrillig
Copy link
Owner

@sirbrillig sirbrillig commented Jan 23, 2018

There are already three options for ignoring unused variables. This PR adds documentation for those options and also adds a new option to allow ignoring variables by regular expression. This will bring the available options to the following:

  • allowUnusedFunctionParameters (bool, default false): if set to true, function arguments will never be marked as unused.
  • allowUnusedCaughtExceptions (bool, default false): if set to true, caught Exception variables will never be marked as unused.
  • validUnusedVariableNames (string, default null): a space-separated list of names of placeholder variables that you want to ignore from unused variable warnings. For example, to ignore the variables $junk and $unused, this could be set to 'junk unused'.
  • ignoreUnusedRegexp (string, default null): a PHP regexp string (note that this requires explicit delimiters) for variables that you want to ignore from unused variable warnings. For example, to ignore the variables $_junk and $_unused, this could be set to '/^_/'.

Fixes #21.

To do

  • Add tests for allowed unused function arguments via validUnusedVariableNames
  • Convert validUnusedVariableNames to array late
  • Add ignoreUnusedRegexp option to allow unused arguments regexp
  • Add tests for multi-line function arguments
  • Add documentation for allowUnusedFunctionParameters, validUnusedVariableNames, allowUnusedCaughtExceptions and ignoreUnusedRegexp

@sirbrillig sirbrillig force-pushed the update/allow-unused-args branch 3 times, most recently from 66813c2 to 2f14ecb Compare January 27, 2018 20:49
@sirbrillig sirbrillig changed the title Allow unused function arguments Allow unused function arguments as regexp Feb 7, 2018
@sirbrillig sirbrillig force-pushed the update/allow-unused-args branch 2 times, most recently from 76d448a to 2e59460 Compare February 7, 2018 00:16
Previously the property was converted to an array when the Sniff was
registered. This could cause issues if the property was changed (I know
it's unlikely but it can happen in tests pretty easily) after
registration. Furthermore, it was convered to an array and then used to
replace the original string property, which introduces risk by both
mutating a property during an object lifecycle and even changing its type.

With this change, we never change the property from a string, and
instead we convert it to an array just before it is used.
@sirbrillig sirbrillig force-pushed the update/allow-unused-args branch from 2e59460 to 3976667 Compare April 20, 2018 14:46
@sirbrillig sirbrillig merged commit c1fb8f6 into master Apr 27, 2018
@sirbrillig sirbrillig deleted the update/allow-unused-args branch April 27, 2018 15:26
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.

1 participant