Skip to content

Commit

Permalink
rubocop: autocorrect with -A and disable fronzen strings
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Jan 5, 2024
1 parent f16a5ee commit a0960be
Show file tree
Hide file tree
Showing 15 changed files with 132 additions and 123 deletions.
5 changes: 5 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# use the shared YaST defaults
inherit_from:
rubocop-1.59.0_yast_style.yml

# this needs a lot of testing
Style/FrozenStringLiteralComment:
Enabled: false

8 changes: 4 additions & 4 deletions console/src/modules/Console.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ def Save
SCR.Write(path(".sysconfig.console.CONSOLE_ENCODING"), WFM.GetEncoding)
SCR.Write(
path(".sysconfig.console.CONSOLE_ENCODING.comment"),
"\n" +
"# Encoding used for output of non-ascii characters.\n" +
"#\n"
"\n" \
"# Encoding used for output of non-ascii characters.\n" \
"#\n"
)
SCR.Write(path(".sysconfig.console"), nil)

Expand Down Expand Up @@ -245,7 +245,7 @@ def Console
def consolefonts
return @consolefonts if @consolefonts

@consolefonts = JSON.load(File.read(Directory.find_data_file("consolefonts.json")))
@consolefonts = JSON.parse(File.read(Directory.find_data_file("consolefonts.json")))
end
end

Expand Down
6 changes: 3 additions & 3 deletions keyboard/src/lib/y2keyboard/strategies/kb_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ class KbStrategy
# Writing rules in /etc/udev would result in those files being copied to
# the installed system. That's not what we want. sys-int is temporary, so
# writing in its /run is safe.
UDEV_FILE = "/run/udev/rules.d/70-installation-keyboard.rules"
UDEV_FILE = "/run/udev/rules.d/70-installation-keyboard.rules".freeze
UDEV_COMMENT = "# Generated by Yast to handle the layout of keyboards " \
"connected during installation\n"
"connected during installation\n".freeze

# Used to set keybaord layout in a running system.
# @param keyboard_code [String] the keyboard layout (e.g. "us") to set
Expand Down Expand Up @@ -78,7 +78,7 @@ def set_x11_layout(keyboard_code)
x11data = get_x11_data(keyboard_code)
return if x11data.empty?

Yast::Execute.locally("/usr/bin/setxkbmap", *x11data["Apply"].split(" "))
Yast::Execute.locally("/usr/bin/setxkbmap", *x11data["Apply"].split)

# bnc#885271: set udev rule to handle incoming attached keyboards
# While installation/update only.
Expand Down
4 changes: 2 additions & 2 deletions keyboard/src/modules/Keyboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def MakeProposal(force_reset, language_changed)
#
def Selection
lang = Keyboards.all_keyboards.map { |k| { k["alias"] => k["description"] } }
Hash[*lang.collect { |h| h.to_a }.flatten]
Hash[*lang.collect(&:to_a).flatten]
end

# Returns all defined codes and the regarding aliases.
Expand All @@ -237,7 +237,7 @@ def Selection
# e.g. {"jp106"=>"japanese", "us"=>"english-us",....}
def Codes
lang = Keyboards.all_keyboards.map { |k| { k["code"] => k["alias"] } }
Hash[*lang.collect { |h| h.to_a }.flatten]
Hash[*lang.collect(&:to_a).flatten]
end

# Return item list of keyboard items, sorted according to current language
Expand Down
4 changes: 2 additions & 2 deletions keyboard/test/keyboard_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@
expect(ret.first.params[0]).to be_kind_of(Yast::Term)
expect(ret.first.params[0].value).to eq(:id)
expect(ret.first.params[1]).to be_kind_of(String)
expect(ret.first.params[2].class == FalseClass ||
ret.first.params[2].class == TrueClass).to eq(true)
expect(ret.first.params[2].instance_of?(FalseClass) ||
ret.first.params[2].instance_of?(TrueClass)).to eq(true)
end
end

Expand Down
2 changes: 1 addition & 1 deletion keyboard/test/keyboards_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
expect(ret.first.key?("alias")).to eq(true)
expect(ret.first.key?("code")).to eq(true)
if ret.first.key?("suggested_for_lang")
expect(ret.first["suggested_for_lang"].class == Array).to eq(true)
expect(ret.first["suggested_for_lang"].instance_of?(Array)).to eq(true)
end
end

Expand Down
7 changes: 4 additions & 3 deletions language/src/clients/country_simple_proposal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ def main
@param = Convert.to_map(WFM.Args(1))
@ret = {}

if @func == "MakeProposal"
case @func
when "MakeProposal"
@force_reset = Ops.get_boolean(@param, "force_reset", false)
@language_changed = Ops.get_boolean(@param, "language_changed", false)
# summary label <%1>-<%2> are HTML tags, leave untouched
Expand Down Expand Up @@ -65,7 +66,7 @@ def main
"language_changed" => false,
"links" => ["country--language", "country--keyboard"]
}
elsif @func == "Description"
when "Description"
@ret = {
# rich text label
"rich_text_title" => _("Locale Settings"),
Expand All @@ -77,7 +78,7 @@ def main
],
"id" => "country"
}
elsif @func == "AskUser"
when "AskUser"
@ret = if Ops.get_string(@param, "chosen_id", "") == "country--keyboard"
Convert.to_map(
WFM.CallFunction("keyboard_proposal", [@func, @param])
Expand Down
4 changes: 2 additions & 2 deletions language/src/clients/language.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def LanguageSequence

# Handler for language summary
def LanguageSummaryHandler(options)
options = deep_copy(options)
deep_copy(options)
selection = Language.Selection
# summary label
CommandLine.Print(
Expand Down Expand Up @@ -270,7 +270,7 @@ def LanguageSummaryHandler(options)

# Handler for listing available languages
def LanguageListHandler(options)
options = deep_copy(options)
deep_copy(options)
Builtins.foreach(Language.Selection) do |lang_code, lang_info|
CommandLine.Print(
Builtins.sformat(
Expand Down
7 changes: 4 additions & 3 deletions language/src/clients/language_proposal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ def main
@language_on_entry = Language.language
Builtins.y2milestone("language_on_entry - 1: %1", @language_on_entry)

if @func == "MakeProposal"
case @func
when "MakeProposal"
@force_reset = Ops.get_boolean(@param, "force_reset", false)
@language_changed = Ops.get_boolean(@param, "language_changed", false)

Expand Down Expand Up @@ -87,7 +88,7 @@ def main
"raw_proposal" => @prop,
"language_changed" => @language_on_entry != Language.language
}
elsif @func == "AskUser"
when "AskUser"
Wizard.OpenAcceptDialog
@args = {
"enable_back" => true,
Expand Down Expand Up @@ -119,7 +120,7 @@ def main
"Returning from proposal_language::AskUser() with: %1",
@ret
)
elsif @func == "Description"
when "Description"
# Fill return map.
#
# Static values do just nicely here, no need to call a function.
Expand Down
84 changes: 43 additions & 41 deletions language/src/clients/select_language.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,79 +223,79 @@ def main
@help_text = ""
# help text (language dependent packages) - at the end of help
@packages_help = _(
"<p>\n" +
"Additional packages with support for the selected primary and secondary languages will be installed. Packages no longer needed will be removed.\n" +
"</p>"
"<p>\n" \
"Additional packages with support for the selected primary and secondary languages will be installed. Packages no longer needed will be removed.\n" \
"</p>"
)

if Stage.initial
# help text for initial (first time) language screen
@help_text = _(
"<p>\n" +
"Choose the <b>Language</b> to use during installation and for\n" +
"the installed system.\n" +
"</p>\n"
"<p>\n" \
"Choose the <b>Language</b> to use during installation and for\n" \
"the installed system.\n" \
"</p>\n"
)

# help text, continued
@help_text = Ops.add(
@help_text,
_(
"<p>\n" +
"Click <b>Next</b> to proceed to the next dialog.\n" +
"</p>\n"
"<p>\n" \
"Click <b>Next</b> to proceed to the next dialog.\n" \
"</p>\n"
)
)

# help text, continued
@help_text = Ops.add(
@help_text,
_(
"<p>\n" +
"Nothing will happen to your computer until you confirm\n" +
"all your settings in the last installation dialog.\n" +
"</p>\n"
"<p>\n" \
"Nothing will happen to your computer until you confirm\n" \
"all your settings in the last installation dialog.\n" \
"</p>\n"
)
)
if @set_default
# help text, continued
@help_text = Ops.add(
@help_text,
_(
"<p>\n" +
"You can select <b>Abort</b> at any time to abort the\n" +
"installation process.\n" +
"</p>\n"
"<p>\n" \
"You can select <b>Abort</b> at any time to abort the\n" \
"installation process.\n" \
"</p>\n"
)
)
end
else
# different help text when called after installation
# in an installed system
@help_text = _(
"<p>\n" +
"Choose the new <b>Language</b> for your system.\n" +
"</p>\n"
"<p>\n" \
"Choose the new <b>Language</b> for your system.\n" \
"</p>\n"
)
end

if @more_languages
# help text when "multiple languages" are suported 1/2
@help_text = _(
"<p>\n" +
"Choose the new <b>Primary Language</b> for your system.\n" +
"</p>\n"
"<p>\n" \
"Choose the new <b>Primary Language</b> for your system.\n" \
"</p>\n"
)

if @adapt_term
# help text for 'adapt keyboard checkbox'
@help_text = Ops.add(
@help_text,
_(
"<p>\n" +
"Check <b>Adapt Keyboard Layout</b> to change the keyboard layout to the primary language.\n" +
"Check <b>Adapt Time Zone</b> to change the current time zone according to the primary language. If the keyboard layout or time zone is already adapted to the default language setting, the respective option is disabled.\n" +
"</p>\n"
"<p>\n" \
"Check <b>Adapt Keyboard Layout</b> to change the keyboard layout to the primary language.\n" \
"Check <b>Adapt Time Zone</b> to change the current time zone according to the primary language. If the keyboard layout or time zone is already adapted to the default language setting, the respective option is disabled.\n" \
"</p>\n"
)
)
end
Expand All @@ -304,10 +304,10 @@ def main
@help_text = Ops.add(
@help_text,
_(
"<p>\n" +
"<b>Secondary Languages</b><br>\n" +
"In the selection box, specify additional languages to use on your system.\n" +
"</p>\n"
"<p>\n" \
"<b>Secondary Languages</b><br>\n" \
"In the selection box, specify additional languages to use on your system.\n" \
"</p>\n"
)
)

Expand Down Expand Up @@ -350,7 +350,7 @@ def main
@kbd_adapt = @set_default && !Mode.config
# adapt timezone for language?
@tmz_adapt = @set_default && !Mode.config
begin
loop do
@ret = Wizard.UserInput
Builtins.y2debug("UserInput() returned %1", @ret)

Expand Down Expand Up @@ -554,7 +554,8 @@ def main
end
end
end
end until @ret == :next || @ret == :back
break if @ret == :next || @ret == :back
end

Convert.to_symbol(@ret)
end
Expand All @@ -563,11 +564,11 @@ def main
def LanguageExpertDialog
# help text for langauge expert screen
help_text = _(
"<p>\n" +
"Here, fine-tune settings for the language handling.\n" +
"These settings are written into the file <tt>/etc/sysconfig/language</tt>.\n" +
"If unsure, use the default values already selected.\n" +
"</p>\n"
"<p>\n" \
"Here, fine-tune settings for the language handling.\n" \
"These settings are written into the file <tt>/etc/sysconfig/language</tt>.\n" \
"If unsure, use the default values already selected.\n" \
"</p>\n"
)

# help text for langauge expert screen
Expand Down Expand Up @@ -639,7 +640,7 @@ def LanguageExpertDialog

ret = :none
retval = :expert
begin
loop do
ret = Convert.to_symbol(UI.UserInput)
if ret == :ok
val = {}
Expand All @@ -655,7 +656,8 @@ def LanguageExpertDialog
retval = :changed_locale
end
end
end until [:cancel, :ok].include?(ret)
break if [:cancel, :ok].include?(ret)
end
UI.CloseDialog
retval
end
Expand Down
12 changes: 5 additions & 7 deletions language/src/modules/Language.rb
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,8 @@ def correct_language(language, error_report: true)
# with variable content - do not translate them, please.
if error_report
Report.Error(
format(_("Language '%{language}' was not found within the list of supported languages\n" +
"available at %{directory}.\n\nFallback language %{fallback} will be used."), language:, directory: @languages_directory, fallback: DEFAULT_FALLBACK_LANGUAGE)
format(_("Language '%{language}' was not found within the list of supported languages\n" \
"available at %{directory}.\n\nFallback language %{fallback} will be used."), language:, directory: @languages_directory, fallback: DEFAULT_FALLBACK_LANGUAGE)
)
end

Expand All @@ -420,24 +420,22 @@ def adapt_install_inf
yinf = yinf_ref.value
lines = AsciiFile.FindLineField(yinf, 0, "Language:")

yinf_ref = arg_ref(yinf)
if Ops.greater_than(Builtins.size(lines), 0)
yinf_ref = arg_ref(yinf)
AsciiFile.ChangeLineField(
yinf_ref,
Ops.get_integer(lines, 0, -1),
1,
@language
)
yinf = yinf_ref.value
else
yinf_ref = arg_ref(yinf)
AsciiFile.AppendLine(yinf_ref, ["Language:", @language])
yinf = yinf_ref.value
end
yinf = yinf_ref.value

yinf_ref = arg_ref(yinf)
AsciiFile.RewriteFile(yinf_ref, "/etc/yast.inf")
yinf = yinf_ref.value
yinf_ref.value
end

# Set module to selected language.
Expand Down
4 changes: 2 additions & 2 deletions timezone/src/clients/timezone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def TimezoneSequence

# Handler for timezone summary
def TimezoneSummaryHandler(options)
options = deep_copy(options)
deep_copy(options)
# summary label
CommandLine.Print(
Builtins.sformat(_("Current Time Zone:\t%1"), Timezone.timezone)
Expand Down Expand Up @@ -181,7 +181,7 @@ def TimezoneSummaryHandler(options)

# Handler for listing timezone layouts
def TimezoneListHandler(options)
options = deep_copy(options)
deep_copy(options)
Builtins.foreach(Timezone.get_zonemap) do |zone|
CommandLine.Print("")
# summary label
Expand Down
Loading

0 comments on commit a0960be

Please sign in to comment.