Skip to content

feat: support file arguments in CLI for targeted linting#556

Merged
chenjiahan merged 1 commit intomainfrom
feat/cli-file-args-20260320
Mar 20, 2026
Merged

feat: support file arguments in CLI for targeted linting#556
chenjiahan merged 1 commit intomainfrom
feat/cli-file-args-20260320

Conversation

@fansenze
Copy link
Copy Markdown
Contributor

Summary

Add support for rslint [OPTIONS] [files...] so users can lint specific files instead of always scanning the entire project. This enables lint-staged integration and faster feedback loops during development.

Changes

Core (cmd/rslint/cmd.go)

  • Parse positional arguments via flag.Args() and resolve to absolute paths
  • Pass allowFiles to RunLinter to restrict linting scope
  • Exit with code 1 when specified files are not found in the project

Linter (internal/linter/linter.go)

  • Extract path comparison into isFileAllowed() function
  • Fast path: string equality check (zero overhead for normal cases)
  • Fallback: os.SameFile inode comparison to handle directory symlinks (e.g. /var/private/var on macOS)

Docs (website/docs/en/guide/cli.md)

  • Add "File Arguments" section documenting the new behavior

Behavior

rslint file1.ts file2.ts        # Only lint these files
rslint --fix file1.ts file2.ts  # Only fix these files
rslint                          # No args → full scan (unchanged)
rslint nonexistent.ts           # Error + exit 1

When file arguments are provided, only those files are linted. Configuration rules still apply — only the scan scope changes.

Related Links

Addresses user feedback that rslint CLI does not support passing file arguments, preventing lint-staged integration.

Checklist

  • Tests updated (or not required).
    • 10 Go unit tests (internal/linter/linter_test.go)
    • 18 e2e tests (packages/rslint-test-tools/tests/cli/file-args.test.ts)
  • Documentation updated (or not required).
    • CLI reference updated with File Arguments section

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the rslint CLI by introducing the ability to specify individual files or a subset of files for linting. This feature improves developer workflow by enabling faster feedback loops and seamless integration with tools like lint-staged, allowing users to focus linting efforts only on relevant changes rather than scanning an entire project.

Highlights

  • Targeted Linting Support: Introduced support for passing file arguments to the rslint CLI, enabling users to lint specific files or a subset of files instead of always scanning the entire project.
  • Improved Developer Workflow: This feature facilitates faster feedback loops during development and enables seamless integration with tools like lint-staged.
  • Robust File Path Handling: Implemented logic to parse CLI file arguments, resolve them to absolute paths, and efficiently compare file paths, including handling symlinks via os.SameFile.
  • Error Handling for Missing Files: The CLI now exits with an error code (1) if file arguments are provided but none of the specified files are found within the project.
  • Comprehensive Testing and Documentation: Added extensive Go unit tests for the linter's file filtering logic and e2e tests for the CLI's new behavior, alongside updated documentation for the new feature.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a valuable feature for targeted linting by allowing file paths as CLI arguments. The implementation is well-structured, with changes to the CLI handling, linter logic, and comprehensive unit and end-to-end tests. The documentation has also been updated accordingly. I've identified one potential performance issue in the file filtering logic that could affect larger projects, and I've left a specific comment with a suggestion for optimization. Overall, this is a great addition that will improve the developer experience.

@fansenze fansenze force-pushed the feat/cli-file-args-20260320 branch from 965eb20 to 9643334 Compare March 20, 2026 08:15
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages bot commented Mar 20, 2026

Deploying rslint with  Cloudflare Pages  Cloudflare Pages

Latest commit: fa7dde6
Status: ✅  Deploy successful!
Preview URL: https://739d0dcf.rslint.pages.dev
Branch Preview URL: https://feat-cli-file-args-20260320.rslint.pages.dev

View logs

@fansenze fansenze force-pushed the feat/cli-file-args-20260320 branch from 9643334 to b210d25 Compare March 20, 2026 08:25
Add support for `rslint [OPTIONS] [files...]` so users can lint specific
files instead of always scanning the entire project. This enables
lint-staged integration and faster feedback loops.

- Parse positional args via flag.Args() and pass as allowFiles to RunLinter
- Add isFileAllowed() with os.SameFile fallback for symlink compatibility
- Exit with code 1 when specified files are not found in the project
- Add 10 Go unit tests and 18 e2e tests covering edge cases
- Update CLI docs with file arguments section
@fansenze fansenze force-pushed the feat/cli-file-args-20260320 branch from b210d25 to fa7dde6 Compare March 20, 2026 08:41
@chenjiahan chenjiahan merged commit 1cbb18d into main Mar 20, 2026
15 checks passed
@chenjiahan chenjiahan deleted the feat/cli-file-args-20260320 branch March 20, 2026 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants