Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
- **Breaking:** the `source` of every diagnostic is `ruby-templates`, for templates and for problems in a `.ruby-templates.toml` (it was `erb`, `haml`, `slim`, `ruby`, `liquid` and `ruby-templates-ls`).
- **Breaking:** `Rails/I18nMissingKey` is renamed `Rails/MissingTranslation`, in diagnostics, `.ruby-templates.toml` and `disabledDiagnostics`; the old name is an unknown rule.
- **Breaking:** the `rubyTemplates.reindentHaml` command is removed; Format Document and Format Selection do the same.
- Liquid is documented as experimental: the `liquid` language id, its extensions and its grammar are outside the 1.0 stability guarantees.
- Liquid is finished for 1.0: Go to Definition, document links, hover and completion for the files `{% render %}`, `{% include %}` and `{% include_relative %}` name (Jekyll `_includes/` under the nearest `_config.yml`, `_config.yaml` or `_config.toml`; a Shopify theme's `snippets/`; otherwise `_<name>.liquid` next to the file), and errors for a `{{` or `{%` that is never closed, a block tag without its end tag, a stray end tag and a mismatched one (`Syntax/LiquidUnclosedTag`, `Syntax/LiquidUnclosedBlock`, `Syntax/LiquidStrayEndTag`, `Syntax/LiquidMismatchedEndTag`; `rubyTemplates.liquid.disabledDiagnostics`), also from `ruby-templates check`. Liquid is no longer labelled experimental.
- The rules reference and the guides no longer describe shipped rules as a draft, a roadmap or planned, and no longer mention `ruby-templates-ls --check`.
- `ruby-templates --version` and `ruby-templates-ls --version` (or `-V`) print the version and exit 0 (the language server no longer starts for them); `ruby-templates --help`, `check --help` and `format --help` exit 0 instead of 2.
- `ruby-templates check` is faster on apps with many locale files or a large `app/javascript` (one template: about 700 ms to 45 ms on an app with 500 locale files, 700 scripts and `config.i18n.fallbacks = true`): `Rails/MissingTranslation` reads the default locale's files, once, and the other locales only when a key is missing there; the Stimulus check runs its patterns only over scripts that can register controllers.
Expand Down
5 changes: 3 additions & 2 deletions demo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
- [ ] **D-30** `engine_render.html.erb` (партіали engine `blog`): рядок 1 «missing local: :post for app/views/blog/_post.html.erb» (сигнатура береться з engine). Рядок 2 (`blog/summary`, якого немає) не підкреслюється: `blog` це гем із `Gemfile.lock`, а гем може мати власні в'ю. Без блоку `PATH` у `Gemfile.lock` (див. D-28) з'являється й «Missing partial blog/_summary». Власні в'ю engine (`engines/blog/app/views/…`) render-перевірок не мають.
- [ ] **D-31** `$B check demo/shop_app` (див. розділ 7) дає єдине попередження: `pages/index.html.erb:2`, `render "banner"` → «Missing partial pages/_banner, application/_banner». `products/index.html.erb:3`, `render "badge"` без попередження: `ProductsController` робить `include Themeable`, а `lib/themeable.rb` викликає `prepend_view_path`, тож Rails шукає ще й у `themes/` (там `products/_badge.html.erb`). `PagesController` нічого не підключає, тому там перевірка працює.
- [ ] **D-32** Без файлу: `Ctrl+N`, мова _ERB_, встав `<img src="x">`, `<div>` і `<%= render "users/card" %>` окремими рядками. З'являються «`<img>` without `alt`» і «`<div>` is never closed» (HTML-перевірки діють і в безіменному документі). Hover і F12 на `"users/card"` нічого не дають, а Output без помилок.
- [ ] **D-33** `bad.html.liquid`: три помилки (error), по одній на проблему. Рядок 1 `{% endunless %}` «has no open `unless` tag to close» (`Syntax/LiquidStrayEndTag`); рядок 4 `{% endfor %}` «doesn't close the open `if` tag; Liquid expects `endif`» (`Syntax/LiquidMismatchedEndTag`), `if` з рядка 2 окремо не підкреслюється; рядок 5 `{{` «is never closed» (`Syntax/LiquidUnclosedTag`), бо `}}` далі немає. Видали `{% endfor %}`: з'являється «`if` is never closed; add `endif`» на рядку 2 (`Syntax/LiquidUnclosedBlock`). `"rubyTemplates.liquid.disabledDiagnostics": ["Syntax/LiquidStrayEndTag"]` ховає перше. Вміст `{% comment %}` і `{% raw %}` не перевіряється.

## 4. Rails-навігація (`rails_app`)

Expand Down Expand Up @@ -192,7 +193,7 @@
- [ ] **N-46** Перенесення партіала в `app/views`. `shared/_notice.html.erb` викликають два різні layout-и (вони не рендеряться разом). У Explorer перетягни файл у `app/views`: `render "shared/notice"` у `layouts/application.html.erb` (рядок 10) і `layouts/admin.html.slim` (рядок 7) стають `render "/notice"`. F12 на `"/notice"` відкриває `app/views/_notice.html.erb`. Після перевірки поверни файл (`git checkout -- demo && git clean -fd demo`).
- [ ] **N-47** Підказки посилань (`Ctrl`/`Cmd` + наведення) показують шлях від кореня застосунку, а не повний шлях на диску: `"users/card"` (`users/index.html.erb:6`) → `app/views/users/_card.html.erb`, `data-controller="hello"` (там само, рядок 24) → `app/javascript/controllers/hello_controller.js`, `stylesheet_link_tag "application"` (`layouts/application.html.erb:6`) → `app/assets/stylesheets/application.css`, `layout "admin"` (`admin/base_controller.rb:3`) → `app/views/layouts/admin.html.slim`.
- [ ] **N-48** Два застосунки (`demo/run.sh demo.code-workspace`). У `shop_app/app/views/products/index.html.erb` усе береться зі `shop_app`: F12 на `"users/card"` (рядок 4) і `"shared/footer"` (5) відкриває файли `shop_app/app/views/…`, а не `rails_app/…`; після `render "users/card", ` пропонується `customer:` (не `user:`); hover на `t(".title")` (2) показує лише `en: Products`; hover на `about_path` (6) дає `/about` → `pages#index`, F12 веде в `shop_app/config/routes.rb:5`. У `rails_app` лишається своє (N-01…N-25): `new_user_path` там є, а `about_path` ні.
- [ ] **N-49** Liquid не дає відповідей Rails. `playground/liquid/product.html.liquid`: F12, hover і `Ctrl`+клік на `"card"` (рядок 5) та `"users/card"` (6) нічого не роблять, посилань немає, у Problems порожньо, _Format Document_ нічого не змінює. `playground/liquid/_includes/header.html` це Liquid лише завдяки `files.associations` (S-07): звичайні `.html` розширення не забирає.
- [ ] **N-49** Liquid має власну навігацію, а не Rails-ну. `playground/liquid/product.html.liquid`: F12, hover і `Ctrl`+клік на `"card"` (рядок 5) ведуть у `liquid/_card.liquid` (hover показує цей файл, посилання є), на `header.html` (рядок 10) в `_includes/header.html` (тека з `_config.yml` це корінь Jekyll-сайту), на `"users/card"` (6) нікуди («No matching file found.» у hover), хоч поруч у Rails є `users/_card.html.*`. На новому рядку набери `{% include '`: пропонуються `header.html` і `nav.html`. `playground/liquid/_includes/header.html` це Liquid лише завдяки `files.associations` (S-07): `nav.html` у рядку 4 веде в `_includes/nav.html`. _Format Document_ нічого не змінює.

**Контролери, суміжні файли, outline**

Expand Down Expand Up @@ -241,7 +242,7 @@ B=server/target/release/ruby-templates
$B check demo/rails_app/app/views # exit 1: playground/broken, format/heredoc (html_safe, F-12), format/unsafe.*, rules/*, shared/_nav (R-04), users/new
$B check demo/rails_app/app/views/users # exit 1, рівно 3 попередження з new.html.erb
$B check demo/rails_app/app/views/playground/preview # exit 0, нічого
$B check demo/rails_app/app/views/playground/liquid # exit 0, Liquid CLI не перевіряє
$B check demo/rails_app/app/views/playground/liquid # exit 0, нічого (теги збалансовані)
$B check demo/rails_app/app/views/playground/rules # exit 1, 83 попередження: 78 у файлах правил (R-01…R-19), 5 у rules/format (R-27); routes.* без жодного (R-11)
$B check demo/rails_app/app/views/playground/rules/img.html.erb # exit 0, нічого (C-04)
$B check demo/rails_app/app/views/playground/rules/format # exit 1, 5 попереджень: Layout/LineLength і Style/ErbTrimMode (R-27)
Expand Down
5 changes: 5 additions & 0 deletions demo/rails_app/app/views/playground/broken/bad.html.liquid
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% endunless %}
{% if user %}
<p>{{ user.name }}</p>
{% endfor %}
<p>{{ title</p>
1 change: 1 addition & 0 deletions demo/rails_app/app/views/playground/liquid/_card.liquid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div class="card">{{ product.title }}</div>
1 change: 1 addition & 0 deletions demo/rails_app/app/views/playground/liquid/_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
title: Demo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<nav><a href="/">Home</a></nav>
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
<a href="{{ product.url }}">Buy</a>
{% endif %}
</article>
{% include header.html %}
15 changes: 15 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,21 @@
"uniqueItems": true,
"description": "Built-in diagnostics to turn off in Jbuilder and Builder views, by rule name (`Department/Name`). A rule a `.ruby-templates.toml` switches with `enabled` follows the file."
},
"rubyTemplates.liquid.disabledDiagnostics": {
"type": "array",
"items": {
"type": "string",
"enum": [
"Syntax/LiquidUnclosedTag",
"Syntax/LiquidUnclosedBlock",
"Syntax/LiquidStrayEndTag",
"Syntax/LiquidMismatchedEndTag"
]
},
"default": [],
"uniqueItems": true,
"description": "Built-in Liquid diagnostics to turn off, by rule name (`Department/Name`). A rule a `.ruby-templates.toml` switches with `enabled` follows the file."
},
"rubyTemplates.slim.disabledDiagnostics": {
"type": "array",
"items": {
Expand Down
19 changes: 15 additions & 4 deletions server/src/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::erb::{html_lint, tags};
use crate::haml;
use crate::lang::{haml_html_host, html_host, is_partial, slim_html_host, TemplateLang};
use crate::line_length;
use crate::liquid;
use crate::rails::project::{Framework, Project, Projects};
use crate::rails::render_call::HamlPipes;
use crate::rails::{
Expand Down Expand Up @@ -77,9 +78,14 @@ pub(crate) fn diagnostics_in(
) -> Vec<Diagnostic> {
// Thor templates (`*.html.erb.tt`, `*.haml.tt`) mix the generator's ERB with the template's own tags or
// lines, and their partials live outside app/views, so no check applies.
if doc.lang == TemplateLang::Liquid || uri.path().as_str().to_ascii_lowercase().ends_with(".tt") || !rules.diagnostics_enabled() {
if uri.path().as_str().to_ascii_lowercase().ends_with(".tt") || !rules.diagnostics_enabled() {
return vec![];
}
// Liquid has none of the Rails lookups, so only its own tags are checked.
if doc.lang == TemplateLang::Liquid {
let reported = liquid::diagnostics(&doc.text).into_iter().filter(|d| util::code(d).is_none_or(|code| rules.reports(code)));
return reported.map(|d| Diagnostic { source: Some(DIAGNOSTIC_SOURCE.into()), ..d }).collect();
}
let path = util::file_path(uri);
let project = path.as_deref().map(|path| Project::memoized(projects, path, None));
let ruby = path.as_deref().zip(project).map_or_else(RubyContext::outside_project, |(path, project)| project.ruby_context(path));
Expand Down Expand Up @@ -686,9 +692,13 @@ mod tests {
let items = |lang: &str| {
manifest["contributes"]["configuration"]["properties"][format!("rubyTemplates.{lang}.disabledDiagnostics")]["items"].clone()
};
for (section, lang) in
[("erb", TemplateLang::Erb), ("haml", TemplateLang::Haml), ("slim", TemplateLang::Slim), ("jbuilder", TemplateLang::Ruby)]
{
for (section, lang) in [
("erb", TemplateLang::Erb),
("haml", TemplateLang::Haml),
("slim", TemplateLang::Slim),
("jbuilder", TemplateLang::Ruby),
("liquid", TemplateLang::Liquid),
] {
let items = items(section);
let listed: BTreeSet<&str> = items["enum"].as_array().unwrap().iter().map(|c| c.as_str().unwrap()).collect();
let lints = || crate::rules::RULES.iter().filter(|rule| rule.kind == crate::rules::Kind::Lint);
Expand All @@ -711,6 +721,7 @@ mod tests {
include_str!("rails/unknown_route.rs"),
include_str!("haml/indent.rs"),
include_str!("slim/indent.rs"),
include_str!("liquid.rs"),
] {
assert!(!literal.is_match(src.split("#[cfg(test)]").next().unwrap()), "coded(…, \"literal\")");
}
Expand Down
2 changes: 1 addition & 1 deletion server/src/lang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub enum TemplateLang {
Skim,
/// Jbuilder and Builder views: plain Ruby, attached through the `ruby` language id.
Ruby,
/// Liquid (Rails `liquid` gem, Jekyll): highlighted only, none of the Rails features apply.
/// Liquid (Rails `liquid` gem, Jekyll, Shopify): its own file lookups and tag checks; none of the Rails features apply.
Liquid,
}

Expand Down
1 change: 1 addition & 0 deletions server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ mod helpers;
mod html;
mod lang;
mod line_length;
mod liquid;
mod lsp;
mod nested_interactive;
mod options;
Expand Down
Loading
Loading