From 03db49a837959af84a08aa5b0c517c9e113b933c Mon Sep 17 00:00:00 2001 From: Joel Hawksley Date: Mon, 30 Nov 2026 10:57:25 -0700 Subject: [PATCH 1/4] Enable Herb template tooling Enable every lint rule, formatting, Tailwind class sorting, and editor support with pinned development packages and CI enforcement. Preserve compatibility and exact-output fixtures with documented exceptions, while retaining embedded Ruby linting. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .devcontainer/devcontainer.json | 7 +- .erb_lint.yml | 7 +- .github/workflows/lint.yml | 15 +- .gitignore | 3 + .herb.yml | 92 +++ .vscode/extensions.json | 3 + .vscode/settings.json | 6 + app/views/view_components/index.html.erb | 9 +- app/views/view_components/previews.html.erb | 5 +- docs/CHANGELOG.md | 4 + docs/CONTRIBUTING.md | 21 + package-lock.json | 630 ++++++++++++++++++ package.json | 18 + performance/views/benchmarks/_nested.html.erb | 2 + .../views/benchmarks/_partial.html.erb | 4 +- ...heable_untracked_parent_component.html.erb | 4 +- .../collection_counter_component.html.erb | 3 +- .../collection_iteration_component.html.erb | 8 +- ...eration_extend_override_component.html.erb | 8 +- .../components/content_for_component.html.erb | 1 + ...forwarding_slot_wrapper_component.html.erb | 2 +- ...lambda_slot_passthrough_component.html.erb | 1 + .../header_component.html.erb | 9 +- .../app/components/partial_component.html.erb | 4 +- .../app/components/path_component.html.erb | 2 +- .../polymorphic_slot_component.html.erb | 2 + ...action_with_js_included_component.html.erb | 2 +- ...ion_without_js_included_component.html.erb | 3 +- .../slot_name_override_component.html.erb | 6 +- .../slots_before_render_component.html.erb | 1 + .../my_greeting_component.html.erb | 2 +- .../my_title_component.html.erb | 2 +- .../app/components/slots_component.html.erb | 15 +- ...slots_with_empty_lambda_component.html.erb | 2 +- .../slots_with_pos_arg_component.html.erb | 2 +- .../app/components/url_component.html.erb | 2 +- .../components/url_helper_component.html.erb | 2 +- test/sandbox/app/views/forms/_label.html.erb | 2 + .../_controller_inline.html.erb | 2 + .../_erb_partial.html.erb | 5 +- .../cached_partial.html.erb | 2 +- .../integration_examples/partial.html.erb | 2 +- .../integration_examples/products.html.erb | 1 + .../views/integration_examples/slots.html.erb | 4 + .../translations_in_block.html.erb | 2 + .../app/views/internal/secret.html.erb | 14 +- test/sandbox/app/views/layouts/admin.html.erb | 16 +- .../layouts/admin/application_Foobar.html.erb | 16 +- .../app/views/layouts/application.html.erb | 32 +- .../views/layouts/explicit_in_action.html.erb | 16 +- .../views/layouts/global_for_action.html.erb | 16 +- .../views/layouts/with_content_for.html.erb | 18 +- .../views/partial_helper/_fragment.html.erb | 2 + .../views/shared/_action_menu_panel.html.erb | 2 + .../views/shared/_deep_navigation.html.erb | 2 + .../shared/_lambda_slot_translation.html.erb | 2 + .../app/views/shared/_partial.html.erb | 2 + .../shared/_yielding_form_partial.html.erb | 2 + .../views/shared/_yielding_partial.html.erb | 2 + .../views/view_components/_inline.html.erb | 2 + .../default.html.erb | 4 +- 61 files changed, 978 insertions(+), 99 deletions(-) create mode 100644 .herb.yml create mode 100644 .vscode/extensions.json create mode 100644 .vscode/settings.json create mode 100644 package-lock.json create mode 100644 package.json diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index b08f1ec97..b8d6d1b34 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -9,6 +9,10 @@ // Set *default* container specific settings.json values on container create. "settings": { + "[erb]": { + "editor.defaultFormatter": "marcoroth.herb-lsp", + "editor.formatOnSave": true + }, "sqltools.connections": [ { "name": "Rails Development Database", @@ -38,6 +42,7 @@ // Add the IDs of extensions you want installed when the container is created. "extensions": [ "rebornix.Ruby", + "marcoroth.herb-lsp", "mtxr.sqltools", "mtxr.sqltools-driver-pg" ], @@ -46,7 +51,7 @@ // "forwardPorts": [3000, 5432], // Use 'postCreateCommand' to run commands after the container is created. - "postCreateCommand": "script/replicate-bug", + "postCreateCommand": "npm ci && script/replicate-bug", // Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. "remoteUser": "vscode" diff --git a/.erb_lint.yml b/.erb_lint.yml index 6e01701b8..5b52ad0bf 100644 --- a/.erb_lint.yml +++ b/.erb_lint.yml @@ -1,13 +1,10 @@ --- -EnableDefaultLinters: true +EnableDefaultLinters: false exclude: - '**/vendor/**/*' - 'test/sandbox/app/components/content_security_policy_nonce_component.html.erb' linters: - ErbSafety: - enabled: true - FinalNewline: - enabled: true + # Herb handles HTML and ERB rules; keep Standard's embedded Ruby checks. Rubocop: enabled: true rubocop_config: diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index ae3597a78..2e7043ada 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -96,7 +96,7 @@ jobs: with: path: vendor/bundle key: gems-build-rails-8-ruby-3.2-${{ hashFiles('**/Gemfile.lock') }} - - name: Lint with Rubocop and ERB Lint + - name: Lint Ruby, including Ruby embedded in ERB run: | bundle config path vendor/bundle bundle update @@ -104,6 +104,19 @@ jobs: bundle exec erb_lint --lint-all env: RAILS_VERSION: '~> 8' + herb: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 + with: + persist-credentials: false + - uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5 + with: + node-version: 22 + cache: npm + - run: npm ci + - run: npm run herb:lint + - run: npm run herb:format:check yard-lint: runs-on: ubuntu-latest steps: diff --git a/.gitignore b/.gitignore index 42fec50d4..bce56e0b8 100644 --- a/.gitignore +++ b/.gitignore @@ -47,3 +47,6 @@ build-iPhoneSimulator/ # Appraisal /gemfiles/.bundle/ + +# Template development tools +/node_modules/ diff --git a/.herb.yml b/.herb.yml new file mode 100644 index 000000000..34d2f4a98 --- /dev/null +++ b/.herb.yml @@ -0,0 +1,92 @@ +version: 0.11.2 +framework: actionview + +files: + include: + - "**/*.erb" + - "**/*.html.erb.tt" + exclude: + - "**/*.text.erb" + - "**/*.json.erb" + - "**/*.css.erb" + # Jekyll processes this file as Liquid, not Action View. + - "docs/404.html" + +linter: + enabled: true + failLevel: hint + rules: + all: + enabled: true + actionview-no-implicit-partial: + exclude: + # These render ViewComponent instances, not implicit Active Record partials. + - "app/views/view_components/preview.html.erb" + - "test/sandbox/app/components/cacheable_explicit_dependency_component.html.erb" + - "test/sandbox/app/components/cacheable_method_built_component.html.erb" + actionview-prefer-form-with: + exclude: + # Compatibility fixtures must continue exercising form_for. + - "test/sandbox/app/components/form_for_component.html.erb" + - "test/sandbox/app/components/form_partial_component.html.erb" + - "test/sandbox/app/components/incompatible_form_component.html.erb" + actionview-no-local-assigns: + exclude: + # The preview security regression demonstrates access to arbitrary locals. + - "test/sandbox/app/views/internal/secret.html.erb" + erb-require-template-format: + exclude: + # These fixtures test templates without a format suffix. + - "test/sandbox/app/components/no_format_component.erb" + - "test/sandbox/app/components/format_less_parent_component.erb" + - "test/sandbox/app/components/format_less_child_component.erb" + erb-no-silent-statement: + exclude: + # Slot setters register content without emitting their return value. + - "performance/components/slots_wrapper_component.html.erb" + erb-no-output-in-attribute-position: + exclude: + # Thor expands these attributes before the generated template is rendered. + - "lib/generators/view_component/erb/templates/component.html.erb.tt" + - "lib/generators/view_component/tailwindcss/templates/component.html.erb.tt" + erb-strict-locals-required: + exclude: + # Object rendering supplies implicit locals to this compatibility fixture. + - "test/sandbox/app/views/integration_examples/_test_partial.html.erb" + erb-prefer-explicit-conditionals: + exclude: + # Allocation assertions depend on this fixture's original compiled Ruby. + - "test/sandbox/app/components/product_component.html.erb" + html-no-title-attribute: + exclude: + # Integration tests exercise this legacy Primer component's title attribute. + - "test/sandbox/app/lib/primer/state_component.html.erb" + html-no-inline-script-elements: + exclude: + # System tests render these as standalone HTML, without an asset server. + - "test/sandbox/app/components/simple_javascript_interaction_with_js_included_component.html.erb" + - "test/sandbox/app/views/layouts/application.html.erb" + html-no-style-attributes: + exclude: + # System tests reveal this element by changing its inline display property. + - "test/sandbox/app/components/simple_javascript_interaction_without_js_included_component.html.erb" + +formatter: + enabled: true + indentWidth: 2 + indentStyle: space + maxLineLength: 80 + exclude: + # Formatting the Thor placeholders changes whitespace in generated output. + - "lib/generators/view_component/erb/templates/component.html.erb.tt" + - "lib/generators/view_component/tailwindcss/templates/component.html.erb.tt" + # This template emits Markdown, where indentation and line breaks are syntax. + - "lib/docs/docs_builder_component.html.erb" + # Preserve the compiled Ruby used by exact allocation assertions. + - "test/sandbox/app/components/product_component.html.erb" + # These fixtures assert exact rendered text and Turbo Stream output. + - "test/sandbox/app/views/shared/_yielding_partial.html.erb" + - "test/sandbox/app/components/turbo_stream_component.html.erb" + rewriter: + pre: + - tailwind-class-sorter diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 000000000..396941026 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,3 @@ +{ + "recommendations": ["marcoroth.herb-lsp"] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..f3f58d0c4 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "[erb]": { + "editor.defaultFormatter": "marcoroth.herb-lsp", + "editor.formatOnSave": true + } +} diff --git a/app/views/view_components/index.html.erb b/app/views/view_components/index.html.erb index df54d7810..093dc7659 100644 --- a/app/views/view_components/index.html.erb +++ b/app/views/view_components/index.html.erb @@ -1,8 +1,13 @@ <% @previews.each do |preview| %> -

<%= link_to preview.preview_name.titleize, preview_view_component_path(preview.preview_name) %>

+

+ <%= link_to preview.preview_name.titleize, preview_view_component_path(preview.preview_name) %> +

+ <% end %> diff --git a/app/views/view_components/previews.html.erb b/app/views/view_components/previews.html.erb index b9fc319db..cbe2d5169 100644 --- a/app/views/view_components/previews.html.erb +++ b/app/views/view_components/previews.html.erb @@ -1,6 +1,9 @@

<%= @preview.preview_name.titleize %>

+ diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index a05ca2b80..dea3512e5 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -10,6 +10,10 @@ nav_order: 6 ## main +* Enable all Herb lint rules, template formatting, Tailwind class sorting, and editor support for development. + + *Joel Hawksley* + * Fix gem publishing workflow failures when waiting for a release to propagate on RubyGems. *Joel Hawksley* diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md index c85633d49..8a752842b 100644 --- a/docs/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -87,6 +87,27 @@ Use [`m`](https://rubygems.org/gems/m): bundle exec m test/view_component/YOUR_COMPONENT_test.rb:line_number ``` +### Template tooling + +Install Node.js 22 or newer and run `npm ci` in the repository root. + +```command +npm run herb:lint +npm run herb:lint:fix +npm run herb:format +npm run herb:format:check +``` + +Herb enables every available lint rule, fails on findings of any severity, and formats templates with two-space indentation and Tailwind class sorting. CI checks the full template set, not just changed files. Package versions are pinned; review newly introduced rules when updating them. + +The shared `.herb.yml` covers HTML templates, variants, formatless ERB fixtures, and generator templates. Text and CSS templates and Jekyll's Liquid page are excluded. Herb's file-based tools don't discover inline ERB in Ruby source. Standard checks Ruby files, and ERB Lint runs only RuboCop for Ruby embedded in template files. + +Exceptions in `.herb.yml` name individual files and explain the behavior being preserved. Formatting exceptions preserve generated Markdown, Thor's attribute placeholders, and fixtures with exact output or allocation assertions. Keep exceptions limited to compatibility fixtures, generator syntax, or unsupported ViewComponent patterns. + +The formatter is experimental. Review its output and run the relevant rendering and generator tests after formatting. + +VS Code recommends the Herb extension and enables ERB format-on-save. Codespaces installs the extension and npm dependencies automatically. Other editors can run the pinned language server with `npx --no-install herb-language-server --stdio`; see [Herb's editor integrations](https://herb-tools.dev/integrations/editors). + ### Running tests for a specific version of Rails Specify one of the supported versions listed in [Appraisals](https://github.com/viewcomponent/view_component/blob/main/Appraisals): diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 000000000..739fff89a --- /dev/null +++ b/package-lock.json @@ -0,0 +1,630 @@ +{ + "name": "view-component-development", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "view-component-development", + "devDependencies": { + "@herb-tools/formatter": "0.11.2", + "@herb-tools/language-server": "0.11.2", + "@herb-tools/linter": "0.11.2" + }, + "engines": { + "node": ">=22" + } + }, + "node_modules/@herb-tools/analysis": { + "version": "0.11.2", + "integrity": "sha512-kAsliQmpP9HIIv2OliSLrCXX0etfC5CIkWNM+zx1wRzeC/hVD4drQs4uCKdWlXcIVqva34gsDIqI5dDOdZfaVQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@herb-tools/core": "0.11.2", + "picomatch": "^4.0.7", + "tinyglobby": "^0.2.15" + }, + "peerDependencies": { + "@herb-tools/core": "0.11.2" + } + }, + "node_modules/@herb-tools/client": { + "version": "0.11.2", + "integrity": "sha512-B/IvlDZcg6LNsFKfk9xKWWx8aNc/oAtgRcFZo0gXhOGwVuSh9rQOUIuE6KHC/Iv9IcvkewrGSxAJMeMY2tYwqw==", + "dev": true, + "license": "MIT" + }, + "node_modules/@herb-tools/config": { + "version": "0.11.2", + "integrity": "sha512-7zP+xr2QGlarJx1E95eIkeCALnnv6wEyX6NIgtdZ+nmBlVtoTugMMr83upjmpxxR4iwLmLTU4p24chZzP5LcJw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@herb-tools/core": "0.11.2", + "picomatch": "^4.0.7", + "tinyglobby": "^0.2.16", + "yaml": "^2.9.1" + } + }, + "node_modules/@herb-tools/core": { + "version": "0.11.2", + "integrity": "sha512-5v4cd4PZ882tWHHBTKXXxbacN31PeH/i6UT8na43JWlw81qev2WRCpMTNe4LSLGAYuEA/nH12BO69IoKiYLn0Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "@ruby/prism": "2.1.0" + } + }, + "node_modules/@herb-tools/formatter": { + "version": "0.11.2", + "integrity": "sha512-XzwBEDitVImC0rvknBZXIWg6rRYyQWWykurbGczbYoKZuAf/t2EHsK0Ljc82rcefv7H7ymZeubeWNxjIaFkJ5w==", + "dev": true, + "license": "MIT", + "dependencies": { + "@herb-tools/config": "0.11.2", + "@herb-tools/core": "0.11.2", + "@herb-tools/highlighter": "0.11.2", + "@herb-tools/node-wasm": "0.11.2", + "@herb-tools/printer": "0.11.2", + "@herb-tools/rewriter": "0.11.2", + "@ruby/prism": "2.1.0", + "tinyglobby": "^0.2.15" + }, + "bin": { + "herb-format": "bin/herb-format" + } + }, + "node_modules/@herb-tools/highlighter": { + "version": "0.11.2", + "integrity": "sha512-GHvqh5/DoDX3hYQRFiLCWxqOGP03vwhu0054dDgNj67p1zGItdTLR9GChb0YnMPd6cPhdR7sVPbVxG0h3u9Reg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@herb-tools/core": "0.11.2", + "@herb-tools/node-wasm": "0.11.2", + "ansi_up": "^6.0.6" + }, + "bin": { + "herb-highlight": "bin/herb-highlight" + } + }, + "node_modules/@herb-tools/language-server": { + "version": "0.11.2", + "integrity": "sha512-pX3XQLyDb8tg+owicW5XArK3Tpm/gXqVQk9/ocj2xTuRFwQJQNm6tRZKBqgSOKEh0b4rduRZpEePFOKOlI59pg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@herb-tools/analysis": "0.11.2", + "@herb-tools/config": "0.11.2", + "@herb-tools/core": "0.11.2", + "@herb-tools/formatter": "0.11.2", + "@herb-tools/language-service": "0.11.2", + "@herb-tools/linter": "0.11.2", + "@herb-tools/node-wasm": "0.11.2", + "@herb-tools/printer": "0.11.2", + "@herb-tools/rewriter": "0.11.2", + "vscode-html-languageservice": "^5.1.0", + "vscode-languageserver": "^10.1.2", + "vscode-languageserver-textdocument": "^1.0.15" + }, + "bin": { + "herb-language-server": "bin/herb-language-server" + }, + "engines": { + "node": "*" + } + }, + "node_modules/@herb-tools/language-service": { + "version": "0.11.2", + "integrity": "sha512-ffFydGbPWUZ0hsMvGV2axD25sBjf1QP5TquU2QsTfYMQQEn1IAPYDfYFJkQqLKTN00IYd1xPX1J6tZmBIDSwyA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@herb-tools/analysis": "0.11.2", + "@herb-tools/client": "0.11.2", + "@herb-tools/config": "0.11.2", + "@herb-tools/core": "0.11.2", + "@herb-tools/printer": "0.11.2", + "@herb-tools/rewriter": "0.11.2", + "vscode-html-languageservice": "^5.1.0", + "vscode-languageserver-textdocument": "^1.0.15", + "vscode-languageserver-types": "^3.18.3" + }, + "peerDependencies": { + "@herb-tools/core": "0.11.2", + "vscode-html-languageservice": "^5.1.0", + "vscode-languageserver-textdocument": "^1.0.15" + } + }, + "node_modules/@herb-tools/linter": { + "version": "0.11.2", + "integrity": "sha512-7doeONcRI01kl0anyAcv+kxd+H3zx2ApgpXWwoQt4N0W2iSxSqNZg+itHyom+f0SDq3LS902Z4lNn1QNmECE8Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "@herb-tools/analysis": "0.11.2", + "@herb-tools/client": "0.11.2", + "@herb-tools/config": "0.11.2", + "@herb-tools/core": "0.11.2", + "@herb-tools/highlighter": "0.11.2", + "@herb-tools/node-wasm": "0.11.2", + "@herb-tools/printer": "0.11.2", + "@herb-tools/rewriter": "0.11.2", + "@ruby/prism": "2.1.0", + "picomatch": "^4.0.7", + "postcss": "^8.5.29", + "postcss-selector-parser": "^7.1.7", + "tinyglobby": "^0.2.15" + }, + "bin": { + "herb-lint": "bin/herb-lint" + } + }, + "node_modules/@herb-tools/node-wasm": { + "version": "0.11.2", + "integrity": "sha512-o8k2wjePfym17jdqzKypek+LyGzvLvJsQPpnVqAxRl4bg+CVtlbZonFW+1ScYgrffcJKdiUVeruOn//iOxFJug==", + "dev": true, + "license": "MIT", + "dependencies": { + "@herb-tools/core": "0.11.2", + "@ruby/prism": "2.1.0" + } + }, + "node_modules/@herb-tools/printer": { + "version": "0.11.2", + "integrity": "sha512-D6VDvRZrz0a56l1XW0l+zJoxlF57w7WrrvA3Zfhg4c0hGRTL8cjEQWxr69gasn539K5Zs72gXlvUEIfbLuTlWg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@herb-tools/config": "0.11.2", + "@herb-tools/core": "0.11.2", + "@herb-tools/node-wasm": "0.11.2", + "tinyglobby": "^0.2.15" + }, + "bin": { + "herb-print": "bin/herb-print" + } + }, + "node_modules/@herb-tools/rewriter": { + "version": "0.11.2", + "integrity": "sha512-ilIU2DbqSYK0wahP3HzFp5zSlMxqzYhXyCr8ZHNvDcIjc6E/PnbF6cLl+IJS1A+6hGJLc6DOyjk+UYd4t5MZOw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@herb-tools/core": "0.11.2", + "@herb-tools/printer": "0.11.2", + "@herb-tools/tailwind-class-sorter": "0.11.2", + "@ruby/prism": "2.1.0", + "tinyglobby": "^0.2.15" + } + }, + "node_modules/@herb-tools/tailwind-class-sorter": { + "version": "0.11.2", + "integrity": "sha512-DiAfzGIjiYz4IIZUkeqfThTli2eSskc8R/ccUNCFsAlgK7CW+Y+Rrhf4DjlYMHrITMnAoQ8iwQVju7TqNBuXjg==", + "dev": true, + "license": "MIT", + "dependencies": { + "clear-module": "^4.1.3", + "escalade": "^3.2.0", + "jiti": "^2.7.0", + "postcss": "^8.5.29", + "postcss-import": "^17.0.1" + }, + "engines": { + "node": ">=14.21.3" + }, + "peerDependencies": { + "tailwindcss": "^3.0 || ^4.0" + }, + "peerDependenciesMeta": { + "tailwindcss": { + "optional": true + } + } + }, + "node_modules/@ruby/prism": { + "version": "2.1.0", + "integrity": "sha512-+lMGoxR5YQ8HEX7e2EuLn4H9GBpaDIrIkwtaAdTo/+lhzCxijAOhjrNBMFJtFr+DhbX+32CrA+j0R/WsLYrefw==", + "dev": true, + "license": "MIT" + }, + "node_modules/@vscode/l10n": { + "version": "0.0.18", + "integrity": "sha1-kW06XpYNurR8HFb1iny1CHsTXJU=", + "dev": true, + "license": "MIT" + }, + "node_modules/ansi_up": { + "version": "6.0.6", + "integrity": "sha1-gE+vMfA4XlYtL3EnXqjP8Nnc9tw=", + "dev": true, + "license": "MIT", + "engines": { + "node": "*" + } + }, + "node_modules/callsites": { + "version": "3.1.0", + "integrity": "sha1-s2MKvYlDQy9Us/BRkjjjPNffL3M=", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6" + } + }, + "node_modules/clear-module": { + "version": "4.1.3", + "integrity": "sha1-BYi+VJcLK+8h22Z79rbMdI0An9s=", + "dev": true, + "license": "MIT", + "dependencies": { + "parent-module": "^2.0.0", + "resolve-from": "^5.0.0" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/es-errors": { + "version": "1.3.0", + "integrity": "sha1-BfdaJdq5jk+x3NXhRywFRtUFfI8=", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/escalade": { + "version": "3.2.0", + "integrity": "sha1-ARo/aYVroYnf+n3I/M6Z0qh5A+U=", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6" + } + }, + "node_modules/fdir": { + "version": "6.5.0", + "integrity": "sha1-7Sq5Z6MxreYvGNB32uGSaE1Q01A=", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12.0.0" + }, + "peerDependencies": { + "picomatch": "^3 || ^4" + }, + "peerDependenciesMeta": { + "picomatch": { + "optional": true + } + } + }, + "node_modules/function-bind": { + "version": "1.1.2", + "integrity": "sha1-LALYZNl/PqbIgwxGTL0Rq26rehw=", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/hasown": { + "version": "2.0.4", + "integrity": "sha1-jGLYy5C+sqrV0KW2dYGtmFTD8AM=", + "dev": true, + "license": "MIT", + "dependencies": { + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/is-core-module": { + "version": "2.18.0", + "integrity": "sha512-qyax9fgaKOEC4qK8WZn7Q4IcoZC9RC1O1fFxRcRTq/oMMkWT/uXpqpXa12kzWR409zAt1drYN9N9BO26UmBCmw==", + "dev": true, + "license": "MIT", + "dependencies": { + "hasown": "^2.0.4" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/jiti": { + "version": "2.7.0", + "integrity": "sha1-l0Io8vTKK8IYhaF5e0X+po6VDGQ=", + "dev": true, + "license": "MIT", + "bin": { + "jiti": "lib/jiti-cli.mjs" + } + }, + "node_modules/nanoid": { + "version": "3.3.20", + "integrity": "sha512-uKdg2G3GNCKQn9byYOpxbGqrT2fGO5KRt5J/8b3pok8rT6qxGWF6hxMyJiEYtAf+FVyYuD9hRaDqX5uPFYJ4ZQ==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "license": "MIT", + "bin": { + "nanoid": "bin/nanoid.cjs" + }, + "engines": { + "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" + } + }, + "node_modules/parent-module": { + "version": "2.0.0", + "integrity": "sha1-+nH4j/GlDCfhXY/3Tg46lSO/hwg=", + "dev": true, + "license": "MIT", + "dependencies": { + "callsites": "^3.1.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/path-parse": { + "version": "1.0.7", + "integrity": "sha1-+8EUtgykKzDZ2vWFjkvWi77bZzU=", + "dev": true, + "license": "MIT" + }, + "node_modules/picocolors": { + "version": "1.1.1", + "integrity": "sha1-PTIa8+q5ObCDyPkpodEs2oHCa2s=", + "dev": true, + "license": "ISC" + }, + "node_modules/picomatch": { + "version": "4.0.7", + "integrity": "sha1-YxM2ADTMs2s9xh7L3/eBIfkP4h8=", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, + "node_modules/postcss": { + "version": "8.5.33", + "integrity": "sha512-RVHEU9/Pp1Fnjr/MpAJsZoADukCKhfIi15OunEYiGktIkYLkPVvC1sioWolGDS7XByMTx9m/IGbro0Js13zhnQ==", + "dev": true, + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/postcss/" + }, + { + "type": "tidelift", + "url": "https://tidelift.com/funding/github/npm/postcss" + }, + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "license": "MIT", + "dependencies": { + "nanoid": "^3.3.20", + "picocolors": "^1.1.1", + "source-map-js": "^1.2.2" + }, + "engines": { + "node": "^10 || ^12 || >=14" + } + }, + "node_modules/postcss-import": { + "version": "17.0.1", + "integrity": "sha512-lthLZRa+sMc/xo+lG7TMUvOviwP9ngR0VULnvfXTyOE3JIc0mFrbjcubI6Jx52X+B3IKt9yfp6wwVWE768JezA==", + "dev": true, + "license": "MIT", + "dependencies": { + "postcss-value-parser": "^4.0.0", + "read-cache": "^1.0.0", + "resolve": "^1.1.7" + }, + "engines": { + "node": ">=22.0.0" + }, + "peerDependencies": { + "postcss": "^8.0.0" + } + }, + "node_modules/postcss-selector-parser": { + "version": "7.2.1", + "integrity": "sha512-GwxlMgTTXwIom+ebC7an3k6RaJDwklRQQnfiXsLPGicu8FYV/k/+1/9YY2OU2+r938H2t4X0TDxoif+HP2rjzQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "util-deprecate": "^1.0.2" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/postcss-value-parser": { + "version": "4.2.0", + "integrity": "sha1-cjwJkgg2um0+WvAZ+SvAlxwC5RQ=", + "dev": true, + "license": "MIT" + }, + "node_modules/read-cache": { + "version": "1.0.2", + "integrity": "sha1-O/pA4nV0IWvYkyds7XXYHmZJylI=", + "dev": true, + "license": "MIT" + }, + "node_modules/resolve": { + "version": "1.22.14", + "integrity": "sha512-1ZjYvR9sbkiwC5+9QHetqW5HmA2pHRMaoupD01t2HlYnV/vydC2zPwLixhsMieSWVZt0JJRg5LVIk0Ow1D/TrA==", + "dev": true, + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "is-core-module": "^2.18.0", + "path-parse": "^1.0.7", + "supports-preserve-symlinks-flag": "^1.0.0" + }, + "bin": { + "resolve": "bin/resolve" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/resolve-from": { + "version": "5.0.0", + "integrity": "sha1-w1IlhD3493bfIcV1V7wIfp39/Gk=", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/source-map-js": { + "version": "1.2.4", + "integrity": "sha512-J7ZjMvHd9O1fcT/5V09QWaaSl2BbWx3F6O08spde82Namf9UB0GxRVIPiNbVsdKkoizHiSpTodo3vp2bAy91MA==", + "dev": true, + "license": "BSD-3-Clause", + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/supports-preserve-symlinks-flag": { + "version": "1.0.0", + "integrity": "sha1-btpL00SjyUrqN21MwxvHcxEDngk=", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/tinyglobby": { + "version": "0.2.17", + "integrity": "sha1-ViqabJ6ys7Ej05cZ+a9btE/NdjE=", + "dev": true, + "license": "MIT", + "dependencies": { + "fdir": "^6.5.0", + "picomatch": "^4.0.4" + }, + "engines": { + "node": ">=12.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/SuperchupuDev" + } + }, + "node_modules/util-deprecate": { + "version": "1.0.2", + "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=", + "dev": true, + "license": "MIT" + }, + "node_modules/vscode-html-languageservice": { + "version": "5.6.2", + "integrity": "sha1-MvUyYdpdD61PachdwA3mZJ4hC9E=", + "dev": true, + "license": "MIT", + "dependencies": { + "@vscode/l10n": "^0.0.18", + "vscode-languageserver-textdocument": "^1.0.12", + "vscode-languageserver-types": "^3.17.5", + "vscode-uri": "^3.1.0" + } + }, + "node_modules/vscode-jsonrpc": { + "version": "9.0.3", + "integrity": "sha512-qETYf9PCl1lVfwR+oBmMfc4vP2nqLNA35ABxorw3j06+xlKRgDVxbLgKm4Y/xPL0YWdeDjLoI4ImICIT3nB0zQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/vscode-languageserver": { + "version": "10.1.2", + "integrity": "sha512-pXPWde3RytdeBVEs6PulOOT5OpeXC5GkWRpcT11f5rNn41jviQsAYPyAqJ/0oVGETQLKPJtYbHNiMPlfLb0NTQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "vscode-languageserver-protocol": "3.18.4" + }, + "bin": { + "installServerIntoExtension": "bin/installServerIntoExtension" + } + }, + "node_modules/vscode-languageserver-protocol": { + "version": "3.18.4", + "integrity": "sha512-CCXbyr99dafRJzJH/0Ryk7ly5T8XPmSR0//OuF2w4m+9JiOin7zcAT5iET8GRE7Z9taFBejb3GbM0a0mbjdbrg==", + "dev": true, + "license": "MIT", + "dependencies": { + "vscode-jsonrpc": "9.0.3", + "vscode-languageserver-types": "3.18.4" + } + }, + "node_modules/vscode-languageserver-protocol/node_modules/vscode-languageserver-types": { + "version": "3.18.4", + "integrity": "sha512-nQsacoiijvl0fRf2q28uFDrAVwRhdCa3QveiF7/CX0r18mLR5FU/1WskSsCKOjmEbtteKUnY8x8Yzxop+k0zwg==", + "dev": true, + "license": "MIT" + }, + "node_modules/vscode-languageserver-textdocument": { + "version": "1.0.16", + "integrity": "sha512-qeNEuOi9a3qkqRf7Gfez2WL2VwlBTLCNekHBGO9kxPVUp9XuY15yfTJ9jwvOwKI0I2MhUUfZq95NSp+LK1CLQg==", + "dev": true, + "license": "MIT" + }, + "node_modules/vscode-languageserver-types": { + "version": "3.18.6", + "integrity": "sha512-DEDtik4YupS+nOg4JxqJ2H5ec/m4tTD9a5mGcBVGYkQKZQo1AIF3ZToiP8+A0kUzyhyqX5dMnPDEnhtmzts7GA==", + "dev": true, + "license": "MIT" + }, + "node_modules/vscode-uri": { + "version": "3.2.0", + "integrity": "sha1-HLH9PO50JrZnMq/D+4Y0PVltX7Q=", + "dev": true, + "license": "MIT" + }, + "node_modules/yaml": { + "version": "2.9.1", + "integrity": "sha512-3NxN8+78OdzbT7C/WjGsyfPAtJaN3FNDsWxv7Y7mcDsT/oOmgW8BpyQQFFBnvZE3j9Y2Sdz1ULFLezL7Eb2yFw==", + "dev": true, + "license": "ISC", + "bin": { + "yaml": "bin.mjs" + }, + "engines": { + "node": ">= 14.6" + }, + "funding": { + "url": "https://github.com/sponsors/eemeli" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 000000000..162f65777 --- /dev/null +++ b/package.json @@ -0,0 +1,18 @@ +{ + "name": "view-component-development", + "private": true, + "engines": { + "node": ">=22" + }, + "scripts": { + "herb:lint": "herb-lint", + "herb:lint:fix": "herb-lint --fix", + "herb:format": "herb-format", + "herb:format:check": "herb-format --check" + }, + "devDependencies": { + "@herb-tools/formatter": "0.11.2", + "@herb-tools/language-server": "0.11.2", + "@herb-tools/linter": "0.11.2" + } +} diff --git a/performance/views/benchmarks/_nested.html.erb b/performance/views/benchmarks/_nested.html.erb index 12b942ba0..94bd34590 100644 --- a/performance/views/benchmarks/_nested.html.erb +++ b/performance/views/benchmarks/_nested.html.erb @@ -1 +1,3 @@ +<%# locals: (name:) %> +

nested hello <%= name %>

diff --git a/performance/views/benchmarks/_partial.html.erb b/performance/views/benchmarks/_partial.html.erb index 6a642003b..99d9dc03a 100644 --- a/performance/views/benchmarks/_partial.html.erb +++ b/performance/views/benchmarks/_partial.html.erb @@ -1,5 +1,7 @@ +<%# locals: (name:) %> +

hello <%= name %>

<% 50.times do %> - <%= render "nested", name: name, nested: false %> + <%= render "benchmarks/nested", name: name %> <% end %> diff --git a/test/sandbox/app/components/cacheable_untracked_parent_component.html.erb b/test/sandbox/app/components/cacheable_untracked_parent_component.html.erb index 6898f8e50..eb8a681dd 100644 --- a/test/sandbox/app/components/cacheable_untracked_parent_component.html.erb +++ b/test/sandbox/app/components/cacheable_untracked_parent_component.html.erb @@ -1 +1,3 @@ -
<%= render UntrackedChildComponent.new %>
+
+ <%= render UntrackedChildComponent.new %> +
diff --git a/test/sandbox/app/components/collection_counter_component.html.erb b/test/sandbox/app/components/collection_counter_component.html.erb index cc543236d..5d09f90fd 100644 --- a/test/sandbox/app/components/collection_counter_component.html.erb +++ b/test/sandbox/app/components/collection_counter_component.html.erb @@ -1,5 +1,6 @@
- <%= @item.title %> + <%= image_tag @item.url, alt: @item.title %> +
Photo.<%= @counter %> - <%= @item.caption %>
diff --git a/test/sandbox/app/components/collection_iteration_component.html.erb b/test/sandbox/app/components/collection_iteration_component.html.erb index 440cea0ef..945a433d8 100644 --- a/test/sandbox/app/components/collection_iteration_component.html.erb +++ b/test/sandbox/app/components/collection_iteration_component.html.erb @@ -1,5 +1,9 @@ -
"> - <%= @item.title %> +
+ <%= image_tag @item.url, alt: @item.title %> +
Photo.<%= @counter %> - <%= @item.caption %>
diff --git a/test/sandbox/app/components/collection_iteration_extend_override_component.html.erb b/test/sandbox/app/components/collection_iteration_extend_override_component.html.erb index 52c176cba..e369db137 100644 --- a/test/sandbox/app/components/collection_iteration_extend_override_component.html.erb +++ b/test/sandbox/app/components/collection_iteration_extend_override_component.html.erb @@ -1,5 +1,9 @@ -
"> - <%= @override.title %> +
+ <%= image_tag @override.url, alt: @override.title %> +
Photo.<%= @counter %> - <%= @override.caption %>
diff --git a/test/sandbox/app/components/content_for_component.html.erb b/test/sandbox/app/components/content_for_component.html.erb index 48e29733f..3772efede 100644 --- a/test/sandbox/app/components/content_for_component.html.erb +++ b/test/sandbox/app/components/content_for_component.html.erb @@ -1,2 +1,3 @@ <% content_for(:foo, "bar") %> +
Hello content for
diff --git a/test/sandbox/app/components/forwarding_slot_wrapper_component.html.erb b/test/sandbox/app/components/forwarding_slot_wrapper_component.html.erb index 4d1939750..32f572855 100644 --- a/test/sandbox/app/components/forwarding_slot_wrapper_component.html.erb +++ b/test/sandbox/app/components/forwarding_slot_wrapper_component.html.erb @@ -1,5 +1,5 @@ <%= render(ForwardingSlotComponent.new) do |panel| %> - <% panel.with_target_content do |header| %> + <% panel.with_target_content do %> Target content <% end %> <% end %> diff --git a/test/sandbox/app/components/lambda_slot_passthrough_component.html.erb b/test/sandbox/app/components/lambda_slot_passthrough_component.html.erb index 56b438089..f76411db9 100644 --- a/test/sandbox/app/components/lambda_slot_passthrough_component.html.erb +++ b/test/sandbox/app/components/lambda_slot_passthrough_component.html.erb @@ -2,6 +2,7 @@
<%= lambda_slot %>
+
<%= content %>
diff --git a/test/sandbox/app/components/nested_shared_state/header_component.html.erb b/test/sandbox/app/components/nested_shared_state/header_component.html.erb index 463622557..d04b5d5ef 100644 --- a/test/sandbox/app/components/nested_shared_state/header_component.html.erb +++ b/test/sandbox/app/components/nested_shared_state/header_component.html.erb @@ -1,4 +1,9 @@ <%= content_tag(:div, **@tag_arguments) do %> - <% if @selectable %>Selectable<% end %> - <% cells.each do |cell| %><%= cell %><% end %> + <% if @selectable %> + Selectable + <% end %> + + <% cells.each do |cell| %> + <%= cell %> + <% end %> <% end %> diff --git a/test/sandbox/app/components/partial_component.html.erb b/test/sandbox/app/components/partial_component.html.erb index 047170063..611d0b203 100644 --- a/test/sandbox/app/components/partial_component.html.erb +++ b/test/sandbox/app/components/partial_component.html.erb @@ -1,3 +1,3 @@ -<%= render partial: "test_partial" %> -<%= render "test_partial" %> +<%= render partial: "integration_examples/test_partial" %> +<%= render "integration_examples/test_partial" %> <%= render PartialModel.new(to_partial_path: "test_partial") %> diff --git a/test/sandbox/app/components/path_component.html.erb b/test/sandbox/app/components/path_component.html.erb index dff60c4ff..2ccf7dd97 100644 --- a/test/sandbox/app/components/path_component.html.erb +++ b/test/sandbox/app/components/path_component.html.erb @@ -1 +1 @@ - <%= root_path %> +<%= root_path %> diff --git a/test/sandbox/app/components/polymorphic_slot_component.html.erb b/test/sandbox/app/components/polymorphic_slot_component.html.erb index 1c07db548..69d7def83 100644 --- a/test/sandbox/app/components/polymorphic_slot_component.html.erb +++ b/test/sandbox/app/components/polymorphic_slot_component.html.erb @@ -2,9 +2,11 @@ <% if header? %> <% end %> + <% items.each do |item| %> <%= item %> <% end %> + <% fields.each do |field| %> <%= field %> <% end %> diff --git a/test/sandbox/app/components/simple_javascript_interaction_with_js_included_component.html.erb b/test/sandbox/app/components/simple_javascript_interaction_with_js_included_component.html.erb index 9d81c7e4e..df9910e42 100644 --- a/test/sandbox/app/components/simple_javascript_interaction_with_js_included_component.html.erb +++ b/test/sandbox/app/components/simple_javascript_interaction_with_js_included_component.html.erb @@ -1,4 +1,4 @@ - - + + diff --git a/test/sandbox/app/views/layouts/explicit_in_action.html.erb b/test/sandbox/app/views/layouts/explicit_in_action.html.erb index 24b60902d..7eaee9ea4 100644 --- a/test/sandbox/app/views/layouts/explicit_in_action.html.erb +++ b/test/sandbox/app/views/layouts/explicit_in_action.html.erb @@ -1,10 +1,12 @@ + - - ViewComponent - Test - <%= stylesheet_link_tag "application" %> - - - <%= yield %> - + + ViewComponent - Test + <%= stylesheet_link_tag "application" %> + + + + <%= yield %> + diff --git a/test/sandbox/app/views/layouts/global_for_action.html.erb b/test/sandbox/app/views/layouts/global_for_action.html.erb index e3f1b91c1..6f018ed04 100644 --- a/test/sandbox/app/views/layouts/global_for_action.html.erb +++ b/test/sandbox/app/views/layouts/global_for_action.html.erb @@ -1,10 +1,12 @@ + - - ViewComponent - Test - <%= stylesheet_link_tag "application" %> - - - <%= yield %> - + + ViewComponent - Test + <%= stylesheet_link_tag "application" %> + + + + <%= yield %> + diff --git a/test/sandbox/app/views/layouts/with_content_for.html.erb b/test/sandbox/app/views/layouts/with_content_for.html.erb index 1fe14bc7e..7c058b993 100644 --- a/test/sandbox/app/views/layouts/with_content_for.html.erb +++ b/test/sandbox/app/views/layouts/with_content_for.html.erb @@ -1,11 +1,13 @@ + - - ViewComponent - Global For Action - Test - <%= stylesheet_link_tag "application" %> - - - <%= yield %> - Foo: <%= content_for(:foo) %> - + + ViewComponent - Global For Action - Test + <%= stylesheet_link_tag "application" %> + + + + <%= yield %> + Foo: <%= content_for(:foo) %> + diff --git a/test/sandbox/app/views/partial_helper/_fragment.html.erb b/test/sandbox/app/views/partial_helper/_fragment.html.erb index 25310b08f..9ebe9ab7c 100644 --- a/test/sandbox/app/views/partial_helper/_fragment.html.erb +++ b/test/sandbox/app/views/partial_helper/_fragment.html.erb @@ -1 +1,3 @@ +<%# locals: () %> + <%= expensive_message %> diff --git a/test/sandbox/app/views/shared/_action_menu_panel.html.erb b/test/sandbox/app/views/shared/_action_menu_panel.html.erb index 5e8d98862..f6f80592b 100644 --- a/test/sandbox/app/views/shared/_action_menu_panel.html.erb +++ b/test/sandbox/app/views/shared/_action_menu_panel.html.erb @@ -1,3 +1,5 @@ +<%# locals: () %> + <%= render ActionMenuComponent.new do |menu| %> <% menu.with_list do |list| %> <% list.with_item do %> diff --git a/test/sandbox/app/views/shared/_deep_navigation.html.erb b/test/sandbox/app/views/shared/_deep_navigation.html.erb index 690ad6820..b76bd174e 100644 --- a/test/sandbox/app/views/shared/_deep_navigation.html.erb +++ b/test/sandbox/app/views/shared/_deep_navigation.html.erb @@ -1,3 +1,5 @@ +<%# locals: () %> + <%= render SectionComponent.new do |section| %> <% section.with_nav do |nav| %> <% nav.with_action_menu do |menu| %> diff --git a/test/sandbox/app/views/shared/_lambda_slot_translation.html.erb b/test/sandbox/app/views/shared/_lambda_slot_translation.html.erb index 5a9c55446..ac62bec4a 100644 --- a/test/sandbox/app/views/shared/_lambda_slot_translation.html.erb +++ b/test/sandbox/app/views/shared/_lambda_slot_translation.html.erb @@ -1,3 +1,5 @@ +<%# locals: () %> + <%= render LambdaSlotOuterComponent.new do |outer| %> <% outer.with_inner do |inner| %> <% inner.with_aside do %> diff --git a/test/sandbox/app/views/shared/_partial.html.erb b/test/sandbox/app/views/shared/_partial.html.erb index 37f0bddbd..2d6eefee4 100644 --- a/test/sandbox/app/views/shared/_partial.html.erb +++ b/test/sandbox/app/views/shared/_partial.html.erb @@ -1 +1,3 @@ +<%# locals: () %> + <%= yield %> diff --git a/test/sandbox/app/views/shared/_yielding_form_partial.html.erb b/test/sandbox/app/views/shared/_yielding_form_partial.html.erb index d4f2ca982..d949ee534 100644 --- a/test/sandbox/app/views/shared/_yielding_form_partial.html.erb +++ b/test/sandbox/app/views/shared/_yielding_form_partial.html.erb @@ -1,3 +1,5 @@ +<%# locals: (form:) %> + <%= form.label :something do %> <%= yield %> <% end %> diff --git a/test/sandbox/app/views/shared/_yielding_partial.html.erb b/test/sandbox/app/views/shared/_yielding_partial.html.erb index 10503e2b3..bc1a8a407 100644 --- a/test/sandbox/app/views/shared/_yielding_partial.html.erb +++ b/test/sandbox/app/views/shared/_yielding_partial.html.erb @@ -1 +1,3 @@ +<%# locals: () %> + hello <%= yield %> diff --git a/test/sandbox/app/views/view_components/_inline.html.erb b/test/sandbox/app/views/view_components/_inline.html.erb index 95ee82c14..3a223845e 100644 --- a/test/sandbox/app/views/view_components/_inline.html.erb +++ b/test/sandbox/app/views/view_components/_inline.html.erb @@ -1 +1,3 @@ +<%# locals: () %> + Hello, world! diff --git a/test/sandbox/test/components/previews/lambda_slot_passthrough_component_preview/default.html.erb b/test/sandbox/test/components/previews/lambda_slot_passthrough_component_preview/default.html.erb index 0aac5aed9..231dff939 100644 --- a/test/sandbox/test/components/previews/lambda_slot_passthrough_component_preview/default.html.erb +++ b/test/sandbox/test/components/previews/lambda_slot_passthrough_component_preview/default.html.erb @@ -1,3 +1,5 @@ <%= render LambdaSlotPassthroughComponent.new do |component| %> - <% component.with_lambda_slot do %>hello,world!<% end %> + <% component.with_lambda_slot do %> + hello,world! + <% end %> <% end %> From 3734328072084c7aafd2f78bdcce15e065a4d494 Mon Sep 17 00:00:00 2001 From: Joel Hawksley Date: Mon, 30 Nov 2026 11:00:39 -0700 Subject: [PATCH 2/4] Exclude generator templates from Herb tooling Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .herb.yml | 10 +--------- docs/CONTRIBUTING.md | 4 ++-- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/.herb.yml b/.herb.yml index 34d2f4a98..5dcf493fc 100644 --- a/.herb.yml +++ b/.herb.yml @@ -4,8 +4,8 @@ framework: actionview files: include: - "**/*.erb" - - "**/*.html.erb.tt" exclude: + - "**/*.tt" - "**/*.text.erb" - "**/*.json.erb" - "**/*.css.erb" @@ -44,11 +44,6 @@ linter: exclude: # Slot setters register content without emitting their return value. - "performance/components/slots_wrapper_component.html.erb" - erb-no-output-in-attribute-position: - exclude: - # Thor expands these attributes before the generated template is rendered. - - "lib/generators/view_component/erb/templates/component.html.erb.tt" - - "lib/generators/view_component/tailwindcss/templates/component.html.erb.tt" erb-strict-locals-required: exclude: # Object rendering supplies implicit locals to this compatibility fixture. @@ -77,9 +72,6 @@ formatter: indentStyle: space maxLineLength: 80 exclude: - # Formatting the Thor placeholders changes whitespace in generated output. - - "lib/generators/view_component/erb/templates/component.html.erb.tt" - - "lib/generators/view_component/tailwindcss/templates/component.html.erb.tt" # This template emits Markdown, where indentation and line breaks are syntax. - "lib/docs/docs_builder_component.html.erb" # Preserve the compiled Ruby used by exact allocation assertions. diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md index 8a752842b..182aedc7c 100644 --- a/docs/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -100,9 +100,9 @@ npm run herb:format:check Herb enables every available lint rule, fails on findings of any severity, and formats templates with two-space indentation and Tailwind class sorting. CI checks the full template set, not just changed files. Package versions are pinned; review newly introduced rules when updating them. -The shared `.herb.yml` covers HTML templates, variants, formatless ERB fixtures, and generator templates. Text and CSS templates and Jekyll's Liquid page are excluded. Herb's file-based tools don't discover inline ERB in Ruby source. Standard checks Ruby files, and ERB Lint runs only RuboCop for Ruby embedded in template files. +The shared `.herb.yml` covers HTML templates, variants, and formatless ERB fixtures. All `.tt` generator templates, text and CSS templates, and Jekyll's Liquid page are excluded. Herb's file-based tools don't discover inline ERB in Ruby source. Standard checks Ruby files, and ERB Lint runs only RuboCop for Ruby embedded in template files. -Exceptions in `.herb.yml` name individual files and explain the behavior being preserved. Formatting exceptions preserve generated Markdown, Thor's attribute placeholders, and fixtures with exact output or allocation assertions. Keep exceptions limited to compatibility fixtures, generator syntax, or unsupported ViewComponent patterns. +Exceptions in `.herb.yml` name individual files and explain the behavior being preserved. Formatting exceptions preserve generated Markdown and fixtures with exact output or allocation assertions. Keep exceptions limited to compatibility fixtures or unsupported ViewComponent patterns. The formatter is experimental. Review its output and run the relevant rendering and generator tests after formatting. From 76bb4e437bbed278c5345fc93958d16f6a5d7f0b Mon Sep 17 00:00:00 2001 From: Joel Hawksley Date: Mon, 30 Nov 2026 11:01:53 -0700 Subject: [PATCH 3/4] Remove contributor documentation changes Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- docs/CONTRIBUTING.md | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md index 182aedc7c..c85633d49 100644 --- a/docs/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -87,27 +87,6 @@ Use [`m`](https://rubygems.org/gems/m): bundle exec m test/view_component/YOUR_COMPONENT_test.rb:line_number ``` -### Template tooling - -Install Node.js 22 or newer and run `npm ci` in the repository root. - -```command -npm run herb:lint -npm run herb:lint:fix -npm run herb:format -npm run herb:format:check -``` - -Herb enables every available lint rule, fails on findings of any severity, and formats templates with two-space indentation and Tailwind class sorting. CI checks the full template set, not just changed files. Package versions are pinned; review newly introduced rules when updating them. - -The shared `.herb.yml` covers HTML templates, variants, and formatless ERB fixtures. All `.tt` generator templates, text and CSS templates, and Jekyll's Liquid page are excluded. Herb's file-based tools don't discover inline ERB in Ruby source. Standard checks Ruby files, and ERB Lint runs only RuboCop for Ruby embedded in template files. - -Exceptions in `.herb.yml` name individual files and explain the behavior being preserved. Formatting exceptions preserve generated Markdown and fixtures with exact output or allocation assertions. Keep exceptions limited to compatibility fixtures or unsupported ViewComponent patterns. - -The formatter is experimental. Review its output and run the relevant rendering and generator tests after formatting. - -VS Code recommends the Herb extension and enables ERB format-on-save. Codespaces installs the extension and npm dependencies automatically. Other editors can run the pinned language server with `npx --no-install herb-language-server --stdio`; see [Herb's editor integrations](https://herb-tools.dev/integrations/editors). - ### Running tests for a specific version of Rails Specify one of the supported versions listed in [Appraisals](https://github.com/viewcomponent/view_component/blob/main/Appraisals): From 7e10ae019b8e2abec4bb39b1b80278d724f35049 Mon Sep 17 00:00:00 2001 From: Joel Hawksley Date: Mon, 30 Nov 2026 11:21:51 -0700 Subject: [PATCH 4/4] Remove avoidable Herb fixture exceptions Use semantic hidden and accessible status markup, assert Turbo Stream structure, format product and yielding fixtures, and update measured allocation expectations across Rails versions. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .herb.yml | 17 ----------------- .../app/components/product_component.html.erb | 6 +++++- ...eraction_with_js_included_component.html.erb | 2 +- ...ction_without_js_included_component.html.erb | 2 +- .../components/turbo_stream_component.html.erb | 4 +++- .../app/lib/primer/state_component.html.erb | 6 +++++- .../app/views/layouts/application.html.erb | 2 +- .../app/views/shared/_yielding_partial.html.erb | 2 +- test/sandbox/test/integration_test.rb | 15 +++++++++------ test/sandbox/test/rendering_allocations_test.rb | 14 +++++++------- 10 files changed, 33 insertions(+), 37 deletions(-) diff --git a/.herb.yml b/.herb.yml index 5dcf493fc..5874a21a6 100644 --- a/.herb.yml +++ b/.herb.yml @@ -48,23 +48,11 @@ linter: exclude: # Object rendering supplies implicit locals to this compatibility fixture. - "test/sandbox/app/views/integration_examples/_test_partial.html.erb" - erb-prefer-explicit-conditionals: - exclude: - # Allocation assertions depend on this fixture's original compiled Ruby. - - "test/sandbox/app/components/product_component.html.erb" - html-no-title-attribute: - exclude: - # Integration tests exercise this legacy Primer component's title attribute. - - "test/sandbox/app/lib/primer/state_component.html.erb" html-no-inline-script-elements: exclude: # System tests render these as standalone HTML, without an asset server. - "test/sandbox/app/components/simple_javascript_interaction_with_js_included_component.html.erb" - "test/sandbox/app/views/layouts/application.html.erb" - html-no-style-attributes: - exclude: - # System tests reveal this element by changing its inline display property. - - "test/sandbox/app/components/simple_javascript_interaction_without_js_included_component.html.erb" formatter: enabled: true @@ -74,11 +62,6 @@ formatter: exclude: # This template emits Markdown, where indentation and line breaks are syntax. - "lib/docs/docs_builder_component.html.erb" - # Preserve the compiled Ruby used by exact allocation assertions. - - "test/sandbox/app/components/product_component.html.erb" - # These fixtures assert exact rendered text and Turbo Stream output. - - "test/sandbox/app/views/shared/_yielding_partial.html.erb" - - "test/sandbox/app/components/turbo_stream_component.html.erb" rewriter: pre: - tailwind-class-sorter diff --git a/test/sandbox/app/components/product_component.html.erb b/test/sandbox/app/components/product_component.html.erb index b9b7f6a95..6bb151d68 100644 --- a/test/sandbox/app/components/product_component.html.erb +++ b/test/sandbox/app/components/product_component.html.erb @@ -1,6 +1,10 @@
  • Product

    -

    "><%= @product.name %>

    + +

    + <%= @product.name %> +

    +

    <%= @notice %>

    <%= @product.name %> counter: <%= @counter %>

  • diff --git a/test/sandbox/app/components/simple_javascript_interaction_with_js_included_component.html.erb b/test/sandbox/app/components/simple_javascript_interaction_with_js_included_component.html.erb index df9910e42..12aa6b4d3 100644 --- a/test/sandbox/app/components/simple_javascript_interaction_with_js_included_component.html.erb +++ b/test/sandbox/app/components/simple_javascript_interaction_with_js_included_component.html.erb @@ -3,7 +3,7 @@ let button = document.querySelector('[data-button]') let hiddenField = document.querySelector('[data-hidden-field]') button.addEventListener('click', function() { - hiddenField.style.display = "block" + hiddenField.hidden = false }) }) diff --git a/test/sandbox/app/components/simple_javascript_interaction_without_js_included_component.html.erb b/test/sandbox/app/components/simple_javascript_interaction_without_js_included_component.html.erb index 36d185486..f8b14eb21 100644 --- a/test/sandbox/app/components/simple_javascript_interaction_without_js_included_component.html.erb +++ b/test/sandbox/app/components/simple_javascript_interaction_without_js_included_component.html.erb @@ -1,5 +1,5 @@ -
    + diff --git a/test/sandbox/app/components/turbo_stream_component.html.erb b/test/sandbox/app/components/turbo_stream_component.html.erb index c1ffb202f..b0595be17 100644 --- a/test/sandbox/app/components/turbo_stream_component.html.erb +++ b/test/sandbox/app/components/turbo_stream_component.html.erb @@ -1 +1,3 @@ -<%= turbo_stream.update "area1" do %>Hello, world!<% end %> +<%= turbo_stream.update "area1" do %> + Hello, world! +<% end %> diff --git a/test/sandbox/app/lib/primer/state_component.html.erb b/test/sandbox/app/lib/primer/state_component.html.erb index f7025dea2..ce479cbe7 100644 --- a/test/sandbox/app/lib/primer/state_component.html.erb +++ b/test/sandbox/app/lib/primer/state_component.html.erb @@ -1,3 +1,7 @@ -
    +
    <%= content %>
    diff --git a/test/sandbox/app/views/layouts/application.html.erb b/test/sandbox/app/views/layouts/application.html.erb index 705acf795..d48ec221e 100644 --- a/test/sandbox/app/views/layouts/application.html.erb +++ b/test/sandbox/app/views/layouts/application.html.erb @@ -14,7 +14,7 @@ let button = document.querySelector("[data-button]") let hiddenField = document.querySelector("[data-hidden-field]") button.addEventListener("click", function() { - hiddenField.style.display = "block" + hiddenField.hidden = false }) }) diff --git a/test/sandbox/app/views/shared/_yielding_partial.html.erb b/test/sandbox/app/views/shared/_yielding_partial.html.erb index bc1a8a407..f252b0e1f 100644 --- a/test/sandbox/app/views/shared/_yielding_partial.html.erb +++ b/test/sandbox/app/views/shared/_yielding_partial.html.erb @@ -1,3 +1,3 @@ <%# locals: () %> -hello <%= yield %> +hello <%= yield %> diff --git a/test/sandbox/test/integration_test.rb b/test/sandbox/test/integration_test.rb index 82d06ef66..073fdbcc8 100644 --- a/test/sandbox/test/integration_test.rb +++ b/test/sandbox/test/integration_test.rb @@ -225,7 +225,7 @@ def test_rendering_component_with_content get "/content" assert_response :success assert_select "div.State--green" - assert_select "div[title='Status: Open']" + assert_select "[role='status'][aria-label='Status: Open']", text: "Open" assert_includes response.body, "Open" end @@ -550,11 +550,14 @@ def test_does_not_render_additional_newline_with_render_in def test_render_component_in_turbo_stream without_template_annotations do get turbo_stream_path, headers: {"HTTP_ACCEPT" => "text/vnd.turbo-stream.html"} - expected_response_body = <<~TURBOSTREAM - - TURBOSTREAM - - assert_equal expected_response_body, response.body + assert_response :success + assert_equal "text/vnd.turbo-stream.html", response.media_type + assert_select "turbo-stream", count: 1 + assert_select "turbo-stream[action='update'][target='area1']", count: 1 do + assert_select "template", count: 1 do + assert_select "span", text: "Hello, world!", count: 1 + end + end end end diff --git a/test/sandbox/test/rendering_allocations_test.rb b/test/sandbox/test/rendering_allocations_test.rb index 617d70ac1..0513440e2 100644 --- a/test/sandbox/test/rendering_allocations_test.rb +++ b/test/sandbox/test/rendering_allocations_test.rb @@ -14,13 +14,13 @@ class RenderingAllocationsTest < ViewComponent::TestCase }.freeze COLLECTION_ALLOCATIONS = { - ["7.1", "3.2"] => 76, - ["7.2", "3.3"] => 79, - ["8.0", "3.4"] => 67, - ["8.1", "4.0"] => 53, - ["8.1", "4.1"] => 53, - ["8.2", "4.0"] => 53, - ["8.2", "4.1"] => 53 + ["7.1", "3.2"] => 74, + ["7.2", "3.3"] => 77, + ["8.0", "3.4"] => 65, + ["8.1", "4.0"] => 52, + ["8.1", "4.1"] => 52, + ["8.2", "4.0"] => 52, + ["8.2", "4.1"] => 52 }.freeze class TestController < IntegrationExamplesController