Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-12-20 17:22:11 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-12-20 17:22:11 +0300
commit0c872e02b2c822e3397515ec324051ff540f0cd5 (patch)
treece2fb6ce7030e4dad0f4118d21ab6453e5938cdd /spec/rubocop/cop/graphql/descriptions_spec.rb
parentf7e05a6853b12f02911494c4b3fe53d9540d74fc (diff)
Add latest changes from gitlab-org/gitlab@15-7-stable-eev15.7.0-rc42
Diffstat (limited to 'spec/rubocop/cop/graphql/descriptions_spec.rb')
-rw-r--r--spec/rubocop/cop/graphql/descriptions_spec.rb241
1 files changed, 238 insertions, 3 deletions
diff --git a/spec/rubocop/cop/graphql/descriptions_spec.rb b/spec/rubocop/cop/graphql/descriptions_spec.rb
index 8826e700fdf..0ff2812d6f6 100644
--- a/spec/rubocop/cop/graphql/descriptions_spec.rb
+++ b/spec/rubocop/cop/graphql/descriptions_spec.rb
@@ -16,6 +16,8 @@ RSpec.describe RuboCop::Cop::Graphql::Descriptions do
end
end
TYPE
+
+ expect_no_corrections
end
it 'adds an offense when description does not end in a period' do
@@ -44,6 +46,8 @@ RSpec.describe RuboCop::Cop::Graphql::Descriptions do
end
end
TYPE
+
+ expect_no_corrections
end
it 'adds an offense when description begins with "The"' do
@@ -58,6 +62,46 @@ RSpec.describe RuboCop::Cop::Graphql::Descriptions do
end
end
TYPE
+
+ expect_no_corrections
+ end
+
+ it 'adds an offense when description contains the demonstrative "this"' do
+ expect_offense(<<~TYPE)
+ module Types
+ class FakeType < BaseObject
+ field :a_thing,
+ ^^^^^^^^^^^^^^^ #{described_class::MSG_CONTAINS_THIS}
+ GraphQL::Types::String,
+ null: false,
+ description: 'Description of this thing.'
+ end
+ end
+ TYPE
+
+ expect_correction(<<~TYPE)
+ module Types
+ class FakeType < BaseObject
+ field :a_thing,
+ GraphQL::Types::String,
+ null: false,
+ description: 'Description of the thing.'
+ end
+ end
+ TYPE
+ end
+
+ it 'does not add an offense when a word does not contain the substring "this"' do
+ expect_no_offenses(<<~TYPE)
+ module Types
+ class FakeType < BaseObject
+ field :a_thing,
+ GraphQL::Types::String,
+ null: false,
+ description: 'Description of thistle.'
+ end
+ end
+ TYPE
end
it 'does not add an offense when description is correct' do
@@ -96,6 +140,8 @@ RSpec.describe RuboCop::Cop::Graphql::Descriptions do
end
end
TYPE
+
+ expect_no_corrections
end
it 'adds an offense when description does not end in a period' do
@@ -124,6 +170,8 @@ RSpec.describe RuboCop::Cop::Graphql::Descriptions do
end
end
TYPE
+
+ expect_no_corrections
end
it 'adds an offense when description begins with "The"' do
@@ -138,6 +186,46 @@ RSpec.describe RuboCop::Cop::Graphql::Descriptions do
end
end
TYPE
+
+ expect_no_corrections
+ end
+
+ it 'adds an offense when description contains the demonstrative "this"' do
+ expect_offense(<<~TYPE)
+ module Types
+ class FakeType < BaseObject
+ argument :a_thing,
+ ^^^^^^^^^^^^^^^^^^ #{described_class::MSG_CONTAINS_THIS}
+ GraphQL::Types::String,
+ null: false,
+ description: 'Description of this thing.'
+ end
+ end
+ TYPE
+
+ expect_correction(<<~TYPE)
+ module Types
+ class FakeType < BaseObject
+ argument :a_thing,
+ GraphQL::Types::String,
+ null: false,
+ description: 'Description of the thing.'
+ end
+ end
+ TYPE
+ end
+
+ it 'does not add an offense when a word does not contain the substring "this"' do
+ expect_no_offenses(<<~TYPE)
+ module Types
+ class FakeType < BaseObject
+ argument :a_thing,
+ GraphQL::Types::String,
+ null: false,
+ description: 'Description of thistle.'
+ end
+ end
+ TYPE
end
it 'does not add an offense when description is correct' do
@@ -164,6 +252,8 @@ RSpec.describe RuboCop::Cop::Graphql::Descriptions do
end
end
TYPE
+
+ expect_no_corrections
end
it 'adds an offense when description does not end in a period' do
@@ -186,6 +276,8 @@ RSpec.describe RuboCop::Cop::Graphql::Descriptions do
end
end
TYPE
+
+ expect_no_corrections
end
it 'adds an offense when description begins with "A"' do
@@ -197,6 +289,37 @@ RSpec.describe RuboCop::Cop::Graphql::Descriptions do
end
end
TYPE
+
+ expect_no_corrections
+ end
+
+ it 'adds an offense when description contains the demonstrative "this"' do
+ expect_offense(<<~TYPE.strip)
+ module Types
+ class FakeEnum < BaseEnum
+ value 'FOO', value: 'foo', description: 'Description of this issue.'
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{described_class::MSG_CONTAINS_THIS}
+ end
+ end
+ TYPE
+
+ expect_correction(<<~TYPE.strip)
+ module Types
+ class FakeEnum < BaseEnum
+ value 'FOO', value: 'foo', description: 'Description of the issue.'
+ end
+ end
+ TYPE
+ end
+
+ it 'does not add an offense when a word does not contain the substring "this"' do
+ expect_no_offenses(<<~TYPE.strip)
+ module Types
+ class FakeEnum < BaseEnum
+ value 'FOO', value: 'foo', description: 'Description of thistle.'
+ end
+ end
+ TYPE
end
it 'does not add an offense when description is correct (defined using `description:`)' do
@@ -220,8 +343,8 @@ RSpec.describe RuboCop::Cop::Graphql::Descriptions do
end
end
- describe 'autocorrecting descriptions without periods' do
- it 'can autocorrect' do
+ describe 'autocorrecting periods in descriptions' do
+ it 'autocorrects missing periods' do
expect_offense(<<~TYPE)
module Types
class FakeType < BaseObject
@@ -246,7 +369,20 @@ RSpec.describe RuboCop::Cop::Graphql::Descriptions do
TYPE
end
- it 'can autocorrect a heredoc' do
+ it 'does not autocorrect if periods exist' do
+ expect_no_offenses(<<~TYPE)
+ module Types
+ class FakeType < BaseObject
+ field :a_thing,
+ GraphQL::Types::String,
+ null: false,
+ description: 'Behold! A description.'
+ end
+ end
+ TYPE
+ end
+
+ it 'autocorrects a heredoc' do
expect_offense(<<~TYPE)
module Types
class FakeType < BaseObject
@@ -274,5 +410,104 @@ RSpec.describe RuboCop::Cop::Graphql::Descriptions do
end
TYPE
end
+
+ it 'does not autocorrect a heredoc if periods exist' do
+ expect_no_offenses(<<~TYPE)
+ module Types
+ class FakeType < BaseObject
+ field :a_thing,
+ GraphQL::Types::String,
+ null: false,
+ description: <<~DESC
+ Behold! A description.
+ DESC
+ end
+ end
+ TYPE
+ end
+ end
+
+ describe 'autocorrecting "this" to "the"' do
+ it 'autocorrects if "this" is found' do
+ expect_offense(<<~TYPE)
+ module Types
+ class FakeType < BaseObject
+ field :a_thing,
+ ^^^^^^^^^^^^^^^ #{described_class::MSG_CONTAINS_THIS}
+ GraphQL::Types::String,
+ null: false,
+ description: 'Description of this thing.'
+ end
+ end
+ TYPE
+
+ expect_correction(<<~TYPE)
+ module Types
+ class FakeType < BaseObject
+ field :a_thing,
+ GraphQL::Types::String,
+ null: false,
+ description: 'Description of the thing.'
+ end
+ end
+ TYPE
+ end
+
+ it 'does not autocorrect if "this" is not found' do
+ expect_no_offenses(<<~TYPE)
+ module Types
+ class FakeType < BaseObject
+ field :a_thing,
+ GraphQL::Types::String,
+ null: false,
+ description: 'Description of the thing.'
+ end
+ end
+ TYPE
+ end
+
+ it 'autocorrects a heredoc if "this" is found' do
+ expect_offense(<<~TYPE)
+ module Types
+ class FakeType < BaseObject
+ field :a_thing,
+ ^^^^^^^^^^^^^^^ #{described_class::MSG_CONTAINS_THIS}
+ GraphQL::Types::String,
+ null: false,
+ description: <<~DESC
+ Description of this thing.
+ DESC
+ end
+ end
+ TYPE
+
+ expect_correction(<<~TYPE)
+ module Types
+ class FakeType < BaseObject
+ field :a_thing,
+ GraphQL::Types::String,
+ null: false,
+ description: <<~DESC
+ Description of the thing.
+ DESC
+ end
+ end
+ TYPE
+ end
+
+ it 'does not autocorrect a heredoc if "this" is not found' do
+ expect_no_offenses(<<~TYPE)
+ module Types
+ class FakeType < BaseObject
+ field :a_thing,
+ GraphQL::Types::String,
+ null: false,
+ description: <<~DESC
+ Description of the thing.
+ DESC
+ end
+ end
+ TYPE
+ end
end
end