From 83f97f8a7e3b5a5ff4367388dbb67db9fc298bd9 Mon Sep 17 00:00:00 2001 From: Geremia Taglialatela Date: Sat, 20 Apr 2024 15:16:39 +0200 Subject: [PATCH] Autofix minor safe offenses - Layout/CaseIndentation - Layout/ElseAlignment - Layout/EndAlignment - Layout/IndentationWidth - Style/FileRead - Style/NestedParenthesizedCalls - Style/RedundantReturn - Style/StringLiterals - Style/StringLiteralsInInterpolation - Style/SuperWithArgsParentheses - Style/TrailingCommaInArguments --- .rubocop_todo.yml | 71 ---------------------------------- lib/sharepoint/client.rb | 42 ++++++++++---------- lib/sharepoint/errors.rb | 8 ++-- lib/sharepoint/spec_helpers.rb | 14 +++---- 4 files changed, 32 insertions(+), 103 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index a802be2..b5e687f 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -6,25 +6,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle, IndentOneStep, IndentationWidth. -# SupportedStyles: case, end -Layout/CaseIndentation: - Exclude: - - 'lib/sharepoint/spec_helpers.rb' - -# This cop supports safe autocorrection (--autocorrect). -Layout/ElseAlignment: - Exclude: - - 'lib/sharepoint/client.rb' - -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyleAlignWith, Severity. -# SupportedStylesAlignWith: keyword, variable, start_of_line -Layout/EndAlignment: - Exclude: - - 'lib/sharepoint/client.rb' - # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle, IndentationWidth. # SupportedStyles: special_inside_parentheses, consistent, align_braces @@ -41,12 +22,6 @@ Layout/HashAlignment: Exclude: - 'lib/sharepoint/client.rb' -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: Width, AllowedPatterns. -Layout/IndentationWidth: - Exclude: - - 'lib/sharepoint/client.rb' - # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle, IndentationWidth. # SupportedStyles: aligned, indented, indented_relative_to_receiver @@ -159,11 +134,6 @@ Style/EvalWithLocation: Exclude: - 'lib/sharepoint/client.rb' -# This cop supports safe autocorrection (--autocorrect). -Style/FileRead: - Exclude: - - 'lib/sharepoint/spec_helpers.rb' - # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: EnforcedStyle. # SupportedStyles: always, always_true, never @@ -197,13 +167,6 @@ Style/MutableConstant: Exclude: - 'lib/sharepoint/client.rb' -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowedMethods. -# AllowedMethods: be, be_a, be_an, be_between, be_falsey, be_kind_of, be_instance_of, be_truthy, be_within, eq, eql, end_with, include, match, raise_error, respond_to, start_with -Style/NestedParenthesizedCalls: - Exclude: - - 'lib/sharepoint/client.rb' - # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: PreferredDelimiters. Style/PercentLiteralDelimiters: @@ -216,12 +179,6 @@ Style/PercentLiteralDelimiters: Style/RaiseArgs: EnforcedStyle: compact -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowMultipleReturnValues. -Style/RedundantReturn: - Exclude: - - 'lib/sharepoint/client.rb' - # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle, AllowInnerSlashes. # SupportedStyles: slashes, percent_r, mixed @@ -242,27 +199,6 @@ Style/StringConcatenation: Exclude: - 'lib/sharepoint/client.rb' -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline. -# SupportedStyles: single_quotes, double_quotes -Style/StringLiterals: - Exclude: - - 'lib/sharepoint/client.rb' - - 'lib/sharepoint/errors.rb' - - 'lib/sharepoint/spec_helpers.rb' - -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: single_quotes, double_quotes -Style/StringLiteralsInInterpolation: - Exclude: - - 'lib/sharepoint/client.rb' - -# This cop supports safe autocorrection (--autocorrect). -Style/SuperWithArgsParentheses: - Exclude: - - 'lib/sharepoint/errors.rb' - # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: AllowMethodsWithArguments, AllowedMethods, AllowedPatterns, AllowComments. # AllowedMethods: define_method, mail, respond_to @@ -270,13 +206,6 @@ Style/SymbolProc: Exclude: - 'lib/sharepoint/client.rb' -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyleForMultiline. -# SupportedStylesForMultiline: comma, consistent_comma, no_comma -Style/TrailingCommaInArguments: - Exclude: - - 'lib/sharepoint/client.rb' - # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: WordRegex. # SupportedStyles: percent, brackets diff --git a/lib/sharepoint/client.rb b/lib/sharepoint/client.rb index d8945aa..ff54456 100644 --- a/lib/sharepoint/client.rb +++ b/lib/sharepoint/client.rb @@ -1,8 +1,8 @@ -require "ostruct" -require "ethon" -require "uri" -require "json" -require "time" +require 'ostruct' +require 'ethon' +require 'uri' +require 'json' +require 'time' require 'active_support/core_ext/string/inflections' require 'active_support/core_ext/object/blank' @@ -50,7 +50,7 @@ def documents_for(path, site_path = '') created_at: Time.parse(file['TimeCreated']), updated_at: Time.parse(file['TimeLastModified']), record_type: nil, - date_of_issue: nil, + date_of_issue: nil ) threads << Thread.new { @@ -91,7 +91,7 @@ def document_exists?(file_path, site_path = nil) exists = true end end - return exists + exists end # Get a document's metadata @@ -237,7 +237,7 @@ def list_documents_page(url) ethon.perform check_and_raise_failure(ethon) - return JSON.parse(ethon.response_body) + JSON.parse(ethon.response_body) end # Get a document's file contents. If it's a link to another document, it's followed. @@ -382,7 +382,7 @@ def update_metadata(filename, metadata, path, site_path = nil) 'content-type' => 'application/json;odata=verbose', 'X-RequestDigest' => xrequest_digest(site_path), 'X-Http-Method' => 'PATCH', - 'If-Match' => "*" } + 'If-Match' => '*' } easy.http_request(update_metadata_url, :post, { body: prepared_metadata }) @@ -426,7 +426,7 @@ def lists(site_path = '', query = {}) def index(list_name, site_path = '', fields = []) url = computed_web_api_url(site_path) url = "#{url}lists/GetByTitle('#{odata_escape_single_quote(list_name)}')/items" - url += "?$select=#{fields.join(",")}" if fields + url += "?$select=#{fields.join(',')}" if fields process_url(uri_escape(url), fields) end @@ -460,10 +460,10 @@ def process_url(url, fields) parsed_response_body = JSON.parse(easy.response_body) page_content = if fields - parsed_response_body['d']['results'].map { |v| v.fetch_values(*fields) } - else - parsed_response_body['d']['results'] - end + parsed_response_body['d']['results'].map { |v| v.fetch_values(*fields) } + else + parsed_response_body['d']['results'] + end if next_url = parsed_response_body['d']['__next'] page_content + process_url(next_url, fields) @@ -520,7 +520,7 @@ def xrequest_digest(site_path = nil) url = remove_double_slashes("#{computed_api_url(site_path)}/contextinfo") easy.http_request(url, :post, { body: '' }) easy.perform - JSON.parse(easy.response_body)['d']["GetContextWebInformation"]["FormDigestValue"] + JSON.parse(easy.response_body)['d']['GetContextWebInformation']['FormDigestValue'] end def last_location_header(ethon) @@ -543,7 +543,7 @@ def prepare_metadata(metadata, type) key = element[0] value = element[1] result += ", '#{json_escape_single_quote(key.to_s)}': '#{json_escape_single_quote(value.to_s)}'" - } + " }" + } + ' }' end def json_escape_single_quote(s) @@ -564,7 +564,7 @@ def split_path(file_path) def extract_paths(url) unescaped_url = string_unescape(url) - uri = URI(uri_escape unescaped_url) + uri = URI(uri_escape(unescaped_url)) path = utf8_encode uri_unescape(uri.path) sites_match = /\/sites\/[^\/]+/.match(path) site_path = sites_match[0] unless sites_match.nil? @@ -586,7 +586,7 @@ def validate_config! end def string_not_blank?(object) - !object.nil? && object != "" && object.is_a?(String) + !object.nil? && object != '' && object.is_a?(String) end def valid_config_uri? @@ -636,8 +636,8 @@ def sanitize_filename(filename) def build_search_kql_conditions(options) conditions = [] - conditions << "IsContainer<>true" - conditions << "contentclass:STS_ListItem" + conditions << 'IsContainer<>true' + conditions << 'contentclass:STS_ListItem' conditions << "WebId=#{options[:web_id]}" unless options[:web_id].nil? conditions << "ListId:#{options[:list_id]}" unless options[:list_id].nil? "'#{conditions.join('+')}'" @@ -751,7 +751,7 @@ def update_object_metadata(metadata, new_metadata, site_path = '') 'content-type' => 'application/json;odata=verbose', 'X-RequestDigest' => xrequest_digest(site_path), 'X-Http-Method' => 'PATCH', - 'If-Match' => "*" } + 'If-Match' => '*' } easy.http_request(update_metadata_url, :post, diff --git a/lib/sharepoint/errors.rb b/lib/sharepoint/errors.rb index 03642ea..d4fe870 100644 --- a/lib/sharepoint/errors.rb +++ b/lib/sharepoint/errors.rb @@ -2,25 +2,25 @@ module Sharepoint module Errors class UsernameConfigurationError < StandardError def initialize - super "Invalid Username Configuration" + super('Invalid Username Configuration') end end class PasswordConfigurationError < StandardError def initialize - super "Invalid Password configuration" + super('Invalid Password configuration') end end class UriConfigurationError < StandardError def initialize - super "Invalid Uri configuration" + super('Invalid Uri configuration') end end class EthonOptionsConfigurationError < StandardError def initialize - super "Invalid ethon easy options" + super('Invalid ethon easy options') end end end diff --git a/lib/sharepoint/spec_helpers.rb b/lib/sharepoint/spec_helpers.rb index 2ee9abc..ef073aa 100644 --- a/lib/sharepoint/spec_helpers.rb +++ b/lib/sharepoint/spec_helpers.rb @@ -2,12 +2,12 @@ module Sharepoint module SpecHelpers def value_to_string(value) case value - when nil - "nil" - when "" - "blank" - else - value + when nil + 'nil' + when '' + 'blank' + else + value end end @@ -24,7 +24,7 @@ def mock_responses(fixture_file) allow_any_instance_of(Ethon::Easy) .to receive(:response_body) .and_return( - File.open("spec/fixtures/responses/#{fixture_file}").read + File.read("spec/fixtures/responses/#{fixture_file}") ) end end