Showing 49 of 49 total issues
Complex method Spree::Inventory::Providers::Fake::MetadataProvider#call (27.6) Open
def call
return if isbn == UNKNOWN_ISBN
{
title: book_title,
- Read upRead up
- Exclude checks
Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.
You can read more about ABC metrics or the flog tool
Complex method describe(creation)::context(with known isbn)::context(with long title)::it#creates product (27.1) Open
it 'creates product' do
expect(product.name).to eq long_title
expect(product.meta_title).to eq long_title.truncate(255)
- Read upRead up
- Exclude checks
Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.
You can read more about ABC metrics or the flog tool
Complex method describe(creation)::context(with known isbn)::context#with variant notes (25.8) Open
context 'with variant notes' do
Spree::Variant.class_eval do
attr_accessor :notes
end
- Read upRead up
- Exclude checks
Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.
You can read more about ABC metrics or the flog tool
Complex method Spree::Inventory::Providers::DefaultVariantProvider#create_product (25.5) Open
def create_product(identifier)
metadata = find_metadata(identifier)
raise ImportError, t('metadata_not_found', default: I18n.t('actions.spree.inventory.providers.default_variant_provider.metadata_not_found')) if metadata.blank?
create_stock_location
- Read upRead up
- Exclude checks
Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.
You can read more about ABC metrics or the flog tool
Complex method context(when provider is specified)::context#with not existing provider (25.2) Open
context 'with not existing provider' do
it { expect(upload.reload.upload_errors.count).to eq(1) }
it { expect(Spree::Product.count).to eq(0) }
- Read upRead up
- Exclude checks
Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.
You can read more about ABC metrics or the flog tool
Method build_option_value
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def build_option_value(opt_name, opt_value)
# no option values on master
return if is_master
option_type = Spree::OptionType.where(name: opt_name).first_or_initialize do |o|
- 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
Complex method describe(#check_product_type)::context#with not supported product type (24.1) Open
context 'with not supported product type' do
subject(:upload) { described_class.call(format: file_format, file_path: 'ean', product_type: product_type) }
let(:product_type) { 'electronics' }
- Read upRead up
- Exclude checks
Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.
You can read more about ABC metrics or the flog tool
Complex method describe#upload flow (24.1) Open
describe 'upload flow', run_jobs: true do
let(:file_path) { File.join(Dir.pwd, 'spec/fixtures', 'inventory.update.csv') }
let(:variant) { Spree::Variant.last }
before { upload }
- Read upRead up
- Exclude checks
Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.
You can read more about ABC metrics or the flog tool
Complex method describe##check_format (22.7) Open
describe '#check_format' do
let(:file_format) { 'csv1' }
it { expect { upload }.not_to change(Spree::Upload, :count) }
it { expect(upload[:errors].first).to include('"format"=>["must be one of') }
- Read upRead up
- Exclude checks
Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.
You can read more about ABC metrics or the flog tool
Complex method Spree::Inventory::BaseImportAction#call (22.2) Open
def call # rubocop:disable Metrics/MethodLength
total = 0
args = []
map_items do |item_json, index|
- Read upRead up
- Exclude checks
Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.
You can read more about ABC metrics or the flog tool
Complex method Spree::Inventory::Providers::DefaultVariantProvider#update_variant (22.0) Open
def update_variant(variant, item)
variant.price = variant.cost_price = item[:price]
variant.notes = item[:notes] if variant.respond_to?(:notes)
update_variant_hook(variant, item)
variant.build_options(variant_options(item))
- Read upRead up
- Exclude checks
Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.
You can read more about ABC metrics or the flog tool
Complex method Spree::ImportInventoryItemWorker#perform (20.7) Open
def perform(upload_item_id)
item = UploadItem.find(upload_item_id)
upload = item.upload
options = item.options
- Read upRead up
- Exclude checks
Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.
You can read more about ABC metrics or the flog tool
Complex method describe(creation)::context(with known isbn)::context#with taxonomy option (20.2) Open
context 'with taxonomy option' do
let(:options) { { taxonomy: 'Books' } }
it { expect(product.taxons.first.taxonomy.name).to eq('Books') }
- Read upRead up
- Exclude checks
Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.
You can read more about ABC metrics or the flog tool
Code block style Open
```ruby
- Exclude checks
Line is too long. [156/150] Open
worker = UploadItem.bulk_insert(:upload_id, :index, :item_json, :options, :created_at, :updated_at, set_size: BATCH_SIZE, return_primary_keys: true)
- Read upRead up
- Exclude checks
This cop checks the length of lines in the source code.
The maximum length is configurable.
The tab size is configured in the IndentationWidth
of the Layout/Tab
cop.
Use //
comments everywhere Open
/*
- Exclude checks
Code block style Open
```ruby
- Exclude checks
Line length Open
First bundle your dependencies, then run `rake`. `rake` will default to building the dummy app if it does not exist, then it will run specs. The dummy app can be regenerated by using `rake test_app`.
- Read upRead up
- Exclude checks
MD013 - Line length
Tags: line_length
Aliases: line-length Parameters: linelength, codeblocks, tables (number; default 80, boolean; default true)
This rule is triggered when there are lines that are longer than the configured line length (default: 80 characters). To fix this, split the line up into multiple lines.
This rule has an exception where there is no whitespace beyond the configured line length. This allows you to still include items such as long URLs without being forced to break them in the middle.
You also have the option to exclude this rule for code blocks and tables. To
do this, set the code_blocks
and/or tables
parameters to false.
Code blocks are included in this rule by default since it is often a requirement for document readability, and tentatively compatible with code rules. Still, some languages do not lend themselves to short lines.
Pass &:to_i
as an argument to cast
instead of a block. Open
item_json[:quantity] = cast(item_json[:quantity]) { |v| v.to_i }
- Read upRead up
- Exclude checks
Use symbols as procs when possible.
Example:
# bad
something.map { |s| s.upcase }
# good
something.map(&:upcase)
Line length Open
* by writing code (*no patch is too small*: fix typos, add comments, clean up inconsistent whitespace)
- Read upRead up
- Exclude checks
MD013 - Line length
Tags: line_length
Aliases: line-length Parameters: linelength, codeblocks, tables (number; default 80, boolean; default true)
This rule is triggered when there are lines that are longer than the configured line length (default: 80 characters). To fix this, split the line up into multiple lines.
This rule has an exception where there is no whitespace beyond the configured line length. This allows you to still include items such as long URLs without being forced to break them in the middle.
You also have the option to exclude this rule for code blocks and tables. To
do this, set the code_blocks
and/or tables
parameters to false.
Code blocks are included in this rule by default since it is often a requirement for document readability, and tentatively compatible with code rules. Still, some languages do not lend themselves to short lines.