Ensure that Ruby syntax is valid in all supported versions
Problem
Currently, we support Ruby version 3.0 and 3.1 which has some difference when it comes to syntax.
For example:
Values in Hash literals and keyword arguments can be omitted https://rubyreferences.github.io/rubychanges/3.1.html#values-in-hash-literals-and-keyword-arguments-can-be-omitted
# Works in Ruby 3.1
# Syntax Error in Ruby 3.0
def foo(arg:)
bar(arg:)
end
!140031 (merged) broke master
(running Ruby 3.0) because CI of this MR (running Ruby 3.1) did not catch the failure.
Proposed solution
Check Ruby syntax (ruby -c
) for supported Ruby versions in CI.
For example, in MRs (Ruby 3.1), run a CI job to check Ruby syntax for Ruby 3.0.
Alternative solutions
RuboCop provides a Style/HashSyntax
with EnforcedShorthandSyntax: never
and it'd solve the issue but only for this case.
Follow-up
Later, we could extend this CI job to also check Ruby compile time warnings (ruby -wc
) as discussed in #196852.