Skip to content

Commit

Permalink
Merge pull request #30 from yast/update_rubocop
Browse files Browse the repository at this point in the history
Update rubocop
  • Loading branch information
jreidinger committed Dec 29, 2023
2 parents 8a35ef9 + 758931b commit d0ae145
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 165 deletions.
118 changes: 5 additions & 113 deletions .rubocop.yml
@@ -1,48 +1,6 @@
# use the shared YaST defaults
inherit_from:
/usr/share/YaST2/data/devtools/data/rubocop-0.71.0_yast_style.yml

# Offense count: 1
# Cop supports --auto-correct.
Layout/EmptyLineAfterGuardClause:
Exclude:
- 'src/modules/Pam.rb'

# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: AllowAdjacentOneLineDefs, NumberOfEmptyLines.
Layout/EmptyLineBetweenDefs:
Exclude:
- 'src/modules/Autologin.rb'
- 'src/modules/Nsswitch.rb'

# Offense count: 3
# Cop supports --auto-correct.
Layout/EmptyLines:
Exclude:
- 'src/modules/Autologin.rb'
- 'src/modules/Nsswitch.rb'

# Offense count: 15
# Cop supports --auto-correct.
# Configuration parameters: IndentationWidth.
Layout/Tab:
Exclude:
- 'src/modules/Autologin.rb'
- 'src/modules/Nsswitch.rb'
- 'src/modules/Pam.rb'

# Offense count: 1
Lint/ShadowingOuterLocalVariable:
Exclude:
- 'src/modules/Pam.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods.
Lint/UnusedMethodArgument:
Exclude:
- 'src/modules/Autologin.rb'
/usr/share/YaST2/data/devtools/data/rubocop-1.24.1_yast_style.yml

# Offense count: 5
# Configuration parameters: CountComments, ExcludedMethods.
Expand All @@ -51,18 +9,14 @@ Metrics/BlockLength:
Exclude:
- 'test/**/*'

# Offense count: 3
# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms.
# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
# Backward compatibility
Naming/FileName:
Exclude:
- 'src/modules/Autologin.rb'
- 'src/modules/Nsswitch.rb'
- 'src/modules/Pam.rb'

# Offense count: 16
# Configuration parameters: .
# SupportedStyles: snake_case, camelCase
# Backward compatibility
Naming/MethodName:
Exclude:
- 'src/modules/Nsswitch.rb'
Expand All @@ -78,68 +32,6 @@ Style/Documentation:
- 'src/modules/Nsswitch.rb'
- 'src/modules/Pam.rb'

# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: compact, expanded
Style/EmptyMethod:
Exclude:
- 'src/modules/Pam.rb'

# Offense count: 3
# Cop supports --auto-correct.
Style/Encoding:
Exclude:
- 'src/modules/Autologin.rb'
- 'src/modules/Nsswitch.rb'
- 'src/modules/Pam.rb'

# Offense count: 8
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: always, never
# Disable as it is too bug prone to enable it
Style/FrozenStringLiteralComment:
Exclude:
- 'Rakefile'
- 'src/lib/cfa/nsswitch.rb'
- 'src/modules/Autologin.rb'
- 'src/modules/Nsswitch.rb'
- 'src/modules/Pam.rb'
- 'test/cfa/nsswitch_test.rb'
- 'test/nsswitch_test.rb'
- 'test/test_helper.rb'

# Offense count: 1
# Configuration parameters: MinBodyLength.
Style/GuardClause:
Exclude:
- 'src/lib/cfa/nsswitch.rb'

# Offense count: 43
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
Style/HashSyntax:
Exclude:
- 'src/modules/Autologin.rb'
- 'src/modules/Nsswitch.rb'
- 'src/modules/Pam.rb'

# Offense count: 2
# Cop supports --auto-correct.
Style/LineEndConcatenation:
Exclude:
- 'src/modules/Autologin.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: predicate, comparison
Style/NilComparison:
Exclude:
- 'src/modules/Autologin.rb'

# Offense count: 1
# Cop supports --auto-correct.
Style/RedundantBegin:
Exclude:
- 'test/nsswitch_test.rb'
Enabled: false
8 changes: 4 additions & 4 deletions src/lib/cfa/nsswitch.rb
Expand Up @@ -151,10 +151,10 @@ def save
@parser.file_name = write_path if @parser.respond_to?(:file_name=)
content = @parser.serialize(data)

if content != @current_content
@file_handler.write(write_path, content)
@current_content = content
end
return if content == @current_content

@file_handler.write(write_path, content)
@current_content = content
end

private
Expand Down
38 changes: 17 additions & 21 deletions src/modules/Autologin.rb
@@ -1,5 +1,3 @@
# encoding: utf-8

# ------------------------------------------------------------------------------
# Copyright (c) 2006-2012 Novell, Inc. All Rights Reserved.
#
Expand Down Expand Up @@ -93,17 +91,16 @@ def Read
)
) == "yes"

@user = "" if @user == nil || @user == ""
@user ||= ""

@used = @user != ""
@used
end


# Write autologin settings
# @param [Boolean] write_only when true, suseconfig script will not be run
# @param [Boolean] _write_only deprecated. suseconfig is dead
# @return written anything?
def Write(write_only)
def Write(_write_only)
return false if !available || !@modified

Builtins.y2milestone(
Expand Down Expand Up @@ -163,9 +160,9 @@ def AskForDisabling(new)
# like "Now LDAP was enabled")
question = Builtins.sformat(
_(
"The automatic login feature is enabled for user %1.\n" +
"%2\n" +
"Disable automatic login?"
"The automatic login feature is enabled for user %1.\n" \
"%2\n" \
"Disable automatic login?"
),
@user,
new
Expand Down Expand Up @@ -211,18 +208,17 @@ def pkg_lazy_init
@pkg_initialized = true
end


publish :variable => :user, :type => "string"
publish :variable => :pw_less, :type => "boolean"
publish :variable => :used, :type => "boolean"
publish :variable => :modified, :type => "boolean"
publish :function => :Read, :type => "boolean ()"
publish :function => :Write, :type => "boolean (boolean)"
publish :function => :Disable, :type => "void ()"
publish :function => :Use, :type => "void (boolean)"
publish :function => :supported?, :type => "boolean ()"
publish :function => :DisableAndWrite, :type => "boolean (boolean)"
publish :function => :AskForDisabling, :type => "boolean (string)"
publish variable: :user, type: "string"
publish variable: :pw_less, type: "boolean"
publish variable: :used, type: "boolean"
publish variable: :modified, type: "boolean"
publish function: :Read, type: "boolean ()"
publish function: :Write, type: "boolean (boolean)"
publish function: :Disable, type: "void ()"
publish function: :Use, type: "void (boolean)"
publish function: :supported?, type: "boolean ()"
publish function: :DisableAndWrite, type: "boolean (boolean)"
publish function: :AskForDisabling, type: "boolean (string)"
end

Autologin = AutologinClass.new
Expand Down
11 changes: 4 additions & 7 deletions src/modules/Nsswitch.rb
@@ -1,5 +1,3 @@
# encoding: utf-8

# ------------------------------------------------------------------------------
# Copyright (c) 2006-2012 Novell, Inc. All Rights Reserved.
#
Expand Down Expand Up @@ -45,7 +43,6 @@ def ReadDb(db_name)
cfa_model.services_for(db_name)
end


# Writes a database entry as a list to nsswitch_conf or deletes an existing
# database entry
#
Expand Down Expand Up @@ -106,10 +103,10 @@ def reset
@cfa_model = nil
end

publish :function => :ReadDb, :type => "list <string> (string)"
publish :function => :WriteDb, :type => "boolean (string, list <string>)"
publish :function => :WriteAutofs, :type => "boolean (boolean, string)"
publish :function => :Write, :type => "boolean ()"
publish function: :ReadDb, type: "list <string> (string)"
publish function: :WriteDb, type: "boolean (string, list <string>)"
publish function: :WriteAutofs, type: "boolean (boolean, string)"
publish function: :Write, type: "boolean ()"

private

Expand Down
24 changes: 11 additions & 13 deletions src/modules/Pam.rb
@@ -1,5 +1,3 @@
# encoding: utf-8

# ------------------------------------------------------------------------------
# Copyright (c) 2006-2012 Novell, Inc. All Rights Reserved.
#
Expand Down Expand Up @@ -32,8 +30,7 @@ module Yast
class PamClass < Module
include Yast::Logger

def main
end
def main; end

PAM_CONFIG_BIN = "/usr/sbin/pam-config".freeze

Expand All @@ -46,22 +43,22 @@ def main
def List
begin
lines = Yast::Execute.locally!(PAM_CONFIG_BIN, "--list-modules",
:stdout => :capture).split("\n")
stdout: :capture).split("\n")
rescue Cheetah::ExecutionFailed => e
log.error "pam-config --list-modules failed #{e.message}"
return []
end

rx = /[ \t]*pam_([a-z0-9_]+)\.so[ \t]*/

mods = lines.reduce([]) do |mods, line|
res = lines.reduce([]) do |mods, line|
m = line.match(rx)
m ? mods.push(m[1]) : mods
end

log.info("pam modules #{mods}")
log.info("pam modules #{res}")

mods
res
end

# Query PAM configuration for status of given module
Expand All @@ -82,6 +79,7 @@ def Query(mod)
) do |line|
l = Builtins.splitstring(line, ":")
next if line == "" || Ops.less_than(Builtins.size(l), 2)

key = Ops.get_string(l, 0, "")
Ops.set(
ret,
Expand Down Expand Up @@ -135,11 +133,11 @@ def Set(mod, set)
set ? Add(mod) : Remove(mod)
end

publish :function => :Query, :type => "map (string)"
publish :function => :Enabled, :type => "boolean (string)"
publish :function => :Add, :type => "boolean (string)"
publish :function => :Remove, :type => "boolean (string)"
publish :function => :Set, :type => "boolean (string, boolean)"
publish function: :Query, type: "map (string)"
publish function: :Enabled, type: "boolean (string)"
publish function: :Add, type: "boolean (string)"
publish function: :Remove, type: "boolean (string)"
publish function: :Set, type: "boolean (string, boolean)"
end

Pam = PamClass.new
Expand Down
14 changes: 7 additions & 7 deletions test/nsswitch_test.rb
Expand Up @@ -31,13 +31,13 @@
let(:file_path) { "#{tmpdir}/etc/nsswitch.conf" }

around do |example|
begin
FileUtils.cp_r(original_data_example, tmpdir)
change_scr_root(tmpdir, &example)
nsswitch.reset
ensure
FileUtils.remove_entry(tmpdir)
end

FileUtils.cp_r(original_data_example, tmpdir)
change_scr_root(tmpdir, &example)
nsswitch.reset
ensure
FileUtils.remove_entry(tmpdir)

end

describe "#ReadDb" do
Expand Down

0 comments on commit d0ae145

Please sign in to comment.