This document provides comprehensive examples of the syntax errors and warnings that the Slim VS Code extension will detect.
Error: Tag names cannot start with numbers
123invalid This will show an errorMessage: Invalid tag name: '123invalid'. Tag names must start with a letter and contain only letters and numbers.
Error: Invalid characters at line start
@invalid-start This is not valid Slim syntax
$also-invalid Another invalid startMessage: Invalid syntax. Lines must start with a tag name, #id, .class, [attributes], *, -, =, /, |, ' or <.
Error: Missing closing square bracket
div[class="test" Missing closing bracketMessage: Unclosed square brackets in attributes.
Error: Missing closing parenthesis
= some_method(param1, param2 Missing closing parenMessage: Unclosed parentheses.
Error: Missing closing curly brace
= { key: "value" Missing closing braceMessage: Unclosed curly braces.
Error: Empty attribute name
div[="no-name"] Attribute name is missingMessage: Attribute name cannot be empty.
Error: Invalid attribute name starting with number
div[123attr="invalid"] Attribute names cannot start with numbersMessage: Invalid attribute name: '123attr'. Attribute names must start with a letter.
Error: Empty attribute brackets
div[] Empty brackets are not allowedMessage: Empty attribute brackets are not allowed.
Error: Unmatched quotes
= "This string is not closed properly
- name = 'Another unclosed stringMessage: Unmatched double quote in Ruby code. or Unmatched single quote in Ruby code.
Quotes inside other strings (t("it's here")), escaped quotes, #{} interpolation and comments are handled, and a line ending in , or \ is checked together with the lines that continue it.
Error: Explicit end
- if user_signed_in?
p = current_user.name
- endMessage: Explicit 'end' is not allowed. Slim closes Ruby blocks by indentation.
Note: Only a - end line is an error. end as a method name, symbol or in a string (= range.end, = t(".end")) is fine.
The lines nested in a - or = line (- if, - each do, = form_with ... do) are Slim, and are linted like any other Slim.
Warning: Mixed spaces and tabs
div
p Normal 2-space indentation
span This line uses a tab instead of spacesMessage: Inconsistent indentation: expected spaces but found tabs.
Warning: Wrong indentation size
div
p This has 3 spaces instead of 2 (assuming 2-space config)Message: Inconsistent indentation: expected multiples of 2 spaces.
Warning: Same ID used multiple times
div#duplicate-id First element with this ID
span#duplicate-id Second element with same IDMessage: Duplicate ID 'duplicate-id'. IDs must be unique within the document.
Warning: Tags with only selectors but no content
.empty-class-only
#empty-id-onlyMessage: Empty tag with only selectors. Consider adding content or removing the line.
The linter automatically skips validation for non-Slim content blocks. These blocks can contain any syntax without triggering Slim linting errors:
javascript:
console.log("JavaScript code");
// Even invalid Slim syntax here is ignored:
123invalid = "this looks like invalid Slim but it's JavaScript"
[unclosed-bracket = "this is fine in JavaScript context"css:
.valid-css {
color: red;
}
/* CSS with Slim-looking syntax is ignored: */
.123starts-with-number { color: blue; }
scss:
$primary-color: #333;
.nested {
&:hover { color: lighten($primary-color, 20%); }
}
// Invalid Slim syntax in SCSS is ignored:
123invalid { color: red; }ruby:
def some_method
puts "This is Ruby code"
end
# Ruby code that looks like invalid Slim is ignored:
123variable = "starts with number but it's Ruby"
[some_array] = ["this", "looks", "like", "slim", "attributes"]/
This is a comment block
123invalid syntax here is ignored
[unclosed brackets are ignored
Even @invalid characters are fine in commentsThe same applies to every Slim embedded engine: sass:, less:, coffee:, markdown:, erb:, textile:, rdoc: and asciidoc:.
markdown:
Some *emphasis*
* item one
sass:
$c: red
erb:
<%= 1 %>These examples show correct Slim syntax that won't trigger any linting errors:
doctype html
html
head
title My Page
body.main-content
h1#page-title Welcome
div.container[data-role="main"]
p.description This is valid content
- if user_signed_in?
p = "Hello, #{current_user.name}!"
= link_to "Profile", user_path(current_user), class: "btn"
- else
p Please sign in
ul.nav-list
- menu_items.each do |item|
li.nav-item[data-id=item.id]
= link_to item.name, item.path
javascript:
console.log("Valid JavaScript block");
css:
.valid-styles {
color: blue;
}You can customize which linting rules are active through VS Code settings:
slim.linting.enabled: Enable/disable all linting (default: true)slim.linting.validateSyntax: Check basic Slim syntax (default: true)slim.linting.validateIndentation: Check indentation consistency (default: true)slim.linting.validateRuby: Validate embedded Ruby code (default: true)slim.linting.validateIds: Check for duplicate IDs (default: true)slim.linting.warnEmptyTags: Warn about empty tags (default: false)
- Open any
.slimfile in VS Code - The linter runs automatically as you type
- Errors appear as red squiggly underlines
- Warnings appear as yellow squiggly underlines
- Hover over the underlines to see detailed error messages
- Check the "Problems" panel (View → Problems) to see all issues at once
The linting helps catch common mistakes early and ensures your Slim templates follow proper syntax conventions!