Skip to content

Refactor regex usage#1951

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

Refactor regex usage#1951
ai merged 2 commits intopostcss:mainfrom
bluwy:refactor-regex

Conversation

@bluwy
Copy link
Contributor

@bluwy bluwy commented Jul 26, 2024

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/postcss@8.4.39/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/postcss@8.4.39/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.

@ai ai merged commit 85e8d68 into postcss:main Jul 26, 2024
@ai
Copy link
Member

ai commented Jul 26, 2024

Thanks!

@bluwy bluwy deleted the refactor-regex branch July 26, 2024 14:23
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