Skip to content

Commit

Permalink
chore: rubocop fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ronaldtse committed Oct 17, 2024
1 parent 90b45d5 commit 7837e6f
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 34 deletions.
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Auto-generated by Cimas: Do not edit it manually!
# See https://github.com/metanorma/cimas
inherit_from:
- .rubocop_todo.yml
- https://raw.githubusercontent.com/riboseinc/oss-guides/master/ci/rubocop.yml

# local repo-specific modifications
Expand Down
77 changes: 77 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2024-10-17 02:50:55 UTC using RuboCop version 1.67.0.
# 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
# versions of RuboCop, may require this file to be generated again.

# Offense count: 3
# Configuration parameters: Severity, Include.
# Include: **/*.gemspec
Gemspec/DuplicatedAssignment:
Exclude:
- 'suma.gemspec'

# Offense count: 1
# Configuration parameters: Severity, Include.
# Include: **/*.gemspec
Gemspec/RequiredRubyVersion:
Exclude:
- 'suma.gemspec'

# Offense count: 21
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: Max, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
# URISchemes: http, https
Layout/LineLength:
Exclude:
- 'lib/suma/cli.rb'
- 'lib/suma/collection_manifest.rb'
- 'lib/suma/processor.rb'
- 'lib/suma/schema_attachment.rb'
- 'lib/suma/schema_collection.rb'
- 'lib/suma/schema_document.rb'
- 'lib/suma/thor_ext.rb'
- 'suma.gemspec'

# Offense count: 1
Lint/DuplicateMethods:
Exclude:
- 'lib/suma/express_schema.rb'

# Offense count: 8
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes, Max.
Metrics/AbcSize:
Exclude:
- 'lib/suma/collection_manifest.rb'
- 'lib/suma/processor.rb'
- 'lib/suma/schema_attachment.rb'
- 'lib/suma/schema_collection.rb'
- 'lib/suma/schema_config/config.rb'
- 'lib/suma/schema_document.rb'
- 'lib/suma/thor_ext.rb'

# Offense count: 1
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
# AllowedMethods: refine
Metrics/BlockLength:
Max: 33

# Offense count: 2
# Configuration parameters: AllowedMethods, AllowedPatterns, Max.
Metrics/CyclomaticComplexity:
Exclude:
- 'lib/suma/collection_manifest.rb'
- 'lib/suma/thor_ext.rb'

# Offense count: 7
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
Metrics/MethodLength:
Max: 52

# Offense count: 1
# Configuration parameters: AllowedMethods, AllowedPatterns, Max.
Metrics/PerceivedComplexity:
Exclude:
- 'lib/suma/schema_collection.rb'
10 changes: 6 additions & 4 deletions lib/suma/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ module Suma
class Cli < Thor
extend ThorExt::Start

desc "build METANORMA_SITE_MANIFEST", "Build collection specified in site manifest (`metanorma*.yml`)"
option :compile, type: :boolean, default: true, desc: "Compile or skip compile of collection"
desc "build METANORMA_SITE_MANIFEST",
"Build collection specified in site manifest (`metanorma*.yml`)"
option :compile, type: :boolean, default: true,
desc: "Compile or skip compile of collection"
option :schemas_all_path, type: :string, aliases: "-s",
desc: "Generate file that contains all schemas in the collection."

Expand All @@ -22,14 +24,14 @@ def build(metanorma_site_manifest)

# Set schemas_all_path to match metanorma_yaml_path
schemas_all_path = options[:schemas_all_path] ||
metanorma_site_manifest.gsub("metanorma", "schemas")
metanorma_site_manifest.gsub("metanorma", "schemas")

begin
Processor.run(
metanorma_yaml_path: metanorma_site_manifest,
schemas_all_path: schemas_all_path,
compile: options[:compile],
output_directory: "_site"
output_directory: "_site",
)
rescue StandardError => e
Utils.log "[ERROR] Error occurred during processing. See details below."
Expand Down
6 changes: 3 additions & 3 deletions lib/suma/collection_manifest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def expand_schemas_only(schema_output_path)

# If there is collection.yml, this is a document collection, we process
# schemas.yaml.
if File.basename(file) == 'collection.yml'
if File.basename(file) == "collection.yml"
schemas_yaml_path = File.join(File.dirname(file), "schemas.yaml")
if schemas_yaml_path && File.exist?(schemas_yaml_path)
@schema_config = Suma::SchemaConfig::Config.from_file(schemas_yaml_path)
Expand Down Expand Up @@ -99,8 +99,8 @@ def expand_schemas_only(schema_output_path)
# we need to separate this file from the following new entries
added = CollectionManifest.new(
title: "Collection",
type: "collection",
identifier: self.identifier + "_"
type: "collection",
identifier: "#{identifier}_",
)

added.entry = [
Expand Down
7 changes: 4 additions & 3 deletions lib/suma/processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
module Suma
class Processor
class << self

def run(metanorma_yaml_path:, schemas_all_path:, compile:, output_directory: "_site")
def run(metanorma_yaml_path:, schemas_all_path:, compile:,
output_directory: "_site")
Utils.log "Current directory: #{Dir.getwd}"

# This reads the metanorma.yml file
Expand Down Expand Up @@ -70,7 +70,8 @@ def run(metanorma_yaml_path:, schemas_all_path:, compile:, output_directory: "_s
metanorma_collection.render(collection_opts)

# TODO: Temporarily disable removal of XML files
Dir.glob(File.join(Dir.getwd, output_directory, "*.xml")).each do |file|
Dir.glob(File.join(Dir.getwd, output_directory,
"*.xml")).each do |file|
puts "NOT DELETING ANY FILE #{file.inspect}"
# File.delete(file)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/suma/schema_attachment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def save_adoc
FileUtils.mkdir_p(File.dirname(filename_adoc))

relative_path = Pathname.new(filename_config)
.relative_path_from(Pathname.new(File.dirname(filename_adoc)))
.relative_path_from(Pathname.new(File.dirname(filename_adoc)))

# Utils.log "relative_path #{relative_path}"

Expand Down
13 changes: 7 additions & 6 deletions lib/suma/schema_collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
module Suma
class SchemaCollection
attr_accessor :config, :schemas, :docs, :output_path_docs, :output_path_schemas,
:manifest
:manifest

def initialize(config: nil, config_yaml: nil, output_path_docs: nil, output_path_schemas: nil, manifest: nil)
def initialize(config: nil, config_yaml: nil, output_path_docs: nil,
output_path_schemas: nil, manifest: nil)
@schemas = {}
@docs = {}
@schema_name_to_docs = {}
Expand Down Expand Up @@ -44,12 +45,12 @@ def process_schemas(schemas, klass)
s = ExpressSchema.new(
id: config_schema.id,
path: config_schema.path.to_s,
output_path: @output_path_schemas.to_s
output_path: @output_path_schemas.to_s,
)

doc = klass.new(
schema: s,
output_path: @output_path_docs.join(s.id)
output_path: @output_path_docs.join(s.id),
)

@docs[s.id] = doc
Expand All @@ -74,11 +75,11 @@ def finalize

def compile
finalize
schemas.each_pair do |schema_id, entry|
schemas.each_pair do |_schema_id, entry|
entry.save_exp
end

docs.each_pair do |schema_id, entry|
docs.each_pair do |_schema_id, entry|
entry.compile
end

Expand Down
1 change: 1 addition & 0 deletions lib/suma/schema_config/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def path_relative_to_absolute(relative_path)

# Or based on current working directory?
return relative_path unless @path

# ... but if this calculates path, we end up expanding it anyway

Pathname.new(File.dirname(@path)).join(eval_path).expand_path.to_s
Expand Down
34 changes: 17 additions & 17 deletions lib/suma/schema_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,70 +16,70 @@ def schema_anchors
// _constants.liquid
{% if schema.constants.size > 0 %}
#{bookmark("constants")}
#{bookmark('constants')}
{% for thing in schema.constants %}
#{bookmark("{{thing.id}}")}
#{bookmark('{{thing.id}}')}
{% endfor %}
{% endif %}
// _types.liquid
{% if schema.types.size > 0 %}
#{bookmark("types")}
#{bookmark('types')}
// _type.liquid
{% for thing in schema.types %}
#{bookmark("{{thing.id}}")}
#{bookmark('{{thing.id}}')}
{% if thing.items.size > 0 %}
// _type_items.liquid
#{bookmark("{{thing.id}}.items")}
#{bookmark('{{thing.id}}.items')}
{% for item in thing.items %}
#{bookmark("{{thing.id}}.items.{{item.id}}")}
#{bookmark('{{thing.id}}.items.{{item.id}}')}
{% endfor %}
{% endif %}
{% endfor %}
{% endif %}
// _entities.liquid
{% if schema.entities.size > 0 %}
#{bookmark("entities")}
#{bookmark('entities')}
{% for thing in schema.entities %}
// _entity.liquid
#{bookmark("{{thing.id}}")}
#{bookmark('{{thing.id}}')}
{% endfor %}
{% endif %}
// _subtype_constraints.liquid
{% if schema.subtype_constraints.size > 0 %}
#{bookmark("subtype_constraints")}
#{bookmark('subtype_constraints')}
// _subtype_constraint.liquid
{% for thing in schema.subtype_constraints %}
#{bookmark("{{thing.id}}")}
#{bookmark('{{thing.id}}')}
{% endfor %}
{% endif %}
// _functions.liquid
{% if schema.functions.size > 0 %}
#{bookmark("functions")}
#{bookmark('functions')}
// _function.liquid
{% for thing in schema.functions %}
#{bookmark("{{thing.id}}")}
#{bookmark('{{thing.id}}')}
{% endfor %}
{% endif %}
// _procedures.liquid
{% if schema.procedures.size > 0 %}
#{bookmark("procedures")}
#{bookmark('procedures')}
// _procedure.liquid
{% for thing in schema.procedures %}
#{bookmark("{{thing.id}}")}
#{bookmark('{{thing.id}}')}
{% endfor %}
{% endif %}
// _rules.liquid
{% if schema.rules.size > 0 %}
#{bookmark("rules")}
#{bookmark('rules')}
// _rule.liquid
{% for thing in schema.rules %}
#{bookmark("{{thing.id}}")}
#{bookmark('{{thing.id}}')}
{% endfor %}
{% endif %}
HEREDOC
Expand Down Expand Up @@ -117,7 +117,7 @@ def to_adoc(path_to_schema_yaml)
[[#{@id}]]
[%unnumbered,type=express]
== #{@id} #{schema_anchors.gsub(%r{//[^\r\n]+}, "").gsub(/[\n\r]+/, "").gsub(/^[\n\r]/, "")}
== #{@id} #{schema_anchors.gsub(%r{//[^\r\n]+}, '').gsub(/[\n\r]+/, '').gsub(/^[\n\r]/, '')}
[source%unnumbered]
--
Expand Down

0 comments on commit 7837e6f

Please sign in to comment.