WordPress / WordPress/WordPress-Coding-Standards
Some regex best practices
Open
Nobody has claimed this yet.
Focus: Code analysis
Type: Enhancement
Upstream: PHPCSExtra
- Dominant language
- PHP
- Stars
- 2.8k
- Forks
- 521
- Avg merge
- 5d 20h
- Merged PRs (30d)
- 1
Description
With the regex functions, there are some best practices we could advise on /often made "mistakes" which we could warn people about.
I'm thinking along the lines of:
- Use of
/as delimiter -> advise to use other delimiter - Use of variables in the regex -> use
preg_quote() - Use of
gmodifier -> Not used in PHP usepreg_match_all()function instead - Use of
sandmmodifier in one regex -> they don't go together, review regex
Additionally the sniff could potentially check for:
- non-PCRE syntaxes used in the regex
- modifiers which are not implemented/available in PHP
This sniff would go into the extra ruleset.
Opinions ?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the extra ruleset, which the issue identifies as the intended home for the sniff. The scope is not decided: clarify which regex practices and syntax or modifier checks are required, then define how completion will be verified; no file or test is named.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100