diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 266855f86..2b28b2a67 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - ruby-version: ['3.0', '3.1', '3.2'] + ruby-version: ['3.2', '3.3'] steps: - uses: actions/checkout@v2 diff --git a/.rubocop.yml b/.rubocop.yml index 871542bba..67922eed2 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -27,6 +27,8 @@ Style/HashTransformKeys: Enabled: true Style/HashTransformValues: Enabled: true +Style/AccessModifierDeclarations: + Enabled: false Style/ModuleFunction: Enabled: false Style/SymbolArray: diff --git a/.ruby-version b/.ruby-version index ef538c281..9c25013db 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -3.1.2 +3.3.6 diff --git a/.tool-versions b/.tool-versions index 0b2d85878..5aa8e0c30 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1 +1 @@ -ruby 3.1.2 +ruby 3.3.6 diff --git a/Gemfile b/Gemfile index 9bd327ec2..7365d7d0b 100644 --- a/Gemfile +++ b/Gemfile @@ -5,6 +5,8 @@ gemspec group :development, :test do gem 'debug' + gem 'parallel', '1.26.3' gem 'pry' gem 'pry-byebug' + gem 'rubocop', '~> 1.86', require: false end diff --git a/Gemfile.lock b/Gemfile.lock index 4e3a94e63..a38c868a6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -5,34 +5,39 @@ PATH bcp47 (>= 0.3) date_time_precision (>= 0.8) mime-types (>= 3.0) - nokogiri (>= 1.11.4) + nokogiri (>= 1.19.1) GEM remote: https://rubygems.org/ specs: - ast (2.4.2) + ast (2.4.3) bcp47 (0.3.3) i18n - byebug (11.1.3) + byebug (13.0.0) + reline (>= 0.6.0) coderay (1.1.3) - concurrent-ruby (1.3.1) + concurrent-ruby (1.3.6) coolline (0.5.0) unicode_utils (~> 1.4) + date (3.5.1) date_time_precision (0.8.1) - debug (1.9.2) + debug (1.11.1) irb (~> 1.10) reline (>= 0.3.8) - diff-lcs (1.4.4) - docile (1.3.2) - ffi (1.13.1) - formatador (0.2.5) - guard (2.16.2) + diff-lcs (1.6.2) + docile (1.4.1) + erb (6.0.3) + ffi (1.17.4) + formatador (1.2.3) + reline + guard (2.20.1) formatador (>= 0.2.4) listen (>= 2.7, < 4.0) + logger (~> 1.6) lumberjack (>= 1.0.12, < 2.0) nenv (~> 0.1) notiffany (~> 0.0) - pry (>= 0.9.12) + pry (>= 0.13.0) shellany (~> 0.0) thor (>= 0.18.1) guard-compat (1.2.1) @@ -43,84 +48,101 @@ GEM guard-test (2.0.8) guard-compat (~> 1.2) test-unit (~> 3.0) - i18n (1.14.5) + i18n (1.14.8) concurrent-ruby (~> 1.0) - io-console (0.7.2) - irb (1.13.2) + io-console (0.8.2) + irb (1.17.0) + pp (>= 0.6.0) + prism (>= 1.3.0) rdoc (>= 4.0.0) reline (>= 0.4.2) - json (2.3.1) - listen (3.3.1) + json (2.19.4) + language_server-protocol (3.17.0.5) + lint_roller (1.1.0) + listen (3.10.0) + logger rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) - lumberjack (1.2.8) - method_source (1.0.0) - mime-types (3.5.2) - mime-types-data (~> 3.2015) - mime-types-data (3.2024.0702) - mini_portile2 (2.8.6) + logger (1.7.0) + lumberjack (1.4.2) + method_source (1.1.0) + mime-types (3.7.0) + logger + mime-types-data (~> 3.2025, >= 3.2025.0507) + mime-types-data (3.2026.0414) + mini_portile2 (2.8.9) nenv (0.3.0) - nokogiri (1.16.5) + nokogiri (1.19.2) mini_portile2 (~> 2.8.2) racc (~> 1.4) - nokogiri-diff (0.2.0) + nokogiri-diff (0.3.0) nokogiri (~> 1.5) - tdiff (~> 0.3, >= 0.3.2) + tdiff (~> 0.4) notiffany (0.1.3) nenv (~> 0.1) shellany (~> 0.0) - parallel (1.23.0) - parser (3.2.2.4) + parallel (1.26.3) + parser (3.3.11.1) ast (~> 2.4.1) racc - power_assert (1.2.0) - pry (0.14.2) + power_assert (3.0.1) + pp (0.6.3) + prettyprint + prettyprint (0.2.0) + prism (1.9.0) + pry (0.16.0) coderay (~> 1.1) method_source (~> 1.0) - pry-byebug (3.10.1) - byebug (~> 11.0) - pry (>= 0.13, < 0.15) - pry-coolline (0.2.5) + reline (>= 0.6.0) + pry-byebug (3.12.0) + byebug (~> 13.0) + pry (>= 0.13, < 0.17) + pry-coolline (0.2.6) coolline (~> 0.5) - psych (5.1.2) + pry (~> 0.13) + psych (5.3.1) + date stringio - racc (1.8.0) + racc (1.8.1) rainbow (3.1.1) - rake (13.0.1) - rb-fsevent (0.10.4) - rb-inotify (0.10.1) + rake (13.4.2) + rb-fsevent (0.11.2) + rb-inotify (0.11.1) ffi (~> 1.0) - rdoc (6.7.0) + rdoc (7.2.0) + erb psych (>= 4.0.0) - regexp_parser (2.8.2) - reline (0.5.9) + tsort + regexp_parser (2.12.0) + reline (0.6.3) io-console (~> 0.5) - rexml (3.2.8) - strscan (>= 3.0.9) - rspec (3.10.0) - rspec-core (~> 3.10.0) - rspec-expectations (~> 3.10.0) - rspec-mocks (~> 3.10.0) - rspec-core (3.10.0) - rspec-support (~> 3.10.0) - rspec-expectations (3.10.0) + rspec (3.13.2) + rspec-core (~> 3.13.0) + rspec-expectations (~> 3.13.0) + rspec-mocks (~> 3.13.0) + rspec-core (3.13.6) + rspec-support (~> 3.13.0) + rspec-expectations (3.13.5) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.10.0) - rspec-mocks (3.10.0) + rspec-support (~> 3.13.0) + rspec-mocks (3.13.8) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.10.0) - rspec-support (3.10.0) - rubocop (1.23.0) - parallel (~> 1.10) - parser (>= 3.0.0.0) + rspec-support (~> 3.13.0) + rspec-support (3.13.7) + rubocop (1.86.1) + json (~> 2.3) + language_server-protocol (~> 3.17.0.2) + lint_roller (~> 1.1.0) + parallel (>= 1.10) + parser (>= 3.3.0.2) rainbow (>= 2.2.2, < 4.0) - regexp_parser (>= 1.8, < 3.0) - rexml - rubocop-ast (>= 1.12.0, < 2.0) + regexp_parser (>= 2.9.3, < 3.0) + rubocop-ast (>= 1.49.0, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 3.0) - rubocop-ast (1.30.0) - parser (>= 3.2.1.0) + unicode-display_width (>= 2.4.0, < 4.0) + rubocop-ast (1.49.1) + parser (>= 3.3.7.2) + prism (~> 1.7) ruby-progressbar (1.13.0) shellany (0.0.1) simplecov (0.17.1) @@ -128,13 +150,15 @@ GEM json (>= 1.8, < 3) simplecov-html (~> 0.10.0) simplecov-html (0.10.2) - stringio (3.1.1) - strscan (3.1.0) - tdiff (0.3.4) - test-unit (3.3.6) + stringio (3.2.0) + tdiff (0.4.0) + test-unit (3.7.7) power_assert - thor (1.0.1) - unicode-display_width (2.5.0) + thor (1.5.0) + tsort (0.2.0) + unicode-display_width (3.2.0) + unicode-emoji (~> 4.1) + unicode-emoji (4.2.0) unicode_utils (1.4.0) PLATFORMS @@ -147,17 +171,18 @@ DEPENDENCIES guard-rspec guard-test nokogiri-diff + parallel (= 1.26.3) pry pry-byebug pry-coolline rake rspec - rubocop (= 1.23.0) + rubocop (~> 1.86) simplecov (~> 0.17.0) test-unit RUBY VERSION - ruby 3.1.2p20 + ruby 3.3.6p108 BUNDLED WITH - 2.2.21 + 2.3.7 diff --git a/fhir_models.gemspec b/fhir_models.gemspec index 0ac4f527c..a24861123 100644 --- a/fhir_models.gemspec +++ b/fhir_models.gemspec @@ -22,7 +22,7 @@ Gem::Specification.new do |spec| spec.require_paths = ['lib'] spec.required_ruby_version = '>= 3.0.0' - spec.add_dependency 'nokogiri', '>= 1.11.4' + spec.add_dependency 'nokogiri', '>= 1.19.1' spec.add_dependency 'date_time_precision', '>= 0.8' spec.add_dependency 'bcp47', '>= 0.3' spec.add_dependency 'mime-types', '>= 3.0' @@ -35,7 +35,6 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'rspec' spec.add_development_dependency 'simplecov', '~> 0.17.0' spec.add_development_dependency 'nokogiri-diff' - spec.add_development_dependency 'rubocop', '1.23.0' spec.add_development_dependency 'guard-rspec' spec.add_development_dependency 'guard-test' end diff --git a/lib/fhir_models/bootstrap/model.rb b/lib/fhir_models/bootstrap/model.rb index 3ed4ebec3..2e6cc80bd 100644 --- a/lib/fhir_models/bootstrap/model.rb +++ b/lib/fhir_models/bootstrap/model.rb @@ -163,7 +163,7 @@ def validate_profile(metadata, contained = nil) errors.delete(typename) unless present.include?(typename) end end - errors.keep_if { |_k, v| (v && !v.empty?) } + errors.keep_if { |_k, v| v && !v.empty? } end # ----- validate a field ----- @@ -232,7 +232,7 @@ def validate_field(field, value, contained_here, meta, errors) end has_valid_code = false if meta['valid_codes'] - meta['valid_codes'].each do |_key, codes| + meta['valid_codes'].each_value do |codes| has_valid_code = true unless (codes & the_codes).empty? break if has_valid_code end @@ -287,7 +287,7 @@ def primitive?(datatype, value) def check_binding_uri(uri, value) valid = false # Strip off the |4.0.0 or |4.0.1 or |2014-03-26 or similar from the ends of URLs - uri&.gsub!(/\|[A-Za-z0-9.\-]*/, '') + uri&.gsub!(/\|[A-Za-z0-9.-]*/, '') valueset = versioned_fhir_module::Definitions.get_codes(uri) if ['http://hl7.org/fhir/ValueSet/mimetypes', 'http://www.rfc-editor.org/bcp/bcp13.txt'].include?(uri) @@ -332,7 +332,7 @@ def find_extension(extension_source, method_name) extension_source.select do |extension| name = extension.url.tr('-', '_').split('/').last anchor = name.split('#').last - (method_name.to_s == name || method_name.to_s == anchor) + [name, anchor].include?(method_name.to_s) end end diff --git a/lib/fhir_models/bootstrap/preprocess.rb b/lib/fhir_models/bootstrap/preprocess.rb index 273e0fc6e..af960288a 100644 --- a/lib/fhir_models/bootstrap/preprocess.rb +++ b/lib/fhir_models/bootstrap/preprocess.rb @@ -92,7 +92,7 @@ def self.pre_process_searchparam(hash) def self.remove_fhir_comments(hash) hash.delete('fhir_comments') - hash.each do |_key, value| + hash.each_value do |value| case value when Hash remove_fhir_comments(value) diff --git a/lib/fhir_models/fhir.rb b/lib/fhir_models/fhir.rb index 230f19ce6..0f8dcb75b 100644 --- a/lib/fhir_models/fhir.rb +++ b/lib/fhir_models/fhir.rb @@ -74,7 +74,7 @@ def self.primitive?(datatype:, value:) !(value.to_s =~ /\A[A-Za-z0-9\-.]{1,64}\Z/).nil? when 'xhtml' fragment = Nokogiri::HTML::DocumentFragment.parse(value) - value.is_a?(String) && fragment.errors.size.zero? + value.is_a?(String) && fragment.errors.empty? when 'unsignedint' !(value.to_s =~ /\A(0|([1-9][0-9]*))\Z/).nil? when 'positiveint' diff --git a/lib/fhir_models/fhir_ext/common_structure_definition.rb b/lib/fhir_models/fhir_ext/common_structure_definition.rb index 42e8c0e1e..dc607d32b 100644 --- a/lib/fhir_models/fhir_ext/common_structure_definition.rb +++ b/lib/fhir_models/fhir_ext/common_structure_definition.rb @@ -78,7 +78,7 @@ def valid_json?(json) verify_element(element, json) end - @errors.size.zero? + @errors.empty? end deprecate :is_valid_json?, :valid_json? @@ -410,7 +410,7 @@ def check_binding_element(element, value) if ['http://hl7.org/fhir/ValueSet/mimetypes', 'http://www.rfc-editor.org/bcp/bcp13.txt'].include?(vs_uri) matches = MIME::Types[value] known_weird = ['text/cql', 'application/cql+text', 'application/hl7-v2'].include?(value) - if (matches.nil? || matches.size.zero? || known_weird) && !some_type_of_xml_or_json?(value) + if (matches.nil? || matches.empty? || known_weird) && !some_type_of_xml_or_json?(value) @errors << "#{element.path} has invalid mime-type: '#{value}'" matching_type -= 1 if element.binding.strength == 'required' end diff --git a/lib/fhir_models/fhir_ext/common_structure_definition_compare.rb b/lib/fhir_models/fhir_ext/common_structure_definition_compare.rb index 3599c4fd6..bd7aa1b35 100644 --- a/lib/fhir_models/fhir_ext/common_structure_definition_compare.rb +++ b/lib/fhir_models/fhir_ext/common_structure_definition_compare.rb @@ -140,7 +140,7 @@ def compatible?(another_definition) end @errors.flatten! @warnings.flatten! - @errors.size.zero? + @errors.empty? end deprecate :is_compatible?, :compatible? @@ -225,7 +225,7 @@ def compare_extension_definition(x, y, another_definition) x_only = x_profiles - y_profiles shared = x_profiles - x_only - if !shared.nil? && shared.size.zero? + if !shared.nil? && shared.empty? # same name, but different profiles # maybe the profiles are the same, just with different URLs... # ... so we have to compare them, if we can. @@ -269,7 +269,7 @@ def compare_element_definitions(x, y, another_definition) y_only = y_types - x_types shared = x_types - x_only - if !shared.nil? && shared.size.zero? && !x_types.empty? && !y_types.empty? && !x.constraint.empty? && !y.constraint.empty? + if !shared.nil? && shared.empty? && !x_types.empty? && !y_types.empty? && !x.constraint.empty? && !y.constraint.empty? @errors << @finding.error(x.path.to_s, 'type.code', 'Incompatible data types', x_types.to_s, y_types.to_s) end if !x_only.nil? && !x_only.empty? @@ -359,7 +359,7 @@ def compare_element_definitions(x, y, another_definition) y_only = y_constraints - x_constraints shared = x_constraints - x_only - if !shared.nil? && shared.size.zero? && !x.constraint.empty? && !y.constraint.empty? + if !shared.nil? && shared.empty? && !x.constraint.empty? && !y.constraint.empty? @errors << @finding.error(x.path.to_s, 'constraint.xpath', 'Incompatible constraints', x_constraints.map { |z| z.tr(',', ';') }.join(' && ').to_s, y_constraints.map { |z| z.tr(',', ';') }.join(' && ').to_s) end if !x_only.nil? && !x_only.empty? diff --git a/lib/fhir_models/fhirpath/parse.rb b/lib/fhir_models/fhirpath/parse.rb index 676946a70..6b93a449d 100644 --- a/lib/fhir_models/fhirpath/parse.rb +++ b/lib/fhir_models/fhirpath/parse.rb @@ -36,7 +36,7 @@ def self.tokenize(expression) end # we may need to reassemble quoted strings again reassemble_strings(tokens) - tokens.delete_if { |token| (token.length.zero? || (token.is_a?(String) && token.match(/\S/).nil?)) } + tokens.delete_if { |token| token.empty? || (token.is_a?(String) && token.match(/\S/).nil?) } FHIR.logger.debug "TOKENS: #{tokens}" tokens end diff --git a/lib/fhir_models/generator/class_generator.rb b/lib/fhir_models/generator/class_generator.rb index fe0c016ba..2a8b7fe75 100644 --- a/lib/fhir_models/generator/class_generator.rb +++ b/lib/fhir_models/generator/class_generator.rb @@ -96,7 +96,7 @@ def generate_class(hierarchy, structure_def, top_level: false) if !element['type'].nil? # profiles contains a list of profiles if the datatype is Reference or Extension profiles = [] - element['type'].select { |t| t['code'] == 'Reference' || t['code'] == 'Extension' }.each do |data_type| + element['type'].select { |t| ['Reference', 'Extension'].include?(t['code']) }.each do |data_type| profiles << data_type['targetProfile'] end profiles.reject!(&:nil?) diff --git a/lib/fhir_models/generator/ig_resources.rb b/lib/fhir_models/generator/ig_resources.rb index 3e644374f..c193ffea8 100644 --- a/lib/fhir_models/generator/ig_resources.rb +++ b/lib/fhir_models/generator/ig_resources.rb @@ -124,7 +124,7 @@ def get_codes(url) end end end - transformed_expansion[url].each { |_system, codes| codes.uniq! } + transformed_expansion[url].each_value(&:uniq!) end transformed_expansion[url] end diff --git a/test/unit/profile_validation_test.rb b/test/unit/profile_validation_test.rb index 4dd7dadfd..404c7bf8a 100644 --- a/test/unit/profile_validation_test.rb +++ b/test/unit/profile_validation_test.rb @@ -1,4 +1,5 @@ require_relative '../test_helper' +require 'ostruct' class ProfileValidationTest < Test::Unit::TestCase ERROR_DIR = File.join('tmp', 'errors', 'ProfileValidationTest')