cuke_linter 1.2.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +12 -1
  3. data/LICENSE.txt +1 -1
  4. data/README.md +1 -1
  5. data/lib/cuke_linter/default_linters.rb +1 -1
  6. data/lib/cuke_linter/linters/background_does_more_than_setup_linter.rb +0 -1
  7. data/lib/cuke_linter/linters/element_with_common_tags_linter.rb +0 -1
  8. data/lib/cuke_linter/linters/element_with_duplicate_tags_linter.rb +0 -1
  9. data/lib/cuke_linter/linters/element_with_too_many_tags_linter.rb +0 -1
  10. data/lib/cuke_linter/linters/example_without_name_linter.rb +0 -1
  11. data/lib/cuke_linter/linters/feature_file_with_invalid_name_linter.rb +0 -1
  12. data/lib/cuke_linter/linters/feature_file_with_mismatched_name_linter.rb +0 -1
  13. data/lib/cuke_linter/linters/feature_with_too_many_different_tags_linter.rb +0 -1
  14. data/lib/cuke_linter/linters/feature_without_description_linter.rb +0 -1
  15. data/lib/cuke_linter/linters/feature_without_name_linter.rb +0 -1
  16. data/lib/cuke_linter/linters/feature_without_scenarios_linter.rb +6 -3
  17. data/lib/cuke_linter/linters/linter.rb +0 -1
  18. data/lib/cuke_linter/linters/outline_with_single_example_row_linter.rb +0 -1
  19. data/lib/cuke_linter/linters/single_test_background_linter.rb +0 -1
  20. data/lib/cuke_linter/linters/step_with_end_period_linter.rb +0 -1
  21. data/lib/cuke_linter/linters/step_with_too_many_characters_linter.rb +0 -1
  22. data/lib/cuke_linter/linters/test_name_with_too_many_characters_linter.rb +38 -0
  23. data/lib/cuke_linter/linters/test_should_use_background_linter.rb +2 -2
  24. data/lib/cuke_linter/linters/test_with_action_step_as_final_step_linter.rb +0 -1
  25. data/lib/cuke_linter/linters/test_with_bad_name_linter.rb +0 -1
  26. data/lib/cuke_linter/linters/test_with_no_action_step_linter.rb +0 -1
  27. data/lib/cuke_linter/linters/test_with_no_name_linter.rb +0 -1
  28. data/lib/cuke_linter/linters/test_with_no_verification_step_linter.rb +0 -1
  29. data/lib/cuke_linter/linters/test_with_setup_step_after_action_step_linter.rb +0 -1
  30. data/lib/cuke_linter/linters/test_with_setup_step_after_verification_step_linter.rb +0 -1
  31. data/lib/cuke_linter/linters/test_with_setup_step_as_final_step_linter.rb +0 -1
  32. data/lib/cuke_linter/linters/test_with_too_many_steps_linter.rb +0 -1
  33. data/lib/cuke_linter/version.rb +1 -1
  34. data/lib/cuke_linter.rb +1 -3
  35. data/testing/cucumber/features/linters/feature_without_scenarios.feature +23 -1
  36. data/testing/cucumber/features/linters/rule_without_name.feature +18 -0
  37. data/testing/cucumber/features/linters/test_name_too_long.feature +41 -0
  38. metadata +5 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a58ecea412dacacc176aff36844a22a2be89b6e8fb530140c4a4c9af6f68b33d
4
- data.tar.gz: 6c59e3ef19cecf4f8348ffbb4b6e5f64b230bd38c569c776dda1afe0b214c856
3
+ metadata.gz: c131f0cd2c39b7ca961f791d36057e5bb502a58642b81a87f0e5ced67fca7e30
4
+ data.tar.gz: 131411ade0634a8a03813996cab553303f78d28208d015302089400af07bb6e5
5
5
  SHA512:
6
- metadata.gz: 163ed0e7cc11da407ce4af1a275f2cd51d0513caacdd007395af27782a111af83baa72928a85c7ba13b6a47d332564a71da906d068293f0d5cb4a5074c27d563
7
- data.tar.gz: 0d8098a3e266207030fa8bfcd573344aacf849eda5f33a308a3ecea3f4931ff6fb3f8dd86b62afcf76116ba30e5b2fad468d8ad287d8cb45aa1a3f6819c41c62
6
+ metadata.gz: 8d6ed6d47f19beefe74c57865171d6cfc0ccf8770ef648dd7103ff4c4fc183a621dc24fc53cb6d3ab9b6adb1e713b6f871d1c782d2514f1c301dc5590b9d8bb8
7
+ data.tar.gz: 1b8d2841790e2f48351f01ae3af0c230256ec3b2a020317469b46bd1f7279d055963f6c050f1889e08482f592af9f4fa853b1f82e10eb4fe81254fa8c2faecde
data/CHANGELOG.md CHANGED
@@ -8,6 +8,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
8
8
 
9
9
  Nothing yet...
10
10
 
11
+ ## [1.3.0] - 2022-05-23
12
+
13
+ ### Added
14
+ - New linters
15
+ - TestNameWithTooManyCharactersLinter
16
+
17
+ - Linters that are impacted by `Rule` elements in Gherkin have been updated, now that Rules models are available
18
+ in CukeModeler
19
+ - FeatureWithoutScenariosLinter
20
+
11
21
  ## [1.2.1] - 2021-06-13
12
22
 
13
23
  ### Fixed
@@ -176,7 +186,8 @@ Nothing yet...
176
186
  - Custom linters, formatters, and command line usability
177
187
 
178
188
 
179
- [Unreleased]: https://github.com/enkessler/cuke_linter/compare/v1.2.1...HEAD
189
+ [Unreleased]: https://github.com/enkessler/cuke_linter/compare/v1.3.0...HEAD
190
+ [1.3.0]: https://github.com/enkessler/cuke_linter/compare/v1.2.1...v1.3.0
180
191
  [1.2.1]: https://github.com/enkessler/cuke_linter/compare/v1.2.0...v1.2.1
181
192
  [1.2.0]: https://github.com/enkessler/cuke_linter/compare/v1.1.0...v1.2.0
182
193
  [1.1.0]: https://github.com/enkessler/cuke_linter/compare/v1.0.1...v1.1.0
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2018-2021 Eric Kessler
3
+ Copyright (c) 2018-2022 Eric Kessler
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -148,7 +148,7 @@ Rather than using the default linters or providing a custom set of of modified l
148
148
 
149
149
  ### <a id="documentation"></a>Everything Else
150
150
 
151
- For more detailed examples of usage, see the documentation [here](https://app.cucumber.pro/projects/cuke_linter).
151
+ For more detailed examples of usage, see the documentation [here](https://github.com/enkessler/cuke_linter/tree/master/testing/cucumber/features).
152
152
 
153
153
  ## Development and Contributing
154
154
 
@@ -1,4 +1,4 @@
1
- module CukeLinter
1
+ module CukeLinter # rubocop:disable Style/Documentation
2
2
 
3
3
  # Long names inherently result in long lines
4
4
  # rubocop:disable Metrics/LineLength
@@ -1,7 +1,6 @@
1
1
  module CukeLinter
2
2
 
3
3
  # A linter that detects backgrounds that have non-setup steps
4
-
5
4
  class BackgroundDoesMoreThanSetupLinter < Linter
6
5
 
7
6
  # Changes the linting settings on the linter using the provided configuration
@@ -1,7 +1,6 @@
1
1
  module CukeLinter
2
2
 
3
3
  # A linter that detects Gherkin elements that have the same tag on all of their taggable child elements
4
-
5
4
  class ElementWithCommonTagsLinter < Linter
6
5
 
7
6
  # The rule used to determine if a model has a problem
@@ -1,7 +1,6 @@
1
1
  module CukeLinter
2
2
 
3
3
  # A linter that detects taggable Gherkin elements that have duplicate tags
4
-
5
4
  class ElementWithDuplicateTagsLinter < Linter
6
5
 
7
6
  # Changes the linting settings on the linter using the provided configuration
@@ -1,7 +1,6 @@
1
1
  module CukeLinter
2
2
 
3
3
  # A linter that detects taggable Gherkin elements that have too many tags
4
-
5
4
  class ElementWithTooManyTagsLinter < Linter
6
5
 
7
6
  # Changes the linting settings on the linter using the provided configuration
@@ -1,7 +1,6 @@
1
1
  module CukeLinter
2
2
 
3
3
  # A linter that detects unnamed example groups
4
-
5
4
  class ExampleWithoutNameLinter < Linter
6
5
 
7
6
  # The rule used to determine if a model has a problem
@@ -1,7 +1,6 @@
1
1
  module CukeLinter
2
2
 
3
3
  # A linter that detects invalid feature file names
4
-
5
4
  class FeatureFileWithInvalidNameLinter < Linter
6
5
 
7
6
  # The rule used to determine if a model has a problem
@@ -1,7 +1,6 @@
1
1
  module CukeLinter
2
2
 
3
3
  # A linter that detects mismatched feature file names
4
-
5
4
  class FeatureFileWithMismatchedNameLinter < Linter
6
5
 
7
6
  # The rule used to determine if a model has a problem
@@ -1,7 +1,6 @@
1
1
  module CukeLinter
2
2
 
3
3
  # A linter that detects features that contain too many different tags
4
-
5
4
  class FeatureWithTooManyDifferentTagsLinter < Linter
6
5
 
7
6
  # Changes the linting settings on the linter using the provided configuration
@@ -1,7 +1,6 @@
1
1
  module CukeLinter
2
2
 
3
3
  # A linter that detects features that don't have a description
4
-
5
4
  class FeatureWithoutDescriptionLinter < Linter
6
5
 
7
6
  # The rule used to determine if a model has a problem
@@ -1,7 +1,6 @@
1
1
  module CukeLinter
2
2
 
3
3
  # A linter that detects features that don't have a name
4
-
5
4
  class FeatureWithoutNameLinter < Linter
6
5
 
7
6
  # The rule used to determine if a model has a problem
@@ -1,14 +1,17 @@
1
1
  module CukeLinter
2
2
 
3
3
  # A linter that detects empty features
4
-
5
4
  class FeatureWithoutScenariosLinter < Linter
6
5
 
7
6
  # The rule used to determine if a model has a problem
8
- def rule(model)
7
+ def rule(model) # rubocop:disable Metrics/CyclomaticComplexity # It's good enough
9
8
  return false unless model.is_a?(CukeModeler::Feature)
10
9
 
11
- model.tests.nil? || model.tests.empty?
10
+ feature_tests = model.tests && model.tests.any?
11
+ rule_tests = model.respond_to?(:rules) && # Earlier versions of CukeModeler did not have Rule models
12
+ model.rules && model.rules.any? { |rule| rule.tests && rule.tests.any? }
13
+
14
+ !(feature_tests || rule_tests)
12
15
  end
13
16
 
14
17
  # The message used to describe the problem that has been found
@@ -1,7 +1,6 @@
1
1
  module CukeLinter
2
2
 
3
3
  # A generic linter that can be used to make arbitrary linting rules
4
-
5
4
  class Linter
6
5
 
7
6
  # Returns the name of the linter
@@ -1,7 +1,6 @@
1
1
  module CukeLinter
2
2
 
3
3
  # A linter that detects outlines that don't have multiple example rows
4
-
5
4
  class OutlineWithSingleExampleRowLinter < Linter
6
5
 
7
6
  # The rule used to determine if a model has a problem
@@ -1,7 +1,6 @@
1
1
  module CukeLinter
2
2
 
3
3
  # A linter that detects backgrounds that apply to only one test
4
-
5
4
  class SingleTestBackgroundLinter < Linter
6
5
 
7
6
  # The rule used to determine if a model has a problem
@@ -1,7 +1,6 @@
1
1
  module CukeLinter
2
2
 
3
3
  # A linter that detects steps that end in a period
4
-
5
4
  class StepWithEndPeriodLinter < Linter
6
5
 
7
6
  # The rule used to determine if a model has a problem
@@ -1,7 +1,6 @@
1
1
  module CukeLinter
2
2
 
3
3
  # A linter that detects steps that are too long
4
-
5
4
  class StepWithTooManyCharactersLinter < Linter
6
5
 
7
6
  # The threshold used if not otherwise configured
@@ -0,0 +1,38 @@
1
+ module CukeLinter
2
+
3
+ # A linter that detects test names that are too long
4
+ class TestNameWithTooManyCharactersLinter < Linter
5
+
6
+ # The threshold used if not otherwise configured
7
+ DEFAULT_TEST_NAME_LENGTH_THRESHOLD = 80
8
+
9
+ # Changes the linting settings on the linter using the provided configuration
10
+ def configure(options)
11
+ @test_name_length_threshold = options['TestNameLengthThreshold'] if options['TestNameLengthThreshold']
12
+ end
13
+
14
+ # The rule used to determine if a model has a problem
15
+ def rule(model)
16
+ return false unless model.is_a?(CukeModeler::Scenario) || model.is_a?(CukeModeler::Outline)
17
+
18
+ @linted_test_name_length = model.name.nil? ? 0 : model.name.length
19
+
20
+ @linted_test_name_length > test_name_length_threshold
21
+ end
22
+
23
+ # The message used to describe the problem that has been found
24
+ def message
25
+ "Scenario name is too long. #{@linted_test_name_length} characters found (max #{test_name_length_threshold})"
26
+ end
27
+
28
+
29
+ private
30
+
31
+
32
+ # The maximum length allowable of a scenario name
33
+ def test_name_length_threshold
34
+ @test_name_length_threshold || DEFAULT_TEST_NAME_LENGTH_THRESHOLD
35
+ end
36
+
37
+ end
38
+ end
@@ -1,8 +1,8 @@
1
+ # TODO: Make a new class that it is from the POV of a Feature model instead
2
+
1
3
  module CukeLinter
2
4
 
3
- # TODO: Make a new class that it is from the POV of a Feature model instead
4
5
  # A linter that detects scenarios and outlines within a feature that all share common beginning steps
5
-
6
6
  class TestShouldUseBackgroundLinter < Linter
7
7
 
8
8
  # The rule used to determine if a model has a problem
@@ -1,7 +1,6 @@
1
1
  module CukeLinter
2
2
 
3
3
  # A linter that detects scenarios and outlines that have an action step as their final step
4
-
5
4
  class TestWithActionStepAsFinalStepLinter < Linter
6
5
 
7
6
  # Changes the linting settings on the linter using the provided configuration
@@ -1,7 +1,6 @@
1
1
  module CukeLinter
2
2
 
3
3
  # A linter that detects scenarios and outlines that have a bad name
4
-
5
4
  class TestWithBadNameLinter < Linter
6
5
 
7
6
  # The rule used to determine if a model has a problem
@@ -1,7 +1,6 @@
1
1
  module CukeLinter
2
2
 
3
3
  # A linter that detects scenarios and outlines that do not have an action (i.e. 'When') step
4
-
5
4
  class TestWithNoActionStepLinter < Linter
6
5
 
7
6
  # Changes the linting settings on the linter using the provided configuration
@@ -1,7 +1,6 @@
1
1
  module CukeLinter
2
2
 
3
3
  # A linter that detects scenarios and outlines that do not have a name
4
-
5
4
  class TestWithNoNameLinter < Linter
6
5
 
7
6
  # The rule used to determine if a model has a problem
@@ -1,7 +1,6 @@
1
1
  module CukeLinter
2
2
 
3
3
  # A linter that detects scenarios and outlines that do not have a verification (i.e. 'Then') step
4
-
5
4
  class TestWithNoVerificationStepLinter < Linter
6
5
 
7
6
  # Changes the linting settings on the linter using the provided configuration
@@ -1,7 +1,6 @@
1
1
  module CukeLinter
2
2
 
3
3
  # A linter that detects scenarios and outlines that have a setup step that comes after an action step
4
-
5
4
  class TestWithSetupStepAfterActionStepLinter < Linter
6
5
 
7
6
  # Changes the linting settings on the linter using the provided configuration
@@ -1,7 +1,6 @@
1
1
  module CukeLinter
2
2
 
3
3
  # A linter that detects scenarios and outlines that have a setup step that comes after a verification step
4
-
5
4
  class TestWithSetupStepAfterVerificationStepLinter < Linter
6
5
 
7
6
  # Changes the linting settings on the linter using the provided configuration
@@ -1,7 +1,6 @@
1
1
  module CukeLinter
2
2
 
3
3
  # A linter that detects scenarios and outlines that have a setup step as their final step
4
-
5
4
  class TestWithSetupStepAsFinalStepLinter < Linter
6
5
 
7
6
  # Changes the linting settings on the linter using the provided configuration
@@ -1,7 +1,6 @@
1
1
  module CukeLinter
2
2
 
3
3
  # A linter that detects scenarios and outlines that have too many steps
4
-
5
4
  class TestWithTooManyStepsLinter < Linter
6
5
 
7
6
  # Changes the linting settings on the linter using the provided configuration
@@ -1,4 +1,4 @@
1
1
  module CukeLinter
2
2
  # The release version of this gem
3
- VERSION = '1.2.1'.freeze
3
+ VERSION = '1.3.0'.freeze
4
4
  end
data/lib/cuke_linter.rb CHANGED
@@ -19,6 +19,7 @@ require 'cuke_linter/linters/outline_with_single_example_row_linter'
19
19
  require 'cuke_linter/linters/single_test_background_linter'
20
20
  require 'cuke_linter/linters/step_with_end_period_linter'
21
21
  require 'cuke_linter/linters/step_with_too_many_characters_linter'
22
+ require 'cuke_linter/linters/test_name_with_too_many_characters_linter'
22
23
  require 'cuke_linter/linters/test_should_use_background_linter'
23
24
  require 'cuke_linter/linters/test_with_action_step_as_final_step_linter'
24
25
  require 'cuke_linter/linters/test_with_bad_name_linter'
@@ -164,9 +165,6 @@ module CukeLinter
164
165
  def dynamic_linters
165
166
  # No need to keep making new ones over and over...
166
167
  @dynamic_linters ||= Hash.new { |hash, key| hash[key] = key.new }
167
- # return @dynamic_linters if @dynamic_linters
168
- #
169
- # @dynamic_linters = {}
170
168
  end
171
169
 
172
170
  def format_data(formatters, linting_data)
@@ -5,7 +5,7 @@ Feature: Feature without scenarios linter
5
5
  So that I do not have incomplete documentation
6
6
 
7
7
 
8
- Scenario: Linting
8
+ Scenario: Linting (Bad)
9
9
  Given a linter for features without scenarios
10
10
  And the following feature:
11
11
  """
@@ -15,3 +15,25 @@ Feature: Feature without scenarios linter
15
15
  Then an error is reported:
16
16
  | linter | problem | location |
17
17
  | FeatureWithoutScenariosLinter | Feature has no scenarios | <path_to_file>:1 |
18
+
19
+ Scenario: Linting (Good)
20
+ Given a linter for features without scenarios
21
+ And the following feature:
22
+ """
23
+ Feature:
24
+ Scenario:
25
+ """
26
+ When it is linted
27
+ Then no error is reported
28
+
29
+ @cuke_modeler_min_version_3
30
+ Scenario: Linting (Good, with Rules)
31
+ Given a linter for features without scenarios
32
+ And the following feature:
33
+ """
34
+ Feature:
35
+ Rule:
36
+ Scenario:
37
+ """
38
+ When it is linted
39
+ Then no error is reported
@@ -0,0 +1,18 @@
1
+ Feature: Feature without name linter
2
+
3
+ As a reader of documentation
4
+ I want every feature to have a name
5
+ So that I can get an idea of what the feature is about without having to read every use case
6
+
7
+
8
+ Scenario: Linting
9
+ Given a linter for features without a name
10
+ And the following feature:
11
+ """
12
+ Feature:
13
+ This feature does not have a name
14
+ """
15
+ When it is linted
16
+ Then an error is reported:
17
+ | linter | problem | location |
18
+ | FeatureWithoutNameLinter | Feature does not have a name. | <path_to_file>:1 |
@@ -0,0 +1,41 @@
1
+ Feature: Scenario name with too many characters
2
+
3
+ As a reader of documentation
4
+ I want test names not to be unduly long
5
+ So that I can easily understand its purpose
6
+
7
+
8
+ Scenario: Linter
9
+
10
+ Given a linter for test names with too many characters
11
+ And the following feature:
12
+ """
13
+ Feature:
14
+
15
+ Scenario: tea exists and teapots exist and so do cups and saucers and there might be milk in the milk jug together with sugar cubes
16
+ """
17
+ When it is linted
18
+ Then an error is reported:
19
+ | linter | problem | location |
20
+ | TestNameWithTooManyCharactersLinter | Scenario name is too long. 121 characters found (max 80) | <path_to_file>:3 |
21
+
22
+
23
+ Scenario: Configuration of test name count threshold
24
+
25
+ Given a linter for test names with too many characters has been registered
26
+ And the following configuration file:
27
+ """
28
+ TestNameWithTooManyCharactersLinter:
29
+ TestNameLengthThreshold: 30
30
+ """
31
+ And the following feature:
32
+ """
33
+ Feature:
34
+
35
+ Scenario: This scenario name is way too long so it would be better to shorten it somehow, please do so
36
+ """
37
+ When the configuration file is loaded
38
+ And the feature is linted
39
+ Then an error is reported:
40
+ | linter | problem | location |
41
+ | TestNameWithTooManyCharactersLinter | Scenario name is too long. 92 characters found (max 30) | <path_to_file>:3 |
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cuke_linter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Kessler
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-06-14 00:00:00.000000000 Z
11
+ date: 2022-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cuke_modeler
@@ -269,6 +269,7 @@ files:
269
269
  - lib/cuke_linter/linters/single_test_background_linter.rb
270
270
  - lib/cuke_linter/linters/step_with_end_period_linter.rb
271
271
  - lib/cuke_linter/linters/step_with_too_many_characters_linter.rb
272
+ - lib/cuke_linter/linters/test_name_with_too_many_characters_linter.rb
272
273
  - lib/cuke_linter/linters/test_should_use_background_linter.rb
273
274
  - lib/cuke_linter/linters/test_with_action_step_as_final_step_linter.rb
274
275
  - lib/cuke_linter/linters/test_with_bad_name_linter.rb
@@ -299,9 +300,11 @@ files:
299
300
  - testing/cucumber/features/linters/feature_without_name.feature
300
301
  - testing/cucumber/features/linters/feature_without_scenarios.feature
301
302
  - testing/cucumber/features/linters/outline_with_single_example_row.feature
303
+ - testing/cucumber/features/linters/rule_without_name.feature
302
304
  - testing/cucumber/features/linters/single_test_background.feature
303
305
  - testing/cucumber/features/linters/step_too_long.feature
304
306
  - testing/cucumber/features/linters/step_with_end_period.feature
307
+ - testing/cucumber/features/linters/test_name_too_long.feature
305
308
  - testing/cucumber/features/linters/test_should_use_background.feature
306
309
  - testing/cucumber/features/linters/test_with_action_as_final_step.feature
307
310
  - testing/cucumber/features/linters/test_with_bad_name.feature