Showing 2,661 of 2,661 total issues
File internal_package_update_message_spec.rb
has 336 lines of code (exceeds 250 allowed). Consider refactoring. Open
require 'spec_helper'
require 'messages/internal_package_update_message'
module VCAP::CloudController
RSpec.describe InternalPackageUpdateMessage do
File service_instance_update_managed.rb
has 335 lines of code (exceeds 250 allowed). Consider refactoring. Open
require 'services/service_brokers/service_client_provider'
require 'actions/metadata_update'
require 'cloud_controller/errors/api_error'
module VCAP::CloudController
File security_group_create_message_spec.rb
has 334 lines of code (exceeds 250 allowed). Consider refactoring. Open
require 'spec_helper'
require 'messages/security_group_create_message'
module VCAP::CloudController
RSpec.describe SecurityGroupCreateMessage do
Function 'porterStemmer' has a complexity of 26. Open
var porterStemmer = function porterStemmer(w) {
- Read upRead up
- Exclude checks
Limit Cyclomatic Complexity (complexity)
Cyclomatic complexity measures the number of linearly independent paths through a program's source code. This rule allows setting a cyclomatic complexity threshold.
function a(x) {
if (true) {
return x; // 1st path
} else if (false) {
return x+1; // 2nd path
} else {
return 4; // 3rd path
}
}
Rule Details
This rule is aimed at reducing code complexity by capping the amount of cyclomatic complexity allowed in a program. As such, it will warn when the cyclomatic complexity crosses the configured threshold (default is 20
).
Examples of incorrect code for a maximum of 2:
/*eslint complexity: ["error", 2]*/
function a(x) {
if (true) {
return x;
} else if (false) {
return x+1;
} else {
return 4; // 3rd path
}
}
Examples of correct code for a maximum of 2:
/*eslint complexity: ["error", 2]*/
function a(x) {
if (true) {
return x;
} else {
return 4;
}
}
Options
Optionally, you may specify a max
object property:
"complexity": ["error", 2]
is equivalent to
"complexity": ["error", { "max": 2 }]
Deprecated: the object property maximum
is deprecated. Please use the property max
instead.
When Not To Use It
If you can't determine an appropriate complexity limit for your code, then it's best to disable this rule.
Further Reading
Related Rules
- [max-depth](max-depth.md)
- [max-len](max-len.md)
- [max-nested-callbacks](max-nested-callbacks.md)
- [max-params](max-params.md)
- [max-statements](max-statements.md) Source: http://eslint.org/docs/rules/
Method generate_diff
has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring. Open
def generate_diff(app_manifests, space)
json_diff = []
recognized_top_level_keys = AppManifestMessage.allowed_keys.map(&:to_s).map(&:dasherize)
- 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
File api_schema.rb
has 329 lines of code (exceeds 250 allowed). Consider refactoring. Open
require 'vcap/config'
require 'cloud_controller/resource_pool'
module VCAP::CloudController
module ConfigSchemas
File manifest_process_update_message_spec.rb
has 329 lines of code (exceeds 250 allowed). Consider refactoring. Open
require 'spec_helper'
require 'messages/manifest_process_update_message'
module VCAP::CloudController
RSpec.describe ManifestProcessUpdateMessage do
File process_stats_presenter_spec.rb
has 329 lines of code (exceeds 250 allowed). Consider refactoring. Open
require 'spec_helper'
require 'presenters/v3/process_stats_presenter'
module VCAP::CloudController::Presenters::V3
RSpec.describe ProcessStatsPresenter do
File service_brokers_spec.rb
has 327 lines of code (exceeds 250 allowed). Consider refactoring. Open
require 'spec_helper'
require 'request_spec_shared_examples'
require 'cloud_controller'
require 'services'
require 'messages/service_broker_update_message'
File route_create_message_spec.rb
has 326 lines of code (exceeds 250 allowed). Consider refactoring. Open
require 'spec_helper'
require 'messages/route_create_message'
module VCAP::CloudController
RSpec.describe RouteCreateMessage do
Similar blocks of code found in 2 locations. Consider refactoring. Open
_focusable: function( element ) {
this.focusable = this.focusable.add( element );
this._on( element, {
focusin: function( event ) {
$( event.currentTarget ).addClass( "ui-state-focus" );
- 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 107.
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
_hoverable: function( element ) {
this.hoverable = this.hoverable.add( element );
this._on( element, {
mouseenter: function( event ) {
$( event.currentTarget ).addClass( "ui-state-hover" );
- 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 107.
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 update
has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring. Open
def update(app, message, lifecycle)
validate_not_changing_lifecycle_type!(app, lifecycle)
app.db.transaction do
app.lock!
- 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
File reoccurring_job_spec.rb
has 304 lines of code (exceeds 250 allowed). Consider refactoring. Open
require 'rails_helper'
require 'jobs/reoccurring_job'
module VCAP
module CloudController
File process_event_repository_spec.rb
has 304 lines of code (exceeds 250 allowed). Consider refactoring. Open
require 'spec_helper'
require 'repositories/process_event_repository'
module VCAP::CloudController
module Repositories
Class Service
has 27 methods (exceeds 20 allowed). Consider refactoring. Open
class Service < Sequel::Model
plugin :serialization
many_to_one :service_broker
one_to_many :service_plans
File space_quotas_create_message_spec.rb
has 297 lines of code (exceeds 250 allowed). Consider refactoring. Open
require 'spec_helper'
require 'messages/space_quotas_create_message'
module VCAP::CloudController
RSpec.describe SpaceQuotasCreateMessage do
Class ApplicationController
has 26 methods (exceeds 20 allowed). Consider refactoring. Open
class ApplicationController < ActionController::Base
include VCAP::CloudController
include V3ErrorsHelper
include VCAP::CloudController::ParamsHashifier
File desired_lrp_builder_spec.rb
has 291 lines of code (exceeds 250 allowed). Consider refactoring. Open
require 'spec_helper'
module VCAP::CloudController
module Diego
module Buildpack
File service_operation_shared.rb
has 289 lines of code (exceeds 250 allowed). Consider refactoring. Open
RSpec.shared_examples 'a model including the ServiceOperationMixin' do |service_class, operation_association, operation_class, service_key|
let(:service) { service_class.make }
before do
@service = service