Lint your Haml files in VS Code


Alan Vardy
 haml  rails  ruby  vscode

Next to ERB, haml can be a bit overwhelmimg. The code is terse and (unlike ERB) indentation really matters.

I didn’t realise until recently that linting haml is an option, and want to share my current configuration.

Configure VS Code

Set tab size in your settings.json

  "[haml]": {
    "editor.tabSize": 2,

Add VS Code Extensions

Better Haml

Haml Lint

Install Haml-lint gem

Add the haml-lint gem either manually

gem install haml_lint

or in your gemfile

gem 'haml_lint', require: false

Add the configuration file

Create .haml-lint.yml in the base of your project directory

touch .haml-lint.yml

and add your configuration

  InlineStyles: {enabled: false}
  LineLength: {enabled: true, max: 120}

    enabled: true
    # These cops are incredibly noisy when it comes to HAML templates, so we
    # ignore them.
      - Lint/BlockAlignment
      - Lint/EndAlignment
      - Lint/Void
      - Layout/AlignHash
      - Layout/AlignParameters
      - Layout/ElseAlignment
      - Layout/EndOfLine
      - Layout/IndentationWidth
      - Layout/TrailingBlankLines
      - Layout/TrailingWhitespace
      - Metrics/BlockLength
      - Metrics/BlockNesting
      - Metrics/LineLength
      - Naming/FileName
      - Style/FrozenStringLiteralComment
      - Style/IfUnlessModifier
      - Style/Next
      - Style/WhileUntilModifier

  SpaceInsideHashAttributes: {enabled: false, style: space}
  ViewLength: {enabled: true, max: 120}
Like what you see?

Related Posts