chutney 3.1.1 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f9a4331eb00fea09babefa186ea7d1e51f13bacbd56cf381cf3fb3d58f293346
4
- data.tar.gz: 16b169146ac5034d46eee9d6858a6b219d854b00d71445a5baca5d6532340b4a
3
+ metadata.gz: 6725cb1d8360b6cf746da8362a04e4e1e1795ee21d70876d39ff08e230ffd0dd
4
+ data.tar.gz: ad0cc926afdacbdcd8853866073102f0796f0cd3338b02f5ff5bdc69060c2724
5
5
  SHA512:
6
- metadata.gz: 2a8000d183486b9c3201ff22e43fbcfc316d5117b68539aae88b0d22ec2d9d549fdd945c8a4a15393f14d147e53c038923be3aa1dda3483a6066fb58a48ff50f
7
- data.tar.gz: a9a32669fb7ddfd30e742647883a079b654e570b2e6653996a8c9ea26fe1601a402148aabf357e6a79f9150d9f747c8ce6fc80b8036180e3a5b53b3096930950
6
+ metadata.gz: a36c2f5da40c1672b77dbbc836a4db6cccf7f445547303aae8e85392ab7b84daba918c8d0343eb73c4683f42c0fce03ebbaf4500a2690878a1fe4fdb5fe0385a
7
+ data.tar.gz: 5a51f02edf59cee68d71855263cdc7692d6132c8eddeb5f97f8d1e3d0512a08e1533457f6545abf6f737dada8c36f81a83d29d6cea15a8c6f4c198a51a7c5728
data/.gitignore CHANGED
@@ -10,6 +10,7 @@
10
10
  Gemfile.lock
11
11
  # rspec failure tracking
12
12
  .rspec_status
13
+ .idea/
13
14
 
14
15
  .DS_Store
15
16
 
data/.rubocop.yml CHANGED
@@ -63,3 +63,4 @@ Style/StringConcatenation:
63
63
 
64
64
  AllCops:
65
65
  NewCops: enable
66
+ SuggestExtensions: false
data/Rakefile CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'rake/testtask'
4
4
 
5
- task default: :build
5
+ task default: :test
6
6
 
7
7
  desc 'Builds the Gem.'
8
8
  task build: :format
@@ -27,7 +27,7 @@ rescue RuntimeError => e
27
27
  end
28
28
 
29
29
  task :spec do
30
- sh 'rspec'
30
+ sh 'bundle exec rspec'
31
31
  end
32
32
 
33
33
  task :cucumber do
data/chutney.gemspec CHANGED
@@ -50,18 +50,18 @@ Gem::Specification.new do |spec|
50
50
 
51
51
  spec.add_runtime_dependency 'amatch', '~> 0.4.0'
52
52
  spec.add_runtime_dependency 'cuke_modeler', '~> 3.3'
53
- spec.add_runtime_dependency 'i18n', '~> 1.8.2'
53
+ spec.add_runtime_dependency 'i18n', '>= 1.8.2', '< 1.13.0'
54
54
  spec.add_runtime_dependency 'pastel', '~> 0.7'
55
55
  spec.add_runtime_dependency 'tty-pie', '~> 0.3'
56
56
 
57
57
 
58
58
  spec.add_development_dependency 'coveralls', '~> 0.8'
59
- spec.add_development_dependency 'cucumber', '~> 6.0'
59
+ spec.add_development_dependency 'cucumber', '>= 7.0'
60
60
  spec.add_development_dependency 'pry-byebug', '~> 3.0'
61
61
  spec.add_development_dependency 'rake', '~> 13.0'
62
62
  spec.add_development_dependency 'rerun', '~> 0.13'
63
63
  spec.add_development_dependency 'rspec-expectations', '~> 3.0'
64
- spec.add_development_dependency 'rubocop', '~> 1.14.0'
64
+ spec.add_development_dependency 'rubocop', '~> 1.32.0'
65
65
  spec.add_development_dependency 'rspec', '~> 3.8'
66
66
 
67
67
  spec.required_ruby_version = '>= 2.6'
@@ -4,6 +4,10 @@ AvoidFullStop:
4
4
  Enabled: true
5
5
  AvoidScripting:
6
6
  Enabled: true
7
+ AvoidSplatStepsInBackground:
8
+ Enabled: true
9
+ AvoidSplatStepsInScenarios:
10
+ Enabled: true
7
11
  AvoidTypographersQuotes:
8
12
  Enabled: true
9
13
  BackgroundDoesMoreThanSetup:
data/config/cucumber.yml CHANGED
@@ -1 +1 @@
1
- default: --publish-quiet
1
+ default: --publish-quiet
@@ -9,4 +9,4 @@ nav_order: 3
9
9
 
10
10
  Chutney looks for a configuration file in the current directory called `config/.chutney.yml`. This configuration mostly switches on individual linters globally, but a few have addition parameters which can be configured (e.g. the maximum characters in a step).
11
11
 
12
- A default configuration can be found [here](https://github.com/BillyRuffian/chutney/blob/master/config/chutney.yml).
12
+ A default configuration can be found [here](https://github.com/BillyRuffian/chutney/blob/master/config/chutney_defaults.yml).
data/docs/usage/rules.md CHANGED
@@ -15,6 +15,10 @@ Chutney enforces its rules with the linters. These are:
15
15
 
16
16
  [AvoidScripting](https://github.com/BillyRuffian/chutney/blob/master/features/avoid_scripting.feature): You have a lot of steps, are you sure you're not scripting the scenario when you should be specifying the behaviour of the system?
17
17
 
18
+ [AvoidSplatStepsInBackground](https://github.com/BillyRuffian/chutney/blob/master/features/avoid_splat_steps_in_background.feature): The Background contains a splat step. It should only contain named steps.
19
+
20
+ [AvoidSplatStepsInScenarios](https://github.com/BillyRuffian/chutney/blob/master/features/avoid_splat_steps_in_scenarios.feature): The Scenario contains a splat step. It should only contain named steps.
21
+
18
22
  [AvoidTypographersQuotes](https://github.com/BillyRuffian/chutney/blob/master/features/avoid_typographers_quotes.feature): Cutting and pasting from Word documents? Is that pasting in curly-quotes instead of neutral ones you would type on a keyboard? Are you sure that's what you want?
19
23
 
20
24
  [BackgroundDoesMoreThanSetup](https://github.com/BillyRuffian/chutney/blob/master/features/background_does_more_than_setup.feature): Background in feature files should only do setup activity and so they should only contain `Given` steps.
data/exe/chutney CHANGED
@@ -10,6 +10,7 @@ require 'optparse'
10
10
 
11
11
  formatters = Set.new
12
12
 
13
+ # rubocop:disable Metrics/BlockLength
13
14
  OptionParser.new do |opts|
14
15
  opts.banner = 'Usage: chutney [files]'
15
16
  opts.on('-f',
@@ -20,6 +21,11 @@ OptionParser.new do |opts|
20
21
  formatters << formatter
21
22
  end
22
23
 
24
+ opts.on('-v', '--version', 'Display the version.') do
25
+ puts Chutney::VERSION
26
+ exit
27
+ end
28
+
23
29
  opts.on('-l',
24
30
  '--linters',
25
31
  'List the linter status by this configuration and exit') do
@@ -38,6 +44,7 @@ OptionParser.new do |opts|
38
44
  exit
39
45
  end
40
46
  end.parse!
47
+ # rubocop:enable Metrics/BlockLength
41
48
 
42
49
  formatters << 'RainbowFormatter' if formatters.empty?
43
50
 
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Chutney
4
+ # service class to lint for avoiding splats
5
+ class AvoidSplatStepsInBackground < Linter
6
+ def lint
7
+ background do |feature, background|
8
+ splat_steps = background&.steps&.select { |s| s.keyword == '*' }
9
+ # add_issue(I18n.t('linters.avoid_full_stop'), feature, child, step) if step.text.strip.end_with? '.'
10
+ if splat_steps && !splat_steps.empty?
11
+ add_issue(I18n.t('linters.avoid_splat_steps_in_background'), feature, background, splat_steps.first)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Chutney
4
+ # service class to lint for avoiding splats
5
+ class AvoidSplatStepsInScenarios < Linter
6
+ def lint
7
+ steps do |feature, child, step|
8
+ add_issue(I18n.t('linters.avoid_splat_steps_in_scenarios'), feature, child, step) if step.keyword == '*'
9
+ end
10
+ end
11
+ end
12
+ end
@@ -66,7 +66,14 @@ module Chutney
66
66
  end
67
67
 
68
68
  def dialect
69
- @content.feature&.parsing_data&.dig(:language) || 'en'
69
+ parsing_data = @content.feature&.parsing_data
70
+ if !parsing_data.nil? && parsing_data.respond_to?(:language)
71
+ parsing_data.language
72
+ elsif parsing_data
73
+ parsing_data[:language]
74
+ else
75
+ raise UnsupportedCucumberError, 'This version of cucumber is unsupported (langauge detection)'
76
+ end
70
77
  end
71
78
 
72
79
  def tags_for(element)
@@ -79,19 +86,12 @@ module Chutney
79
86
  gherkin_type: type(feature, scenario, item),
80
87
  location: location(feature, scenario, item),
81
88
  feature: feature&.name,
82
- scenario: scenario&.name,
83
- step: item&.parsing_data&.dig(:name)
89
+ scenario: scenario&.name
84
90
  ).to_h
85
91
  end
86
92
 
87
93
  def location(feature, scenario, step)
88
- if step
89
- step.parsing_data[:location]
90
- elsif scenario
91
- scenario.parsing_data.dig(:scenario, :location) || scenario.parsing_data.dig(:background, :location)
92
- else
93
- feature ? feature.parsing_data[:location] : { line: 0, column: 0 }
94
- end
94
+ Locator.locate(feature, scenario, step)
95
95
  end
96
96
 
97
97
  def type(_feature, scenario, step)
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Chutney
4
+ # Utility module to assist in locating the source of parts of a gherkin specification
5
+ module Locator
6
+ module_function
7
+
8
+ def locate(feature, scenario, step)
9
+ if step
10
+ locate_step(step)
11
+ elsif scenario
12
+ locate_scenario(scenario)
13
+ elsif feature
14
+ locate_feature(feature)
15
+ else
16
+ feature
17
+ end
18
+ end
19
+
20
+ def locate_step(step)
21
+ return step.parsing_data.location.to_h if step.parsing_data.respond_to?(:location)
22
+ return step.parsing_data[:location] if step.parsing_data.is_a?(Hash)
23
+
24
+ raise UnsupportedCucumberError, 'This version of cucumber is unsupported (step location)'
25
+ end
26
+
27
+ def locate_scenario(scenario)
28
+ parsing_data = scenario.parsing_data
29
+
30
+ if parsing_data.is_a?(Hash)
31
+ parsing_data.dig(:scenario, :location) || parsing_data.dig(:background, :location)
32
+ elsif parsing_data.respond_to?(:scenario)
33
+ (parsing_data.scenario || parsing_data.background).location.to_h
34
+ else
35
+ raise UnsupportedCucumberError, 'This version of cucumber is unsupported (scenario location)'
36
+ end
37
+ end
38
+
39
+ def locate_feature(feature)
40
+ return feature.parsing_data.location.to_h if feature.parsing_data.respond_to?(:location)
41
+ return feature.parsing_data[:location] if feature.parsing_data.is_a?(Hash)
42
+
43
+ raise UnsupportedCucumberError, 'This version of cucumber is unsupported (feature location)'
44
+ end
45
+ end
46
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Chutney
4
- VERSION = '3.1.1'
4
+ VERSION = '3.3.0'
5
5
  end
data/lib/chutney.rb CHANGED
@@ -7,6 +7,8 @@ require 'chutney/linter'
7
7
  require 'chutney/linter/avoid_full_stop'
8
8
  require 'chutney/linter/avoid_outline_for_single_example'
9
9
  require 'chutney/linter/avoid_scripting'
10
+ require 'chutney/linter/avoid_splat_steps_in_background'
11
+ require 'chutney/linter/avoid_splat_steps_in_scenarios'
10
12
  require 'chutney/linter/avoid_typographers_quotes'
11
13
  require 'chutney/linter/background_does_more_than_setup'
12
14
  require 'chutney/linter/background_requires_multiple_scenarios'
@@ -37,6 +39,7 @@ require 'chutney/linter/unknown_variable'
37
39
  require 'chutney/linter/unused_variable'
38
40
  require 'chutney/linter/use_background'
39
41
  require 'chutney/linter/use_outline'
42
+ require 'chutney/locator'
40
43
  require 'chutney/version'
41
44
 
42
45
  require 'cuke_modeler'
@@ -48,6 +51,8 @@ require 'set'
48
51
  require 'yaml'
49
52
 
50
53
  module Chutney
54
+ class UnsupportedCucumberError < StandardError; end
55
+
51
56
  # gherkin linter
52
57
  class ChutneyLint
53
58
  extend Forwardable
@@ -11,6 +11,10 @@ en:
11
11
  avoid_scripting: >-
12
12
  You have %{count} When steps when you should only have one.
13
13
  Be careful not to add And steps following a When.
14
+ avoid_splat_steps_in_background: >-
15
+ The Background contains a splat step. It should only contain named steps.
16
+ avoid_splat_steps_in_scenarios: >-
17
+ The Scenario contains a splat step. It should only contain named steps.
14
18
  avoid_typographers_quotes: >-
15
19
  You are using typographers quotation marks (curly quotes).
16
20
  Make sure you intend to use this character and not a neutral quote
data/spec/spec_helper.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'simplecov'
4
- require 'coveralls'
5
- # Coveralls.wear!
6
- SimpleCov.start
3
+ # require 'simplecov'
4
+ # require 'coveralls'
5
+ # # Coveralls.wear!
6
+ # SimpleCov.start
7
7
 
8
8
  # This file was generated by the `rspec --init` command. Conventionally, all
9
9
  # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chutney
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.1
4
+ version: 3.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nigel Brookes-Thomas
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: exe
13
13
  cert_chain: []
14
- date: 2021-05-12 00:00:00.000000000 Z
14
+ date: 2022-08-26 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: amatch
@@ -45,16 +45,22 @@ dependencies:
45
45
  name: i18n
46
46
  requirement: !ruby/object:Gem::Requirement
47
47
  requirements:
48
- - - "~>"
48
+ - - ">="
49
49
  - !ruby/object:Gem::Version
50
50
  version: 1.8.2
51
+ - - "<"
52
+ - !ruby/object:Gem::Version
53
+ version: 1.13.0
51
54
  type: :runtime
52
55
  prerelease: false
53
56
  version_requirements: !ruby/object:Gem::Requirement
54
57
  requirements:
55
- - - "~>"
58
+ - - ">="
56
59
  - !ruby/object:Gem::Version
57
60
  version: 1.8.2
61
+ - - "<"
62
+ - !ruby/object:Gem::Version
63
+ version: 1.13.0
58
64
  - !ruby/object:Gem::Dependency
59
65
  name: pastel
60
66
  requirement: !ruby/object:Gem::Requirement
@@ -101,16 +107,16 @@ dependencies:
101
107
  name: cucumber
102
108
  requirement: !ruby/object:Gem::Requirement
103
109
  requirements:
104
- - - "~>"
110
+ - - ">="
105
111
  - !ruby/object:Gem::Version
106
- version: '6.0'
112
+ version: '7.0'
107
113
  type: :development
108
114
  prerelease: false
109
115
  version_requirements: !ruby/object:Gem::Requirement
110
116
  requirements:
111
- - - "~>"
117
+ - - ">="
112
118
  - !ruby/object:Gem::Version
113
- version: '6.0'
119
+ version: '7.0'
114
120
  - !ruby/object:Gem::Dependency
115
121
  name: pry-byebug
116
122
  requirement: !ruby/object:Gem::Requirement
@@ -173,14 +179,14 @@ dependencies:
173
179
  requirements:
174
180
  - - "~>"
175
181
  - !ruby/object:Gem::Version
176
- version: 1.14.0
182
+ version: 1.32.0
177
183
  type: :development
178
184
  prerelease: false
179
185
  version_requirements: !ruby/object:Gem::Requirement
180
186
  requirements:
181
187
  - - "~>"
182
188
  - !ruby/object:Gem::Version
183
- version: 1.14.0
189
+ version: 1.32.0
184
190
  - !ruby/object:Gem::Dependency
185
191
  name: rspec
186
192
  requirement: !ruby/object:Gem::Requirement
@@ -247,6 +253,8 @@ files:
247
253
  - lib/chutney/linter/avoid_full_stop.rb
248
254
  - lib/chutney/linter/avoid_outline_for_single_example.rb
249
255
  - lib/chutney/linter/avoid_scripting.rb
256
+ - lib/chutney/linter/avoid_splat_steps_in_background.rb
257
+ - lib/chutney/linter/avoid_splat_steps_in_scenarios.rb
250
258
  - lib/chutney/linter/avoid_typographers_quotes.rb
251
259
  - lib/chutney/linter/background_does_more_than_setup.rb
252
260
  - lib/chutney/linter/background_requires_multiple_scenarios.rb
@@ -277,6 +285,7 @@ files:
277
285
  - lib/chutney/linter/unused_variable.rb
278
286
  - lib/chutney/linter/use_background.rb
279
287
  - lib/chutney/linter/use_outline.rb
288
+ - lib/chutney/locator.rb
280
289
  - lib/chutney/version.rb
281
290
  - lib/config/locales/en.yml
282
291
  - spec/chutney_spec.rb
@@ -303,7 +312,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
303
312
  - !ruby/object:Gem::Version
304
313
  version: '0'
305
314
  requirements: []
306
- rubygems_version: 3.1.4
315
+ rubygems_version: 3.3.7
307
316
  signing_key:
308
317
  specification_version: 4
309
318
  summary: A linter for multi-lingual Gherkin