Skip to content

feat(linter/approx-constant): implement fixer#16847

Merged
graphite-app[bot] merged 1 commit intomainfrom
c/12-14-feat_linter_approx-constant_implement_fixer
Dec 14, 2025
Merged

feat(linter/approx-constant): implement fixer#16847
graphite-app[bot] merged 1 commit intomainfrom
c/12-14-feat_linter_approx-constant_implement_fixer

Conversation

@camc314
Copy link
Copy Markdown
Contributor

@camc314 camc314 commented Dec 14, 2025

No description provided.

@camc314 camc314 marked this pull request as ready for review December 14, 2025 16:51
Copilot AI review requested due to automatic review settings December 14, 2025 16:51
@github-actions github-actions bot added A-linter Area - Linter C-enhancement Category - New feature or request labels Dec 14, 2025
Copy link
Copy Markdown
Contributor Author

camc314 commented Dec 14, 2025


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@camc314 camc314 force-pushed the c/12-14-feat_linter_approx-constant_implement_fixer branch 2 times, most recently from 9cbb26e to 5c58c95 Compare December 14, 2025 16:52
@camc314 camc314 self-assigned this Dec 14, 2025
Copy link
Copy Markdown
Contributor

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 implements an auto-fixer for the oxc/approx-constant linter rule and adds comprehensive oxlint plugin demo files. The approx-constant rule now provides suggestions to replace approximate constant values with their Math object equivalents (e.g., 3.14159Math.PI). The PR also includes a detailed investigation document about an unrelated oxlint hang issue in the next.js ecosystem CI.

Key Changes

  • Implements suggestion fixer for the approx-constant rule that replaces numeric literals with Math constants
  • Adds 5 progressive demo examples showing how to write custom oxlint plugins (from basic rules to complex configurations)
  • Includes HANG_INVESTIGATION.md documenting a performance issue with the constructor-super rule

Reviewed changes

Copilot reviewed 1 out of 1 changed files in this pull request and generated no comments.

Show a summary per file
File Description
crates/oxc_linter/src/rules/oxc/approx_constant.rs Added fixer implementation using diagnostic_with_suggestion and changed rule status from pending to suggestion. Includes comprehensive test cases for all supported Math constants.
oxlint-plugin-demo/README.md Comprehensive documentation for writing custom oxlint plugins with 5 progressive examples covering basic rules, fixers, selectors, configuration options, and message IDs.
oxlint-plugin-demo/demo-1/01-basic-plugin.ts Basic plugin example demonstrating comment detection (TODO/FIXME/HACK).
oxlint-plugin-demo/demo-2/02-fixable-rule.ts Demonstrates auto-fixable rules with no-var and no-debugger examples.
oxlint-plugin-demo/demo-3/03-selectors.ts Shows CSS-like selector usage for matching AST patterns.
oxlint-plugin-demo/demo-4/04-rule-with-options.ts Demonstrates configurable rules with user-provided options.
oxlint-plugin-demo/demo-5/05-message-ids.ts Shows message IDs and placeholders for organized error messages.
oxlint-plugin-demo/demo-[1-5]/{test.js,oxlintrc.json,package.json} Supporting test files and configuration for each demo.
oxlint-plugin-demo/test-file.js Comprehensive test file exercising all demo plugin rules.
HANG_INVESTIGATION.md Detailed analysis of exponential path explosion in constructor-super rule causing hangs on large Next.js files.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@camc314 camc314 added the 0-merge Merge with Graphite Merge Queue label Dec 14, 2025
Copy link
Copy Markdown
Contributor Author

camc314 commented Dec 14, 2025

Merge activity

Copy link
Copy Markdown

@charliecreates charliecreates bot left a comment

Choose a reason for hiding this comment

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

The core ApproxConstant fixer is a solid step forward, but it should avoid emitting multiple competing fixes for one literal and should be more conservative when Math may be shadowed. The new oxlint-plugin-demo content has several correctness/UX issues: inconsistent #oxlint vs oxlint imports, a top-level config that points at non-existent plugin paths, and a test/config that references rules that aren’t implemented. A committed *.profraw profiling artifact should not live in the repo and needs removal/ignore rules.

Additional notes (2)
  • Maintainability | default_14849635966089712973_0_16428.profraw:1-1
    This adds a raw profiler output file to the repo. These artifacts are typically machine-specific, large, and noisy in diffs, and they tend to bloat the repository history. Unless there’s a clear policy/need for committing *.profraw (e.g., reproducible perf regression evidence that is consumed by CI), it should be excluded and uploaded to CI artifacts instead.

  • Maintainability | crates/oxc_linter/src/rules/oxc/approx_constant.rs:51-51
    number_lit_str is generated via number_literal.value.to_string(), which can normalize/round values and produce formats (e.g., scientific notation) that don’t reflect the original source. That can cause the matcher to trigger (or not trigger) inconsistently compared to what the user typed, and it can also generate a fix that replaces a literal that wasn’t actually “approximate” textually.

Given this PR adds a fixer, correctness here matters more: the rule should ideally compare against the source text of the literal (including user formatting) and only then apply a fix.

Summary of changes

Summary of changes

ApproxConstant rule now offers an auto-fix

  • Updated crates/oxc_linter/src/rules/oxc/approx_constant.rs to make the rule fixable via suggestions:
    • Switched from pending to suggestion in declare_oxc_lint!.
    • Added ctx.diagnostic_with_suggestion(...) to propose replacing numeric approximations with Math.<CONST>.
    • Introduced helper ApproxConstant::fix_with_math_constant(...) using RuleFixer::replace.
    • Extended tests to validate fixes via Tester::expect_fix(...).

Added documentation / demo content

  • Added oxlint-plugin-demo/ with five progressive plugin examples (basic rule, fixable rule, selectors, options, message IDs) plus configs and test files.
  • Added HANG_INVESTIGATION.md documenting an ecosystem CI hang in constructor-super.

Added profiling artifact

  • Added a binary profiling file: default_14849635966089712973_0_16428.profraw.

@charliecreates charliecreates bot removed the request for review from CharlieHelps December 14, 2025 16:57
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Dec 14, 2025

CodSpeed Performance Report

Merging #16847 will not alter performance

Comparing c/12-14-feat_linter_approx-constant_implement_fixer (5c58c95) with main (59d589d)1

Summary

✅ 4 untouched
⏩ 41 skipped2

Footnotes

  1. No successful run was found on main (cd43ae3) during the generation of this report, so 59d589d was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

  2. 41 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@graphite-app graphite-app bot force-pushed the c/12-14-feat_linter_approx-constant_implement_fixer branch from fe8f421 to 99c0496 Compare December 14, 2025 17:14
@graphite-app graphite-app bot merged commit 99c0496 into main Dec 14, 2025
20 checks passed
@graphite-app graphite-app bot deleted the c/12-14-feat_linter_approx-constant_implement_fixer branch December 14, 2025 17:19
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Dec 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-linter Area - Linter C-enhancement Category - New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants