Skip to content

feat: add no-ls-iteration rule - #9

Open
nzakas wants to merge 6 commits into
rule/no-useless-echofrom
rule/no-ls-iteration
Open

nzakas wants to merge 6 commits into
rule/no-useless-echofrom
rule/no-ls-iteration

Conversation

@nzakas

@nzakas nzakas commented Sep 18, 2026 •

Copy link
Copy Markdown
Member

Adds shell/no-ls-iteration, which mirrors ShellCheck SC2045: for f in $(ls) breaks on filenames with spaces or glob characters; use a glob instead.

Behavior

  • Reports a command substitution in a for ... in word list whose first statement is ls, or a pipeline that starts with ls ($(ls | grep log)). Both $(...) and backticks are checked.
  • Not reported: globs, other commands such as $(find ...), and ls outside a for word list. ShellCheck's broader "parsing ls output" check, SC2012, isn't covered.
  • No autofix: the right glob depends on the ls flags and arguments.
  • Recommended config: "error".

Documentation

Adds docs/rules/no-ls-iteration.md, following the format of the @eslint/json, @eslint/css, and @eslint/markdown rule docs: description, background, rule details with incorrect and correct examples, options, when not to use it, and the ShellCheck reference. The rule's meta.docs.url points at that file, and its README table entry links to it.

Testing

9 RuleTester cases and 5 documentation checks (259 total); build, lint, and format checks pass.

🤖 Generated with Claude Code


Stack created with GitHub Stacks CLI • Give Feedback 💬

@coderabbitai

coderabbitai Bot commented Sep 18, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 59 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Central YAML; Path: .coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 73e49d0c-f764-4619-8f4b-2918fc4f2681
📥 Commits

Reviewing files that changed from the base of the PR and between 01edc8b and 133bc25.

📒 Files selected for processing: 9
  • README.md
  • docs/rules/no-ls-iteration.md
  • src/index.spec.ts
  • src/index.ts
  • src/rules/no-ls-iteration.spec.ts
  • src/rules/no-ls-iteration.ts
  • src/rules/no-unquoted-expansions.ts
  • src/rules/utils.ts
  • tests/plugin.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@nzakas
nzakas added this pull request to stack #16 September 18, 2026 15:00
@nzakas
nzakas marked this pull request as ready for review September 18, 2026 15:01
@nzakas
nzakas force-pushed the rule/no-ls-iteration branch 2 times, most recently from 8764821 to efd8304 Compare September 22, 2026 19:56
@nzakas
nzakas force-pushed the rule/no-ls-iteration branch from efd8304 to 553fdfc Compare September 22, 2026 20:24
@nzakas
nzakas force-pushed the rule/no-ls-iteration branch 2 times, most recently from 160d71e to 7662f4e Compare September 22, 2026 21:21
@nzakas
nzakas requested a balanced review from Copilot September 28, 2026 18:25

Copilot AI 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.

Copilot review overview

🟡 Changes recommended

The recommended autofix interaction can silence the new rule while changing loop behavior.

Review effort: Balanced
Findings: 1 High severity · 1 Low severity

Open (2)
What changed in this PR

Adds the bash/no-ls-iteration rule to detect fragile iteration over ls output.

Changes:

  • Implements and tests SC2045-style detection.
  • Enables the rule in the recommended configuration.
  • Adds rule documentation and README registration.
File Description
src/​rules/​no-ls-iteration.ts Implements the rule.
src/​rules/​no-ls-iteration.spec.ts Adds rule tests.
src/​index.ts Registers and enables the rule.
src/​index.spec.ts Verifies rule registration.
README.md Adds the rule to the catalog.
docs/​rules/​no-ls-iteration.md Documents behavior and examples.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/index.ts Outdated
Comment thread src/rules/no-ls-iteration.ts Outdated
@nzakas

nzakas commented Sep 29, 2026

Copy link
Copy Markdown
Member Author

@copilot address review comments. Be sure to add tests.

Copilot AI commented Sep 29, 2026

Copy link
Copy Markdown

@copilot address review comments. Be sure to add tests.

Addressed in commit f7c9598: no-unquoted-expansions no longer autofixes ls substitutions in for word lists, added recommended-config integration coverage, and corrected the ShellCheck reference to SC2045.

@nzakas
nzakas force-pushed the rule/no-ls-iteration branch from f7c9598 to a7a4c99 Compare October 1, 2026 18:07
@nzakas
nzakas force-pushed the rule/no-ls-iteration branch from 81a81b1 to d41d6b2 Compare October 2, 2026 16:05
@nzakas
nzakas force-pushed the rule/no-ls-iteration branch from d41d6b2 to c021333 Compare October 2, 2026 16:18
@nzakas
nzakas force-pushed the rule/no-ls-iteration branch from c021333 to 91cf318 Compare October 6, 2026 19:09
@nzakas
nzakas force-pushed the rule/no-ls-iteration branch from 91cf318 to 9cd7af7 Compare October 6, 2026 19:26
@nzakas
nzakas force-pushed the rule/no-ls-iteration branch from 9cd7af7 to b58e27b Compare October 6, 2026 19:37
@nzakas
nzakas force-pushed the rule/no-ls-iteration branch 2 times, most recently from 0d0c411 to a7458b2 Compare October 8, 2026 20:51
nzakas and others added 6 commits October 22, 2026 15:45
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-authored-by: nzakas <38546+nzakas@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The rule only listed shell/bash in meta.languages, so ESLint rejected it
when used with the shell/posix or shell/mksh language.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add section headers and an @author tag to the fileoverview comment of
each source file to match the conventions used in other ESLint language
plugins.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nzakas
nzakas force-pushed the rule/no-ls-iteration branch from a7458b2 to 133bc25 Compare October 22, 2026 19:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants