Switch PercentLiteralDelimiters to new default

Let's change that to the new rubocop default, which is also the
suggestion in the ruby style guide.

See https://github.com/bbatsov/ruby-style-guide#percent-literal-braces

This was changed in diaspora too, see diaspora/diaspora#7466

It also includes the changes in the code. This was done with
`rubocop --auto-correct` and no we have zero offenses again.
This commit is contained in:
Benjamin Neff 2017-06-30 02:17:01 +02:00
parent 5730b88296
commit e26a86c173
No known key found for this signature in database
GPG key ID: 971464C3F1A90194
50 changed files with 80 additions and 90 deletions

View file

@ -189,16 +189,6 @@ Layout/EmptyLineBetweenDefs:
Style/NumericPredicate:
EnforcedStyle: comparison
# Old defaults from rubocop < 0.48.1 (Maybe change this in the future?)
Style/PercentLiteralDelimiters:
PreferredDelimiters:
default: '()'
'%i': '()'
'%I': '()'
'%r': '{}'
'%w': '()'
'%W': '()'
### backward compatibility
# only with ruby >= 2.3

View file

@ -1,2 +1,2 @@
# Don't log received xml data.
Rails.application.config.filter_parameters += %i(xml aes_key encrypted_magic_envelope)
Rails.application.config.filter_parameters += %i[xml aes_key encrypted_magic_envelope]

View file

@ -23,7 +23,7 @@ require "diaspora_federation/federation"
module DiasporaFederation
extend Logging
@callbacks = Callbacks.new %i(
@callbacks = Callbacks.new %i[
fetch_person_for_webfinger
fetch_person_for_hcard
save_person_after_webfinger
@ -36,7 +36,7 @@ module DiasporaFederation
fetch_public_entity
fetch_person_url_to
update_pod
)
]
# defaults
@http_concurrency = 20

View file

@ -32,7 +32,7 @@ module DiasporaFederation
XMLNS = "http://docs.oasis-open.org/ns/xri/xrd-1.0".freeze
# +Link+ element attributes
LINK_ATTRS = %i(rel type href template).freeze
LINK_ATTRS = %i[rel type href template].freeze
# format string for datetime (+Expires+ element)
DATETIME_FORMAT = "%Y-%m-%dT%H:%M:%SZ".freeze

View file

@ -100,7 +100,7 @@ module DiasporaFederation
# The order for signing
# @return [Array]
def signature_order
@signature_order || self.class.class_props.keys - %i(author_signature parent_author_signature parent)
@signature_order || self.class.class_props.keys - %i[author_signature parent_author_signature parent]
end
private
@ -145,7 +145,7 @@ module DiasporaFederation
data = super.tap do |hash|
hash[:parent_author_signature] = parent_author_signature || sign_with_parent_author_if_available.to_s
end
order = signature_order + %i(author_signature parent_author_signature)
order = signature_order + %i[author_signature parent_author_signature]
order.map {|element| [element, data[element] || ""] }.to_h
end

View file

@ -214,7 +214,7 @@ module DiasporaFederation
end
def setable_string?(type, val)
%i(string integer boolean).include?(type) && val.respond_to?(:to_s)
%i[string integer boolean].include?(type) && val.respond_to?(:to_s)
end
def setable_nested?(type, val)

View file

@ -30,7 +30,7 @@ module DiasporaFederation
def parse_element_from_value(type, value)
return if value.nil?
if %i(integer boolean timestamp).include?(type) && !value.is_a?(String)
if %i[integer boolean timestamp].include?(type) && !value.is_a?(String)
value
elsif type.instance_of?(Symbol)
parse_string(type, value)
@ -45,7 +45,7 @@ module DiasporaFederation
end
def from_json_sanity_validation(json_hash)
missing = %w(entity_type entity_data).map {|prop|
missing = %w[entity_type entity_data].map {|prop|
prop if json_hash[prop].nil?
}.compact.join(", ")
raise DeserializationError, "Required properties are missing in JSON object: #{missing}" unless missing.empty?

View file

@ -127,7 +127,7 @@ module DiasporaFederation
end
def property_type_valid?(type)
%i(string integer boolean timestamp).include?(type)
%i[string integer boolean timestamp].include?(type)
end
# Checks if the type extends {Entity}

View file

@ -4,7 +4,7 @@ module DiasporaFederation
class AccountDeletionValidator < Validation::Validator
include Validation
rule :author, %i(not_empty diaspora_id)
rule :author, %i[not_empty diaspora_id]
end
end
end

View file

@ -4,7 +4,7 @@ module DiasporaFederation
class AccountMigrationValidator < Validation::Validator
include Validation
rule :author, %i(not_empty diaspora_id)
rule :author, %i[not_empty diaspora_id]
rule :profile, :not_nil
end

View file

@ -4,8 +4,8 @@ module DiasporaFederation
class ContactValidator < Validation::Validator
include Validation
rule :author, %i(not_empty diaspora_id)
rule :recipient, %i(not_empty diaspora_id)
rule :author, %i[not_empty diaspora_id]
rule :recipient, %i[not_empty diaspora_id]
rule :following, :boolean
rule :sharing, :boolean
end

View file

@ -4,7 +4,7 @@ module DiasporaFederation
class ConversationValidator < Validation::Validator
include Validation
rule :author, %i(not_empty diaspora_id)
rule :author, %i[not_empty diaspora_id]
rule :guid, :guid
rule :subject, [:not_empty, length: {maximum: 255}]

View file

@ -4,7 +4,7 @@ module DiasporaFederation
class EventValidator < Validation::Validator
include Validation
rule :author, %i(not_empty diaspora_id)
rule :author, %i[not_empty diaspora_id]
rule :guid, :guid

View file

@ -4,7 +4,7 @@ module DiasporaFederation
class MessageValidator < Validation::Validator
include Validation
rule :author, %i(not_empty diaspora_id)
rule :author, %i[not_empty diaspora_id]
rule :guid, :guid
rule :conversation_guid, :guid

View file

@ -4,7 +4,7 @@ module DiasporaFederation
class ParticipationValidator < Validation::Validator
include Validation
rule :author, %i(not_empty diaspora_id)
rule :author, %i[not_empty diaspora_id]
rule :guid, :guid
rule :parent_guid, :guid
rule :parent_type, [:not_empty, regular_expression: {regex: /\APost\z/}]

View file

@ -6,9 +6,9 @@ module DiasporaFederation
rule :guid, :guid
rule :author, %i(not_empty diaspora_id)
rule :author, %i[not_empty diaspora_id]
rule :url, %i(not_nil URI)
rule :url, %i[not_nil URI]
rule :profile, :not_nil

View file

@ -6,7 +6,7 @@ module DiasporaFederation
rule :guid, :guid
rule :author, %i(not_empty diaspora_id)
rule :author, %i[not_empty diaspora_id]
rule :public, :boolean

View file

@ -4,7 +4,7 @@ module DiasporaFederation
class RelatedEntityValidator < Validation::Validator
include Validation
rule :author, %i(not_empty diaspora_id)
rule :author, %i[not_empty diaspora_id]
rule :local, :boolean
rule :public, :boolean
end

View file

@ -6,7 +6,7 @@ module DiasporaFederation
# @param [Validation::Validator] validator the validator in which it is included
def self.included(validator)
validator.class_eval do
rule :author, %i(not_empty diaspora_id)
rule :author, %i[not_empty diaspora_id]
rule :guid, :guid
rule :parent_guid, :guid
rule :parent, :not_nil

View file

@ -4,11 +4,11 @@ module DiasporaFederation
class ReshareValidator < Validation::Validator
include Validation
rule :root_author, %i(not_empty diaspora_id)
rule :root_author, %i[not_empty diaspora_id]
rule :root_guid, :guid
rule :author, %i(not_empty diaspora_id)
rule :author, %i[not_empty diaspora_id]
rule :guid, :guid

View file

@ -4,7 +4,7 @@ module DiasporaFederation
class RetractionValidator < Validation::Validator
include Validation
rule :author, %i(not_empty diaspora_id)
rule :author, %i[not_empty diaspora_id]
rule :target_guid, :guid
rule :target_type, :not_empty

View file

@ -4,7 +4,7 @@ module DiasporaFederation
class StatusMessageValidator < Validation::Validator
include Validation
rule :author, %i(not_empty diaspora_id)
rule :author, %i[not_empty diaspora_id]
rule :guid, :guid

View file

@ -9,11 +9,11 @@ module DiasporaFederation
rule :acct_uri, :not_empty
rule :hcard_url, [:not_nil, URI: %i(host path)]
rule :seed_url, %i(not_nil URI)
rule :profile_url, URI: %i(host path)
rule :atom_url, URI: %i(host path)
rule :salmon_url, URI: %i(host path)
rule :hcard_url, [:not_nil, URI: %i[host path]]
rule :seed_url, %i[not_nil URI]
rule :profile_url, URI: %i[host path]
rule :atom_url, URI: %i[host path]
rule :salmon_url, URI: %i[host path]
end
end
end

View file

@ -85,7 +85,7 @@ module DiasporaFederation
include Validation
rule :test, :boolean
rule :author, %i(not_empty diaspora_id)
rule :author, %i[not_empty diaspora_id]
rule :guid, :guid
end
end

View file

@ -1,6 +1,6 @@
module DiasporaFederation
describe Callbacks do
subject(:callbacks) { Callbacks.new %i(some_event another_event) }
subject(:callbacks) { Callbacks.new %i[some_event another_event] }
context "callbacks" do
it "defines a callback and calls it" do
@ -56,12 +56,12 @@ module DiasporaFederation
describe "#missing_handlers" do
it "contains all events if nothing isdefined" do
expect(callbacks.missing_handlers).to eq(%i(some_event another_event))
expect(callbacks.missing_handlers).to eq(%i[some_event another_event])
end
it "contains the missing events if not all events are defined" do
callbacks.on(:some_event) {}
expect(callbacks.missing_handlers).to eq(%i(another_event))
expect(callbacks.missing_handlers).to eq(%i[another_event])
end
it "is empty if all events are defined" do

View file

@ -19,10 +19,10 @@ XML
{
subject: "http://blog.example.com/article/id/314",
expires: DateTime.parse("2010-01-30T09:30:00Z"),
aliases: %w(
aliases: %w[
http://blog.example.com/cool_new_thing
http://blog.example.com/steve/article/7
),
],
properties: {
"http://blgx.example.net/ns/version" => "1.3",
"http://blgx.example.net/ns/ext" => nil

View file

@ -42,7 +42,7 @@ XML
it_behaves_like "an Entity subclass"
it_behaves_like "an XML Entity", %i(parent parent_guid)
it_behaves_like "an XML Entity", %i[parent parent_guid]
context "default values" do
it "allows no nested messages" do

View file

@ -13,7 +13,7 @@ module DiasporaFederation
let(:hash) { {guid: guid, author: author, parent_guid: parent_guid, parent: local_parent, property: property} }
let(:hash_with_fake_signatures) { hash.merge!(author_signature: "aa", parent_author_signature: "bb") }
let(:signature_order) { %i(author guid parent_guid property) }
let(:signature_order) { %i[author guid parent_guid property] }
let(:signature_data) { "#{author};#{guid};#{parent_guid};#{property}" }
describe "#initialize" do
@ -132,7 +132,7 @@ XML
end
it "accepts string names of known properties in signature_order" do
signature_order = %w(author guid parent_guid property new_property)
signature_order = %w[author guid parent_guid property new_property]
xml = Entities::SomeRelayable.new(
hash_with_fake_signatures, signature_order, "new_property" => new_property
).to_xml
@ -294,7 +294,7 @@ XML
let(:entity_class) { Entities::SomeRelayable }
it "contains the property order within the property_order property" do
property_order = %i(author guid parent_guid property)
property_order = %i[author guid parent_guid property]
json = entity_class.new(hash_with_fake_signatures, property_order).to_json.to_json
expect(json).to include_json(property_order: property_order.map(&:to_s))
@ -304,7 +304,7 @@ XML
entity = entity_class.new(hash_with_fake_signatures)
expect(
entity.to_json.to_json
).to include_json(property_order: %w(author guid parent_guid property))
).to include_json(property_order: %w[author guid parent_guid property])
end
it "adds new unknown elements to the json again" do
@ -385,7 +385,7 @@ XML
:parent_author_signature => parent_author_signature
}
}
let(:property_order) { %w(author guid parent_guid new_property property) }
let(:property_order) { %w[author guid parent_guid new_property property] }
it "parses entity properties from the input data" do
entity = Entities::SomeRelayable.from_hash(entity_data, property_order)
@ -419,7 +419,7 @@ XML
parent_author_signature: parent_author_signature,
parent: remote_parent
}.merge("new_property" => new_property),
%w(author guid parent_guid new_property property),
%w[author guid parent_guid new_property property],
"new_property" => new_property
).and_call_original
Entities::SomeRelayable.from_hash(entity_data, property_order)
@ -427,7 +427,7 @@ XML
end
it "creates Entity with empty 'additional_data' if it has only known properties" do
property_order = %w(author guid parent_guid property)
property_order = %w[author guid parent_guid property]
entity_data = {
guid: guid,
@ -447,7 +447,7 @@ XML
context "relayable signature verification feature support" do
it "calls signatures verification on relayable unpack" do
property_order = %w(guid author property parent_guid)
property_order = %w[guid author property parent_guid]
entity_data = {
guid: guid,
author: author,

View file

@ -52,7 +52,7 @@ XML
end
end
%w(Comment Like PollParticipation).each do |target_type|
%w[Comment Like PollParticipation].each do |target_type|
context "#{target_type} target" do
let(:relayable_target) {
Fabricate(

View file

@ -138,7 +138,7 @@ module DiasporaFederation
xml_children = entity.to_xml.children
expect(xml_children).to have_exactly(4).items
xml_children.each do |node|
expect(%w(test1 test2 test3 test4)).to include(node.name)
expect(%w[test1 test2 test3 test4]).to include(node.name)
end
end
@ -319,7 +319,7 @@ JSON
end
expect(EntityWithFromHashMethod).to receive(:json_parser_class).and_call_original
expect_any_instance_of(Parsers::JsonParser).to receive(:parse).with("{}").and_return(%i(arg1 arg2 arg3))
expect_any_instance_of(Parsers::JsonParser).to receive(:parse).with("{}").and_return(%i[arg1 arg2 arg3])
expect(EntityWithFromHashMethod).to receive(:from_hash).with(:arg1, :arg2, :arg3)
EntityWithFromHashMethod.from_json("{}")
end
@ -456,7 +456,7 @@ JSON
xml = entity.to_xml
expect(xml.children).to have_exactly(4).items
xml.children.each do |node|
expect(%w(asdf test_entity other_entity)).to include(node.name)
expect(%w[asdf test_entity other_entity]).to include(node.name)
end
expect(xml.xpath("test_entity")).to have_exactly(1).items
expect(xml.xpath("other_entity")).to have_exactly(2).items

View file

@ -24,7 +24,7 @@ JSON
expect(parsed_data[0][:guid]).to eq("im a guid")
expect(parsed_data[0][:property]).to eq("value")
expect(parsed_data[0][:author]).to eq("id@example.tld")
expect(parsed_data[1]).to eq(%w(property guid author))
expect(parsed_data[1]).to eq(%w[property guid author])
end
end
end

View file

@ -17,7 +17,7 @@ XML
expect(parsed_data[0][:guid]).to eq("im a guid")
expect(parsed_data[0][:property]).to eq("value")
expect(parsed_data[0][:author]).to eq("id@example.tld")
expect(parsed_data[1]).to eq(%i(guid property author))
expect(parsed_data[1]).to eq(%i[guid property author])
end
end
end

View file

@ -87,7 +87,7 @@ XML
end
it "parses boolean fields with a randomly matching pattern as nil" do
%w(ttFFFtt yesFFDSFSDy noDFDSFFDFn fXf LLyes).each do |weird_value|
%w[ttFFFtt yesFFDSFSDy noDFDSFFDFn fXf LLyes].each do |weird_value|
xml = <<-XML.strip
<test_entity_with_boolean>
<test>#{weird_value}</test>
@ -102,7 +102,7 @@ XML
end
it "parses integer fields with a randomly matching pattern as nil" do
%w(1,2,3 foobar two).each do |weird_value|
%w[1,2,3 foobar two].each do |weird_value|
xml = <<-XML.strip
<test_entity_with_integer>
<test>#{weird_value}</test>
@ -117,7 +117,7 @@ XML
end
it "parses timestamp fields with a randomly matching pattern as nil" do
%w(foobar yesterday now 1.2.foo).each do |weird_value|
%w[foobar yesterday now 1.2.foo].each do |weird_value|
xml = <<-XML.strip
<test_entity_with_timestamp>
<test>#{weird_value}</test>

View file

@ -28,7 +28,7 @@ module DiasporaFederation
end
it "accepts only supported types" do
%i(text number foobar).each do |val|
%i[text number foobar].each do |val|
expect {
dsl.property :fail, val
}.to raise_error PropertiesDSL::InvalidType

View file

@ -49,7 +49,7 @@ module DiasporaFederation
env_xml = envelope.envelop(privkey).root
expect(env_xml.name).to eq("env")
control = %w(data encoding alg sig)
control = %w[data encoding alg sig]
env_xml.children.each do |node|
expect(control).to include(node.name)
control.reject! {|i| i == node.name }

View file

@ -4,7 +4,7 @@ module DiasporaFederation
it_behaves_like "a common validator"
%i(author recipient).each do |prop|
%i[author recipient].each do |prop|
describe "##{prop}" do
it_behaves_like "a diaspora* ID validator" do
let(:property) { prop }
@ -13,7 +13,7 @@ module DiasporaFederation
end
end
%i(following sharing).each do |prop|
%i[following sharing].each do |prop|
describe "##{prop}" do
it_behaves_like "a boolean validator" do
let(:property) { prop }

View file

@ -10,7 +10,7 @@ module DiasporaFederation
it_behaves_like "a property with a value validation/restriction" do
let(:property) { :status }
let(:wrong_values) { ["", "yes", "foobar"] }
let(:correct_values) { %w(accepted declined tentative) }
let(:correct_values) { %w[accepted declined tentative] }
end
end
end

View file

@ -11,7 +11,7 @@ module DiasporaFederation
end
end
%i(first_name last_name).each do |prop|
%i[first_name last_name].each do |prop|
describe "##{prop}" do
it_behaves_like "a name validator" do
let(:property) { prop }
@ -20,7 +20,7 @@ module DiasporaFederation
end
end
%i(photo_large_url photo_medium_url photo_small_url).each do |prop|
%i[photo_large_url photo_medium_url photo_small_url].each do |prop|
describe "##{prop}" do
it_behaves_like "a property that mustn't be empty" do
let(:property) { prop }

View file

@ -9,7 +9,7 @@ module DiasporaFederation
it_behaves_like "a property with a value validation/restriction" do
let(:property) { :parent_type }
let(:wrong_values) { [nil, "", "any", "Postxxx", "post"] }
let(:correct_values) { %w(Post Comment) }
let(:correct_values) { %w[Post Comment] }
end
end
end

View file

@ -3,7 +3,7 @@ module DiasporaFederation
let(:entity) { :location_entity }
it_behaves_like "a common validator"
%i(lat lng).each do |prop|
%i[lat lng].each do |prop|
describe "##{prop}" do
it_behaves_like "a property that mustn't be empty" do
let(:property) { prop }

View file

@ -27,7 +27,7 @@ module DiasporaFederation
let(:property) { :public }
end
%i(remote_photo_name remote_photo_path).each do |prop|
%i[remote_photo_name remote_photo_path].each do |prop|
describe "##{prop}" do
it_behaves_like "a property that mustn't be empty" do
let(:property) { prop }
@ -35,7 +35,7 @@ module DiasporaFederation
end
end
%i(height width).each do |prop|
%i[height width].each do |prop|
describe "##{prop}" do
it_behaves_like "a property with a value validation/restriction" do
let(:property) { prop }

View file

@ -9,7 +9,7 @@ module DiasporaFederation
let(:mandatory) { false }
end
%i(first_name last_name).each do |prop|
%i[first_name last_name].each do |prop|
describe "##{prop}" do
it_behaves_like "a name validator" do
let(:property) { prop }
@ -18,7 +18,7 @@ module DiasporaFederation
end
end
%i(image_url image_url_medium image_url_small).each do |prop|
%i[image_url image_url_medium image_url_small].each do |prop|
describe "##{prop}" do
it_behaves_like "a property with a value validation/restriction" do
let(:property) { prop }
@ -61,7 +61,7 @@ module DiasporaFederation
end
end
%i(searchable public nsfw).each do |prop|
%i[searchable public nsfw].each do |prop|
describe "##{prop}" do
it_behaves_like "a boolean validator" do
let(:property) { prop }

View file

@ -9,7 +9,7 @@ module DiasporaFederation
let(:mandatory) { true }
end
%i(local public).each do |prop|
%i[local public].each do |prop|
it_behaves_like "a boolean validator" do
let(:property) { prop }
end

View file

@ -3,7 +3,7 @@ module DiasporaFederation
let(:entity) { :reshare_entity }
it_behaves_like "a common validator"
%i(root_author author).each do |prop|
%i[root_author author].each do |prop|
describe "##{prop}" do
it_behaves_like "a diaspora* ID validator" do
let(:property) { prop }
@ -12,7 +12,7 @@ module DiasporaFederation
end
end
%i(root_guid guid).each do |prop|
%i[root_guid guid].each do |prop|
describe "##{prop}" do
it_behaves_like "a guid validator" do
let(:property) { prop }

View file

@ -13,7 +13,7 @@ describe Validation::Rule::Boolean do
context "validation" do
context "strings" do
it "validates boolean-esque strings" do
%w(true false yes no t f y n 1 0).each do |str|
%w[true false yes no t f y n 1 0].each do |str|
validator = Validation::Validator.new(OpenStruct.new(boolean: str))
validator.rule(:boolean, :boolean)

View file

@ -10,7 +10,7 @@ module DiasporaFederation
end
end
%i(hcard_url).each do |prop|
%i[hcard_url].each do |prop|
describe "##{prop}" do
it_behaves_like "a url validator without path" do
let(:property) { prop }
@ -23,7 +23,7 @@ module DiasporaFederation
end
# optional urls
%i(salmon_url profile_url atom_url).each do |prop|
%i[salmon_url profile_url atom_url].each do |prop|
describe "##{prop}" do
it_behaves_like "a property with a value validation/restriction" do
let(:property) { prop }

View file

@ -107,7 +107,7 @@ shared_examples "a relayable Entity" do
end
it "computes correct signatures for the entity" do
order = described_class.class_props.keys - %i(author_signature parent_author_signature parent)
order = described_class.class_props.keys - %i[author_signature parent_author_signature parent]
signed_string = order.map {|name| data[name].is_a?(Time) ? data[name].iso8601 : data[name] }.join(";")
xml = instance.to_xml

View file

@ -23,6 +23,6 @@ module Dummy
# config.assets.version = "1.0"
# autoload files from test/dummy/lib
config.autoload_once_paths += %W(#{config.root}/lib)
config.autoload_once_paths += %W[#{config.root}/lib]
end
end

View file

@ -40,7 +40,7 @@ Rails.application.configure do
# config.action_view.raise_on_missing_translations = true
# Set the logging destination(s)
config.log_to = %w(stdout file)
config.log_to = %w[stdout file]
# Show the logging configuration on STDOUT
config.show_log_configuration = true

View file

@ -49,7 +49,7 @@ Rails.application.configure do
config.log_level = :debug
# Set the logging destination(s)
config.log_to = %w(file)
config.log_to = %w[file]
# Show the logging configuration on STDOUT
config.show_log_configuration = false