Skip to content

Commit

Permalink
Centralize Ruby Version to .ruby-version (#345)
Browse files Browse the repository at this point in the history
* Update rubocop to 1.62.1

* Centralize Ruby Version to `.ruby-version`

The `.ruby-version` file is the ecosystem standard for defining a Ruby version.  This PR adds the `.ruby-version` file, ensures a `required_ruby_version` is set, and removes all other references to Ruby in this repository, aligning it with the standard.
> [!IMPORTANT]
> Please verify the following before merging:

Verify that the changes in the PR meets the following requirements or adjust manually to make it compliant:
  - [ ] `.ruby-version` file is present with the correct Ruby version defined
  - [ ] A `required_ruby_version` in your gemspec is set
  - [ ] There is no Ruby version present in the  `dev.yml` Ruby task (before: `- ruby: x.x.x`, after: `- ruby`)
  - [ ] There is no Ruby version/requirement referenced in the `Gemfile` (no lines with `ruby  <some-version>`)
  - [ ] A `Gemfile.lock` is built with the defined Ruby version
  - [ ] The version of Rubocop installed is 1.61.0 or greater
  - [ ] There is no `TargetRubyVersion` defined  in `rubocop.yml`
  - [ ] There is no Ruby argument  present in  `ruby/setup-ruby` Github Actions that do **not**  run on a Ruby matrix (no lines with `ruby-version: “x.x”`)

This PR will be merged if there isn't any activity after 4 weeks.

* Temporarily rename the .ruby-version file to pass CI for rubocop-old

Old versions of rubocop read the ruby version from .ruby-version first.
We made the change upstream which is not captured in versions of
rubocop (< 0.87).

Upstream commit: rubocop/rubocop@02b2c3a

Co-authored-by: Étienne Barrié <[email protected]>

* Remove ruby-version mention from linting.yml

* Update rubocop-shopify

* Disable Style/ClassMethodsDefinitions

* Run bundle exec rubocop -a

Ignore the .intersect? autocorrect

* Update better_html to 2.1.1

* Fix consistency typo in CI test versions

---------

Co-authored-by: Étienne Barrié <[email protected]>
  • Loading branch information
george-ma and etiennebarrie authored Apr 4, 2024
1 parent 2b034d3 commit f31f100
Show file tree
Hide file tree
Showing 70 changed files with 379 additions and 268 deletions.
1 change: 0 additions & 1 deletion .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ jobs:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: '3.0'
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
- name: Rubocop
run: bundle exec rubocop
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby: [2.7, '3.0', 3.1, 3.2, 3.3, head]
ruby: [2.7, 3.0, 3.1, 3.2, 3.3, head]
gemfile: [rubocop-next, rubocop-old]
runs-on: ubuntu-latest
env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps
Expand Down
7 changes: 6 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
inherit_gem:
rubocop-shopify: rubocop.yml

Style/ClassMethodsDefinitions:
Enabled: false

Style/ArrayIntersect:
Enabled: false

AllCops:
TargetRubyVersion: 2.7
Exclude:
- 'vendor/**/*'
- 'gemfiles/vendor/**/*'
Expand Down
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.2.2
67 changes: 41 additions & 26 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12,44 +12,57 @@ PATH
GEM
remote: https://rubygems.org/
specs:
actionview (7.0.7.2)
activesupport (= 7.0.7.2)
actionview (7.1.3.2)
activesupport (= 7.1.3.2)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
activesupport (7.0.7.2)
erubi (~> 1.11)
rails-dom-testing (~> 2.2)
rails-html-sanitizer (~> 1.6)
activesupport (7.1.3.2)
base64
bigdecimal
concurrent-ruby (~> 1.0, >= 1.0.2)
connection_pool (>= 2.2.5)
drb
i18n (>= 1.6, < 2)
minitest (>= 5.1)
mutex_m
tzinfo (~> 2.0)
ast (2.4.2)
better_html (2.0.2)
base64 (0.2.0)
better_html (2.1.1)
actionview (>= 6.0)
activesupport (>= 6.0)
ast (~> 2.0)
erubi (~> 1.4)
parser (>= 2.4)
smart_properties
bigdecimal (3.1.7)
builder (3.2.4)
concurrent-ruby (1.2.2)
concurrent-ruby (1.2.3)
connection_pool (2.4.1)
crass (1.0.6)
diff-lcs (1.5.0)
drb (2.2.1)
erubi (1.12.0)
fakefs (1.5.1)
i18n (1.14.1)
i18n (1.14.4)
concurrent-ruby (~> 1.0)
loofah (2.21.3)
json (2.7.1)
language_server-protocol (3.17.0.3)
loofah (2.22.0)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
mini_portile2 (2.8.5)
minitest (5.19.0)
nokogiri (1.15.6)
minitest (5.22.3)
mutex_m (0.2.0)
nokogiri (1.16.3)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
parallel (1.22.1)
parser (3.1.2.1)
parallel (1.24.0)
parser (3.3.0.5)
ast (~> 2.4.1)
racc
racc (1.7.3)
rails-dom-testing (2.2.0)
activesupport (>= 5.0.0)
Expand All @@ -60,8 +73,8 @@ GEM
nokogiri (~> 1.14)
rainbow (3.1.1)
rake (13.0.6)
regexp_parser (2.5.0)
rexml (3.2.5)
regexp_parser (2.9.0)
rexml (3.2.6)
rspec (3.11.0)
rspec-core (~> 3.11.0)
rspec-expectations (~> 3.11.0)
Expand All @@ -75,24 +88,26 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.11.0)
rspec-support (3.11.0)
rubocop (1.30.1)
rubocop (1.62.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.1.0.0)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.18.0, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.18.0)
parser (>= 3.1.1.0)
rubocop-shopify (2.7.0)
rubocop (~> 1.30)
ruby-progressbar (1.11.0)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.31.2)
parser (>= 3.3.0.4)
rubocop-shopify (2.15.1)
rubocop (~> 1.51)
ruby-progressbar (1.13.0)
smart_properties (1.17.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.1.0)
unicode-display_width (2.5.0)

PLATFORMS
ruby
Expand Down
2 changes: 1 addition & 1 deletion dev.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: erb-lint

up:
- ruby: '3.2.2'
- ruby
- bundler

commands:
Expand Down
4 changes: 2 additions & 2 deletions lib/erb_lint/cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def get(filename, file_content)
file_checksum = checksum(filename, file_content)
begin
cache_file_contents_as_offenses = JSON.parse(
File.read(File.join(@cache_dir, file_checksum))
File.read(File.join(@cache_dir, file_checksum)),
).map do |offense_hash|
ERBLint::CachedOffense.new(offense_hash)
end
Expand Down Expand Up @@ -76,7 +76,7 @@ def checksum(filename, file_content)
mode = File.stat(filename).mode

digester.update(
"#{mode}#{config.to_hash}#{ERBLint::VERSION}#{file_content}"
"#{mode}#{config.to_hash}#{ERBLint::VERSION}#{file_content}",
)
digester.hexdigest
rescue Errno::ENOENT
Expand Down
2 changes: 1 addition & 1 deletion lib/erb_lint/cached_offense.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def self.new_from_offense(offense)
last_line: offense.last_line,
last_column: offense.last_column,
length: offense.length,
}
},
)
end

Expand Down
16 changes: 10 additions & 6 deletions lib/erb_lint/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def run(args = ARGV)
rescue => e
@stats.exceptions += 1
puts "Exception occurred when processing: #{relative_filename(filename)}"
puts "If this file cannot be processed by erb-lint, "\
puts "If this file cannot be processed by erb-lint, " \
"you can exclude it in your configuration file."
puts e.message
puts Rainbow(e.backtrace.join("\n")).red
Expand Down Expand Up @@ -303,7 +303,7 @@ def runner_config_override
ERBLint::LinterRegistry.linters.map do |klass|
linters[klass.simple_name] = { "enabled" => enabled_linter_classes.include?(klass) }
end
end
end,
)
end

Expand Down Expand Up @@ -348,8 +348,12 @@ def option_parser
@options[:clear_cache] = config
end

opts.on("--enable-linters LINTER[,LINTER,...]", Array,
"Only use specified linter", "Known linters are: #{known_linter_names.join(", ")}") do |linters|
opts.on(
"--enable-linters LINTER[,LINTER,...]",
Array,
"Only use specified linter",
"Known linters are: #{known_linter_names.join(", ")}",
) do |linters|
linters.each do |linter|
unless known_linter_names.include?(linter)
failure!("#{linter}: not a valid linter name (#{known_linter_names.join(", ")})")
Expand Down Expand Up @@ -382,7 +386,7 @@ def option_parser
opts.on(
"-sFILE",
"--stdin FILE",
"Pipe source from STDIN. Takes the path to be used to check which rules to apply."
"Pipe source from STDIN. Takes the path to be used to check which rules to apply.",
) do |file|
@options[:stdin] = [file]
end
Expand All @@ -398,7 +402,7 @@ def option_parser
end

def format_options_help
"Report offenses in the given format: "\
"Report offenses in the given format: " \
"(#{Reporter.available_formats.join(", ")}) (default: multiline)"
end

Expand Down
2 changes: 1 addition & 1 deletion lib/erb_lint/linter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def support_autocorrect?
def initialize(file_loader, config)
@file_loader = file_loader
@config = config
raise ArgumentError, "expect `config` to be #{self.class.config_schema} instance, "\
raise ArgumentError, "expect `config` to be #{self.class.config_schema} instance, " \
"not #{config.class}" unless config.is_a?(self.class.config_schema)
@offenses = []
end
Expand Down
15 changes: 8 additions & 7 deletions lib/erb_lint/linters/allowed_script_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class AllowedScriptType < Linter
include LinterRegistry

class ConfigSchema < LinterConfig
property :allowed_types, accepts: array_of?(String),
property :allowed_types,
accepts: array_of?(String),
default: -> { ["text/javascript"] }
property :allow_blank, accepts: [true, false], default: true, reader: :allow_blank?
property :disallow_inline_scripts, accepts: [true, false], default: false, reader: :disallow_inline_scripts?
Expand All @@ -30,8 +31,8 @@ def run(processed_source)
name_node = tag_node.to_a[1]
add_offense(
name_node.loc,
"Avoid using inline `<script>` tags altogether. "\
"Instead, move javascript code into a static file."
"Avoid using inline `<script>` tags altogether. " \
"Instead, move javascript code into a static file.",
)
next
end
Expand All @@ -44,14 +45,14 @@ def run(processed_source)
add_offense(
name_node.loc,
"Missing a `type=\"text/javascript\"` attribute to `<script>` tag.",
[type_attribute]
[type_attribute],
)
elsif type_present && !@config.allowed_types.include?(type_attribute.value)
add_offense(
type_attribute.loc,
"Avoid using #{type_attribute.value.inspect} as type for `<script>` tag. "\
"Must be one of: #{@config.allowed_types.join(", ")}"\
"#{" (or no type attribute)" if @config.allow_blank?}."
"Avoid using #{type_attribute.value.inspect} as type for `<script>` tag. " \
"Must be one of: #{@config.allowed_types.join(", ")}" \
"#{" (or no type attribute)" if @config.allow_blank?}.",
)
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/erb_lint/linters/closing_erb_tag_indent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@ def run(processed_source)
add_offense(
code_node.loc.end.adjust(begin_pos: -end_spaces.size),
"Remove newline before `%>` to match start of tag.",
" "
" ",
)
elsif start_with_newline && !end_with_newline
add_offense(
code_node.loc.end.adjust(begin_pos: -end_spaces.size),
"Insert newline before `%>` to match start of tag.",
"\n"
"\n",
)
elsif start_with_newline && end_with_newline
current_indent = end_spaces.split("\n", -1).last
if erb_node.loc.column != current_indent.size
add_offense(
code_node.loc.end.adjust(begin_pos: -current_indent.size),
"Indent `%>` on column #{erb_node.loc.column} to match start of tag.",
" " * erb_node.loc.column
" " * erb_node.loc.column,
)
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/erb_lint/linters/comment_syntax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def run(processed_source)

add_offense(
source_range,
<<~EOF.chomp
<<~EOF.chomp,
Bad ERB comment syntax. Should be #{correct_erb_tag} without a space between.
Leaving a space between ERB tags and the Ruby comment character can cause parser errors.
EOF
Expand Down
4 changes: 2 additions & 2 deletions lib/erb_lint/linters/deprecated_classes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def process_nested_offenses(source:, offset:, parent_source:)
process_nested_offenses(
source: sub_source,
offset: offset + content_node.loc.begin_pos,
parent_source: parent_source
parent_source: parent_source,
)
end
end
Expand Down Expand Up @@ -99,7 +99,7 @@ def generate_offenses(class_name, range)

add_offense(
range,
format(message, class_name, violated_rule[:class_expr], suggestion)
format(message, class_name, violated_rule[:class_expr], suggestion),
)
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/erb_lint/linters/erb_safety.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def run(processed_source)
tester.errors.each do |error|
add_offense(
error.location,
error.message
error.message,
)
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/erb_lint/linters/extra_newline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def run(processed_source)
add_offense(
processed_source
.to_source_range((matches.begin(index) + 2)...matches.end(index)),
"Extra blank line detected."
"Extra blank line detected.",
)
end
end
Expand Down
8 changes: 4 additions & 4 deletions lib/erb_lint/linters/final_newline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,22 @@ def run(processed_source)
add_offense(
processed_source.to_source_range(file_content.size...file_content.size),
"Missing a trailing newline at the end of the file.",
:insert
:insert,
)
else
add_offense(
processed_source.to_source_range(
(file_content.size - final_newline.size + 1)...file_content.size
(file_content.size - final_newline.size + 1)...file_content.size,
),
"Remove multiple trailing newline at the end of the file.",
:remove
:remove,
)
end
elsif !@new_lines_should_be_present && !final_newline.empty?
add_offense(
processed_source.to_source_range(match.begin(0)...match.end(0)),
"Remove #{final_newline.size} trailing newline at the end of the file.",
:remove
:remove,
)
end
end
Expand Down
Loading

0 comments on commit f31f100

Please sign in to comment.