Skip to content

fix: resolve lint and style errors in compiler and build tools#4453

Open
Ritvik718 wants to merge 1 commit into
less:masterfrom
Ritvik718:fix/linting-issues
Open

fix: resolve lint and style errors in compiler and build tools#4453
Ritvik718 wants to merge 1 commit into
less:masterfrom
Ritvik718:fix/linting-issues

Conversation

@Ritvik718

@Ritvik718 Ritvik718 commented Jun 15, 2026

Copy link
Copy Markdown

What:

  • Applied automated style fixes across the codebase using ESLint.
  • Fixed remaining linting errors in packages/less/benchmark/benchmark-runner.js:
    • Removed unused parseTimes array.
    • Omitted the unused output parameter from less.render's callback.
    • Avoided block-scope redeclaration of loop variable i under ES5 standards by reusing the outer declared variable.
  • Fixed quotes formatting from double to single quotes in packages/less/build/rollup.js to match style rules.

Why:
These changes bring the codebase back into full compliance with its ESLint styling standards, resolving 111 warnings/errors and allowing the lint checks (pnpm --filter less lint) to pass cleanly with zero issues.

Checklist:

  • Documentation - N/A
  • Added/updated unit tests - N/A
  • Code complete

Summary by CodeRabbit

  • Chores
    • Improved benchmark runner with enhanced error handling, CLI argument parsing, and detailed statistics reporting.
    • Minor build configuration adjustment.

@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jun 15, 2026
@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The benchmark runner script is refactored to add --key=value CLI argument parsing, multi-path Less compiler discovery with .default interop, high-resolution timing helpers, per-run error tracking with early-exit logic, and an updated statistics pipeline that computes median/stddev/variance and conditionally emits errors in the JSON output. A separate trivial change converts a template literal to a single-quoted string in the rollup build plugin.

Changes

Benchmark Runner Refactor

Layer / File(s) Summary
CLI parsing and Less compiler discovery
packages/less/benchmark/benchmark-runner.js
Parses --key=value arguments into extraOpts, validates the required input file, and discovers the Less compiler by attempting multiple module paths with .default interop and render/parse capability checks.
Timing helpers, run state, and execution orchestration
packages/less/benchmark/benchmark-runner.js
Adds hrNow for high-resolution elapsed time, introduces completed and errors state, and rewrites runOnce/runAll so failures are tracked as { run, error } entries and execution stops early when more than 3 errors accumulate.
Statistics analysis and result reporting
packages/less/benchmark/benchmark-runner.js
analyze skips warmup samples and returns null when too few remain; otherwise computes min/max/avg/median/stddev/variance_pct/throughput_kbs. reportResults emits completedRuns, conditionally includes errors, and sets render to the analysis output.

Rollup Build String Literal Fix

Layer / File(s) Summary
moduleShim stub literal
packages/less/build/rollup.js
The virtual module stub returned by moduleShim().load() is changed from a template literal to a single-quoted string; exported code is unchanged.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 Hop, hop through the benchmarks we go,
Timing each render, high-res and slow,
Errors get tracked in a tidy array,
Stats compute medians without delay,
And a quote swapped for a backtick — hooray! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title directly describes the main purpose of the PR: resolving lint and style errors in compiler and build tools. It accurately reflects both primary changes across the modified files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/less/benchmark/benchmark-runner.js (1)

71-73: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Add error handling for file read operations.

If fs.readFileSync fails (file not found, permission denied, etc.), the script will crash with an uncaught exception instead of the JSON error format used elsewhere (line 57). This inconsistency makes it harder for downstream consumers to parse failures.

🛡️ Proposed fix to add try-catch
-var filePath = path.resolve(file);
-var data = fs.readFileSync(filePath, 'utf8');
-var fileDir = path.dirname(filePath);
+var filePath = path.resolve(file);
+var data;
+try {
+    data = fs.readFileSync(filePath, 'utf8');
+} catch (e) {
+    console.error(JSON.stringify({ error: 'Failed to read benchmark file', file: filePath, message: e.message }));
+    process.exit(2);
+}
+var fileDir = path.dirname(filePath);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/less/benchmark/benchmark-runner.js` around lines 71 - 73, The
`fs.readFileSync` call in the file reading section lacks error handling, causing
the script to crash with an uncaught exception if the file cannot be read (due
to missing file, permission issues, etc.). Wrap the `fs.readFileSync(filePath,
'utf8')` operation in a try-catch block and handle the error by returning or
logging the error in the same JSON error format that is used elsewhere in the
script (like the pattern shown around line 57). This ensures consistent error
reporting across all failure modes in the benchmark runner.
🧹 Nitpick comments (1)
packages/less/benchmark/benchmark-runner.js (1)

112-112: ⚡ Quick win

Replace magic number with named constant.

The error threshold 3 is unexplained and hard-coded. Consider extracting it as a named constant at the top of the file (e.g., var maxErrors = 3;) to document the intent and make it easier to adjust.

Note: The current logic allows 4 errors before bailing (errors are pushed before this check), so the effective threshold is 3 + 1.

♻️ Proposed refactor
+var maxErrors = 3; // Bail after this many failures
+
 var file = process.argv[2];
-        if (err && errors.length > 3) {
+        if (err && errors.length > maxErrors) {
             // Too many errors, bail
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/less/benchmark/benchmark-runner.js` at line 112, The magic number 3
in the condition `if (err && errors.length > 3)` is hard-coded without
explanation. Extract this value as a named constant at the top of the
benchmark-runner.js file (for example, `var maxErrors = 3;`) to document its
purpose, then replace the hard-coded 3 with this constant reference in the
condition to improve code clarity and maintainability.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@packages/less/benchmark/benchmark-runner.js`:
- Around line 71-73: The `fs.readFileSync` call in the file reading section
lacks error handling, causing the script to crash with an uncaught exception if
the file cannot be read (due to missing file, permission issues, etc.). Wrap the
`fs.readFileSync(filePath, 'utf8')` operation in a try-catch block and handle
the error by returning or logging the error in the same JSON error format that
is used elsewhere in the script (like the pattern shown around line 57). This
ensures consistent error reporting across all failure modes in the benchmark
runner.

---

Nitpick comments:
In `@packages/less/benchmark/benchmark-runner.js`:
- Line 112: The magic number 3 in the condition `if (err && errors.length > 3)`
is hard-coded without explanation. Extract this value as a named constant at the
top of the benchmark-runner.js file (for example, `var maxErrors = 3;`) to
document its purpose, then replace the hard-coded 3 with this constant reference
in the condition to improve code clarity and maintainability.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: d8b29868-b1e3-4a41-9898-d6231c79a21a

📥 Commits

Reviewing files that changed from the base of the PR and between 7787557 and 99f0ba8.

📒 Files selected for processing (2)
  • packages/less/benchmark/benchmark-runner.js
  • packages/less/build/rollup.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant