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

[Ruby] Refactor/30 0 1 things #311

Merged
merged 24 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
4219dae
Update changelog for python fix
luke-hill Oct 28, 2024
474bb04
Fix issue with methodname not remedying parser
luke-hill Oct 28, 2024
826fde4
AF: EmptyLineAfterMagicComment
luke-hill Oct 28, 2024
aaada99
AF: EmptyLinesAroundBlockBody
luke-hill Oct 28, 2024
ec2e5ed
Remedy tabbing
luke-hill Oct 28, 2024
0032224
Simplify TokenScanner#read
luke-hill Oct 28, 2024
809d844
AF: Lint/UnusedMethodArgument
luke-hill Oct 28, 2024
ea2d241
Fix Useless Variable Assignment
luke-hill Oct 28, 2024
0e40917
AF: Style/BlockDelimiters
luke-hill Oct 28, 2024
bc4fa61
AF: Style/ExpandPathArguments
luke-hill Oct 28, 2024
22db787
Regenerate TODO
luke-hill Oct 28, 2024
6b9bc28
Pull in cucumber-rails styles
luke-hill Nov 5, 2024
88ee6c8
AF: FrozenStringLiteral
luke-hill Nov 5, 2024
b27cf14
AF: Style/MultilineTernaryOperator
luke-hill Nov 5, 2024
6b80135
Alter razor template to give better name for state matching
luke-hill Nov 5, 2024
9a0fe15
Change lookahead method name and variable name of current token
luke-hill Nov 5, 2024
7e9a394
Fix up todo file and add override to generic styles
luke-hill Nov 5, 2024
12e872e
Regen parser
luke-hill Nov 5, 2024
3aed804
Mutate frozen string
luke-hill Nov 8, 2024
be02017
Remove concept of mutating frozen string, store memoized token reference
luke-hill Nov 8, 2024
3350775
Only perform token formatting when result is attempting to be fetched
luke-hill Nov 8, 2024
f05f7c8
Minor optimisation AstBuilder
luke-hill Nov 8, 2024
f1a06d7
Add note about ruby fixes
luke-hill Nov 8, 2024
9e87b33
Add note about internal refactor
luke-hill Nov 8, 2024
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ This project adheres to [Semantic Versioning](http://semver.org).
This document is formatted according to the principles of [Keep A CHANGELOG](http://keepachangelog.com).

## [Unreleased]
### Changed
- [Ruby] Fixed up some style autofix cops ([#311](https://github.com/cucumber/gherkin/pull/311))
- [Ruby] Internal rewrites to razor template variables and `TokenFormatterBuilder`) ([#311](https://github.com/cucumber/gherkin/pull/311))

### Fixed
- [Python] Release process didn't release to pypi correctly

## [30.0.0] - 2024-10-24
### Added
Expand Down
37 changes: 31 additions & 6 deletions ruby/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,39 @@ inherit_mode:
merge:
- Exclude

#require:
# - rubocop-packaging
# - rubocop-performance
# - rubocop-rails
# - rubocop-rake
# - rubocop-rspec

AllCops:
NewCops: disable
# Keep this inline with the lowest ruby version in the gemspec
TargetRubyVersion: 3.0
# Display cop name / style guide references
DisplayCopNames: true
DisplayStyleGuide: true
NewCops: enable

# Disabled on our repo's to enable polyglot-release
Gemspec/RequireMFA:
Enabled: false

Layout/LineLength:
Max: 200

# This allows us to read the chmod action in a more reproducible way
Style/NumericLiteralPrefix:
EnforcedOctalStyle: zero_only

Style/Documentation:
Enabled: false

Style/RegexpLiteral:
EnforcedStyle: slashes
AllowInnerSlashes: true

## Disabled until rubocop-rspec is introduced
#RSpec/MessageSpies:
# EnforcedStyle: receive

# TODO: [LH] - Investigate this in terms of it not being fixed in rubocop?
# Hack to make rubocop not flag these (We need to re-analyse these later on)
Naming/MethodName:
Enabled: false
134 changes: 12 additions & 122 deletions ruby/.rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2024-09-10 17:08:57 UTC using RuboCop version 1.26.1.
# on 2024-11-05 17:37:25 UTC using RuboCop version 1.26.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand All @@ -11,19 +11,15 @@
# Pass 0 - July 2024 - 26 files inspected, 3031 offenses detected, 2667 offenses auto-correctable
# Pass 1 - August 2024 (Fix up a load of Style autofix cops) - 27 files inspected, 2691 offenses detected, 2356 offenses auto-correctable
# Pass 2 - September 2024 (Reconciled issues) - 27 files inspected, 2823 offenses detected, 2491 offenses auto-correctable
# Pass 3 - October 2024 (Minor tweaks for python fix) - 27 files inspected, 2831 offenses detected, 2472 offenses auto-correctable
# Pass 4 - November 2024 (Minor tweaks ready for 30.0.1) - 27 files inspected, 2725 offenses detected, 2444 offenses auto-correctable

# Offense count: 63
# This cop supports safe auto-correction (--auto-correct).
Layout/EmptyLineAfterGuardClause:
Exclude:
- 'lib/gherkin/parser.rb'

# Offense count: 1
# This cop supports safe auto-correction (--auto-correct).
Layout/EmptyLineAfterMagicComment:
Exclude:
- 'Gemfile'

# Offense count: 51
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EmptyLineBetweenMethodDefs, EmptyLineBetweenClassDefs, EmptyLineBetweenModuleDefs, AllowAdjacentOneLineDefs, NumberOfEmptyLines.
Expand All @@ -38,14 +34,6 @@ Layout/EmptyLines:
- 'lib/gherkin/parser.rb'
- 'spec/gherkin/stream/parser_message_stream_spec.rb'

# Offense count: 1
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: empty_lines, no_empty_lines
Layout/EmptyLinesAroundBlockBody:
Exclude:
- 'lib/gherkin/pickles/compiler.rb'

# Offense count: 1
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle.
Expand All @@ -62,14 +50,6 @@ Layout/EmptyLinesAroundModuleBody:
Exclude:
- 'lib/gherkin/parser.rb'

# Offense count: 6
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle, IndentationWidth.
# SupportedStyles: aligned, indented
Layout/MultilineOperationIndentation:
Exclude:
- 'lib/gherkin/token_matcher.rb'

# Offense count: 2
# This cop supports safe auto-correction (--auto-correct).
Layout/SpaceAfterComma:
Expand Down Expand Up @@ -101,17 +81,6 @@ Layout/SpaceInsideParens:
Exclude:
- 'lib/gherkin/parser.rb'

# Offense count: 1
# Configuration parameters: AllowSafeAssignment.
Lint/AssignmentInCondition:
Exclude:
- 'lib/gherkin/token_scanner.rb'

# Offense count: 2
Lint/ImplicitStringConcatenation:
Exclude:
- 'spec/gherkin/query_spec.rb'

# Offense count: 4
Lint/LiteralAsCondition:
Exclude:
Expand All @@ -123,20 +92,6 @@ Lint/Loop:
Exclude:
- 'lib/gherkin/parser.rb'

# Offense count: 3
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods, IgnoreNotImplementedMethods.
Lint/UnusedMethodArgument:
Exclude:
- 'lib/gherkin/ast_builder.rb'
- 'lib/gherkin/errors.rb'

# Offense count: 2
Lint/UselessAssignment:
Exclude:
- 'lib/gherkin/ast_builder.rb'
- 'spec/gherkin/gherkin_spec.rb'

# Offense count: 59
# Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
Metrics/AbcSize:
Expand All @@ -163,7 +118,7 @@ Metrics/ClassLength:
Metrics/CyclomaticComplexity:
Max: 51

# Offense count: 71
# Offense count: 72
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
Metrics/MethodLength:
Max: 141
Expand All @@ -186,39 +141,11 @@ Naming/AccessorMethodName:
- 'lib/gherkin/parser.rb'
- 'lib/gherkin/token_formatter_builder.rb'

# Offense count: 2
# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
# AllowedNames: at, by, db, id, in, io, ip, of, on, os, pp, to
Naming/MethodParameterName:
Exclude:
- 'lib/gherkin/parser.rb'

# Offense count: 4
# Configuration parameters: EnforcedStyle, AllowedIdentifiers.
# Offense count: 29
# Configuration parameters: IgnoredPatterns.
# SupportedStyles: snake_case, camelCase
Naming/VariableName:
Exclude:
- 'lib/gherkin/parser.rb'

# Offense count: 52
# Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers.
# SupportedStyles: snake_case, normalcase, non_integer
# AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339
Naming/VariableNumber:
Exclude:
- 'lib/gherkin/parser.rb'

# Offense count: 6
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, IgnoredMethods, AllowBracesOnProceduralOneLiners, BracesRequiredMethods.
# SupportedStyles: line_count_based, semantic, braces_for_chaining, always_braces
# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object
# FunctionalMethods: let, let!, subject, watch
# IgnoredMethods: lambda, proc, it
Style/BlockDelimiters:
Exclude:
- 'lib/gherkin/gherkin_line.rb'
- 'spec/gherkin/stream/parser_message_stream_spec.rb'
Naming/MethodName:
EnforcedStyle: snake_case

# Offense count: 2
# This cop supports unsafe auto-correction (--auto-correct-all).
Expand All @@ -233,30 +160,6 @@ Style/DefWithParentheses:
Exclude:
- 'lib/gherkin/parser.rb'

# Offense count: 18
# Configuration parameters: AllowedConstants.
Style/Documentation:
Exclude:
- 'lib/gherkin.rb'
- 'lib/gherkin/ast_builder.rb'
- 'lib/gherkin/ast_node.rb'
- 'lib/gherkin/dialect.rb'
- 'lib/gherkin/errors.rb'
- 'lib/gherkin/gherkin_line.rb'
- 'lib/gherkin/parser.rb'
- 'lib/gherkin/pickles/compiler.rb'
- 'lib/gherkin/query.rb'
- 'lib/gherkin/stream/parser_message_stream.rb'
- 'lib/gherkin/token.rb'
- 'lib/gherkin/token_formatter_builder.rb'
- 'lib/gherkin/token_matcher.rb'

# Offense count: 1
# This cop supports safe auto-correction (--auto-correct).
Style/ExpandPathArguments:
Exclude:
- 'Rakefile'

# Offense count: 2
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle.
Expand All @@ -271,12 +174,13 @@ Style/FormatString:
Style/FormatStringToken:
EnforcedStyle: unannotated

# Offense count: 26
# Offense count: 1
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: always, always_true, never
Style/FrozenStringLiteralComment:
Enabled: false
Exclude:
- 'lib/gherkin/parser.rb'

# Offense count: 1
# This cop supports safe auto-correction (--auto-correct).
Expand All @@ -285,12 +189,6 @@ Style/MethodCallWithoutArgsParentheses:
Exclude:
- 'lib/gherkin/parser.rb'

# Offense count: 3
# This cop supports safe auto-correction (--auto-correct).
Style/MultilineTernaryOperator:
Exclude:
- 'lib/gherkin/pickles/compiler.rb'

# Offense count: 1
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle.
Expand Down Expand Up @@ -372,13 +270,12 @@ Style/SignalException:
Exclude:
- 'lib/gherkin/token_scanner.rb'

# Offense count: 4
# Offense count: 3
# This cop supports unsafe auto-correction (--auto-correct-all).
Style/SlicingWithRange:
Exclude:
- 'lib/gherkin/ast_builder.rb'
- 'lib/gherkin/gherkin_line.rb'
- 'spec/gherkin/gherkin_spec.rb'

# Offense count: 58
# This cop supports safe auto-correction (--auto-correct).
Expand Down Expand Up @@ -480,10 +377,3 @@ Style/TrailingCommaInHashLiteral:
Style/ZeroLengthPredicate:
Exclude:
- 'lib/gherkin/gherkin_line.rb'

# Offense count: 124
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Layout/LineLength:
Max: 177
1 change: 1 addition & 0 deletions ruby/Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gemspec
6 changes: 4 additions & 2 deletions ruby/Rakefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# frozen_string_literal: true

require 'rubygems'
require 'bundler'
Bundler::GemHelper.install_tasks

$:.unshift File.expand_path('../lib', __FILE__)
$:.unshift File.expand_path('lib', __dir__)

Dir['./rake/*.rb'].sort.each { |f| require f }
Dir['./rake/*.rb'].each { |f| require f }

require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
Expand Down
1 change: 1 addition & 0 deletions ruby/bin/gherkin
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '../lib'))

Expand Down
1 change: 1 addition & 0 deletions ruby/bin/gherkin-generate-tokens
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__),'../lib'))
require 'gherkin/parser'
Expand Down
2 changes: 2 additions & 0 deletions ruby/bin/gherkin-ruby
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

load(File.dirname(__FILE__) + '/gherkin')
2 changes: 2 additions & 0 deletions ruby/cucumber-gherkin.gemspec
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

version = File.read(File.expand_path('VERSION', __dir__)).strip

Gem::Specification.new do |s|
Expand Down
10 changes: 5 additions & 5 deletions ruby/gherkin-ruby.razor
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ module Gherkin
@foreach(var state in Model.States.Values.Where(s => !s.IsEndState))
{
@:when @state.Id
@:match_token_at_@(state.Id)(token, context)
@:match_token_at_state@(state.Id)(token, context)
}
else
raise InvalidOperationException, "Unknown state: #{state}"
Expand All @@ -145,15 +145,15 @@ module Gherkin
@foreach(var state in Model.States.Values.Where(s => !s.IsEndState))
{<text>
# @Raw(state.Comment)
def match_token_at_@(state.Id)(token, context)
def match_token_at_state@(state.Id)(token, context)
@foreach(var transition in state.Transitions)
{
@:if @MatchToken(transition.TokenType)
var extraIndent = "";
if (transition.LookAheadHint != null)
{
extraIndent = " ";
@:@("if lookahead_")@(transition.LookAheadHint.Id)(context, token)
@:@("if lookahead")@(transition.LookAheadHint.Id)(context, token)
}
foreach(var production in transition.Productions)
{
Expand All @@ -174,8 +174,8 @@ module Gherkin
@foreach(var lookAheadHint in Model.RuleSet.LookAheadHints)
{
<text>
def lookahead_@(lookAheadHint.Id)(context, currentToken)
currentToken.detach
def lookahead@(lookAheadHint.Id)(context, current_token)
current_token.detach
token = nil
queue = []
match = false
Expand Down
2 changes: 2 additions & 0 deletions ruby/lib/gherkin.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative 'gherkin/stream/parser_message_stream'

module Gherkin
Expand Down
Loading