Skip to content

feat: add shell languages - #3

Open
nzakas wants to merge 3 commits into
parserfrom
language
Open

nzakas wants to merge 3 commits into
parserfrom
language

Conversation

@nzakas

@nzakas nzakas commented Sep 18, 2026 •

Copy link
Copy Markdown
Member

Adds the ESLint language implementation, so ESLint can lint shell scripts with this plugin's parser. After this PR the plugin works end to end; it just has no rules yet.

What's included

  • ShellLanguage (src/languages/shell-language.ts):
    • Text file type with 1-based lines and columns.
    • A mode constructor option ("bash" default, "posix", "mksh") selects the shell dialect. Unknown modes throw a TypeError. There are no language options.
    • Syntax errors come back as a failed parse result with line and column, which ESLint reports as a fatal message.
  • ShellSourceCode (src/languages/shell-source-code.ts), built on TextSourceCodeBase from @eslint/plugin-kit:
    • getLoc() and getRange() compute positions from each node's start/end, using a lazily built line index.
    • traverse() builds the enter/exit steps once and records parents, which back getParent() and getAncestors().
    • Inline configuration from comments: # eslint-disable, -enable, -disable-line, and -disable-next-line (with -- justification), plus # eslint rule: severity.
  • src/visitor-keys.ts: traversal order for all 42 node types.
  • src/types.ts: adds ShellLanguageOptions, a typed ShellRuleVisitor (per-node handlers plus :exit variants), and ShellRuleDefinition, built on plugin-kit's CustomRuleDefinitionType.
  • src/index.ts:
    • Registers one language per shell dialect (shell/bash, shell/posix, and shell/mksh), an empty rules map, and configs.recommended.
    • The recommended config targets **/*.sh and **/*.bash, uses language: "shell/bash", and references the plugin itself. It has no rules yet; each rule PR adds its own entry.
    • Also exports ShellLanguage, ShellSourceCode, and visitorKeys.
  • README: Usage, Languages, and Configuration comments sections. The comment examples mention rules added later in the stack.

Integration tests

These tests use tests/fixtures/test-plugin.ts, a test-only plugin with two trivial rules (test/no-forbidden, test/no-deprecated), so they don't depend on any shipped rule.

  • tests/plugin.test.ts:
    • Reported positions, including after non-ASCII text.
    • Traversal into nested statements and command substitutions.
    • Fatal parse errors.
    • That each language parses its own dialect.
    • That the recommended config applies to .sh/.bash and not .js. This test uses code that is valid JavaScript but invalid Bash, so it can actually tell the difference.
  • tests/directives.test.ts: every disable/enable directive form, unused-directive reporting, and inline severity and enable comments.

Testing

54 new tests (136 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 35 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: defaults

Review profile: CHILL

Plan: Advanced

Run ID: c3c10b2d-257b-4168-a19e-48ca61d91c0d

📥 Commits

Reviewing files that changed from the base of the PR and between 8840b5f and 792a34e.

📒 Files selected for processing (14)
  • README.md
  • src/index.spec.ts
  • src/index.ts
  • src/languages/shell-language.spec.ts
  • src/languages/shell-language.ts
  • src/languages/shell-source-code.spec.ts
  • src/languages/shell-source-code.ts
  • src/types.spec.ts
  • src/types.ts
  • src/visitor-keys.spec.ts
  • src/visitor-keys.ts
  • tests/directives.test.ts
  • tests/fixtures/test-plugin.ts
  • tests/plugin.test.ts
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


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 language branch 2 times, most recently from 29743ab to be54def Compare September 22, 2026 20:34
@nzakas
nzakas requested a balanced review from Copilot September 28, 2026 18:24

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 public visitor type exposes a Comment callback even though comments are intentionally excluded from traversal.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Adds end-to-end ESLint language support for parsing and linting Bash files.

Changes:

  • Implements Bash language parsing, source locations, traversal, and directives.
  • Exposes typed rule APIs, visitor keys, and recommended configuration.
  • Adds unit and integration coverage plus usage documentation.
File Description
src/​languages/​bash-language.ts Implements the ESLint language interface.
src/​languages/​bash-language.spec.ts Tests language behavior and variants.
src/​languages/​bash-source-code.ts Implements traversal, locations, and directives.
src/​languages/​bash-source-code.spec.ts Tests source-code APIs.
src/​visitor-keys.ts Defines AST traversal keys.
src/​visitor-keys.spec.ts Tests visitor-key coverage.
src/​types.ts Adds language and rule types.
src/​types.spec.ts Tests exported types.
src/​index.ts Registers and exports the language.
src/​index.spec.ts Tests plugin exports and configuration.
tests/​fixtures/​test-plugin.ts Provides test-only Bash rules.
tests/​plugin.test.ts Tests ESLint integration.
tests/​directives.test.ts Tests inline configuration directives.
README.md Documents usage and options.

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

Comment thread src/types.ts
nzakas and others added 3 commits October 2, 2026 12:17
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Comments are exposed through Program.comments and are never traversed,
so a Comment handler could be declared but would never run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Replaces the `variant` language option with one language per shell
dialect: `shell/bash`, `shell/posix`, and `shell/mksh`. The dialect is
now set with the `mode` option of the `ShellLanguage` constructor.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nzakas nzakas changed the title feat: add Bash language feat: add shell languages Oct 2, 2026
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