Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RequireInputAutocomplete: add missing helpers + remove utf8_enforcer_tag #233

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion lib/erb_lint/linters/require_input_autocomplete.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,31 @@ class RequireInputAutocomplete < Linter

FORM_HELPERS_REQUIRING_AUTOCOMPLETE = [
:date_field_tag,
:date_field,
:color_field_tag,
:color_field,
:email_field_tag,
:email_field,
:text_field_tag,
:utf8_enforcer_tag,
:text_field,
:month_field_tag,
:month_field,
:number_field_tag,
:number_field,
:password_field_tag,
:password_field,
:search_field_tag,
:search_field,
:telephone_field_tag,
:telephone_field,
:phone_field_tag,
:phone_field,
:time_field_tag,
:time_field,
:url_field_tag,
:url_field,
:week_field_tag,
:week_field,
].freeze

def run(processed_source)
Expand Down
47 changes: 29 additions & 18 deletions spec/erb_lint/linters/require_input_autocomplete_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,31 @@
let(:form_helpers_requiring_autocomplete) do
[
:date_field_tag,
:date_field,
:color_field_tag,
:color_field,
:email_field_tag,
:email_field,
:text_field_tag,
:utf8_enforcer_tag,
:text_field,
:month_field_tag,
:month_field,
:number_field_tag,
:number_field,
:password_field_tag,
:password_field,
:search_field_tag,
:search_field,
:telephone_field_tag,
:telephone_field,
:phone_field_tag,
:phone_field,
:time_field_tag,
:time_field,
:url_field_tag,
:url_field,
:week_field_tag,
:week_field,
].freeze
end
let(:html_message) do
Expand Down Expand Up @@ -65,7 +78,7 @@
<br />
#{
form_helpers_requiring_autocomplete.inject("") do |s, helper|
s + "<%= " + helper.to_s + ' autocomplete: "foo" do %>'
s + "<%= " + helper.to_s + ' autocomplete: "foo" %>'
end
}
FILE
Expand All @@ -78,27 +91,25 @@
<br />
#{
form_helpers_requiring_autocomplete.inject("") do |s, helper|
s + "<%= " + helper.to_s + " do %>"
s + "<%= " + helper.to_s + " %>"
end
}
FILE

it do
expect(subject).to(eq([
build_offense(7..30, form_helper_message),
build_offense(31..55, form_helper_message),
build_offense(56..80, form_helper_message),
build_offense(81..104, form_helper_message),
build_offense(105..131, form_helper_message),
build_offense(132..156, form_helper_message),
build_offense(157..182, form_helper_message),
build_offense(183..210, form_helper_message),
build_offense(211..236, form_helper_message),
build_offense(237..265, form_helper_message),
build_offense(266..289, form_helper_message),
build_offense(290..312, form_helper_message),
build_offense(313..336, form_helper_message),
]))
form_helpers_requiring_autocomplete.each do |helper|
tag = "<%= #{helper} %>"
index = processed_source.file_content.index(tag)

expect(subject).to(
include(
build_offense(
Range.new(index, index + tag.length - 1),
form_helper_message
)
)
)
end
end
end
end
Expand Down