From c8d11b8bdb97a1a2f8aaf5deca5f1c6c7c0d2688 Mon Sep 17 00:00:00 2001 From: Shubhendra Singh Chauhan Date: Mon, 1 Feb 2021 01:56:09 +0530 Subject: [PATCH] Fixed code quality issues (#15541) * Added .deepsource.toml * Removed bad use of `alias` * Fixed operand order in the binary expression * Prefixed unused method arguments with an underscore * Replaced the old OpenSSL algorithmic constants with the newer strings initializers. * Removed unnecessary UTF-8 encoding comment --- .deepsource.toml | 18 ++++++++++++++++++ config/initializers/fast_blank.rb | 2 +- config/initializers/simple_form.rb | 4 ++-- config/initializers/twitter_regex.rb | 2 +- lib/json_ld/identity.rb | 1 - lib/json_ld/security.rb | 1 - lib/mastodon/email_domain_blocks_cli.rb | 2 +- lib/paperclip/color_extractor.rb | 4 ++-- .../activitypub/linked_data_signature_spec.rb | 2 +- 9 files changed, 26 insertions(+), 10 deletions(-) create mode 100644 .deepsource.toml diff --git a/.deepsource.toml b/.deepsource.toml new file mode 100644 index 000000000..73d38901c --- /dev/null +++ b/.deepsource.toml @@ -0,0 +1,18 @@ +version = 1 + +test_patterns = ["/app/javascript/mastodon/**/__tests__/**"] + +[[analyzers]] +name = "ruby" +enabled = true + +[[analyzers]] +name = "javascript" +enabled = true + + [analyzers.meta] + environment = [ + "nodejs", + "browser", + "jest" + ] diff --git a/config/initializers/fast_blank.rb b/config/initializers/fast_blank.rb index 174ea7664..f0b7cac78 100644 --- a/config/initializers/fast_blank.rb +++ b/config/initializers/fast_blank.rb @@ -1,5 +1,5 @@ if String.method_defined?(:blank_as?) class String - alias_method :blank?, :blank_as? + alias blank? blank_as? end end diff --git a/config/initializers/simple_form.rb b/config/initializers/simple_form.rb index 3dc48ef08..3a2097d2f 100644 --- a/config/initializers/simple_form.rb +++ b/config/initializers/simple_form.rb @@ -1,7 +1,7 @@ # Use this setup block to configure all options available in SimpleForm. module AppendComponent - def append(wrapper_options = nil) + def append(_wrapper_options = nil) @append ||= begin options[:append].to_s.html_safe if options[:append].present? end @@ -9,7 +9,7 @@ module AppendComponent end module RecommendedComponent - def recommended(wrapper_options = nil) + def recommended(_wrapper_options = nil) return unless options[:recommended] options[:label_text] = ->(raw_label_text, _required_label_text, _label_present) { safe_join([raw_label_text, ' ', content_tag(:span, I18n.t('simple_form.recommended'), class: 'recommended')]) } nil diff --git a/config/initializers/twitter_regex.rb b/config/initializers/twitter_regex.rb index 7f99a0005..aca85dd43 100644 --- a/config/initializers/twitter_regex.rb +++ b/config/initializers/twitter_regex.rb @@ -75,7 +75,7 @@ module Twitter # XMPP or magnet URIs an empty array will be returned. # # If a block is given then it will be called for each XMPP URI. - def extract_extra_uris_with_indices(text, options = {}) # :yields: uri, start, end + def extract_extra_uris_with_indices(text, _options = {}) # :yields: uri, start, end return [] unless text && text.index(":") urls = [] diff --git a/lib/json_ld/identity.rb b/lib/json_ld/identity.rb index 4fb3f8e9d..f41899150 100644 --- a/lib/json_ld/identity.rb +++ b/lib/json_ld/identity.rb @@ -1,4 +1,3 @@ -# -*- encoding: utf-8 -*- # frozen_string_literal: true # This file generated automatically from http://w3id.org/identity/v1 require 'json/ld' diff --git a/lib/json_ld/security.rb b/lib/json_ld/security.rb index a6fbce95f..ef5391340 100644 --- a/lib/json_ld/security.rb +++ b/lib/json_ld/security.rb @@ -1,4 +1,3 @@ -# -*- encoding: utf-8 -*- # frozen_string_literal: true # This file generated automatically from http://w3id.org/security/v1 require 'json/ld' diff --git a/lib/mastodon/email_domain_blocks_cli.rb b/lib/mastodon/email_domain_blocks_cli.rb index 55a637d68..f79df302a 100644 --- a/lib/mastodon/email_domain_blocks_cli.rb +++ b/lib/mastodon/email_domain_blocks_cli.rb @@ -113,7 +113,7 @@ module Mastodon result = entry.destroy if result - processed += 1 + children_count + processed += children_count + 1 else say("#{domain} could not be unblocked.", :red) failed += 1 diff --git a/lib/paperclip/color_extractor.rb b/lib/paperclip/color_extractor.rb index a70a3d21f..d3b8e1022 100644 --- a/lib/paperclip/color_extractor.rb +++ b/lib/paperclip/color_extractor.rb @@ -55,7 +55,7 @@ module Paperclip # If we don't have enough colors for accent and foreground, generate # new ones by manipulating the background color (2 - foreground_colors.size).times do |i| - foreground_colors << lighten_or_darken(background_color, 35 + (15 * i)) + foreground_colors << lighten_or_darken(background_color, 35 + (i * 15)) end # We want the color with the highest contrast to background to be the foreground one, @@ -147,7 +147,7 @@ module Paperclip g = l.to_f b = l.to_f # achromatic else - q = l < 0.5 ? l * (1 + s) : l + s - l * s + q = l < 0.5 ? l * (s + 1) : l + s - l * s p = 2 * l - q r = hue_to_rgb(p, q, h + 1 / 3.0) g = hue_to_rgb(p, q, h) diff --git a/spec/lib/activitypub/linked_data_signature_spec.rb b/spec/lib/activitypub/linked_data_signature_spec.rb index 1f413eec9..2222c46fb 100644 --- a/spec/lib/activitypub/linked_data_signature_spec.rb +++ b/spec/lib/activitypub/linked_data_signature_spec.rb @@ -81,6 +81,6 @@ RSpec.describe ActivityPub::LinkedDataSignature do options_hash = Digest::SHA256.hexdigest(canonicalize(options.merge('@context' => ActivityPub::LinkedDataSignature::CONTEXT))) document_hash = Digest::SHA256.hexdigest(canonicalize(document)) to_be_verified = options_hash + document_hash - Base64.strict_encode64(from_account.keypair.sign(OpenSSL::Digest::SHA256.new, to_be_verified)) + Base64.strict_encode64(from_account.keypair.sign(OpenSSL::Digest.new('SHA256'), to_be_verified)) end end