Skip to content

Refactor regex usage - #1951

Merged
ai merged 2 commits into
postcss:mainfrom
bluwy:refactor-regex
Jul 26, 2024
Merged

ai merged 2 commits into
postcss:mainfrom
bluwy:refactor-regex

Conversation

@bluwy

@bluwy bluwy commented Jul 26, 2024

Copy link
Copy Markdown
Contributor

I was linting the code with eslint-plugin-regexp and found some improvements that we could do here.

  • Refactor away legacy RegExp.lastMatch usage (they're deprecated)
  • Removed an unneeded non-greedy constant quantifier
  • Removed an unneeded m flag

Here are the lint results that caught these issues:

/Users/bjorn/Work/oss/vite/node_modules/.pnpm/[email protected]/node_modules/postcss/lib/map-generator.js
  78:39  error  Unexpected non-greedy constant quantifier. The quantifier is effectively possessive, so it doesn't matter whether it is greedy or not  regexp/no-useless-lazy

/Users/bjorn/Work/oss/vite/node_modules/.pnpm/[email protected]/node_modules/postcss/lib/previous-map.js
  45:45  error  'RegExp.lastMatch' static property is forbidden                                                   regexp/no-legacy-features
  49:37  error  'RegExp.lastMatch' static property is forbidden                                                   regexp/no-legacy-features
  70:59  error  The 'm' flag is unnecessary because the pattern does not contain start (^) or end ($) assertions  regexp/no-useless-flag

I tested each regex calls manually to make sure the lint errors are accurate, and they should still work as before.

Comment thread lib/previous-map.js Resolved
Comment thread lib/previous-map.js Resolved
@ai
ai merged commit 85e8d68 into postcss:main Jul 26, 2024
@ai

ai commented Jul 26, 2024

Copy link
Copy Markdown
Member

Thanks!

@bluwy
bluwy deleted the refactor-regex branch July 26, 2024 14:23
hanzo-dev pushed a commit to hanzoai/postcss that referenced this pull request Sep 9, 2026
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.

2 participants