rubocop-govuk 3.10.0 → 3.15.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: 9e5ccad5d8a29404c085805725894f1e34fcddd9a8081fb6d49dc46fcb83c442
4
- data.tar.gz: bff295ee9cf144c60f5b2653f7c3744e886c34303032d443d735f022269cb94e
3
+ metadata.gz: 1171ad385c38876c2f62430dcb6adaebaaca00ff54e75a6dd8c270d18c09e841
4
+ data.tar.gz: 3575953156d194c6eb0e2bb6b64244862608fd6980df1a8a30668c6eb088ffa5
5
5
  SHA512:
6
- metadata.gz: 5dfb9ea5aca2f9158feb74e46141b32b0a48054ccfa90e82f5cf337a26bcd9ab12ffefc005f930828f0839afdee26fc9aaf22695421dfc6672678ec6e36ab440
7
- data.tar.gz: 34c1d26adf2d8d9118ffccca9128ba3f402328d6378865d949c50707fcd38d2b58c7dbcd91de33d3ea9937d5b9570c8aee670bc73ed284f405b53d86470503b0
6
+ metadata.gz: 9a76bcf79590b6181faf54c27f19b0674137f78863d2c0a8121291eaa4c4b149e0d239405ed292665b7d6f554eb96d33594aaba6a2ff7508b2b1e0dd3e27c64b
7
+ data.tar.gz: c56adb23766c457038b2a3b9dd4b7f4892258ed309f92d2a2d273ef03fab82c05e4d27b8afcd8c42f2bf962127011dfa619504053dc8f61285231acdd540dc4d
@@ -1,3 +1,33 @@
1
+ # 3.15.0
2
+
3
+ - Remove cops that are RuboCop defaults (#88)
4
+ - Disable Rails/DynamicFindBy
5
+ - Permit "and", "but" with RSpec/ContextWording
6
+
7
+ # 3.14.0
8
+
9
+ - Disable Rails/InverseOf
10
+ - Disable Rails/HasManyOrHasOneDependent
11
+ - Disable Rails/OutputSafety
12
+
13
+ # 3.13.0
14
+
15
+ - Disable Layout/FirstMethodArgumentLineBreak (#79)
16
+ - Disable Layout/MultilineMethodArgumentLineBreaks (#80)
17
+
18
+ # 3.12.0
19
+
20
+ - Disable Rails/HasAndBelongsToMany (#77)
21
+
22
+ # 3.11.0
23
+
24
+ - Add optional config for RSpec Cops (#75)
25
+ - Enable Style/Next (#74)
26
+ - Partially enable Rails/SkipsModelValidations (#74)
27
+ - Partially enable Rails/Output (#74)
28
+ - Enable Rails/HasAndBelongsToMany (#74)
29
+ - Enable Bundler/DuplicatedGem (#74)
30
+
1
31
  # 3.10.0
2
32
 
3
33
  * Enable Style/NegatedIf (#71)
data/README.md CHANGED
@@ -11,35 +11,39 @@ Add `rubocop-govuk` to your Gemfile and then run `bundle install`:
11
11
  gem 'rubocop-govuk'
12
12
  ```
13
13
 
14
- Inherit rules from the gem by adding the following to your project's RuboCop config:
14
+ Then inherit the default rules by adding the following in your project:
15
15
 
16
16
  ```yaml
17
17
  # .rubocop.yml
18
18
  inherit_gem:
19
19
  rubocop-govuk:
20
20
  - config/default.yml
21
+
22
+ inherit_mode:
23
+ merge:
24
+ - Exclude
21
25
  ```
22
26
 
23
- or if you also need Rails specific rules:
27
+ You can also configure additional rules for Rails and RSpec:
24
28
 
25
29
  ```yaml
26
30
  # .rubocop.yml
27
31
  inherit_gem:
28
32
  rubocop-govuk:
29
- - config/default.yml
33
+ ...
30
34
  - config/rails.yml
31
-
32
- inherit_mode:
33
- merge:
34
- - Exclude
35
35
  ```
36
36
 
37
- ## Usage
37
+ ```yaml
38
+ # .rubocop.yml
39
+ inherit_gem:
40
+ rubocop-govuk:
41
+ ...
42
+ - config/rspec.yml
43
+ ```
38
44
 
39
- Run RuboCop:
45
+ ## Testing
40
46
 
41
- ```sh
42
- bundle exec rubocop
43
- ```
47
+ Run `bundle exec rake`.
44
48
 
45
49
  [guides]: https://github.com/alphagov/styleguides
@@ -0,0 +1,5 @@
1
+ # Within GOV.UK we use Capybara test method syntax of feature,
2
+ # scenario. We don't want this outside of feature specs though.
3
+ Capybara/FeatureMethods:
4
+ Exclude:
5
+ - 'spec/features/**/*.rb'
@@ -10,19 +10,15 @@ AllCops:
10
10
  - 'node_modules/**/*'
11
11
 
12
12
  DisplayCopNames:
13
- Description: 'Display cop names in offense messages'
14
13
  Enabled: true
15
14
 
16
15
  ExtraDetails:
17
- Description: 'Display extra details in offense messages.'
18
16
  Enabled: true
19
17
 
20
18
  DisplayStyleGuide:
21
- Description: 'Display style guide URLs in offense messages.'
22
19
  Enabled: true
23
20
 
24
21
  inherit_from:
25
- - bundler.yml
26
22
  - layout.yml
27
23
  - metrics.yml
28
24
  - naming.yml
@@ -1,18 +1,9 @@
1
- # Part of the orignal GDS styleguide
2
- # "Use empty lines between defs and to break up a method into logical paragraphs."
3
- # https://github.com/alphagov/styleguides/blob/6395a10d41c3938f4c147cda443fd83f854c3e7a/ruby.md#general
4
- Layout/EmptyLineBetweenDefs:
5
- Description: Use empty lines between defs.
6
- Enabled: true
7
- AllowAdjacentOneLineDefs: false
8
-
9
1
  # https://github.com/alphagov/govuk-lint/pull/7
10
2
  # "There are occasions where following this rule forces you to make the
11
3
  # code less readable. This is particularly the case for tests where method
12
4
  # names form the test descriptions. Keeping test descriptions under a
13
5
  # certain length can force them to become cryptic."
14
6
  Layout/LineLength:
15
- Description: Limit lines to 80 characters.
16
7
  Enabled: false
17
8
 
18
9
  # We have two styles of method call in our apps:
@@ -33,7 +24,6 @@ Layout/MultilineMethodCallIndentation:
33
24
  # "Outdent private etc"
34
25
  # https://github.com/alphagov/styleguides/blob/6395a10d41c3938f4c147cda443fd83f854c3e7a/ruby.md#classes
35
26
  Layout/AccessModifierIndentation:
36
- Description: Check indentation of private/protected visibility modifiers.
37
27
  Enabled: true
38
28
  EnforcedStyle: outdent
39
29
 
@@ -86,17 +76,3 @@ Layout/MultilineArrayLineBreaks:
86
76
  # and avoids wasting time tweaking an arbitrary layout.
87
77
  Layout/MultilineHashKeyLineBreaks:
88
78
  Enabled: true
89
-
90
- # We should be consistent: if some items of a method call are
91
- # on multiple lines, then all items should be. This works
92
- # better with the indentation Cops, produces clearer diffs,
93
- # and avoids wasting time tweaking an arbitrary layout.
94
- Layout/MultilineMethodArgumentLineBreaks:
95
- Enabled: true
96
-
97
- # We should put each argument of a method call on a new line,
98
- # if any are on new lines. This prevents unnecessary decisions
99
- # about which style to use; the multiline style also helps to
100
- # avoid excessively long lines.
101
- Layout/FirstMethodArgumentLineBreak:
102
- Enabled: true
@@ -46,7 +46,6 @@ Metrics/PerceivedComplexity:
46
46
  # We should avoid cops that are based on heuristics, since
47
47
  # it's not clear what action to take to fix an issue.
48
48
  Metrics/BlockNesting:
49
- Description: 'Avoid excessive block nesting'
50
49
  Enabled: false
51
50
 
52
51
  # Analog of: 736b3d295f88b9ba6676fc168b823535582388c2
@@ -55,7 +54,6 @@ Metrics/BlockNesting:
55
54
  # We should avoid cops that are based on heuristics, since
56
55
  # it's not clear what action to take to fix an issue.
57
56
  Metrics/CyclomaticComplexity:
58
- Description: 'Avoid complex methods.'
59
57
  Enabled: false
60
58
 
61
59
  # Analog of: 736b3d295f88b9ba6676fc168b823535582388c2
@@ -64,7 +62,6 @@ Metrics/CyclomaticComplexity:
64
62
  # We should avoid cops that are based on heuristics, since
65
63
  # it's not clear what action to take to fix an issue.
66
64
  Metrics/MethodLength:
67
- Description: 'Avoid methods longer than 10 lines of code.'
68
65
  Enabled: false
69
66
 
70
67
  # Analog of: 736b3d295f88b9ba6676fc168b823535582388c2
@@ -73,5 +70,4 @@ Metrics/MethodLength:
73
70
  # We should avoid cops that are based on heuristics, since
74
71
  # it's not clear what action to take to fix an issue.
75
72
  Metrics/ParameterLists:
76
- Description: 'Avoid parameter lists longer than three or four parameters.'
77
73
  Enabled: false
@@ -13,8 +13,9 @@
13
13
  Naming/AccessorMethodName:
14
14
  Enabled: false
15
15
 
16
- # Introduced in: c69a7eb3af955d6c4c0cf0c3cec8e9f330c74429
17
- # TODO: unclear why this is here!
16
+ # We should be free to decide on interfaces that make sense to us.
17
+ # At the time of writing, this Cop is not auto-correctable, and
18
+ # would generate a prohibitively high number of issues across our
19
+ # repos, which would require manual intervention.
18
20
  Naming/PredicateName:
19
- Description: 'Check the names of predicate methods.'
20
21
  Enabled: false
@@ -13,20 +13,69 @@ AllCops:
13
13
  Rails:
14
14
  Enabled: true
15
15
 
16
- # Introduced in: c69a7eb3af955d6c4c0cf0c3cec8e9f330c74429
17
- # TODO: unclear why this is here!
18
- Rails/HasAndBelongsToMany:
19
- Description: 'Prefer has_many :through to has_and_belongs_to_many.'
16
+ # We have custom find_by methods in several repos, which
17
+ # we're not going to rename. This Cop also raises false
18
+ # positives for find_by methods that are unrelated to model
19
+ # classes, as well as for repos using Mongoid. The value
20
+ # of the consistency this brings is limited, since we mostly
21
+ # use find_by(key: value) anyway.
22
+ #
23
+ # https://github.com/rubocop-hq/rubocop/issues/3758
24
+ Rails/DynamicFindBy:
20
25
  Enabled: false
21
26
 
22
- # Introduced in: c69a7eb3af955d6c4c0cf0c3cec8e9f330c74429
23
- # TODO: unclear why this is here!
27
+ # We commonly print output in Ruby code that has been
28
+ # extracted from a Rake task in 'lib/'.
24
29
  Rails/Output:
25
- Description: 'Checks for calls to puts, print, etc.'
26
- Enabled: false
30
+ Exclude:
31
+ - 'lib/**/*.rb'
27
32
 
28
- # Introduced in: 91d7bf4895db12727582ad7bf47bdcb20ab178f7
29
- # TODO: unclear (in any real detail) why this is here!
33
+ # It's unclear what remedial action to take for the total
34
+ # set of methods this Cop has issues with. For example, we
35
+ # use 'update_all' in many of our repos, for which there is
36
+ # no efficient alternative. Instead, we should only enable
37
+ # this Cop for methods that have a clear alternative.
30
38
  Rails/SkipsModelValidations:
31
- Description: 'Avoid methods that skip model validations.'
39
+ Blacklist:
40
+ - update_attribute
41
+
42
+ # While using has_many/through does have some advantages,
43
+ # it also requires a significant amount of boilerplate code:
44
+ #
45
+ # - An additional 'has_many :join_table' statement
46
+ # - An additional class for the join table (model)
47
+ #
48
+ # This Cop/rule appears to have been written with the
49
+ # assumption that all join tables have inherent meaning,
50
+ # we want to represent, which is not the case; sometimes
51
+ # relationships are just # many-to-many, and that's it.
52
+ Rails/HasAndBelongsToMany:
53
+ Enabled: false
54
+
55
+ # While using 'inverse_of' can reduce DB queries, we have
56
+ # not found this to be a problem in practice. The advantage
57
+ # of turning this on would be that we make the inverse
58
+ # behaviour explicit everywhere ActiveRecord can't apply it
59
+ # automatically, but this is rarely a surprise for developers.
60
+ # We also don't want to add 'inverse_of: false' everywhere;
61
+ # at the time of writing, there is no auto-correct for this.
62
+ Rails/InverseOf:
63
+ Enabled: false
64
+
65
+ # This is incompatible with the more robust use of foreign
66
+ # key constraints, which provide the same behaviour.
67
+ #
68
+ # Example: https://github.com/alphagov/content-publisher/blob/f26d9b551842fdf2084159b5b7f1bb078da56936/db/schema.rb#L396
69
+ Rails/HasManyOrHasOneDependent:
70
+ Enabled: false
71
+
72
+ # We commonly want to render HTML without escaping it, which
73
+ # is what 'html_safe' is for. In many cases, the content we
74
+ # render has already been sanitised (e.g. through Govspeak),
75
+ # or is otherwise trusted e.g. from a content item. We trust
76
+ # that developers will use 'html_safe' responsibly, and prefer
77
+ # the default, escaped output otherwise. At the time of writing,
78
+ # this Cop is disabled in a lot of repos, indicating it offers
79
+ # little value to many developers.
80
+ Rails/OutputSafety:
32
81
  Enabled: false
@@ -0,0 +1,47 @@
1
+ require: rubocop-rspec
2
+
3
+ inherit_from:
4
+ - capybara.yml
5
+
6
+ # Analog of: 736b3d295f88b9ba6676fc168b823535582388c2
7
+ #
8
+ # We should avoid cops that are based on heuristics, since
9
+ # it's not clear what action to take to fix an issue.
10
+ RSpec/ExampleLength:
11
+ Enabled: false
12
+
13
+ # We have common cases, such as rake tasks, where we do not
14
+ # use a class to the describe the test.
15
+ RSpec/DescribeClass:
16
+ Enabled: false
17
+
18
+ # We accept multiple expectations (within reason), preferring
19
+ # them to running mulitple similar tests.
20
+ RSpec/MultipleExpectations:
21
+ Enabled: false
22
+
23
+ # Part of the GOV.UK feature style involves instance variables.
24
+ RSpec/InstanceVariable:
25
+ Exclude:
26
+ - 'spec/features/**/*.rb'
27
+
28
+ # In GOV.UK we quite often test that a class received a method.
29
+ RSpec/MessageSpies:
30
+ Enabled: false
31
+
32
+ # Analog of: 736b3d295f88b9ba6676fc168b823535582388c2
33
+ #
34
+ # We should avoid cops that are based on heuristics, since
35
+ # it's not clear what action to take to fix an issue.
36
+ RSpec/NestedGroups:
37
+ Enabled: false
38
+
39
+ # Nested contexts make more sense with "and" or "but", since
40
+ # they are a refinement of an outer context.
41
+ RSpec/ContextWording:
42
+ Prefixes:
43
+ - when
44
+ - with
45
+ - without
46
+ - and
47
+ - but
@@ -5,31 +5,14 @@
5
5
  # line statements to re-written makes it a harder
6
6
  # to follow the branching logic."
7
7
  Style/IfUnlessModifier:
8
- Description: Favor modifier if/unless usage when you have a single-line body.
9
8
  Enabled: false
10
9
 
11
10
  # Part of the orignal GDS styleguide
12
11
  # "Never chain do...end"
13
12
  # https://github.com/alphagov/styleguides/blob/6395a10d41c3938f4c147cda443fd83f854c3e7a/ruby.md#syntax
14
13
  Style/MethodCalledOnDoEndBlock:
15
- Description: Avoid chaining a method call on a do...end block.
16
14
  Enabled: true
17
15
 
18
- # Part of the orignal GDS styleguide
19
- # "Omit the parentheses when the method doesn’t accept any arguments"
20
- # https://github.com/alphagov/styleguides/blob/6395a10d41c3938f4c147cda443fd83f854c3e7a/ruby.md#syntax
21
- Style/MethodCallWithoutArgsParentheses:
22
- Description: 'Do not use parentheses for method calls with no arguments.'
23
- Enabled: true
24
-
25
- # Part of the orignal GDS styleguide
26
- # "Use Ruby 1.9 syntax for symbolic hash keys.
27
- # This includes method calls."
28
- # https://github.com/alphagov/styleguides/blob/6395a10d41c3938f4c147cda443fd83f854c3e7a/ruby.md#collections
29
- Style/HashSyntax:
30
- Exclude:
31
- - 'db/schema.rb'
32
-
33
16
  # Part of the orignal GDS styleguide
34
17
  # "Add a trailing comma to multi-line array [...]
35
18
  # for clearer diffs with less line noise."
@@ -116,10 +99,12 @@ Style/AsciiComments:
116
99
  Style/BlockDelimiters:
117
100
  EnforcedStyle: braces_for_chaining
118
101
 
119
- # Introduced in: c69a7eb3af955d6c4c0cf0c3cec8e9f330c74429
120
- # TODO: unclear why this is here!
102
+ # We have no concensus on this. Using the nested style is the
103
+ # default for generated Rails app (see 'config/application.rb').
104
+ # Using the compact style can help to reduce boilerplate within
105
+ # modules. At the time of writing, the auto-correct for this Cop
106
+ # is unsafe for moving to either style.
121
107
  Style/ClassAndModuleChildren:
122
- Description: 'Checks style of children classes and modules.'
123
108
  Enabled: false
124
109
 
125
110
  # Introduced in: c69a7eb3af955d6c4c0cf0c3cec8e9f330c74429
@@ -128,7 +113,6 @@ Style/ClassAndModuleChildren:
128
113
  # more documentation is the potential for confusion if that
129
114
  # documentation gets out-of-sync with the class/module.
130
115
  Style/Documentation:
131
- Description: 'Document classes and non-namespace modules.'
132
116
  Enabled: false
133
117
 
134
118
  # Introduced in: c69a7eb3af955d6c4c0cf0c3cec8e9f330c74429
@@ -138,13 +122,6 @@ Style/Documentation:
138
122
  # "There are occasions where following this rule forces you to make the
139
123
  # code less readable."
140
124
  Style/GuardClause:
141
- Description: 'Check for conditionals that can be replaced with guard clauses'
142
- Enabled: false
143
-
144
- # Introduced in: c69a7eb3af955d6c4c0cf0c3cec8e9f330c74429
145
- # TODO: unclear why this is here!
146
- Style/Next:
147
- Description: 'Use `next` to skip iteration instead of a condition at the end.'
148
125
  Enabled: false
149
126
 
150
127
  # Analog of: 736b3d295f88b9ba6676fc168b823535582388c2
@@ -153,28 +130,15 @@ Style/Next:
153
130
  # We should avoid cops that are based on heuristics, since
154
131
  # it's not clear what action to take to fix an issue.
155
132
  Style/RegexpLiteral:
156
- Description: >-
157
- Use %r for regular expressions matching more than
158
- `MaxSlashes` '/' characters.
159
- Use %r only for regular expressions matching more than
160
- `MaxSlashes` '/' character.
161
133
  Enabled: false
162
134
 
163
- # Introduced in: 7aaebf4dbdf2a8d677b4000d3cd3512d4fb91e99
164
- # "This is a relatively new Ruby feature and is not mentioned in the Style
165
- # guide, so this commit disables it by default."
166
- # TODO: unclear why this is here!
135
+ # Using safe navigation is less explicit than making a clear
136
+ # check for truthiness, as evidenced by its own safelist for
137
+ # certain methods. Safe navigation is also less visible and
138
+ # pollutes otherwise readable method calls.
167
139
  Style/SafeNavigation:
168
- Description: >-
169
- This cop transforms usages of a method call safeguarded by a check for the
170
- existance of the object to safe navigation (`&.`).
171
140
  Enabled: false
172
141
 
173
- # We should allow for single line empty methods, as this
174
- # is a convention for Rails controller actions.
175
- Style/SingleLineMethods:
176
- AllowIfMethodIsEmpty: true
177
-
178
142
  # Introduced in: b171d652d3e434b74ddc621df3b5be24c49bc7e8
179
143
  # This cop was added in preperation for a Ruby feature
180
144
  # that is no longer likely to become part of the language.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-govuk
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.10.0
4
+ version: 3.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Government Digital Service
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-13 00:00:00.000000000 Z
11
+ date: 2020-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 0.83.0
33
+ version: 0.85.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 0.83.0
40
+ version: 0.85.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rubocop-rails
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -90,13 +90,14 @@ files:
90
90
  - CHANGELOG.md
91
91
  - LICENSE.md
92
92
  - README.md
93
- - config/bundler.yml
93
+ - config/capybara.yml
94
94
  - config/default.yml
95
95
  - config/layout.yml
96
96
  - config/metrics.yml
97
97
  - config/naming.yml
98
98
  - config/rails.yml
99
99
  - config/rake.yml
100
+ - config/rspec.yml
100
101
  - config/style.yml
101
102
  homepage: https://github.com/alphagov/rubocop-govuk
102
103
  licenses:
@@ -117,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
118
  - !ruby/object:Gem::Version
118
119
  version: '0'
119
120
  requirements: []
120
- rubygems_version: 3.1.3
121
+ rubygems_version: 3.1.4
121
122
  signing_key:
122
123
  specification_version: 4
123
124
  summary: RuboCop GOV.UK
@@ -1,12 +0,0 @@
1
- # Introduced in: 278fc6e903834acfb37565795a196b85282560b0
2
- # "A common pattern in our Gemfiles is to declare a gem
3
- # differently if we're in a dev mode or not. For example
4
- #
5
- # if ENV['API_DEV']
6
- # gem 'gds-api-adapters', path: '../gds-api-adapters'
7
- # else
8
- # gem 'gds-api-adapters', "~> 50.8.0"
9
- # end"
10
- # TODO: see if we can remove this (no longer valid??)
11
- Bundler/DuplicatedGem:
12
- Enabled: false