Skip to content

fix(scanner): conditionally set jsx parser option based on file extension#208

Open
aniruthramidi wants to merge 2 commits into
flaglint:mainfrom
aniruthramidi:fix/parser-jsx-option
Open

fix(scanner): conditionally set jsx parser option based on file extension#208
aniruthramidi wants to merge 2 commits into
flaglint:mainfrom
aniruthramidi:fix/parser-jsx-option

Conversation

@aniruthramidi

@aniruthramidi aniruthramidi commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

This fixes the failed to parse warnings for .ts files containing JSX, and prevents false syntax errors for un-escaped generics like <T> in .ts files by dynamically setting the jsx parser option based on the file extension.

Summary by CodeRabbit

  • New Features
    • Added support for disabling ANSI रंग/color output with --no-color and the NO_COLOR environment variable.
  • Bug Fixes
    • The CLI now correctly applies color settings per subcommand, keeping output clean when color is disabled.
    • Improved file parsing so JSX is only enabled for JSX-capable file types, reducing parsing issues on other files.
  • Tests
    • Added coverage for no-color behavior across scan and audit commands.

Aniruth Ramidi added 2 commits July 6, 2026 10:42
Signed-off-by: Aniruth Ramidi <aniruthramidi@gmail.com>
…sion

Signed-off-by: Aniruth Ramidi <aniruthramidi@gmail.com>
@aniruthramidi aniruthramidi requested a review from Krishan27 as a code owner July 6, 2026 06:16
@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds a --no-color CLI flag and NO_COLOR environment variable support to disable ANSI color output by disabling chalk rendering in the preAction hook, adds corresponding tests, and updates the scanner to conditionally enable JSX parsing only for .tsx, .jsx, .js files.

Changes

No-color CLI support

Layer / File(s) Summary
Chalk import and --no-color option wiring
src/cli.ts
Imports chalk, adds a --no-color option, and reworks the preAction hook to read options from thisCommand.opts(), disabling chalk rendering (chalk.level = 0) and forcing NO_COLOR=1 when the flag is passed or already set in the environment.
CLI tests for color suppression
src/commands/tests/cli.test.ts
Adds tests verifying ANSI escape codes are absent from stderr/stdout for scan and audit when --no-color or NO_COLOR=1 is used, even with FORCE_COLOR=1.

Conditional JSX parsing

Layer / File(s) Summary
Extension-based JSX parsing
src/scanner/index.ts
Updates the typescript-estree parser config in scan() to enable jsx: true only for .tsx, .jsx, .js files instead of always enabling it.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related issues

Possibly related PRs

  • flaglint/flaglint-js#200: Both PRs modify the same preAction hook and option handling around quiet/verbose/setOutputMode in src/cli.ts.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the scanner JSX parser change, which is a real part of the pull request.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ 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.

@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.

🧹 Nitpick comments (1)
src/scanner/index.ts (1)

666-666: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add scanner test coverage for the new extension-based jsx logic.

No test evidence is shown verifying that .ts files with unescaped generics (e.g. <T>) now parse successfully, or that .js files with JSX still parse correctly under this change.

🤖 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 `@src/scanner/index.ts` at line 666, Add scanner test coverage for the
extension-based jsx handling in the scanner logic. Update or add tests around
the code in src/scanner/index.ts that sets jsx based on file.endsWith checks to
verify `.ts` files with unescaped generics like `<T>` still parse successfully
and that `.js` files containing JSX continue to parse correctly under the new
behavior. Use the scanner entrypoints and parse flow exercised by the existing
scanner tests so the new assertions clearly cover the changed jsx detection
logic.
🤖 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.

Nitpick comments:
In `@src/scanner/index.ts`:
- Line 666: Add scanner test coverage for the extension-based jsx handling in
the scanner logic. Update or add tests around the code in src/scanner/index.ts
that sets jsx based on file.endsWith checks to verify `.ts` files with unescaped
generics like `<T>` still parse successfully and that `.js` files containing JSX
continue to parse correctly under the new behavior. Use the scanner entrypoints
and parse flow exercised by the existing scanner tests so the new assertions
clearly cover the changed jsx detection logic.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 63dcac95-7f3b-4d1a-a1da-199fd272f78c

📥 Commits

Reviewing files that changed from the base of the PR and between f730dcd and e5ab66f.

📒 Files selected for processing (3)
  • src/cli.ts
  • src/commands/tests/cli.test.ts
  • src/scanner/index.ts

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.

1 participant