From 5f318d6a689aca2288669584b83631e8e4f74d84 Mon Sep 17 00:00:00 2001 From: Emil Ong Date: Thu, 11 Nov 2021 14:09:20 -0800 Subject: [PATCH 1/2] Add InstanceVariable linter Adds the InstanceVariable linter, which can be limited to partials only (thus deprecating PartialInstanceVariable), but considers an instance variable in any template to be an offense by default. Also changed range behavior in both linters to highlight the instance variables themselves. The previous behavior highlighted the start of the variable to the end of the file. Finally, added support for detecting class instance variables. --- README.md | 78 ++++++++++++- lib/erb_lint/linters/instance_variable.rb | 45 ++++++++ .../linters/partial_instance_variable.rb | 28 ++--- .../linters/instance_variable_spec.rb | 109 ++++++++++++++++++ .../linters/partial_instance_variable_spec.rb | 21 +++- 5 files changed, 263 insertions(+), 18 deletions(-) create mode 100644 lib/erb_lint/linters/instance_variable.rb create mode 100644 spec/erb_lint/linters/instance_variable_spec.rb diff --git a/README.md b/README.md index 191a4828..7ab86cee 100644 --- a/README.md +++ b/README.md @@ -98,7 +98,8 @@ linters: | [FinalNewline](#FinalNewline) | Yes | warns about missing newline at the end of a ERB template | | [NoJavascriptTagHelper](#NoJavascriptTagHelper) | Yes | prevents the usage of Rails' `javascript_tag` | | ParserErrors | Yes | | -| PartialInstanceVariable | No | detects instance variables in partials | +| [InstanceVariable](#InstanceVariable) | No | detects instance variables | +| PartialInstanceVariable | No | detects instance variables in partials (deprecated in favor of [InstanceVariable](#InstanceVariable))| | [RequireInputAutocomplete](#RequireInputAutocomplete) | Yes | warns about missing autocomplete attributes in input tags | | [RightTrim](#RightTrim) | Yes | enforces trimming at the right of an ERB tag | | [SelfClosingTag](#SelfClosingTag) | Yes | enforces self closing tag styles for void elements | @@ -355,15 +356,15 @@ Linter-Specific Option | Description `correction_style` | When configured with `cdata`, adds CDATA markers. When configured with `plain`, don't add makers. Defaults to `cdata`. ### RequireScriptNonce -This linter prevents the usage of HTML ` Good ✅ - ``` @@ -486,6 +487,75 @@ Linter-Specific Option | Description `allow_blank` | True or false, depending on whether or not the `type` attribute may be omitted entirely from a `