Skip to content

feat: add no-expansions-in-single-quotes rule - #6

Open
nzakas wants to merge 5 commits into
rule/no-backticksfrom
rule/no-expansions-in-single-quotes
Open

nzakas wants to merge 5 commits into
rule/no-backticksfrom
rule/no-expansions-in-single-quotes

Conversation

@nzakas

@nzakas nzakas commented Sep 18, 2026 •

Copy link
Copy Markdown
Member

Adds shell/no-expansions-in-single-quotes, which mirrors ShellCheck SC2016. Expansions don't happen inside single quotes, so '$var' is almost always a mistake.

Behavior

  • Reports a single-quoted string that contains $name, ${...}, $(...), or a backtick pair.
  • Not reported:
    • Positional-style references such as $1, so awk and sed programs like awk '{print $1}' stay clean.
    • A lone $ followed by a digit or punctuation ('costs $5').
    • $'...' strings.
  • No autofix: switching to double quotes can change the meaning of other characters in the string.
  • Recommended config: "warn", not "error", because single-quoting literal $ text is sometimes intentional (for example, text passed to another program).

Documentation

Adds docs/rules/no-expansions-in-single-quotes.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 (191 total); build, lint, and format checks pass.

🤖 Generated with Claude Code


Stack created with GitHub Stacks CLI • Give Feedback 💬

Summary by CodeRabbit

  • New Features

    • Added the no-expansions-in-single-quotes rule, which warns about variable, parameter, command, and backtick-style expansions inside single-quoted strings.
    • Enabled the rule in the recommended Bash configuration at warning level.
    • Includes exceptions for positional references, literal dollar signs, and ANSI-C quoting.
  • Documentation

    • Added usage guidance, examples, configuration details, and a ShellCheck SC2016 reference for the new rule.

@coderabbitai

coderabbitai Bot commented Sep 18, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

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 56 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
  • Configuration used: Repository: eslint/coderabbit/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1085f2af-0169-48db-8ade-687e70038830
📥 Commits

Reviewing files that changed from the base of the PR and between 05416a3 and 205682a.

📒 Files selected for processing (6)
  • README.md
  • docs/rules/no-expansions-in-single-quotes.md
  • src/index.spec.ts
  • src/index.ts
  • src/rules/no-expansions-in-single-quotes.spec.ts
  • src/rules/no-expansions-in-single-quotes.ts
ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Free

Run ID: 7739cf33-c950-463e-b50b-bb4b166fa51f

📥 Commits

Reviewing files that changed from the base of the PR and between add0728 and 9a64120.

📒 Files selected for processing (6)
  • README.md
  • docs/rules/no-expansions-in-single-quotes.md
  • src/index.spec.ts
  • src/index.ts
  • src/rules/no-expansions-in-single-quotes.spec.ts
  • src/rules/no-expansions-in-single-quotes.ts

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

This change adds the no-expansions-in-single-quotes rule. The rule detects expansion-like syntax in single-quoted strings, is enabled in the recommended configuration, has test coverage, and is documented with its ShellCheck SC2016 mapping.

Changes

Single-quoted expansion rule

Layer / File(s) Summary
Rule implementation and validation
src/rules/no-expansions-in-single-quotes.ts, src/rules/no-expansions-in-single-quotes.spec.ts
The new rule reports variable, parameter, command, and backtick expansion-like syntax in single-quoted strings. Tests cover valid exclusions, invalid cases, and diagnostic locations.
Plugin registration
src/index.ts, src/index.spec.ts
The rule is exported and enabled as a warning in the recommended Bash configuration. The entry-point test verifies both exported rules.
Rule documentation
docs/rules/no-expansions-in-single-quotes.md, README.md
Documentation describes detection behavior, exclusions, examples, configuration, severity, and the ShellCheck SC2016 mapping.

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


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-expansions-in-single-quotes branch 2 times, most recently from 9a64120 to d17ba08 Compare September 22, 2026 19:56
@nzakas
nzakas force-pushed the rule/no-expansions-in-single-quotes branch 2 times, most recently from c95a38c to 9055747 Compare September 22, 2026 20:34
@nzakas
nzakas force-pushed the rule/no-expansions-in-single-quotes branch from 9055747 to 05416a3 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

Empty backtick command substitutions are valid but currently evade the documented detection behavior.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Adds a ShellCheck SC2016-inspired rule detecting expansion-like syntax inside single-quoted Bash strings.

Changes:

  • Implements and tests the new rule.
  • Enables it as a recommended warning.
  • Adds rule documentation and README coverage.
File Description
src/​rules/​no-expansions-in-single-quotes.ts Implements expansion detection.
src/​rules/​no-expansions-in-single-quotes.spec.ts Adds rule tests.
src/​index.ts Registers and configures the rule.
src/​index.spec.ts Verifies rule exposure.
README.md Lists the new rule.
docs/​rules/​no-expansions-in-single-quotes.md Documents behavior and usage.

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

Comment thread src/rules/no-expansions-in-single-quotes.ts
@nzakas
nzakas force-pushed the rule/no-expansions-in-single-quotes branch from 5ef65a7 to 73c371e Compare October 1, 2026 18:07
@nzakas
nzakas force-pushed the rule/no-expansions-in-single-quotes branch from d661677 to b7e6d3d Compare October 2, 2026 16:05
@nzakas
nzakas force-pushed the rule/no-expansions-in-single-quotes branch 2 times, most recently from c3ed575 to cb27d20 Compare October 6, 2026 19:09
@nzakas
nzakas force-pushed the rule/no-expansions-in-single-quotes branch 2 times, most recently from b334e7d to 3aa6691 Compare October 6, 2026 19:38
@nzakas
nzakas force-pushed the rule/no-expansions-in-single-quotes branch from 3aa6691 to 383ff55 Compare October 8, 2026 19:46
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
nzakas and others added 4 commits October 8, 2026 16:49
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n-single-quotes

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>
@nzakas
nzakas force-pushed the rule/no-expansions-in-single-quotes branch from 383ff55 to 205682a Compare October 8, 2026 20:51
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.

2 participants