Skip to content

chore(queries): organize and test #366

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

chore(queries): organize and test #366

wants to merge 5 commits into from

Conversation

avivkeller
Copy link
Member

@avivkeller avivkeller commented Jul 21, 2025

The queries and RegExp's we use should be extensively tested to prevent anything slipping through. This PR moves all of our RegExps and queries into their own file, and adds unit tests. This way, we can re-use the same testing structure across our RegExps, to prevent de-syncs.

@Copilot Copilot AI review requested due to automatic review settings July 21, 2025 20:09
@avivkeller avivkeller requested a review from a team as a code owner July 21, 2025 20:09
Copy link

vercel bot commented Jul 21, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
api-docs-tooling ✅ Ready (Inspect) Visit Preview Jul 31, 2025 7:18pm

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR addresses issue #356 by refactoring and organizing regex and Unist query utilities into separate, focused modules. The changes improve code organization by extracting regex patterns into a reusable regex module and creating dedicated Unist query functions.

Key Changes

  • Extracted all regex patterns from queries/index.mjs into a new queries/regex.mjs module for better reusability
  • Created a new queries/unist.mjs module containing node type checking functions that were previously inline
  • Updated all import statements across the codebase to reference the new modular structure

Reviewed Changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/utils/queries/regex.mjs New module containing all regex patterns with comprehensive documentation
src/utils/queries/unist.mjs New module containing Unist node type checking functions
src/utils/queries/index.mjs Refactored to import and use patterns from new modules, removed inline definitions
src/utils/parser/index.mjs Updated import to use YAML_INNER_CONTENT from regex module
src/utils/parser/constants.mjs Updated to import heading regex patterns from regex module
Multiple generator and linter files Updated imports to use functions from the new unist module

Copy link
Member

@AugustinMauroy AugustinMauroy left a comment

Choose a reason for hiding this comment

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

LGTM ! but could you provide a before after for the issue

@avivkeller
Copy link
Member Author

After

Screenshot 2025-07-21 at 16 16 40

Before

Screenshot 2025-07-21 at 16 16 47

@AugustinMauroy
Copy link
Member

Thanks 👍

@avivkeller
Copy link
Member Author

Bump @nodejs/web-infra, this is a bug fix

Copy link
Member

@ovflowd ovflowd left a comment

Choose a reason for hiding this comment

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

Bump @nodejs/web-infra, this is a bug fix

How is such a huge PR a bug fix? This seems a refactor per PR-description. What are you fixing?

@@ -13,6 +13,13 @@ import {
} from '../parser/index.mjs';
import { getRemark } from '../remark.mjs';
import { transformNodesToString } from '../unist.mjs';
import {
Copy link
Member

Choose a reason for hiding this comment

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

I'd rather a prefixed import

Copy link
Member Author

Choose a reason for hiding this comment

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

Why?

Copy link
Member

Choose a reason for hiding this comment

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

Cleaner in this situation, these are a bunch on non prefixed constants, doing a wildcard import here better explains where they belong to.

@ovflowd
Copy link
Member

ovflowd commented Jul 24, 2025

What I fail to understand is why you arbitrarily decided to redesign the structure of the whole queries. Please revert these changes and only include your bug fix.

If you want to separate certain things, that's fine, but at least give an explanation why. Arbitrary refactors aren't something I support.

@avivkeller
Copy link
Member Author

avivkeller commented Jul 25, 2025

How is such a huge PR a bug fix?

This PR refactors our RegExp queries, and, in the process, fixes #356, I should not have classified this as a "bug fix", it's a change that also fixes a bug.

What I fail to understand is why you arbitrarily decided to redesign the structure of the whole queries

I figured, while I'm adding a RegExp file, why not move the query RegExps there as well, and at that point, also move the Unist functions. But I'm happy to revert, since that was quite the tangent.

@avivkeller avivkeller changed the title fix(regexp): organize fix(queries): organize Jul 25, 2025
@ovflowd
Copy link
Member

ovflowd commented Jul 25, 2025

How is such a huge PR a bug fix?

This PR refactors our RegExp queries, and, in the process, fixes #356, I should not have classified this as a "bug fix", it's a change that also fixes a bug.

What I fail to understand is why you arbitrarily decided to redesign the structure of the whole queries

I figured, while I'm adding a RegExp file, why not move the query RegExps there as well, and at that point, also move the Unist functions. But I'm happy to revert, since that was quite the tangent.

I do insist. Not against the refactor, but make a dedicated PR just for the refactor, without the bug fix.

This allows us to discuss the bug fix on this PR and the refactor on another :)

@avivkeller avivkeller marked this pull request as draft July 27, 2025 14:16
@avivkeller
Copy link
Member Author

Blocked by #379.

TODO Add test cases

@avivkeller avivkeller changed the title fix(queries): organize chore(queries): organize and test Jul 28, 2025
@avivkeller avivkeller marked this pull request as ready for review July 28, 2025 18:25
Copy link

codecov bot commented Jul 28, 2025

Codecov Report

❌ Patch coverage is 96.92172% with 35 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.27%. Comparing base (53b457d) to head (ccdd432).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/utils/queries/unist.mjs 87.37% 13 Missing ⚠️
src/generators/metadata/utils/parse.mjs 47.36% 10 Missing ⚠️
src/generators/legacy-html/utils/buildContent.mjs 60.00% 4 Missing ⚠️
src/generators/jsx-ast/utils/buildContent.mjs 62.50% 3 Missing ⚠️
src/generators/json-simple/index.mjs 50.00% 1 Missing ⚠️
...rc/generators/jsx-ast/utils/buildPropertyTable.mjs 75.00% 1 Missing ⚠️
src/generators/jsx-ast/utils/buildSignature.mjs 50.00% 1 Missing ⚠️
src/generators/legacy-json/utils/parseList.mjs 85.71% 1 Missing ⚠️
src/utils/queries/index.mjs 91.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #366      +/-   ##
==========================================
+ Coverage   74.27%   76.27%   +1.99%     
==========================================
  Files         118      120       +2     
  Lines       11041    11906     +865     
  Branches      695      718      +23     
==========================================
+ Hits         8201     9081     +880     
+ Misses       2837     2822      -15     
  Partials        3        3              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@avivkeller
Copy link
Member Author

The RegExps have 100% test coverage, with around 600 lines of tests (but I'm open to adding more). Ideally, these RegExps will almost never change, lest we break something

@@ -99,7 +97,7 @@ function handleExpression(node, basename, nameToLineNumberMap) {
case 'Identifier': {
exports.identifiers.push(value.name);

if (CONSTRUCTOR_EXPRESSION.test(value.name[0])) {
if (/^[A-Z]/.test(value.name)) {
Copy link
Member

Choose a reason for hiding this comment

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

Let's keep regexes in constants for easily finding regexes in one place

Copy link
Member Author

@avivkeller avivkeller Jul 31, 2025

Choose a reason for hiding this comment

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

Even for these, single-character ones? Or, are you referring to all the RegExps?

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.

4 participants