Skip to content

Commit 28a7412

Browse files
committed
modernize hash and array style
1 parent 05dd408 commit 28a7412

19 files changed

+91
-97
lines changed

Diff for: .rubocop.yml

-6
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@ Metrics/MethodLength:
2727
Exclude:
2828
- 'test/**/*'
2929

30-
Style/HashSyntax:
31-
EnforcedStyle: hash_rockets
32-
33-
Style/SymbolArray:
34-
EnforcedStyle: brackets
35-
3630
Naming/MethodParameterName:
3731
Enabled: false
3832

Diff for: Rakefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
require 'bundler'
44

5-
Bundler::GemHelper.install_tasks :name => 'openscap'
5+
Bundler::GemHelper.install_tasks name: 'openscap'
66

77
task :test do
88
$LOAD_PATH.unshift('lib')

Diff for: lib/openscap/ds/arf.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ def html
5858

5959
attach_function :ds_rds_session_new_from_source, [:pointer], :pointer
6060
attach_function :ds_rds_session_free, [:pointer], :void
61-
attach_function :ds_rds_session_select_report, [:pointer, :string], :pointer
62-
attach_function :ds_rds_session_replace_report_with_source, [:pointer, :pointer], :int
63-
attach_function :ds_rds_session_select_report_request, [:pointer, :string], :pointer
61+
attach_function :ds_rds_session_select_report, %i[pointer string], :pointer
62+
attach_function :ds_rds_session_replace_report_with_source, %i[pointer pointer], :int
63+
attach_function :ds_rds_session_select_report_request, %i[pointer string], :pointer
6464
attach_function :ds_rds_session_get_html_report, [:pointer], :pointer
6565
end

Diff for: lib/openscap/ds/sds.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ def destroy
4343

4444
attach_function :ds_sds_session_new_from_source, [:pointer], :pointer
4545
attach_function :ds_sds_session_free, [:pointer], :void
46-
attach_function :ds_sds_session_select_checklist, [:pointer, :string, :string, :string], :pointer
47-
attach_function :ds_sds_session_get_html_guide, [:pointer, :string], :string
46+
attach_function :ds_sds_session_select_checklist, %i[pointer string string string], :pointer
47+
attach_function :ds_sds_session_get_html_guide, %i[pointer string], :string
4848
end

Diff for: lib/openscap/source.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ def create_from_memory(param)
5151
end
5252

5353
attach_function :oscap_source_new_from_file, [:string], :pointer
54-
attach_function :oscap_source_new_from_memory, [:pointer, :int, :string], :pointer
54+
attach_function :oscap_source_new_from_memory, %i[pointer int string], :pointer
5555
attach_function :oscap_source_get_scap_type, [:pointer], :int
5656
attach_function :oscap_source_free, [:pointer], :void
57-
attach_function :oscap_source_save_as, [:pointer, :string], :int
57+
attach_function :oscap_source_save_as, %i[pointer string], :int
5858

59-
callback :xml_reporter, [:string, :int, :string, :pointer], :int
60-
attach_function :oscap_source_validate, [:pointer, :xml_reporter, :pointer], :int
59+
callback :xml_reporter, %i[string int string pointer], :int
60+
attach_function :oscap_source_validate, %i[pointer xml_reporter pointer], :int
6161
XmlReporterCallback = proc do |filename, line_number, error_message, e|
6262
offset = e.get_string(0).length
6363
msg = "#{filename}:#{line_number}: #{error_message}"

Diff for: lib/openscap/text.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ def destroy
3737
end
3838

3939
attach_function :oscap_text_new, [], :pointer
40-
attach_function :oscap_text_set_text, [:pointer, :string], :bool
40+
attach_function :oscap_text_set_text, %i[pointer string], :bool
4141
attach_function :oscap_text_get_text, [:pointer], :string
4242
attach_function :oscap_text_free, [:pointer], :void
4343

44-
attach_function :oscap_textlist_get_preferred_plaintext, [:pointer, :string], :string
44+
attach_function :oscap_textlist_get_preferred_plaintext, %i[pointer string], :string
4545
attach_function :oscap_text_iterator_free, [:pointer], :void
4646
end

Diff for: lib/openscap/xccdf/fix.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ def content
2929

3030
def to_hash
3131
{
32-
:id => id,
33-
:platform => platform,
34-
:system => fix_system,
35-
:content => content
32+
id:,
33+
platform:,
34+
system: fix_system,
35+
content:
3636
}
3737
end
3838
end

Diff for: lib/openscap/xccdf/reference.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ def html_link
2424

2525
def to_hash
2626
{
27-
:title => title,
28-
:href => href,
29-
:html_link => html_link
27+
title:,
28+
href:,
29+
html_link:
3030
}
3131
end
3232
end

Diff for: lib/openscap/xccdf/rule.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ class Rule < Item
1111
def severity
1212
severity = OpenSCAP.xccdf_rule_get_severity(@raw)
1313
severity_mapping = {
14-
:xccdf_level_not_defined => 'Not defined',
15-
:xccdf_unknown => 'Unknown',
16-
:xccdf_info => 'Info',
17-
:xccdf_low => 'Low',
18-
:xccdf_medium => 'Medium',
19-
:xccdf_high => 'High'
14+
xccdf_level_not_defined: 'Not defined',
15+
xccdf_unknown: 'Unknown',
16+
xccdf_info: 'Info',
17+
xccdf_low: 'Low',
18+
xccdf_medium: 'Medium',
19+
xccdf_high: 'High'
2020
}
2121
severity_mapping[severity] || severity_mapping[:xccdf_unknown]
2222
end

Diff for: lib/openscap/xccdf/session.rb

+17-17
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ def sds?
1717

1818
def load(opts = {})
1919
o = {
20-
:datastream_id => nil,
21-
:component_id => nil
20+
datastream_id: nil,
21+
component_id: nil
2222
}.merge(opts)
2323
if sds?
2424
OpenSCAP.xccdf_session_set_datastream_id(@s, o[:datastream_id])
@@ -45,12 +45,12 @@ def remediate
4545

4646
def export_results(opts = {})
4747
o = {
48-
:rds_file => nil,
49-
:xccdf_file => nil,
50-
:report_file => nil,
51-
:oval_results => false,
52-
:oval_variables => false,
53-
:engines_results => false
48+
rds_file: nil,
49+
xccdf_file: nil,
50+
report_file: nil,
51+
oval_results: false,
52+
oval_variables: false,
53+
engines_results: false
5454
}.merge!(opts)
5555
export_targets o
5656
export
@@ -94,13 +94,13 @@ def export_targets(opts = {})
9494

9595
attach_function :xccdf_session_is_sds, [:pointer], :bool
9696

97-
attach_function :xccdf_session_set_profile_id, [:pointer, :string], :bool
98-
attach_function :xccdf_session_set_datastream_id, [:pointer, :string], :void
99-
attach_function :xccdf_session_set_component_id, [:pointer, :string], :void
100-
attach_function :xccdf_session_set_arf_export, [:pointer, :string], :bool
101-
attach_function :xccdf_session_set_xccdf_export, [:pointer, :string], :bool
102-
attach_function :xccdf_session_set_report_export, [:pointer, :string], :bool
103-
attach_function :xccdf_session_set_oval_variables_export, [:pointer, :bool], :void
104-
attach_function :xccdf_session_set_oval_results_export, [:pointer, :bool], :void
105-
attach_function :xccdf_session_set_check_engine_plugins_results_export, [:pointer, :bool], :void
97+
attach_function :xccdf_session_set_profile_id, %i[pointer string], :bool
98+
attach_function :xccdf_session_set_datastream_id, %i[pointer string], :void
99+
attach_function :xccdf_session_set_component_id, %i[pointer string], :void
100+
attach_function :xccdf_session_set_arf_export, %i[pointer string], :bool
101+
attach_function :xccdf_session_set_xccdf_export, %i[pointer string], :bool
102+
attach_function :xccdf_session_set_report_export, %i[pointer string], :bool
103+
attach_function :xccdf_session_set_oval_variables_export, %i[pointer bool], :void
104+
attach_function :xccdf_session_set_oval_results_export, %i[pointer bool], :void
105+
attach_function :xccdf_session_set_check_engine_plugins_results_export, %i[pointer bool], :void
106106
end

Diff for: lib/openscap/xccdf/tailoring.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def profiles_init
4343
end
4444
end
4545

46-
attach_function :xccdf_tailoring_import_source, [:pointer, :pointer], :pointer
46+
attach_function :xccdf_tailoring_import_source, %i[pointer pointer], :pointer
4747
attach_function :xccdf_tailoring_free, [:pointer], :void
4848

4949
attach_function :xccdf_tailoring_get_profiles, [:pointer], :pointer

Diff for: lib/openscap/xccdf/testresult.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ def score_init
7272
while OpenSCAP.xccdf_score_iterator_has_more(scorit)
7373
s = OpenSCAP.xccdf_score_iterator_next(scorit)
7474
scores[OpenSCAP.xccdf_score_get_system(s)] = {
75-
:system => OpenSCAP.xccdf_score_get_system(s),
76-
:value => OpenSCAP.xccdf_score_get_score(s),
77-
:max => OpenSCAP.xccdf_score_get_maximum(s)
75+
system: OpenSCAP.xccdf_score_get_system(s),
76+
value: OpenSCAP.xccdf_score_get_score(s),
77+
max: OpenSCAP.xccdf_score_get_maximum(s)
7878
}
7979
end
8080
OpenSCAP.xccdf_score_iterator_free(scorit)
@@ -87,8 +87,8 @@ def score_init
8787
attach_function :xccdf_result_free, [:pointer], :void
8888
attach_function :xccdf_result_get_id, [:pointer], :string
8989
attach_function :xccdf_result_get_profile, [:pointer], :string
90-
attach_function :xccdf_result_recalculate_scores, [:pointer, :pointer], :int
91-
attach_function :xccdf_result_export_source, [:pointer, :string], :pointer
90+
attach_function :xccdf_result_recalculate_scores, %i[pointer pointer], :int
91+
attach_function :xccdf_result_export_source, %i[pointer string], :pointer
9292

9393
attach_function :xccdf_result_get_rule_results, [:pointer], :pointer
9494
attach_function :xccdf_rule_result_iterator_has_more, [:pointer], :bool

Diff for: test/ds/arf_test.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def test_new_memory
5252
create_arf
5353
raw_data = File.read(REPORT)
5454
refute raw_data.empty?
55-
arf = OpenSCAP::DS::Arf.new :content => raw_data, :path => REPORT
55+
arf = OpenSCAP::DS::Arf.new content: raw_data, path: REPORT
5656
arf.destroy
5757
end
5858

@@ -62,7 +62,7 @@ def test_new_bz_memory
6262
assert !raw_data.empty?
6363
len = File.size(bziped_file)
6464
FileUtils.rm bziped_file
65-
arf = OpenSCAP::DS::Arf.new :content => raw_data, :path => bziped_file, :length => len
65+
arf = OpenSCAP::DS::Arf.new content: raw_data, path: bziped_file, length: len
6666
arf.destroy
6767
end
6868

@@ -88,9 +88,9 @@ def new_arf
8888

8989
def create_arf
9090
@s = OpenSCAP::Xccdf::Session.new('../data/sds-complex.xml')
91-
@s.load(:component_id => 'scap_org.open-scap_cref_second-xccdf.xml')
91+
@s.load(component_id: 'scap_org.open-scap_cref_second-xccdf.xml')
9292
@s.profile = 'xccdf_moc.elpmaxe.www_profile_1'
9393
@s.evaluate
94-
@s.export_results(:rds_file => 'report.rds.xml')
94+
@s.export_results(rds_file: 'report.rds.xml')
9595
end
9696
end

Diff for: test/ds/sds_test.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def test_new_non_sds
1616
assert !@s.nil?
1717
msg = nil
1818
begin
19-
OpenSCAP::DS::Sds.new :source => @s
19+
OpenSCAP::DS::Sds.new source: @s
2020
assert false
2121
rescue OpenSCAP::OpenSCAPError => e
2222
msg = e.to_s
@@ -48,7 +48,7 @@ def tests_select_checklist_wrong
4848
sds = new_sds
4949
msg = nil
5050
begin
51-
benchmark = sds.select_checklist! :datastream_id => 'wrong'
51+
benchmark = sds.select_checklist! datastream_id: 'wrong'
5252
assert false
5353
rescue OpenSCAP::OpenSCAPError => e
5454
msg = e.to_s
@@ -64,7 +64,7 @@ def new_sds
6464
filename = '../data/sds-complex.xml'
6565
@s = OpenSCAP::Source.new filename
6666
assert !@s.nil?
67-
sds = OpenSCAP::DS::Sds.new :source => @s
67+
sds = OpenSCAP::DS::Sds.new source: @s
6868
assert !sds.nil?
6969
sds
7070
end

Diff for: test/integration/arf_waiver_test.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ def test_waiver_and_score
1414
assert_default_score tr.score, -1, 1
1515
assert_default_score tr.score!(benchmark), -1, 1
1616

17-
rr.override!(:new_result => :pass,
18-
:time => 'yesterday',
19-
:authority => 'John Hacker',
20-
:raw_text => 'This should have passed')
17+
rr.override!(new_result: :pass,
18+
time: 'yesterday',
19+
authority: 'John Hacker',
20+
raw_text: 'This should have passed')
2121
assert rr.result == 'pass'
2222

2323
assert_default_score tr.score, -1, 1
@@ -85,7 +85,7 @@ def arf_init
8585
@s = OpenSCAP::Xccdf::Session.new('../data/sds-complex.xml')
8686
@s.load
8787
@s.evaluate
88-
@s.export_results(:rds_file => 'report.rds.xml')
88+
@s.export_results(rds_file: 'report.rds.xml')
8989
OpenSCAP::DS::Arf.new('report.rds.xml')
9090
end
9191
end

Diff for: test/source_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def test_source_new_ok
2424
def test_source_new_memory
2525
raw_data = File.read('../data/xccdf.xml')
2626
refute raw_data.empty?
27-
s = OpenSCAP::Source.new(:content => raw_data, :path => '/mytestpath')
27+
s = OpenSCAP::Source.new(content: raw_data, path: '/mytestpath')
2828
s.destroy
2929
end
3030

Diff for: test/xccdf/benchmark_test.rb

+10-10
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@ def test_items_severity
7878
def test_items_references
7979
b = benchmark_from_file
8080
install_hids_rule = b.items['xccdf_org.ssgproject.content_rule_install_hids']
81-
expected_references = [{ :title => 'SC-7',
82-
:href => 'http://csrc.nist.gov/publications/nistpubs/800-53-Rev3/sp800-53-rev3-final.pdf',
83-
:html_link => "<a href='http://csrc.nist.gov/publications/nistpubs/800-53-Rev3/sp800-53-rev3-final.pdf'>SC-7</a>" },
84-
{ :title => '1263',
85-
:href => 'http://iase.disa.mil/cci/index.html',
86-
:html_link => "<a href='http://iase.disa.mil/cci/index.html'>1263</a>" }]
81+
expected_references = [{ title: 'SC-7',
82+
href: 'http://csrc.nist.gov/publications/nistpubs/800-53-Rev3/sp800-53-rev3-final.pdf',
83+
html_link: "<a href='http://csrc.nist.gov/publications/nistpubs/800-53-Rev3/sp800-53-rev3-final.pdf'>SC-7</a>" },
84+
{ title: '1263',
85+
href: 'http://iase.disa.mil/cci/index.html',
86+
html_link: "<a href='http://iase.disa.mil/cci/index.html'>1263</a>" }]
8787
assert_equal(expected_references, install_hids_rule.references.map(&:to_hash), 'Install hids references should be equal')
8888
b.destroy
8989
end
@@ -93,10 +93,10 @@ def test_items_fixes
9393
login_defs_rule = b.items['xccdf_org.ssgproject.content_rule_accounts_minimum_age_login_defs']
9494
expected_content = ["var_accounts_minimum_age_login_defs=\"<sub xmlns=\"http://checklists.nist.gov/xccdf/1.2\" idref=\"xccdf_org.ssgproject.content_value_var_accounts_minimum_age_login_defs\" use=\"legacy\"/>\"\ngrep -q ^PASS_MIN_DAYS /etc/login.defs &amp;&amp; \\\nsed -i \"s/PASS_MIN_DAYS.*/PASS_MIN_DAYS\\t$var_accounts_minimum_age_login_defs/g\" /etc/login.defs\nif ! [ $? -eq 0 ]\nthen\n echo -e \"PASS_MIN_DAYS\\t$var_accounts_minimum_age_login_defs\" &gt;&gt; /etc/login.defs\nfi\n"]
9595
expected_hashes = [{
96-
:id => nil,
97-
:platform => nil,
98-
:content => expected_content.first,
99-
:system => 'urn:xccdf:fix:script:sh'
96+
id: nil,
97+
platform: nil,
98+
content: expected_content.first,
99+
system: 'urn:xccdf:fix:script:sh'
100100
}]
101101
assert_equal(expected_content, login_defs_rule.fixes.map(&:content), 'Fix content should match')
102102
assert_equal(expected_hashes, login_defs_rule.fixes.map(&:to_hash), 'Fix hash should match')

0 commit comments

Comments
 (0)