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

feat: change px2rem regex config #1469

Merged
merged 5 commits into from
Aug 19, 2024
Merged

feat: change px2rem regex config #1469

merged 5 commits into from
Aug 19, 2024

Conversation

xiaohuoni
Copy link
Member

@xiaohuoni xiaohuoni commented Aug 5, 2024

修改 px2rem 的配置解析,对标 postcss-plugin-px2rem 的现有配置
postcss-plugin-px2rem 配置['.a',/.adm-/, /^:root/, /._CustomClass/]
修改前 mako px2rem 配置 [".a","(.adm-)","^:root","(._CustomClass)"]
修改后 mako px2rem 配置[".a","/.adm-/", "/^:root/", "/._CustomClass/"]
修改后只需把之前的正则表达式当作字符串传递即可,减少项目迁移成本。

Summary by CodeRabbit

  • 新特性

    • 更新了配置文件的文档,详细说明了 selectorBlackListselectorWhiteListselectorDoubleList 属性的行为,用户可以使用字符串或正则表达式。
    • 增加了示例,展示如何使用带有斜杠的字符串来定义正则表达式。
  • 文档

    • 对配置文档进行了增强,明确阐述如何定义选择器以提高灵活性和可用性。

Copy link
Contributor

coderabbitai bot commented Aug 5, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

此次更改主要集中在Px2RemConfig结构体及其parse_patterns函数的改进上。通过简化模式匹配逻辑,移除了对魔法字符的检查,转而采用简单的前后斜杠检测。这使得选择器的表示方式更加清晰,同时文档也相应更新,以帮助用户更好地理解新格式的使用。

Changes

文件 更改摘要
crates/mako/src/visitors/css_px2rem.rs parse_patterns函数逻辑简化,移除contains_magic_chars函数,更新选择器字段以包含斜杠。
docs/config.md 新增selectorBlackListselectorWhiteListselectorDoubleList的详细说明,包含正则表达式使用示例。
docs/config.zh-CN.md 增强配置文档,详细说明选择器属性,并提供示例以说明如何使用正则表达式和字符串。

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Config
    User->>Config: 提交选择器配置
    Config->>Config: 解析选择器模式
    alt 选择器以斜杠包围
        Config->>Config: 识别为正则表达式
    else 选择器未包围
        Config->>Config: 格式化为字符串匹配
    end
    Config->>User: 返回解析结果
Loading

Poem

在代码的草地上,
兔子欢快跳跃着,
斜杠引领新方向,
模式简化真美好!
配置文档更明了,
兔子祝贺新变化! 🐰✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 47aaf56 and 7dc7ed6.

Files selected for processing (3)
  • crates/mako/src/visitors/css_px2rem.rs (8 hunks)
  • docs/config.md (1 hunks)
  • docs/config.zh-CN.md (1 hunks)
Additional comments not posted (4)
docs/config.zh-CN.md (1)

566-573: 文档更新:解释正则表达式和字符串的用法

文档清楚地解释了 selectorBlackListselectorWhiteListselectorDoubleList 属性可以接受正则表达式或字符串,并提供了示例。这有助于用户更好地理解和使用这些配置项。

docs/config.md (1)

566-573: Documentation Update: Clarification on Regex and String Usage

The documentation clearly explains that the selectorBlackList, selectorWhiteList, and selectorDoubleList properties can accept regular expressions or strings, and provides an example. This helps users better understand and use these configuration items.

crates/mako/src/visitors/css_px2rem.rs (2)

149-150: 简化正则表达式解析逻辑

正则表达式解析逻辑被简化为仅检查模式是否以斜杠开头和结尾。这种方法更直观,但需要确保所有模式都符合这种格式。


Line range hint 409-665: 更新测试用例以匹配新的正则表达式格式

测试用例已更新,以确保新的正则表达式格式得到正确验证。这些更改确保了配置的灵活性和清晰度。

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7dc7ed6 and c1aad20.

Files selected for processing (2)
  • docs/config.md (1 hunks)
  • docs/config.zh-CN.md (1 hunks)
Additional comments not posted (2)
docs/config.zh-CN.md (1)

577-584: 文档更新清晰且准确。

selectorBlackListselectorWhiteListselectorDoubleList 的解释清晰,示例也正确地展示了如何使用正则表达式和字符串。

docs/config.md (1)

577-584: Documentation update is clear and accurate.

The explanation of selectorBlackList, selectorWhiteList, and selectorDoubleList is clear, and the example correctly demonstrates how to use regular expressions and strings.

Copy link
Member

@PeachScript PeachScript left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bundler-mako 层可以做一次转换?把正则转成字符串,这样 Umi 应用就不用改了

@xiaohuoni
Copy link
Member Author

@PeachScript Umi 应用没有直接对应的配置吧?

@PeachScript
Copy link
Member

@PeachScript Umi 应用没有直接对应的配置吧?

Umi 有 extraPostCSSPlugins,现在 px2rem 的配置不是从这里转进来的么

@xiaohuoni
Copy link
Member Author

extraPostCSSPlugins

在 bigfish 里面应该也是内置了 postcss-plugin-px2rem 插件,在 umi 里面应该是没有

docs/config.zh-CN.md Outdated Show resolved Hide resolved
docs/config.md Outdated Show resolved Hide resolved
@sorrycc sorrycc merged commit ae37765 into master Aug 19, 2024
4 checks passed
@sorrycc sorrycc deleted the feat-change-px2rem-regex branch August 19, 2024 02:35
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.

3 participants