keepcosmos/terjira

View on GitHub
lib/terjira/utils/file_cache.rb

Summary

Maintainability
A
1 hr
Test Coverage

Method purge_dir has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

    def purge_dir(dir)
      Dir.foreach(dir) do |f|
        next if f =~ /^\.\.?$/
        path = File.join(dir, f)
        if File.directory?(path)
Severity: Minor
Found in lib/terjira/utils/file_cache.rb - About 1 hr to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Avoid using Marshal.load.
Open

        result = Marshal.load(f)
Severity: Minor
Found in lib/terjira/utils/file_cache.rb by rubocop

This cop checks for the use of Marshal class methods which have potential security issues leading to remote code execution when loading from an untrusted source.

Example:

# bad
Marshal.load("{}")
Marshal.restore("{}")

# good
Marshal.dump("{}")

# okish - deep copy hack
Marshal.load(Marshal.dump({}))

Use 0o for octal literals.
Open

      File.chmod(0600, f) unless File.stat(f).mode.to_s(8) =~ /600/
Severity: Minor
Found in lib/terjira/utils/file_cache.rb by rubocop

This cop checks for octal, hex, binary and decimal literals using uppercase prefixes and corrects them to lowercase prefix or no prefix (in case of decimals). eg. for octal use 0o instead of 0 or 0O.

Can be configured to use 0 only for octal literals using EnforcedOctalStyle => zero_only

There are no issues that match your filters.

Category
Status