From ea1829d8e9ee390fad4cb2d4472fb9f17653416e Mon Sep 17 00:00:00 2001 From: Emil Ong Date: Thu, 11 Nov 2021 14:09:20 -0800 Subject: [PATCH] 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 | 259 ++++++++++++------ 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, 357 insertions(+), 105 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 1936ce7b..6645a360 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,10 @@ ## Requirements -* Ruby 2.3.0+ - - This is due to use of the safe navigation operator (`&.`) - - This is also due to the use of the tilde-heredoc `<<~` syntax in some tests. +- Ruby 2.3.0+ + +* This is due to use of the safe navigation operator (`&.`) +* This is also due to the use of the tilde-heredoc `<<~` syntax in some tests. ## Installation @@ -56,8 +57,8 @@ If you want to change the glob & exclude that is used, you can configure it by a --- glob: "**/*.{html,text,js}{+*,}.erb" exclude: - - '**/vendor/**/*' - - '**/node_modules/**/*' + - "**/vendor/**/*" + - "**/node_modules/**/*" linters: ErbSafety: enabled: true @@ -72,12 +73,15 @@ linters: Make sure to add `**/` to exclude patterns; it matches the target files' absolute paths. ## Enable or disable default linters + `EnableDefaultLinters`: enables or disables default linters. [Default linters](#linters) are enabled by default. ## Disable rule at offense-level + You can disable a rule by placing a disable comment in the following format: Comment on offending lines + ```.erb
<%# erblint:disable SelfClosingTag %> ``` @@ -93,36 +97,37 @@ You can specify the exclude patterns both of global and lint-local. ```yaml --- exclude: - - '**/global-lib/**/*' + - "**/global-lib/**/*" linters: ErbSafety: exclude: - - '**/local-lib/**/*' + - "**/local-lib/**/*" ``` ## Linters -| Available Linters | Default | Description | -| ------------------------------------------------ |:--------:|-------------| -| [AllowedScriptType](#allowedscripttype) | Yes | prevents the addition of `