public-market/spree_batch_api

View on GitHub

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,

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)

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

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

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) }

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|
Severity: Minor
Found in app/models/spree/variant_decorator.rb - About 45 mins 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

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' }

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 }

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') }

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|

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))

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

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') }

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
Severity: Info
Found in README.md by markdownlint

Line is too long. [169/150]
Open

          raise ImportError, t('metadata_not_found', default: I18n.t('actions.spree.inventory.providers.default_variant_provider.metadata_not_found')) if metadata.blank?

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.

Do not use a block to set a static value to an attribute.
Open

    metadata do
      {
        file_path: './spec/fixtures/inventory.csv',
        format: 'csv',
        product_type: 'fake'

HTML is not aligned with text: <<-HTML.
Open

              HTML

Checks the indentation of here document closings.

Example:

# bad
class Foo
  def bar
    <<~SQL
      'Hi'
  SQL
  end
end

# good
class Foo
  def bar
    <<~SQL
      'Hi'
    SQL
  end
end

# bad

# heredoc contents is before closing heredoc.
foo arg,
    <<~EOS
  Hi
    EOS

# good
foo arg,
    <<~EOS
  Hi
EOS

# good
foo arg,
    <<~EOS
      Hi
    EOS

Code block style
Open

    ```ruby
Severity: Info
Found in README.md by markdownlint

Line length
Open

* by writing code (*no patch is too small*: fix typos, add comments, clean up inconsistent whitespace)
Severity: Info
Found in CONTRIBUTING.md by markdownlint

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.

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)

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.

Severity
Category
Status
Source
Language