diff --git a/README.md b/README.md index c8b96af..87eaaf0 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ project, whatever style that may be. * Camel case method names * Common syntax * Conditionals wrapped in parentheses + * Unnecessary interpolation in strings * Valid Ruby (warns by default) * Configurable * Specify style in diff --git a/lib/tailor/rulers/allow_unnecessary_interpolation_ruler.rb b/lib/tailor/rulers/allow_unnecessary_interpolation_ruler.rb index bf1a548..6be7bd0 100644 --- a/lib/tailor/rulers/allow_unnecessary_interpolation_ruler.rb +++ b/lib/tailor/rulers/allow_unnecessary_interpolation_ruler.rb @@ -28,12 +28,13 @@ def nl_update(lexed_line, lineno, column) each_string(@tokens).each do |string| measure(line_number(@tokens.first), string) end + reset_tokens end - # Checks if variables are interpolated unnecessarily + # Checks if variables are interpolated unnecessarily. # - # @param [Array] tokens The filtered tokens + # @param [Array] tokens The filtered tokens. def measure(lineno, tokens) return if @config if no_content?(tokens) and one_expression?(tokens) @@ -81,7 +82,6 @@ def reset_tokens def string_tokens(lexed_line) lexed_line.select { |t| EVENTS.include?(t[1]) } end - end end end diff --git a/lib/tailor/tailorrc.erb b/lib/tailor/tailorrc.erb index 36bb5be..3375885 100644 --- a/lib/tailor/tailorrc.erb +++ b/lib/tailor/tailorrc.erb @@ -98,6 +98,10 @@ # wrapped in parentheses. # Default: true # +# allow_unnecessary_interpolation +# Checks for unnecessary interpolation in strings. +# Default: false +# Tailor.config do |config| config.formatters "<%= formatters.join(', ') %>" config.file_set '<%= file_list %>' do |style|<% style.each do |rule, value| %>