Showing 62 of 62 total issues
Similar blocks of code found in 2 locations. Consider refactoring. Open
module LicenseFinder
class JunitReport < ErbReport
ROOT_PATH = Pathname.new(__FILE__).dirname
TEMPLATE_PATH = ROOT_PATH.join('templates')
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 53.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
module LicenseFinder
class XmlReport < ErbReport
ROOT_PATH = Pathname.new(__FILE__).dirname
TEMPLATE_PATH = ROOT_PATH.join('templates')
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 53.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Method get_yarn_packages
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
def get_yarn_packages(json_objects)
packages = []
incompatible_packages = []
json_objects.each do |json_object|
license = json_object['value']
Method current_packages
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def current_packages
unless File.exist?('pubspec.lock')
raise PubError, "No checked-out Pub packages found.
Please install your dependencies first."
end
- Read upRead up
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
Method current_packages
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def current_packages
# check if the minimum version of PNPM is met
raise 'The minimum PNPM version is not met, requires 7.17.0 or later' unless supported_pnpm?
# check if the project directory has workspace file
- Read upRead up
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
Method action_items
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def action_items
finder = LicenseAggregator.new(config, aggregate_paths)
any_packages = finder.any_packages?
unapproved = finder.unapproved
restricted = finder.restricted
- Read upRead up
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
Method options
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
def options # rubocop:disable Metrics/AbcSize
{
logger: logger,
project_path: config.project_path,
log_directory: File.join(config.log_directory, project_name),
Method packages_from_output
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
def packages_from_output(output, path)
package_lines = output.split("\n")
packages_by_sha = {}
package_lines.each do |p|
package_path, sha, repo = p.split
Method get_pnpm_packages
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
def get_pnpm_packages(json_objects)
packages = []
incompatible_packages = []
json_objects.map do |_, value|
Method get_yarn_packages
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def get_yarn_packages(json_objects)
packages = []
incompatible_packages = []
json_objects.each do |json_object|
license = json_object['value']
- Read upRead up
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
Method flattened_dependencies
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def flattened_dependencies(npm_json, existing_packages = {})
identifier = Identifier.from_hash npm_json
if existing_packages[identifier].nil?
existing_packages[identifier] = package_for_dependency(npm_json) if identifier
npm_json.fetch('dependencies', {}).values.map do |d|
- Read upRead up
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
Method initialize
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def initialize(name, version, license_text, url, options = {})
Method conda_search_info
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def conda_search_info(list_entry)
command = 'conda search --info --json '
command += "--channel #{list_entry['channel']} " if list_entry['channel'] && !list_entry['channel'].empty?
command += "'#{list_entry['name']} #{list_entry['version']}'"
- Read upRead up
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
Method current_packages_with_relations
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def current_packages_with_relations
begin
packages = current_packages
rescue StandardError => e
raise e unless @prepare_no_fail
- Read upRead up
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
Method parse
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def parse(info)
@lines = info.lines.map(&:chomp)
@state = :project_level # state of the state machine
@projects = [] # list of projects
@current_project = nil # current project being populated in the SM
- Read upRead up
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
Method definition
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def definition(name, version)
response = request("https://pypi.org/pypi/#{name}/#{version}/json")
response.is_a?(Net::HTTPSuccess) ? JSON.parse(response.body).fetch('info', {}) : {}
rescue *CONNECTION_ERRORS => e
raise e, "Unable to read package from pypi.org #{name} #{version}: #{e}" unless @prepare_no_fail
- Read upRead up
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
Method packages_lines
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def packages_lines(stdout)
packages_lines, last_package_lines =
stdout
.each_line
.map(&:strip)
- Read upRead up
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
Method author_names
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def author_names
names = []
if @json['author'].is_a?(Array)
# "author":["foo","bar"] isn't valid according to the NPM package.json schema, but can be found in the wild.
names += @json['author'].map { |a| author_name(a) }
- Read upRead up
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
Method go_list
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def go_list
Dir.chdir(project_path) do
# avoid checking canonical import path. some projects uses
# non-canonical import path and rely on the fact that the deps are
# checked in. Canonical paths are only checked by `go get'. We
- Read upRead up
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
Method current_packages
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def current_packages
install_command = 'conan install .'
Dir.chdir(project_path) { Cmd.run(install_command) }
deps = deps_list(project_path)
- Read upRead up
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"