Skip to content

Commit

Permalink
[Ruby] refactor: Partial fix of odd linting space rules from templates (
Browse files Browse the repository at this point in the history
#178)

* Fix excess mis-styled spacing when description is nil

* Fix styling

* Remove final duplicate line break

* Remove duplicate space inbetween generated classes and single space after opening classes

* Fix styling for top level class documentation to have no excess padding

* Remove all traces of spare redundant lines

* Manual fixes to message serialization files

* Add some names to some complex logic to improve legibility

* Regenerate messages based on changes

* Add the extra line conditionally

* Fix erroneous final newline after final class
  • Loading branch information
luke-hill authored Nov 1, 2023
1 parent 15e21ec commit 529044c
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 388 deletions.
4 changes: 2 additions & 2 deletions jsonschema/scripts/codegen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,12 @@ def default_value(parent_type_name, property_name, property)
end

def format_description(raw_description, indent_string: " ")
return '' if raw_description.nil?
return '##' if raw_description.nil?

raw_description
.split("\n")
.map { |description_line| "# #{description_line}" }
.push('##')
.join("\n#{indent_string}")
end
end
Expand Down Expand Up @@ -435,7 +436,6 @@ def default_enum(enum_type_name, property)
end
end


clazz = Object.const_get(ARGV[0])
path = ARGV[1]
paths = File.file?(path) ? [path] : Dir["#{path}/*.json"]
Expand Down
6 changes: 3 additions & 3 deletions jsonschema/scripts/templates/ruby.enum.rb.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

<% @enums.each do |enum| -%>
class Cucumber::Messages::<%= enum[:name] %>
<%- enum[:values].each_with_index do |value, index| -%>
<%- enum[:values].each_with_index do |value, index| -%>
<%= enum_constant(value) %> = '<%= value %>'
<%- end -%>
<%- end -%>
end

<%= "\n" unless enum == @enums.last -%>
<%- end -%>
22 changes: 7 additions & 15 deletions jsonschema/scripts/templates/ruby.rb.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,30 @@ require 'cucumber/messages/message'
module Cucumber
module Messages
<%- @schemas.each do |key, schema| %>

##
# Represents the <%= class_name(key) %> message in Cucumber's {message protocol}[https://github.com/cucumber/messages].
#
<%= format_description(schema['description']) %>
#

<%= "#\n " if schema['description'] %><%= format_description(schema['description']) %>
class <%= class_name(key) %> < ::Cucumber::Messages::Message
<%- schema['properties'].each do |property_name, property| -%>

<%- if property['description'] -%>
##
<%= format_description(property['description'], indent_string: ' ') %>

<%- end -%>
attr_reader :<%= underscore(property_name) %>
<%- end -%>

<%- end -%>
def initialize(
<%- schema['properties'].each do |property_name, property| -%>
<%= underscore(property_name) -%>: <%=
(schema['required'] || []).index(property_name) ?
default_value(class_name(key), property_name, property) :
'nil'
-%><%= property_name == schema['properties'].keys.last ? '' : ',' %>
<%- final_key = property_name == schema['properties'].keys.last -%>
<%- individual_value = (schema['required'] || []).index(property_name) ? default_value(class_name(key), property_name, property) : 'nil' -%>
<%= "#{underscore(property_name)}: #{individual_value}" -%><%= final_key ? '' : ',' %>
<%- end -%>
)
<%- schema['properties'].each do |property_name, property| -%>
<%- schema['properties'].each do |property_name, _property| -%>
@<%= underscore(property_name) %> = <%= underscore(property_name) %>
<%- end -%>
end
end
<%- end %>
<%- end -%>
end
end
Loading

0 comments on commit 529044c

Please sign in to comment.