Skip to content

Commit

Permalink
Run Autocorrect
Browse files Browse the repository at this point in the history
  • Loading branch information
360dgries committed Dec 13, 2023
1 parent 3d0ec56 commit 0b75087
Show file tree
Hide file tree
Showing 18 changed files with 199 additions and 216 deletions.
163 changes: 48 additions & 115 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,47 +1,19 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2021-03-30 16:14:38 -0400 using RuboCop version 0.80.0.
# on 2023-12-13 19:55:27 UTC using RuboCop version 1.23.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: 51
# Cop supports --auto-correct.
Layout/EmptyLineAfterGuardClause:
Exclude:
- 'lib/fhir_models/bootstrap/definitions.rb'
- 'lib/fhir_models/bootstrap/generator.rb'
- 'lib/fhir_models/bootstrap/hashable.rb'
- 'lib/fhir_models/bootstrap/model.rb'
- 'lib/fhir_models/bootstrap/preprocess.rb'
- 'lib/fhir_models/bootstrap/xml.rb'
- 'lib/fhir_models/deprecate.rb'
- 'lib/fhir_models/fhir_ext/element_definition.rb'
- 'lib/fhir_models/fhir_ext/structure_definition.rb'
- 'lib/fhir_models/fhir_ext/structure_definition_compare.rb'
- 'lib/fhir_models/fhirpath/parse.rb'

# Offense count: 1
# Cop supports --auto-correct.
Layout/RescueEnsureAlignment:
Exclude:
- 'lib/fhir_models/bootstrap/hashable.rb'

# Offense count: 2
# Cop supports --auto-correct.
Lint/ToJSON:
Exclude:
- 'lib/fhir_models/bootstrap/json.rb'
- 'lib/fhir_models/fhir_ext/structure_definition_finding.rb'

# Offense count: 40
# Offense count: 38
# Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
Metrics/AbcSize:
Max: 392
Max: 394

# Offense count: 7
# Configuration parameters: CountComments, ExcludedMethods.
# ExcludedMethods: refine
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
# IgnoredMethods: refine
Metrics/BlockLength:
Max: 78

Expand All @@ -51,65 +23,75 @@ Metrics/BlockNesting:
Max: 5

# Offense count: 7
# Configuration parameters: CountComments.
# Configuration parameters: CountComments, CountAsOne.
Metrics/ClassLength:
Max: 356
Max: 355

# Offense count: 23
# Offense count: 32
# Configuration parameters: IgnoredMethods.
Metrics/CyclomaticComplexity:
Max: 65
Max: 73

# Offense count: 44
# Configuration parameters: CountComments, ExcludedMethods.
# Offense count: 45
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
Metrics/MethodLength:
Max: 133
Max: 132

# Offense count: 2
# Configuration parameters: CountComments.
# Configuration parameters: CountComments, CountAsOne.
Metrics/ModuleLength:
Max: 114

# Offense count: 23
# Offense count: 28
# Configuration parameters: IgnoredMethods.
Metrics/PerceivedComplexity:
Max: 68
Max: 76

# Offense count: 5
# Configuration parameters: EnforcedStyle, IgnoredPatterns.
# SupportedStyles: snake_case, camelCase
Naming/MethodName:
Exclude:
- 'lib/fhir_models/fhir_ext/structure_definition_finding.rb'

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

# Offense count: 2
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: PreferredName.
Naming/RescuedExceptionsVariableName:
# Configuration parameters: EnforcedStyle.
# SupportedStyles: nested, compact
Style/ClassAndModuleChildren:
Exclude:
- 'lib/fhir_models/bootstrap/hashable.rb'

# Offense count: 1
# Configuration parameters: .
# SupportedStyles: inline, group
Style/AccessModifierDeclarations:
EnforcedStyle: inline
- '.simplecov'

# Offense count: 17
Style/ClassVars:
Exclude:
- 'lib/fhir_models/bootstrap/definitions.rb'
- 'lib/fhir_models/fhirpath/parse.rb'

# Offense count: 1
Style/CombinableLoops:
Exclude:
- 'lib/fhir_models/fhir_ext/structure_definition_compare.rb'

# Offense count: 6
# Cop supports --auto-correct.
Style/CommentedKeyword:
Exclude:
- 'lib/fhir_models/bootstrap/hashable.rb'
- 'lib/fhir_models/bootstrap/model.rb'

# Offense count: 14
# Offense count: 15
# Configuration parameters: AllowedConstants.
Style/Documentation:
Exclude:
- 'spec/**/*'
- 'test/**/*'
- '.simplecov'
- 'lib/fhir_models/bootstrap/definitions.rb'
- 'lib/fhir_models/bootstrap/field.rb'
- 'lib/fhir_models/bootstrap/generator.rb'
Expand All @@ -136,71 +118,22 @@ Style/IfUnlessModifier:
- 'lib/fhir_models/fhir_ext/structure_definition.rb'
- 'lib/fhir_models/fhir_ext/structure_definition_compare.rb'

# Offense count: 1
Style/MethodMissingSuper:
Exclude:
- 'lib/fhir_models/bootstrap/model.rb'

# Offense count: 1
Style/MissingRespondToMissing:
Exclude:
- 'lib/fhir_models/bootstrap/model.rb'

# Offense count: 9
Style/MultipleComparison:
Exclude:
- 'lib/fhir_models/bootstrap/definitions.rb'
- 'lib/fhir_models/bootstrap/generator.rb'
- 'lib/fhir_models/bootstrap/model.rb'
- 'lib/fhir_models/fhir_ext/structure_definition.rb'

# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: AutoCorrect, EnforcedStyle, IgnoredMethods.
# SupportedStyles: predicate, comparison
Style/NumericPredicate:
Exclude:
- 'spec/**/*'
- 'lib/fhir_models/fhir_ext/structure_definition_compare.rb'

# Offense count: 1
# Cop supports --auto-correct.
Style/OrAssignment:
# Configuration parameters: AllowedMethods.
# AllowedMethods: respond_to_missing?
Style/OptionalBooleanParameter:
Exclude:
- 'lib/fhir_models/bootstrap/generator.rb'
- 'lib/fhir_models/bootstrap/template.rb'

# Offense count: 16
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: implicit, explicit
Style/RescueStandardError:
Exclude:
- 'lib/fhir_models/bootstrap/definitions.rb'
- 'lib/fhir_models/bootstrap/hashable.rb'
- 'lib/fhir_models/bootstrap/json.rb'
- 'lib/fhir_models/bootstrap/model.rb'
- 'lib/fhir_models/bootstrap/xml.rb'
- 'lib/fhir_models/fhir.rb'
- 'lib/fhir_models/fhir_ext/structure_definition.rb'
- 'lib/fhir_models/fhir_ext/structure_definition_finding.rb'
- 'lib/fhir_models/fhirpath/expression.rb'
- 'lib/fhir_models/fhirpath/parse.rb'

# Offense count: 4
# Cop supports --auto-correct.
# Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods.
# AllowedMethods: present?, blank?, presence, try, try!
Style/SafeNavigation:
Exclude:
- 'lib/fhir_models/bootstrap/definitions.rb'
- 'lib/fhir_models/bootstrap/xml.rb'
- 'lib/fhir_models/fhir_ext/structure_definition.rb'

# Offense count: 7
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: forbid_for_all_comparison_operators, forbid_for_equality_operators_only, require_for_all_comparison_operators, require_for_equality_operators_only
Style/YodaCondition:
# Configuration parameters: AllowModifier.
Style/SoleNestedConditional:
Exclude:
- 'lib/fhir_models/bootstrap/preprocess.rb'
- 'lib/fhir_models/fhirpath/parse.rb'
- 'lib/fhir_models/fhir_ext/structure_definition_compare.rb'
2 changes: 1 addition & 1 deletion Guardfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"

# Note: The cmd option is now required due to the increasing number of ways
# NOTE: The cmd option is now required due to the increasing number of ways
# rspec may be run, below are examples of the most common uses.
# * bundler: 'bundle exec rspec'
# * bundler binstubs: 'bin/rspec'
Expand Down
19 changes: 16 additions & 3 deletions lib/fhir_models/bootstrap/definitions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def self.complex_types
def self.type_definition(type_name)
return nil if type_name.nil?
return @@cache[type_name] if @@cache[type_name]

definition = types.find { |x| x['xmlId'] == type_name || x['name'] == type_name || x['url'] == type_name }
@@cache[type_name] = FHIR::StructureDefinition.new(definition) if definition
@@cache[type_name]
Expand Down Expand Up @@ -73,6 +74,7 @@ def self.resource_definitions
def self.resource_definition(resource_name)
return nil if resource_name.nil?
return @@cache[resource_name] if @@cache[resource_name]

definition = resources.find { |x| x['xmlId'] == resource_name || x['name'] == resource_name || x['url'] == resource_name }
@@cache[resource_name] = FHIR::StructureDefinition.new(definition) if definition
@@cache[resource_name]
Expand Down Expand Up @@ -103,39 +105,47 @@ def self.extensions

def self.extension_definition(extension_name)
return nil if extension_name.nil?

extension = extensions.find { |x| x['xmlId'] == extension_name || x['name'] == extension_name || x['url'] == extension_name }
return nil if extension.nil?

FHIR::StructureDefinition.new(extension)
end
deprecate :get_extension_definition, :extension_definition

# Get the basetype (String) for a given profile or extension.
def self.basetype(uri)
return nil if uri.nil?

defn = profiles.detect { |x| x['url'] == uri } || extensions.detect { |x| x['url'] == uri }
return nil if defn.nil?

defn['baseType']
end
deprecate :get_basetype, :basetype

# Get the StructureDefinition for a given profile.
def self.profile(uri)
return nil if uri.nil?

defn = profiles.detect { |x| x['url'] == uri } || extensions.detect { |x| x['url'] == uri }
return nil if defn.nil?

FHIR::StructureDefinition.new(defn)
end
deprecate :get_profile, :profile

def self.profiles_for_resource(resource_name)
return nil if resource_name.nil?

profiles.select { |x| x['baseType'] == resource_name }.map { |x| FHIR::StructureDefinition.new(x) }
end
deprecate :get_profiles_for_resource, :profile_for_resource

# Get a dynamically generated class for a given profile.
def self.get_profile_class(uri)
return nil if uri.nil?

load_profiles
load_extensions

Expand All @@ -161,7 +171,7 @@ def self.get_profile_class(uri)
load f
# set the return class type
klass = Object.const_get("FHIR::Profile::#{id}::#{type}")
rescue
rescue StandardError
FHIR.logger.error "Failed to generate class for profile #{uri}"
end
# unlink the file so it can be garbage collected
Expand Down Expand Up @@ -197,6 +207,7 @@ def self.valuesets
def self.get_codes(uri)
return nil if uri.nil?
return @@cache[uri] if @@cache[uri]

valueset = expansions.find { |x| x['url'] == uri } || valuesets.find { |x| x['url'] == uri && x['resourceType'] == 'ValueSet' }
unless valueset.nil?
@@cache[uri] = {}
Expand All @@ -214,12 +225,12 @@ def self.get_codes(uri)
system_url = code_group['system']
@@cache[uri][system_url] ||= []
if !code_group['concept'].nil?
code_group['concept'].each { |y| @@cache[uri][system_url] << y['code'] } if code_group['concept']
code_group['concept']&.each { |y| @@cache[uri][system_url] << y['code'] }
elsif code_group.size == 1
# i.e. the only key is 'system', so you import the entire thing
systems = valuesets.select { |x| x['resourceType'] == 'CodeSystem' && x['url'] == system_url }
systems.each do |included_system|
included_system['concept'].each { |y| @@cache[uri][system_url] << y['code'] } if included_system['concept']
included_system['concept']&.each { |y| @@cache[uri][system_url] << y['code'] }
end
end
end
Expand All @@ -233,6 +244,7 @@ def self.get_codes(uri)
# If one can't be found, return nil
def self.get_display(uri, code)
return nil if uri.nil? || code.nil?

valuesets_and_expansions = expansions.select { |ex| ex['compose']['include'].detect { |i| i['system'] == uri } }
valuesets_and_expansions += valuesets.select { |vs| vs['url'] == uri }
code_hash = nil
Expand Down Expand Up @@ -272,6 +284,7 @@ def self.search_params

def self.search_parameters(type_name)
return nil if type_name.nil?

search_params.select { |p| p['base'].include?(type_name) && p['xpath'] && !p['xpath'].include?('extension') }.map { |p| p['code'] }
end
deprecate :get_search_parameters, :search_parameters
Expand Down
4 changes: 2 additions & 2 deletions lib/fhir_models/bootstrap/field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ def initialize(name = '')
def serialize
hash = {}
instance_variables.each do |v|
hash[v.to_s[1..-1]] = instance_variable_get(v)
hash[v.to_s[1..]] = instance_variable_get(v)
end
hash.delete('name')
prune(hash)
end

def fix_name(name)
fix = nil
fix = "local_#{name}" if %w[class method resourceType].include?(name)
fix = "local_#{name}" if ['class', 'method', 'resourceType'].include?(name)
fix
end
end
Expand Down
Loading

0 comments on commit 0b75087

Please sign in to comment.