{"id":13532990,"url":"https://github.com/Shopify/erb_lint","last_synced_at":"2025-04-01T21:31:35.543Z","repository":{"id":9055187,"uuid":"59674703","full_name":"Shopify/erb_lint","owner":"Shopify","description":"Lint your ERB or HTML files","archived":false,"fork":false,"pushed_at":"2025-03-17T10:15:36.000Z","size":755,"stargazers_count":707,"open_issues_count":80,"forks_count":130,"subscribers_count":167,"default_branch":"main","last_synced_at":"2025-03-25T04:54:31.146Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"justinthec/erb-lint","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Shopify.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-05-25T15:24:46.000Z","updated_at":"2025-03-24T01:25:42.000Z","dependencies_parsed_at":"2025-02-13T21:10:06.123Z","dependency_job_id":"f5d9d549-c199-42bf-bff3-2f7dbe6d6bf5","html_url":"https://github.com/Shopify/erb_lint","commit_stats":{"total_commits":447,"total_committers":84,"mean_commits":5.321428571428571,"dds":0.883668903803132,"last_synced_commit":"52cbaae9e3a1a4ec7a706e4c0f26400e71576d62"},"previous_names":["shopify/erb_lint","shopify/erb-lint"],"tags_count":51,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Shopify%2Ferb_lint","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Shopify%2Ferb_lint/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Shopify%2Ferb_lint/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Shopify%2Ferb_lint/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Shopify","download_url":"https://codeload.github.com/Shopify/erb_lint/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246342992,"owners_count":20761947,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T07:01:15.628Z","updated_at":"2025-04-01T21:31:35.528Z","avatar_url":"https://github.com/Shopify.png","language":"Ruby","readme":"# ERB Lint [![Build Status](https://github.com/Shopify/erb_lint/workflows/Tests/badge.svg)](https://github.com/Shopify/erb_lint/actions)\n\n`erb_lint` is a tool to help lint your ERB or HTML files using the included linters or by writing your own.\n\n## Requirements\n\n* Ruby 2.3.0+\n - This is due to use of the safe navigation operator (`\u0026.`)\n - This is also due to the use of the tilde-heredoc `\u003c\u003c~` syntax in some tests.\n\n## Installation\n\n```bash\ngem install erb_lint\n```\n\n...or add the following to your `Gemfile` and run `bundle install`:\n\n```ruby\ngem 'erb_lint', require: false\n```\n\n## Configuration\n\nCreate a `.erb_lint.yml` file in your project, with the following structure:\n\n```yaml\n---\nEnableDefaultLinters: true\nlinters:\n  ErbSafety:\n    enabled: true\n    better_html_config: .better-html.yml\n  Rubocop:\n    enabled: true\n    rubocop_config:\n      inherit_from:\n        - .rubocop.yml\n```\n\nSee below for linter-specific configuration options.\n\n## Usage\n\nThis gem provides a command-line interface which can be run like so:\n\n1. Run `erb_lint [options]` if the gem is installed standalone.\n2. Run `bundle exec erb_lint [options]` if the gem is installed as a Gemfile dependency for your app.\n\nFor example, `erb_lint --lint-all --enable-all-linters` will run all available\nlinters on all ERB files in the current directory or its descendants (`**/*.html{+*,}.erb`).\n\nIf you want to change the glob \u0026 exclude that is used, you can configure it by adding it to your config file as follows:\n\n```yaml\n---\nglob: \"**/*.{html,text,js}{+*,}.erb\"\nexclude:\n  - '**/vendor/**/*'\n  - '**/node_modules/**/*'\nlinters:\n  ErbSafety:\n    enabled: true\n    better_html_config: .better-html.yml\n  Rubocop:\n    enabled: true\n    rubocop_config:\n      inherit_from:\n        - .rubocop.yml\n```\n\nMake sure to add `**/` to exclude patterns; it matches the target files' absolute paths.\n\n## Enable or disable default linters\n`EnableDefaultLinters`: enables or disables default linters. [Default linters](#linters) are enabled by default.\n\n## Disable rule at offense-level\nYou can disable a rule by placing a disable comment in the following format:\n\nComment on offending lines\n```.erb\n\u003chr /\u003e \u003c%# erb_lint:disable SelfClosingTag %\u003e\n```\n\nTo raise an error when there is a useless disable comment, enable `NoUnusedDisable`.\n\nTo disable inline comments and report all offenses, set `--disable-inline-configs` option.\n\n## Exclude\n\nYou can specify the exclude patterns both of global and lint-local.\n\n```yaml\n---\nexclude:\n  - '**/global-lib/**/*'\nlinters:\n  ErbSafety:\n    exclude:\n      - '**/local-lib/**/*'\n```\n\n## Linters\n\n| Available Linters                                | Default  | Description |\n| ------------------------------------------------ |:--------:|-------------|\n| [AllowedScriptType](#allowedscripttype)          | Yes      | prevents the addition of `\u003cscript\u003e` tags that have `type` attributes that are not in a white-list of allowed values |\n| ClosingErbTagIndent                              | Yes      |             |\n| [CommentSyntax](#commentsyntax)                  | Yes      | detects bad ERB comment syntax |\n| ExtraNewline                                     | Yes      |             |\n| [FinalNewline](#finalnewline)                    | Yes      | warns about missing newline at the end of a ERB template |\n| [NoJavascriptTagHelper](#nojavascripttaghelper)  | Yes      | prevents the usage of Rails' `javascript_tag` |\n| ParserErrors                                     | Yes      |             |\n| [RequireInputAutocomplete](#requireinputautocomplete)        | Yes       | warns about missing autocomplete attributes in input tags |\n| [RightTrim](#righttrim)                          | Yes      | enforces trimming at the right of an ERB tag |\n| [SelfClosingTag](#selfclosingtag)                | Yes      | enforces self closing tag styles for void elements |\n| [SpaceAroundErbTag](#spacearounderbtag)          | Yes      | enforces a single space after `\u003c%` and before `%\u003e`|\n| SpaceIndentation                                 | Yes      |             |\n| SpaceInHtmlTag                                   | Yes      |             |\n| TrailingWhitespace                               | Yes      |             |\n| [DeprecatedClasses](#deprecatedclasses)          | No       | warns about deprecated css classes |\n| [ErbSafety](#erbsafety)                          | No       | detects unsafe interpolation of ruby data into various javascript contexts and enforce usage of safe helpers like `.to_json`. |\n| [HardCodedString](#hardcodedstring)              | No       | warns if there is a visible hardcoded string in the DOM (does not check for a hardcoded string nested inside a JavaScript tag)            |\n| PartialInstanceVariable                          | No       | detects instance variables in partials |\n| [Rubocop](#rubocop)                              | No       | runs RuboCop rules on ruby statements found in ERB templates |\n| [RequireScriptNonce](#requirescriptnonce)        | No       | warns about missing [Content Security Policy nonces](https://guides.rubyonrails.org/security.html#content-security-policy) in script tags |\n| [StrictLocals](#strictlocals)                    | No       | enforces the use of strict locals in Rails view partial templates |\n\n### DeprecatedClasses\n\nDeprecatedClasses will find all classes used on HTML elements and report any classes that violate the rule set that you provide.\n\nA `rule_set` is specified as a list, each with a set of `deprecated` classes and a corresponding `suggestion` to use as an alternative.\n\nExample configuration:\n\n```yaml\n---\nlinters:\n  DeprecatedClasses:\n    enabled: true\n    exclude:\n      - 'app/views/shared/deprecated/**'\n    addendum: \"See UX wiki for help.\"\n    rule_set:\n      - deprecated: ['badge[-_\\w]*']\n        suggestion: \"Use the ui_badge() component instead.\"\n```\n\nYou can specify an `addendum` to be added to the end of each violation.\nThe error message format is: `\"Deprecated class ... #{suggestion}\"`\nor `\"Deprecated class ... #{suggestion} #{addendum}\"` if an `addendum` is present.\n\nLinter-Specific Option | Description\n-----------------------|-----------------------------------------------------------------------------------\n`rule_set`             | A list of rules, each with a `deprecated` and `suggestion` option.\n`deprecated`           | A list of **regular expressions** which specify the classes deprecated by this rule.\n`suggestion`           | A string to be included in the rule's error message. Make this informative and specific to the rule that it is contained in.\n`addendum`             | A string to be included at the end of every error message of the rule set. (Optional)\n\n### FinalNewline\n\nFiles must have a final newline. This results in better diffs when\nadding lines to the file, since SCM systems such as git won't think that you\ntouched the last line.\n\nYou can customize whether or not a final newline exists with the `present`\noption.\n\nExample configuration:\n\n```yaml\n---\nlinters:\n  FinalNewline:\n    enabled: true\n```\n\nLinter-Specific Option | Description\n-----------------------|---------------------------------------------------------\n`present`              | Whether a final newline should be present (default **true**)\n\n### ErbSafety\n\nRuns the checks provided by\n[better-html's erb safety test helper](https://github.com/Shopify/better-html#testing-for-valid-html-and-erb).\n\nWhen using ERB interpolations in javascript contexts, this linter enforces the usage of safe helpers such as `.to_json`.\nSee [better-html's readme](https://github.com/Shopify/better-html#testing-for-valid-html-and-erb) for more information.\n\nAny ERB statement that does not call a safe helper is deemed unsafe and a violation is shown.\n\nFor example:\n```erb\nNot allowed ❌\n\u003ca onclick=\"alert(\u003c%= some_data %\u003e)\"\u003e\n\nAllowed ✅\n\u003ca onclick=\"alert(\u003c%= some_data.to_json %\u003e)\"\u003e\n```\n\n```erb\nNot allowed ❌\n\u003cscript\u003evar myData = \u003c%= some_data %\u003e;\u003c/script\u003e\n\nAllowed ✅\n\u003cscript\u003evar myData = \u003c%= some_data.to_json %\u003e;\u003c/script\u003e\n```\n\nExample configuration:\n\n```yaml\n---\nlinters:\n  ErbSafety:\n    enabled: true\n    better_html_config: .better-html.yml\n```\n\nLinter-Specific Option | Description\n-----------------------|---------------------------------------------------------\n`better_html_config`   | Name of the configuration file to use for `better-html`. Optional. Valid options and their defaults are described [in better-html's readme](https://github.com/Shopify/better-html#configuration).\n\n### Rubocop\n\nRuns RuboCop on all ruby statements found in ERB templates. The RuboCop configuration that `erb_lint` uses can inherit from\nthe configuration that the rest of your application uses. `erb_lint` can be configured independently however, as it will often\nbe necessary to disable specific RuboCop rules that do not apply to ERB files.\n\n**Note**: Each ruby statement (between ERB tags `\u003c% ... %\u003e`) is parsed and analyzed independently of each other. Any rule that requires a broader context can trigger false positives (e.g. `Lint/UselessAssignment` will complaint for an assignment even if used in a subsequent ERB tag).\n\nExample configuration:\n\n```yaml\n---\nlinters:\n  Rubocop:\n    enabled: true\n    rubocop_config:\n      inherit_from:\n        - .rubocop.yml\n      Layout/InitialIndentation:\n        Enabled: false\n      Layout/LineLength:\n        Enabled: false\n      Layout/TrailingEmptyLines:\n        Enabled: false\n      Layout/TrailingWhitespace:\n        Enabled: false\n      Naming/FileName:\n        Enabled: false\n      Style/FrozenStringLiteralComment:\n        Enabled: false\n      Lint/UselessAssignment:\n        Enabled: false\n      Rails/OutputSafety:\n        Enabled: false\n```\n\nThe cops disabled in the example configuration above provide a good starting point.\n\nLinter-Specific Option | Description\n-----------------------|---------------------------------------------------------\n`rubocop_config`       | A valid rubocop configuration hash. Mandatory when this cop is enabled. See [rubocop's manual entry on Configuration](http://rubocop.readthedocs.io/en/latest/configuration/)\n`only`                 | Only run cops listed in this array instead of all cops.\n`config_file_path`     | A path to a valid rubocop configuration file. When this is provided, `rubocop_config` will be ignored.\n\n### RequireInputAutocomplete\nThis linter prevents the usage of certain types of HTML `\u003cinput\u003e` without an `autocomplete` argument: `color`, `date`, `datetime-local`, `email`, `month`, `number`, `password`, `range`, `search`, `tel`, `text`, `time`, `url`, or `week`.\n\nThe HTML autocomplete helps users to complete filling in forms by using data stored in the browser. This is particularly useful for people with **motor disabilities** or **cognitive impairment** who may have difficulties filling out forms online.\n\n```\nBad ❌\n\u003cinput type=\"email\" ...\u003e\nGood ✅\n\u003cinput type=\"email\" autocomplete=\"nope\" ...\u003e\n\u003cinput type=\"email\" autocomplete=\"email\" ...\u003e\n```\n\n### RightTrim\n\nTrimming at the right of an ERB tag can be done with either `=%\u003e` or `-%\u003e`, this linter enforces one of these two styles.\n\nExample configuration:\n\n```yaml\n---\nlinters:\n  RightTrim:\n    enabled: true\n    enforced_style: '-'\n```\n\nLinter-Specific Option | Description\n-----------------------|---------------------------------------------------------\n`enforced_style`       | Which style to enforce, can be either `-` or `=`. Optional. Defaults to `-`.\n\n### SpaceAroundErbTag\n\nEnforce a single space after `\u003c%` and before `%\u003e` in the ERB source.\nThis linter ignores opening ERB tags (`\u003c%`) that are followed by a newline,\nand closing ERB tags (`%\u003e`) that are preceded by a newline.\n\n\n```erb\nBad ❌\n\u003c%foo%\u003e\n\u003c%=foo-%\u003e\n\nGood ✅\n\u003c% foo %\u003e\n\n\u003c%\n  foo\n%\u003e\n```\n\nExample configuration:\n\n```yaml\n---\nlinters:\n  SpaceAroundErbTag:\n    enabled: true\n```\n\n### NoJavascriptTagHelper\n\nThis linter prevents the usage of\nRails' [`javascript_tag`](https://apidock.com/rails/ActionView/Helpers/JavaScriptHelper/javascript_tag)\nhelper in ERB templates.\n\nThe html parser used in this gem knows not to look for html tags within certain other tags\nlike `script`, `style`, and others. The html parser does this to avoid confusing javascript\nexpressions like `if (1\u003ca || b\u003e1)` for a malformed html tag. Using the `javascript_tag` in\na ERB template prevents the parser from recognizing the change of parsing context and may\nfail or produce erroneous output as a result.\n\n```erb\nBad ❌\n\u003c%= javascript_tag(content, defer: true) %\u003e\nGood ✅\n\u003cscript defer=\"true\"\u003e\u003c%== content %\u003e\u003c/script\u003e\n\nBad ❌\n\u003c%= javascript_tag do %\u003e\n  alert(1)\n\u003c% end %\u003e\nGood ✅\n\u003cscript\u003e\n  alert(1)\n\u003c/script\u003e\n```\n\nThe autocorrection rule adds `//\u003c![CDATA[` and `//]]\u003e` markers to the existing script, as this is the default\nbehavior for `javascript_tag`. This can be disabled by changing the `correction_style` linter option\nfrom `cdata` to `plain`.\n\nExample configuration:\n\n```yaml\n---\nlinters:\n  NoJavascriptTagHelper:\n    enabled: true\n    correction_style: 'plain'\n```\n\nLinter-Specific Option | Description\n-----------------------|---------------------------------------------------------\n`correction_style`     | When configured with `cdata`, adds CDATA markers. When configured with `plain`, don't add makers. Defaults to `cdata`.\n\n### RequireScriptNonce\nThis linter prevents the usage of HTML `\u003cscript\u003e`, Rails `javascript_tag`, `javascript_include_tag` and `javascript_pack_tag` without a `nonce` argument. The purpose of such a check is to ensure that when [content securty policy](https://edgeguides.rubyonrails.org/security.html#content-security-policy) is implemented in an application, there is a means of discovering tags that need to be updated with a `nonce` argument to enable script execution at application runtime.\n\n```\nBad ❌\n\u003cscript\u003e\n    alert(1)\n\u003c/script\u003e\nGood ✅\n\u003cscript nonce=\"\u003c%= request.content_security_policy_nonce %\u003e\" \u003e\n    alert(1)\n\u003c/script\u003e\n```\n\n```\nBad ❌\n\u003c%= javascript_tag do -%\u003e\n  alert(1)\n\u003c% end -%\u003e\nGood ✅\n\u003c%= javascript_tag nonce: true do -%\u003e\n  alert(1)\n\u003c% end -%\u003e\n```\n\n```\nBad ❌\n\u003c%= javascript_include_tag \"script\" %\u003e\nGood ✅\n\u003c%= javascript_include_tag \"script\", nonce: true %\u003e\n```\n\n```\nBad ❌\n\u003c%= javascript_pack_tag \"script\" %\u003e\nGood ✅\n\u003c%= javascript_pack_tag \"script\", nonce: true %\u003e\n```\n\n### SelfClosingTag\n\nThis linter enforces self closing tag styles for void elements.\n\nThe void elements are `area`, `base`, `br`, `col`, `embed`, `hr`, `img`, `input`, `keygen`, `link`, `menuitem`, `meta`, `param`, `source`, `track`, and `wbr`.\n\nIf `enforced_style` is set to `always` (XHTML style):\n\n```erb\nBad ❌\n\u003clink rel=\"stylesheet\" type=\"text/css\" href=\"styles.css\"\u003e\nGood ✅\n\u003cimg src=\"someimage.png\" alt=\"Some Image\" /\u003e\n```\n\nIf `enforced_style` is set to `never` (HTML5 style):\n```erb\nBad ❌\n\u003chr /\u003e\nGood ✅\n\u003cmeta charset=\"UTF-8\"\u003e\n```\n\nExample configuration:\n\n```yaml\n---\nlinters:\n  SelfClosingTag:\n    enabled: true\n    enforced_style: 'always'\n```\n\nLinter-Specific Option | Description\n-----------------------|---------------------------------------------------------\n`enforced_style`       |  If we should `always` or `never` expect self closing tags for void elements. Defaults to `never`.\n\n### AllowedScriptType\n\nThis linter prevent the addition of `\u003cscript\u003e` tags that have `type` attributes that are not in a white-list of allowed values.\n\nIt is common practice for web developers to use `\u003cscript\u003e` tags with non-executable\n`type` attributes, such as `application/json` or `text/html` to pass arbitrary data into an html page.\n\nDespite not being executable, these tags are subject to the same parsing quirks as executable script tags, and\nit is therefore more difficult to prevent security issues from creeping in. Consider for instance an application\nwhere it is possible to inject the string `\u003c/script\u003e\u003cscript\u003e` unescaped into a `text/html` tag, the application\nwould be vulnerable to XSS.\n\nThis pattern can easily be replaced by `\u003cdiv\u003e` tags with `data` attributes that can just as easily be read\nfrom javascript, and have the added benefit of being safer. When `content_tag(:div)` or `tag.div()` is used\nto pass arbitrary user data into the html document, it becomes much harder to inadvertently introduce a\nsecurity issue.\n\nIt may also be desirable to avoid typos in `type` attributes.\n\n```html\nBad ❌\n\u003cscript type=\"text/javacsrïpt\"\u003e\u003c/script\u003e\nGood ✅\n\u003cscript type=\"text/javascript\"\u003e\u003c/script\u003e\n```\n\nBy default, this linter allows the `type` attribute to be omitted, as the behavior in browsers is to\nconsider `\u003cscript\u003e` to be the same as `\u003cscript type=\"text/javascript\"\u003e`. When the linter is configured with\n`allow_blank: false`, instances of `\u003cscript\u003e` tags without a type will be auto-corrected\nto `\u003cscript type=\"text/javascript\"\u003e`.\n\nIt may also be desirable to disallow `\u003cscript\u003e` tags from appearing anywhere in your application.\nFor instance, Rails applications can benefit from serving static javascript code from the asset\npipeline, as well as other security benefits.\nThe `disallow_inline_scripts: true` config option may be used for that purpose.\n\nExample configuration:\n\n```yaml\n---\nlinters:\n  AllowedScriptType:\n    enabled: true\n    allowed_types:\n      - 'application/json'\n      - 'text/javascript'\n      - 'text/html'\n    allow_blank: false\n    disallow_inline_scripts: false\n```\n\nLinter-Specific Option    | Description\n--------------------------|---------------------------------------------------------\n`allowed_types`           | An array of allowed types. Defaults to `[\"text/javascript\"]`.\n`allow_blank`             | True or false, depending on whether or not the `type` attribute may be omitted entirely from a `\u003cscript\u003e` tag. Defaults to `true`.\n`disallow_inline_scripts` | Do not allow inline `\u003cscript\u003e` tags anywhere in ERB templates. Defaults to `false`.\n\n\n### HardCodedString\n\n`HardCodedString` warns if there is a visible hardcoded string in the DOM. It does not check for a hardcoded string nested inside a JavaScript tag.\n\nExample configuration:\n\n```yaml\n---\nlinters:\n  HardCodedString:\n    enabled: true\n    corrector:\n      path: path/to/corrector_file.rb\n      name: I18nCorrector\n      i18n_load_path: config/locales/en.yml\n```\n\nTo leverage this linter's autocorrect feature, you must define the configuration for its `corrector`, such that its path, class name, and `i18n_load_path` are resolvable.\n\nLinter-Specific Option    | Description\n--------------------------|---------------------------------------------------------\npath | a string pointing to the path to the corrector file\nname | the name of the corrector class (can [either be `I18nCorrector` or `Rubocop::I18nCorrector`](https://github.com/Shopify/erb-lint/blob/19c9ddb94f0ea1d73ac12e18a7ea822d76adeeab/lib/erb_lint/linters/hard_coded_string.rb#L17))\ni18n_load_path | a string pointing to the path of the file(s) to be translated\n\nBelow is an example corrector file. For your project, the actual details of the `autocorrect` method are left up to how you want to correct those offenses.\n\n```ruby\nclass I18nCorrector\n  attr_reader :node\n\n  def initialize(node, filename, i18n_load_path, range)\n  end\n\n  def autocorrect(tag_start:, tag_end:)\n    -\u003e(corrector) do\n      node\n    end\n  end\nend\n```\n\n### StrictLocals\nThis linter enforces the use of [strict locals](https://guides.rubyonrails.org/layouts_and_rendering.html#strict-locals) in Rails view partial templates.\n\n```\n# app/views/foo/_bar.html.erb\n\nBad ❌\n\u003cdiv\u003e\n  My name is \u003c%= @name %\u003e\n\u003c/div\u003e\n\nGood ✅\n\u003c%# locals: (name:) %\u003e\n\u003cdiv\u003e\n  My name is \u003c%= name %\u003e\n\u003c/div\u003e\n```\n\n**Note**: This linter does not enforce the use of strict locals in view templates (files that don't start with `_`).  \n**Note**: This linter does not prevent the use of instance variables. It merely enforces that a strict locals declaration is present. It's recommended to use this linter in conjunction with the `PartialInstanceVariable` linter to enforce the use of locals.\n\n## CommentSyntax\n\nThis linter enforces the use of the correct ERB comment syntax, since Ruby comments (`\u003c% # comment %\u003e` with a space) are not technically valid ERB comments.\n\n```erb\nBad ❌\n\u003c% # This is a Ruby comment %\u003e\nGood ✅\n\u003c%# This is an ERB comment %\u003e\n\nBad ❌\n\u003c% # This is a Ruby comment; it can fail to parse. %\u003e\nGood ✅\n\u003c%# This is an ERB comment; it is parsed correctly. %\u003e\n\nGood ✅\n\u003c%\n  # This is a multi-line ERB comment.\n%\u003e\n```\n\n## Custom Linters\n\n`erb_lint` allows you to create custom linters specific to your project. It will load linters from the `.erb_linters` directory in the root of your\nrepository. See the [linters directory](lib/erb_lint/linters) for examples of how to write linters.\n\n```ruby\n# .erb_linters/custom_linter.rb\n\nmodule ERBLint\n  module Linters\n    class CustomLinter \u003c Linter\n      include LinterRegistry\n\n      class ConfigSchema \u003c LinterConfig\n        property :custom_message, accepts: String\n      end\n      self.config_schema = ConfigSchema\n\n      def run(processed_source)\n        unless processed_source.file_content.include?('this file is fine')\n          add_offense(\n            processed_source.to_source_range(0 ... processed_source.file_content.size),\n            \"This file isn't fine. #{@config.custom_message}\"\n          )\n        end\n      end\n    end\n  end\nend\n```\n\nBy default, this linter would be disabled. You can enable it by adding an entry to `.erb_lint.yml`:\n\n```yaml\n---\nlinters:\n  CustomLinter:\n    enabled: true\n    custom_message: We suggest you change this file.\n```\n\nTest your linter by running `erb_lint`'s command-line interface:\n\n```bash\nbundle exec erb_lint --enable-linters custom_linter --lint-all\n```\n\nRunning this on a random project might yield this output:\n\n```\nLinting 15 files with 1 linters...\n\nThis file isn't fine. We suggest you change this file.\nIn file: app/views/layouts/application.html.erb:1\n\nErrors were found in ERB files\n```\n\nTo write a linter that can autocorrect offenses it detects, simply add an\n`autocorrect` method that returns a callable. The callable is called with an instance of\n[`RuboCop::Cop::Corrector`](http://www.rubydoc.info/github/bbatsov/RuboCop/RuboCop/Cop/Corrector)\nas argument, and therefore erb_lint correctors work exactly as RuboCop correctors do.\n\n```ruby\ndef autocorrect(_processed_source, offense)\n  lambda do |corrector|\n    corrector.insert_after(offense.source_range, \"this file is fine\")\n  end\nend\n```\n\n## Output formats\n\nYou can change the output format of ERB Lint by specifying formatters with the `-f/--format` option.\n\n### Multiline (default)\n\n```sh\n$ erb_lint\nLinting 8 files with 12 linters...\n\nRemove multiple trailing newline at the end of the file.\nIn file: app/views/users/show.html.erb:95\n\nRemove newline before `%\u003e` to match start of tag.\nIn file: app/views/subscriptions/index.html.erb:38\n\n2 error(s) were found in ERB files\n```\n\n### Compact\n\n```sh\nerb_lint --format compact\nLinting 8 files with 12 linters...\napp/views/users/show.html.erb:95:0: Remove multiple trailing newline at the end of the file.\napp/views/users/_graph.html.erb:27:37: Extra space detected where there should be no space\n2 error(s) were found in ERB files\n```\n\n### JUnit\n\n```sh\nerb_lint --format junit\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\u003ctestsuite name=\"erb_lint\" tests=\"2\" failures=\"2\"\u003e\n  \u003cproperties\u003e\n    \u003cproperty name=\"erb_lint_version\" value=\"%{erb_lint_version}\"/\u003e\n    \u003cproperty name=\"ruby_engine\" value=\"%{ruby_engine}\"/\u003e\n    \u003cproperty name=\"ruby_version\" value=\"%{ruby_version}\"/\u003e\n    \u003cproperty name=\"ruby_patchlevel\" value=\"%{ruby_patchlevel}\"/\u003e\n    \u003cproperty name=\"ruby_platform\" value=\"%{ruby_platform}\"/\u003e\n  \u003c/properties\u003e\n  \u003ctestcase name=\"app/views/subscriptions/_loader.html.erb\" file=\"app/views/subscriptions/_loader.html.erb\" lineno=\"1\"\u003e\n    \u003cfailure message=\"SpaceInHtmlTag: Extra space detected where there should be no space.\" type=\"SpaceInHtmlTag\"\u003e\n      \u003c![CDATA[SpaceInHtmlTag: Extra space detected where there should be no space. at app/views/subscriptions/_loader.html.erb:1:7]]\u003e\n    \u003c/failure\u003e\n  \u003c/testcase\u003e\n  \u003ctestcase name=\"app/views/application/index.html.erb\" file=\"app/views/subscriptions/_menu.html.erb\"/\u003e\n\u003c/testsuite\u003e\n```\n\n### GitLab\n\nUsed by [GitLab Code\nQuality](https://docs.gitlab.com/ee/ci/testing/code_quality.html#implement-a-custom-tool).\n\n```json\n[\n   {\n      \"description\":\"Extra space detected where there should be no space.\",\n      \"check_name\":\"SpaceInHtmlTag\",\n      \"fingerprint\":\"5a259c7cafa2c9ca229dfd7d21536698\",\n      \"severity\":\"info\",\n      \"location\":{\n         \"path\":\"app/views/subscriptions/_loader.html.erb\",\n         \"lines\":{\n            \"begin\":1,\n            \"end\":1\n         }\n      }\n   },\n   {\n      \"description\":\"Remove newline before `%\\u003e` to match start of tag.\",\n      \"check_name\":\"ClosingErbTagIndent\",\n      \"fingerprint\":\"60b4ed2120c7abeebebb43fba4a19559\",\n      \"severity\":\"warning\",\n      \"location\":{\n         \"path\":\"app/views/subscriptions/_loader.html.erb\",\n         \"lines\":{\n            \"begin\":52,\n            \"end\":54\n         }\n      }\n   }\n]\n```\n\n## Caching\n\nThe cache is currently opt-in - to turn it on, use the `--cache` option:\n\n```sh\nerb_lint --cache ./app\nCache mode is on\nLinting 413 files with 15 linters...\nFile names pruned from the cache will be logged\n\nNo errors were found in ERB files\n```\n\nCached lint results are stored in the `.erb_lint_cache` directory by default, though a custom directory can be provided\nvia the `--cache-dir` option. Cache filenames are computed with a hash of information about the file and `erb_lint` settings.\n\nThese files store instance attributes of the `CachedOffense` object, which only contain the `Offense` attributes\nnecessary to restore the results of running `erb_lint` for output. The cache also automatically prunes outdated files each time it's run.\n\nYou can also use the `--clear-cache` option to delete the cache file directory.\n\n## License\n\nThis project is released under the [MIT license](LICENSE.txt).\n","funding_links":[],"categories":["Awesome Ruby CLIs","Ruby"],"sub_categories":["Linting"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FShopify%2Ferb_lint","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FShopify%2Ferb_lint","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FShopify%2Ferb_lint/lists"}