Rails Strict Locals Linter Extension
This repository contains a minimal Visual Studio Code extension that lints Rails partials for strict local declarations. The linter checks the first line of each Rails partial (files named _*.html.erb) for a locals comment in the form:
<%# locals: (var_one:, var_two: "Default Var Two") %>
If the comment is missing or malformed, a warning diagnostic is displayed.
Usage
- Open this folder in VS Code (or Cursor).
- Run
Extensions: Show Built-in Extensions and load this extension in development mode (use F5 in VS Code).
The extension activates for files with the erb language or .erb extension and updates diagnostics when documents are opened, changed, or saved. Only Rails partials named _*.html.erb are linted.
Development
Run the built-in tests with:
npm test
Testing the extension locally
The following steps let you try the linter against the example ERB files in
test/fixtures while developing:
- Open the repository in VS Code.
- Press
F5 to start an Extension Development Host window. This window loads
the extension from source.
- In the new window choose File → Add Folder to Workspace… and select the
test/fixtures directory.
- Open the fixture partials:
_valid.html.erb should show no warnings.
_missing_comment.html.erb should warn about a missing locals comment.
_invalid_syntax.html.erb should warn about invalid locals syntax.
- Edit the first line of any file and save to see diagnostics update
immediately.
- Close the development host window when finished.
Publishing to the VS Code Marketplace
Install the vsce utility and publish using your Marketplace publisher account:
npm install -g vsce
vsce package # create a .vsix file
vsce publish # publish to the Marketplace