Commit 1050ef73 authored by Igor Drozdov's avatar Igor Drozdov Committed by Peter Leitzen

Fix Style/SlicingWithRange offences

parent fddd1c97
......@@ -827,11 +827,6 @@ Style/RescueModifier:
Style/SingleArgumentDig:
Enabled: false
# Offense count: 45
# Cop supports --auto-correct.
Style/SlicingWithRange:
Enabled: false
# Offense count: 63
# Configuration parameters: AllowModifier.
Style/SoleNestedConditional:
......
......@@ -99,7 +99,7 @@ class Projects::BlobController < Projects::ApplicationController
@content = params[:content]
@blob.load_all_data!
diffy = Diffy::Diff.new(@blob.data, @content, diff: '-U 3', include_diff_info: true)
diff_lines = diffy.diff.scan(/.*\n/)[2..-1]
diff_lines = diffy.diff.scan(/.*\n/)[2..]
diff_lines = Gitlab::Diff::Parser.new.parse(diff_lines).to_a
@diff_lines = Gitlab::Diff::Highlight.new(diff_lines, repository: @repository).highlight
......
......@@ -283,7 +283,7 @@ module DiffHelper
return path unless path.size > max && max > 3
"...#{path[-(max - 3)..-1]}"
"...#{path[-(max - 3)..]}"
end
def code_navigation_path(diffs)
......
......@@ -11,7 +11,7 @@ module TokenAuthenticatableStrategies
# The pattern of the token is "#{DYNAMIC_NONCE_IDENTIFIER}#{token}#{iv_of_12_characters}"
if token.start_with?(DYNAMIC_NONCE_IDENTIFIER) && token.size > NONCE_SIZE + DYNAMIC_NONCE_IDENTIFIER.size
token_to_decrypt = token[1...-NONCE_SIZE]
iv = token[-NONCE_SIZE..-1]
iv = token[-NONCE_SIZE..]
Gitlab::CryptoHelper.aes256_gcm_decrypt(token_to_decrypt, nonce: iv)
else
......
......@@ -204,7 +204,7 @@ module Namespaces
end
if bottom
skope = skope.where(id: bottom.traversal_ids[0..-1])
skope = skope.where(id: bottom.traversal_ids)
end
# The original `with_depth` attribute in ObjectHierarchy increments as you
......
......@@ -37,7 +37,7 @@ module Serverless
'a1',
serverless_domain_cluster.uuid[2..-3],
'f2',
serverless_domain_cluster.uuid[-2..-1]
serverless_domain_cluster.uuid[-2..]
].join
end
end
......
......@@ -338,7 +338,7 @@ class WikiPage
current_dirname = File.dirname(title)
if persisted?
return title[1..-1] if current_dirname == '/'
return title[1..] if current_dirname == '/'
return File.join([directory.presence, title].compact) if current_dirname == '.'
end
......
......@@ -38,7 +38,7 @@ class CohortsService
{
registration_month: registration_month,
activity_months: activity_months[1..-1],
activity_months: activity_months[1..],
total: activity_months.first[:total],
inactive: inactive
}
......
......@@ -9,7 +9,7 @@ class LfsObjectUploader < GitlabUploader
alias_method :upload, :model
def filename
model.oid[4..-1]
model.oid[4..]
end
def store_dir
......
......@@ -108,7 +108,7 @@ module WikiCloth
"<span class=\"error\">#{I18n.t('template loop detected', :tree => debug_tree)}</span>"
else
key = params[0].to_s.strip
key_options = params[1..-1].collect { |p| p.is_a?(Hash) ? { :name => p[:name].strip, :value => p[:value].strip } : p.strip }
key_options = params[1..].collect { |p| p.is_a?(Hash) ? { :name => p[:name].strip, :value => p[:value].strip } : p.strip }
key_options ||= []
key_digest = Digest::MD5.hexdigest(key_options.to_a.sort {|x,y| (x.is_a?(Hash) ? x[:name] : x) <=> (y.is_a?(Hash) ? y[:name] : y) }.inspect)
......
......@@ -51,7 +51,7 @@ module Gitlab
index = context_data.index('JID-')
return unless index
context_data[index + 4..-1]
context_data[index + 4..]
end
end
end
......
......@@ -56,7 +56,7 @@ RSpec.describe AddNewDataToMergeRequestsDocuments, :elastic, :sidekiq_inline do
it 'only updates merge_request documents missing visibility_level', :aggregate_failures do
merge_request = merge_requests.first
add_visibility_level_for_merge_requests(merge_requests[1..-1])
add_visibility_level_for_merge_requests(merge_requests[1..])
expected = [Gitlab::Elastic::DocumentReference.new(MergeRequest, merge_request.id, merge_request.es_id, merge_request.es_parent)]
expect(::Elastic::ProcessInitialBookkeepingService).to receive(:track!).with(*expected).once
......
......@@ -51,7 +51,7 @@ RSpec.describe AddUpvotesToIssues, :elastic, :sidekiq_inline do
it 'only updates issue documents missing upvotes', :aggregate_failures do
issue = issues.first
add_upvotes_for_issues(issues[1..-1])
add_upvotes_for_issues(issues[1..])
expected = [Gitlab::Elastic::DocumentReference.new(Issue, issue.id, issue.es_id, issue.es_parent)]
expect(::Elastic::ProcessInitialBookkeepingService).to receive(:track!).with(*expected).once
......
......@@ -53,7 +53,7 @@ RSpec.shared_examples 'migration backfills a field' do
it 'only updates documents missing a field', :aggregate_failures do
object = objects.first
add_field_for_objects(objects[1..-1])
add_field_for_objects(objects[1..])
expected = [Gitlab::Elastic::DocumentReference.new(klass, object.id, object.es_id, object.es_parent)]
expect(::Elastic::ProcessInitialBookkeepingService).to receive(:track!).with(*expected).once.and_call_original
......
......@@ -39,7 +39,7 @@ module Banzai
code[:class] = INLINE_CLASSES
code[STYLE_ATTRIBUTE] = 'inline'
closing.content = closing.content[1..-1]
closing.content = closing.content[1..]
opening.content = opening.content[0..-2]
end
end
......
......@@ -174,7 +174,7 @@ module Banzai
def build_relative_path(path, request_path)
return request_path if path.empty?
return path unless request_path
return path[1..-1] if path.start_with?('/')
return path[1..] if path.start_with?('/')
parts = request_path.split('/')
......
......@@ -113,7 +113,7 @@ module ExtractsRef
best_match = valid_refs.max_by(&:length)
# Partition the string into the ref and the path, ignoring the empty first value
id.partition(best_match)[1..-1]
id.partition(best_match)[1..]
end
def use_first_path_segment?(ref)
......
......@@ -51,7 +51,7 @@ module Flowdock
end
def body
content = @commit[:message][first_line.size..-1]
content = @commit[:message][first_line.size..]
content.strip! if content
"<pre>#{content}</pre>" unless content.empty?
end
......
......@@ -48,10 +48,10 @@ module Gitlab
# follows it will produce a nil. For example:
#
# "\n".split("\n") # => []
# "\n".split("\n")[1..-1] # => nil
# "\n".split("\n")[1..] # => nil
#
# To work around this we only "join" if we're given an Array.
if (converted = output.split("\n")[1..-1])
if (converted = output.split("\n")[1..])
converted.join("\n")
else
''
......
......@@ -51,7 +51,7 @@ module Gitlab
def replace_with!(other)
instance_variables.each do |ivar|
instance_variable_set(ivar, other.public_send(ivar.to_s[1..-1])) # rubocop:disable GitlabSecurity/PublicSend
instance_variable_set(ivar, other.public_send(ivar.to_s[1..])) # rubocop:disable GitlabSecurity/PublicSend
end
end
......
......@@ -36,7 +36,7 @@ module Gitlab
end
def strip_diff_frontmatter(diff_content)
diff_content.scan(/.*\n/)[2..-1]&.join('') if diff_content.present?
diff_content.scan(/.*\n/)[2..]&.join('') if diff_content.present?
end
def blobs_with_transformed_diffs
......
......@@ -6,8 +6,8 @@ module Gitlab
attr_accessor :old_line, :new_line, :offset
def initialize(old_line, new_line, offset: 0)
@old_line = old_line[offset..-1]
@new_line = new_line[offset..-1]
@old_line = old_line[offset..]
@new_line = new_line[offset..]
@offset = offset
end
......
......@@ -57,7 +57,7 @@ module Gitlab
def unfold_reference(reference, match, target_parent)
before = @text[0...match.begin(0)]
after = @text[match.end(0)..-1]
after = @text[match.end(0)..]
referable = find_referable(reference)
return reference unless referable
......
......@@ -48,7 +48,7 @@ module Gitlab
raw_keys.each_with_object({}) do |raw_key, grouped_subkeys|
primary_subkey_id = raw_key.primary_subkey.keyid
grouped_subkeys[primary_subkey_id] = raw_key.subkeys[1..-1].map do |s|
grouped_subkeys[primary_subkey_id] = raw_key.subkeys[1..].map do |s|
{ keyid: s.keyid, fingerprint: s.fingerprint }
end
end
......
......@@ -44,7 +44,7 @@ module Gitlab
next unless match
input = match.split(':')[1..-1].join
input = match.split(':')[1..].join
next if input.empty?
filter[:negated] = match.start_with?("-")
......
......@@ -70,7 +70,7 @@ module Gitlab
next if total_duration <= MINIMUM_DURATION
stats[1..-1].each_with_index do |data, index|
stats[1..].each_with_index do |data, index|
next unless source_lines[index]
duration = microsec_to_millisec(data[0])
......
......@@ -99,7 +99,7 @@ module Gitlab
start = prev = positions[0]
range = MarkerRange.new(start, prev, mode: mode)
positions[1..-1].each do |pos|
positions[1..].each do |pos|
if pos == prev + 1
range = MarkerRange.new(start, pos, mode: mode)
prev = pos
......
......@@ -16,7 +16,7 @@ module Gitlab
# we remove the leading `//` and add `descendant-or-self::`
# in order to ensure we're searching from this node and all
# descendants.
xpath.map { |t| "descendant-or-self::#{t[2..-1]}" }.join('|')
xpath.map { |t| "descendant-or-self::#{t[2..]}" }.join('|')
end
end
end
......
......@@ -184,7 +184,7 @@ class GroupSeeder
group = Group.find(group_id)
@resource_count.times do |i|
_, project_path = PROJECT_URL.split('/')[-2..-1]
_, project_path = PROJECT_URL.split('/')[-2..]
project_path.gsub!('.git', '')
......
......@@ -46,7 +46,7 @@ module RuboCop
end
def arguments(node)
node.children[2..-1]
node.children[2..]
end
end
end
......
......@@ -46,7 +46,7 @@ module RuboCop
end
def arguments(node)
node.children[2..-1]
node.children[2..]
end
end
end
......
......@@ -128,7 +128,7 @@ RSpec.describe Projects::Serverless::FunctionsController do
expect(json_response["functions"]).to all(
include(
'url' => "https://#{function_name}-#{serverless_domain_cluster.uuid[0..1]}a1#{serverless_domain_cluster.uuid[2..-3]}f2#{serverless_domain_cluster.uuid[-2..-1]}#{"%x" % environment.id}-#{environment.slug}.#{serverless_domain_cluster.domain}"
'url' => "https://#{function_name}-#{serverless_domain_cluster.uuid[0..1]}a1#{serverless_domain_cluster.uuid[2..-3]}f2#{serverless_domain_cluster.uuid[-2..]}#{"%x" % environment.id}-#{environment.slug}.#{serverless_domain_cluster.domain}"
)
)
end
......@@ -166,7 +166,7 @@ RSpec.describe Projects::Serverless::FunctionsController do
expect(response).to have_gitlab_http_status(:ok)
expect(json_response).to include(
'url' => "https://#{function_name}-#{serverless_domain_cluster.uuid[0..1]}a1#{serverless_domain_cluster.uuid[2..-3]}f2#{serverless_domain_cluster.uuid[-2..-1]}#{"%x" % environment.id}-#{environment.slug}.#{serverless_domain_cluster.domain}"
'url' => "https://#{function_name}-#{serverless_domain_cluster.uuid[0..1]}a1#{serverless_domain_cluster.uuid[2..-3]}f2#{serverless_domain_cluster.uuid[-2..]}#{"%x" % environment.id}-#{environment.slug}.#{serverless_domain_cluster.domain}"
)
end
......
......@@ -20,7 +20,7 @@ RSpec.describe 'User views an open merge request' do
# Work around a weird Capybara behavior where calling `parent` on a node
# returns the whole document, not the node's actual parent element
expect(find(:xpath, "#{node.path}/..").text).to eq(merge_request.description[2..-1])
expect(find(:xpath, "#{node.path}/..").text).to eq(merge_request.description[2..])
expect(page).to have_content(merge_request.title)
end
......
......@@ -80,7 +80,7 @@ RSpec.describe 'Issue prioritization' do
expect(issue_titles[0..1]).to contain_exactly('issue_5', 'issue_8')
expect(issue_titles[2..4]).to contain_exactly('issue_1', 'issue_3', 'issue_7')
expect(issue_titles[5..-1]).to eq(%w(issue_2 issue_4 issue_6))
expect(issue_titles[5..]).to eq(%w(issue_2 issue_4 issue_6))
end
end
end
......@@ -71,7 +71,7 @@ RSpec.describe Packages::Nuget::PackageFinder do
end
context 'with prefix wildcard' do
let(:package_name) { "%#{package1.name[3..-1]}" }
let(:package_name) { "%#{package1.name[3..]}" }
it { is_expected.to match_array([package1, package2]) }
end
......
......@@ -43,10 +43,10 @@ RSpec.describe Gitlab::GitalyClient::ConflictFilesStitcher do
messages = [
double(files: [double(header: header_1), double(header: nil, content: content_1[0..5])]),
double(files: [double(header: nil, content: content_1[6..-1])]),
double(files: [double(header: nil, content: content_1[6..])]),
double(files: [double(header: header_2)]),
double(files: [double(header: nil, content: content_2[0..5]), double(header: nil, content: content_2[6..10])]),
double(files: [double(header: nil, content: content_2[11..-1])])
double(files: [double(header: nil, content: content_2[11..])])
]
conflict_files = described_class.new(messages, target_repository.gitaly_repository).to_a
......
......@@ -41,7 +41,7 @@ RSpec.describe Gitlab::GitalyClient::DiffStitcher do
msg_2.raw_patch_data = diff_2.patch[0..100]
msg_2.end_of_patch = false
msg_3 = OpenStruct.new(raw_patch_data: diff_2.patch[101..-1], end_of_patch: true)
msg_3 = OpenStruct.new(raw_patch_data: diff_2.patch[101..], end_of_patch: true)
msg_4 = OpenStruct.new(diff_3.to_h.except(:patch))
msg_4.raw_patch_data = diff_3.patch
......
......@@ -192,7 +192,7 @@ RSpec.describe Gitlab::Gpg::InvalidGpgSignatureUpdater do
project: project,
commit_sha: commit_sha,
gpg_key: nil,
gpg_key_primary_keyid: GpgHelpers::User3.subkey_fingerprints.last[24..-1],
gpg_key_primary_keyid: GpgHelpers::User3.subkey_fingerprints.last[24..],
verification_status: 'unknown_key'
end
......
......@@ -98,7 +98,7 @@ RSpec.describe Gitlab::Graphql::Pagination::Keyset::Connection do
let(:nodes) { Project.all.order(Gitlab::Pagination::Keyset::Order.build([column_order_id_desc])) }
it 'returns the correct nodes' do
expect(subject.sliced_nodes).to contain_exactly(*projects[2..-1])
expect(subject.sliced_nodes).to contain_exactly(*projects[2..])
end
end
end
......@@ -107,7 +107,7 @@ RSpec.describe Gitlab::Graphql::Pagination::Keyset::Connection do
let(:arguments) { { after: encoded_cursor(projects[1]) } }
it 'only returns the project before the selected one' do
expect(subject.sliced_nodes).to contain_exactly(*projects[2..-1])
expect(subject.sliced_nodes).to contain_exactly(*projects[2..])
end
context 'when the sort order is descending' do
......
......@@ -120,7 +120,7 @@ RSpec.describe Gitlab::Graphql::Pagination::Keyset::Connection do
let(:nodes) { Project.all.order(id: :desc) }
it 'returns the correct nodes' do
expect(subject.sliced_nodes).to contain_exactly(*projects[2..-1])
expect(subject.sliced_nodes).to contain_exactly(*projects[2..])
end
end
end
......@@ -129,7 +129,7 @@ RSpec.describe Gitlab::Graphql::Pagination::Keyset::Connection do
let(:arguments) { { after: encoded_cursor(projects[1]) } }
it 'only returns the project before the selected one' do
expect(subject.sliced_nodes).to contain_exactly(*projects[2..-1])
expect(subject.sliced_nodes).to contain_exactly(*projects[2..])
end
context 'when the sort order is descending' do
......
......@@ -40,7 +40,7 @@ RSpec.describe Gitlab::MultiCollectionPaginator do
end
it 'fils the last page with elements from the second collection' do
expected_collection = all_groups[-2..-1]
expected_collection = all_groups[-2..]
expect(paginator.paginate(3)).to eq(expected_collection)
end
......
......@@ -127,7 +127,7 @@ RSpec.describe Gitlab::Pagination::Keyset::Order do
end
it do
expect(subject).to eq(expected.reverse[1..-1]) # removing one item because we used it to calculate cursor data for the "last" page in subject
expect(subject).to eq(expected.reverse[1..]) # removing one item because we used it to calculate cursor data for the "last" page in subject
end
end
end
......
......@@ -78,7 +78,7 @@ RSpec.describe Gitlab::RackAttack, :aggregate_failures do
it 'configures tracks and throttles with a selected set of dry-runs' do
dry_run_throttles = throttles.each_key.first(2)
regular_throttles = throttles.keys[2..-1]
regular_throttles = throttles.keys[2..]
stub_env('GITLAB_THROTTLE_DRY_RUN', dry_run_throttles.join(','))
described_class.configure(fake_rack_attack)
......
......@@ -2506,7 +2506,7 @@ RSpec.describe Ci::Build do
it { is_expected.to start_with(project.web_url[0..6]) }
it { is_expected.to include(build.token) }
it { is_expected.to include('gitlab-ci-token') }
it { is_expected.to include(project.web_url[7..-1]) }
it { is_expected.to include(project.web_url[7..]) }
end
context 'when token is empty' do
......
......@@ -57,7 +57,7 @@ RSpec.describe SystemNotes::CommitService do
end
context 'with multiple existing commits' do
let(:old_commits) { noteable.commits[3..-1] }
let(:old_commits) { noteable.commits[3..] }
context 'with oldrev' do
let(:oldrev) { noteable.commits[2].id }
......
......@@ -138,7 +138,7 @@ module GpgHelpers
end
def primary_keyid
fingerprint[-16..-1]
fingerprint[-16..]
end
def fingerprint
......@@ -281,7 +281,7 @@ module GpgHelpers
end
def primary_keyid2
fingerprint2[-16..-1]
fingerprint2[-16..]
end
def fingerprint2
......@@ -374,7 +374,7 @@ module GpgHelpers
end
def primary_keyid
fingerprint[-16..-1]
fingerprint[-16..]
end
def fingerprint
......@@ -776,7 +776,7 @@ module GpgHelpers
end
def primary_keyid
fingerprint[-16..-1]
fingerprint[-16..]
end
def fingerprint
......
......@@ -23,7 +23,7 @@ module MemoryUsageHelper
output, status = Gitlab::Popen.popen(%w(free -m))
abort "`free -m` return code is #{status}: #{output}" unless status == 0
result = output.split("\n")[1].split(" ")[1..-1]
result = output.split("\n")[1].split(" ")[1..]
attrs = %i(m_total m_used m_free m_shared m_buffers_cache m_available).freeze
attrs.zip(result).to_h
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment