betterlint 1.29.0 → 1.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +47 -0
- data/config/default.yml +9 -1
- data/lib/betterlint/version.rb +1 -1
- data/lib/rubocop/cop/betterment/no_down_migrations.rb +48 -0
- data/lib/rubocop/cop/betterment.rb +1 -0
- metadata +8 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fd581451b52d71fae89c2aa596958a8bd87bbddfa13f7e8b9019dbbe34cf3c6d
|
|
4
|
+
data.tar.gz: '0198a7a5d5e9db377f8964db8a7cd3e05c0f227e3f7a047d2914d930103aec81'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c9c17ae11bc30e88ea612dd5a5b77dd8c7a89d9b2c0614a2c88dc53f5fc7099055286b1289c58015d7c8fad069df93f455a34000bf6820f32cb62a4241bc8025
|
|
7
|
+
data.tar.gz: ab5077e13a6044c53fc65654a57f282c14922a5288c1d2115c491cd35c063662f06e07572c7b26de750b4e73334ea26e8754ac1e3e8820c8821f312200960cec
|
data/README.md
CHANGED
|
@@ -19,6 +19,10 @@ plugins:
|
|
|
19
19
|
- betterlint
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
+
## Upgrading to 1.30
|
|
23
|
+
|
|
24
|
+
Migration files are included in normal lint runs. Set `AllCops/MigratedSchemaVersion` to the last existing migration version to [skip historical files](#bettermentnodownmigrations).
|
|
25
|
+
|
|
22
26
|
## Dependencies
|
|
23
27
|
|
|
24
28
|
This gem depends on the following other gems:
|
|
@@ -235,6 +239,49 @@ Betterment/UnsafeJob:
|
|
|
235
239
|
|
|
236
240
|
It may make sense to consult your application's values for `Rails.application.config.filter_parameters`; if the application is filtering specific parameters from being logged, it might be a good idea to prevent these values from being stored in plaintext in a database as well.
|
|
237
241
|
|
|
242
|
+
### Betterment/NoDownMigrations
|
|
243
|
+
|
|
244
|
+
This cop enforces [the rule against down migrations](https://the-book.betterment.io/rules/ruby/#do-not-write-down-migrations)
|
|
245
|
+
by flagging `down` methods and `direction.down` calls in migration `reversible` blocks.
|
|
246
|
+
It allows `change` and standalone `up` methods and does not autocorrect.
|
|
247
|
+
|
|
248
|
+
**Bad**
|
|
249
|
+
|
|
250
|
+
```ruby
|
|
251
|
+
class AddNickname < ActiveRecord::Migration[8.0]
|
|
252
|
+
def up
|
|
253
|
+
add_column :users, :nickname, :string
|
|
254
|
+
end
|
|
255
|
+
|
|
256
|
+
def down
|
|
257
|
+
remove_column :users, :nickname
|
|
258
|
+
end
|
|
259
|
+
end
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
**Good**
|
|
263
|
+
|
|
264
|
+
```ruby
|
|
265
|
+
class AddNickname < ActiveRecord::Migration[8.0]
|
|
266
|
+
def change
|
|
267
|
+
add_column :users, :nickname, :string
|
|
268
|
+
end
|
|
269
|
+
end
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
The cop is disabled by default. Enable it for migrations newer than a chosen version:
|
|
273
|
+
|
|
274
|
+
```yaml
|
|
275
|
+
AllCops:
|
|
276
|
+
MigratedSchemaVersion: '20261030120000'
|
|
277
|
+
|
|
278
|
+
Betterment/NoDownMigrations:
|
|
279
|
+
Enabled: true
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
Set `MigratedSchemaVersion` under this cop to ignore additional migrations.
|
|
283
|
+
Leave `Rails/ReversibleMigrationMethodDefinition` disabled: it requires `up` and `down`.
|
|
284
|
+
|
|
238
285
|
### Betterment/NonStandardActions
|
|
239
286
|
|
|
240
287
|
This cop looks at Rails route files and flags routes that go to non-standard controller actions.
|
data/config/default.yml
CHANGED
|
@@ -20,7 +20,7 @@ AllCops:
|
|
|
20
20
|
- Gemfile
|
|
21
21
|
- bin/**/*
|
|
22
22
|
- build/**/*
|
|
23
|
-
- db
|
|
23
|
+
- db/*schema.rb
|
|
24
24
|
- frontend/**/*
|
|
25
25
|
- node_modules/**/*
|
|
26
26
|
- tmp/**/*
|
|
@@ -62,6 +62,14 @@ Betterment/InternalsProtection:
|
|
|
62
62
|
StyleGuide: '#bettermentinternalsprotection'
|
|
63
63
|
Enabled: false
|
|
64
64
|
|
|
65
|
+
Betterment/NoDownMigrations:
|
|
66
|
+
Description: Disallows explicit rollback code in database migrations.
|
|
67
|
+
Enabled: false
|
|
68
|
+
MigratedSchemaVersion:
|
|
69
|
+
StyleGuide: '#bettermentnodownmigrations'
|
|
70
|
+
Include:
|
|
71
|
+
- db/migrate/**/*.rb
|
|
72
|
+
|
|
65
73
|
Betterment/NonNamespacedClass:
|
|
66
74
|
Description: Detects classes that are not namespaced under a module or constant
|
|
67
75
|
StyleGuide: '#bettermentnonamespacedclass'
|
data/lib/betterlint/version.rb
CHANGED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'rubocop/cop/mixin/migrations_helper'
|
|
4
|
+
|
|
5
|
+
module RuboCop
|
|
6
|
+
module Cop
|
|
7
|
+
module Betterment
|
|
8
|
+
class NoDownMigrations < Base
|
|
9
|
+
include MigrationsHelper
|
|
10
|
+
|
|
11
|
+
MSG = 'Do not write explicit rollback code. Correct deployed migrations with a new forward migration.'
|
|
12
|
+
RESTRICT_ON_SEND = %i(down).freeze
|
|
13
|
+
|
|
14
|
+
def on_def(node)
|
|
15
|
+
add_offense(node.loc.name) if node.method?(:down) && migration_to_check?(node)
|
|
16
|
+
end
|
|
17
|
+
alias on_defs on_def
|
|
18
|
+
|
|
19
|
+
def on_send(node)
|
|
20
|
+
if migration_to_check?(node) && reversible_direction?(node.receiver)
|
|
21
|
+
add_offense(node.loc.selector)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
alias on_csend on_send
|
|
25
|
+
|
|
26
|
+
private
|
|
27
|
+
|
|
28
|
+
def migration_to_check?(node)
|
|
29
|
+
return false unless migration_class?(node.each_ancestor(:class).first)
|
|
30
|
+
|
|
31
|
+
cutoff = cop_config.fetch('MigratedSchemaVersion')
|
|
32
|
+
version = File.basename(processed_source.file_path)[/\A\d+(?=_)/]
|
|
33
|
+
!cutoff || !version || version.to_i > Integer(cutoff)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def reversible_direction?(receiver)
|
|
37
|
+
return false unless receiver&.lvar_type?
|
|
38
|
+
|
|
39
|
+
binding = receiver.each_ancestor(:any_block).find do |block|
|
|
40
|
+
block.argument_list.any? { |argument| argument.name == receiver.children.first }
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
binding&.method?(:reversible) && (binding.receiver.nil? || binding.receiver.self_type?)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -12,6 +12,7 @@ require 'rubocop/cop/betterment/hardcoded_id'
|
|
|
12
12
|
require 'rubocop/cop/betterment/implicit_redirect_type'
|
|
13
13
|
require 'rubocop/cop/betterment/internals_protection'
|
|
14
14
|
require 'rubocop/cop/betterment/memoization_with_arguments'
|
|
15
|
+
require 'rubocop/cop/betterment/no_down_migrations'
|
|
15
16
|
require 'rubocop/cop/betterment/non_namespaced_class'
|
|
16
17
|
require 'rubocop/cop/betterment/non_standard_actions'
|
|
17
18
|
require 'rubocop/cop/betterment/non_standard_controller'
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: betterlint
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.30.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Development
|
|
@@ -105,14 +105,14 @@ dependencies:
|
|
|
105
105
|
requirements:
|
|
106
106
|
- - "~>"
|
|
107
107
|
- !ruby/object:Gem::Version
|
|
108
|
-
version: '2.
|
|
108
|
+
version: '2.36'
|
|
109
109
|
type: :runtime
|
|
110
110
|
prerelease: false
|
|
111
111
|
version_requirements: !ruby/object:Gem::Requirement
|
|
112
112
|
requirements:
|
|
113
113
|
- - "~>"
|
|
114
114
|
- !ruby/object:Gem::Version
|
|
115
|
-
version: '2.
|
|
115
|
+
version: '2.36'
|
|
116
116
|
- !ruby/object:Gem::Dependency
|
|
117
117
|
name: rubocop-rake
|
|
118
118
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -179,6 +179,7 @@ files:
|
|
|
179
179
|
- lib/rubocop/cop/betterment/implicit_redirect_type.rb
|
|
180
180
|
- lib/rubocop/cop/betterment/internals_protection.rb
|
|
181
181
|
- lib/rubocop/cop/betterment/memoization_with_arguments.rb
|
|
182
|
+
- lib/rubocop/cop/betterment/no_down_migrations.rb
|
|
182
183
|
- lib/rubocop/cop/betterment/non_namespaced_class.rb
|
|
183
184
|
- lib/rubocop/cop/betterment/non_standard_actions.rb
|
|
184
185
|
- lib/rubocop/cop/betterment/non_standard_controller.rb
|
|
@@ -203,10 +204,10 @@ licenses:
|
|
|
203
204
|
- MIT
|
|
204
205
|
metadata:
|
|
205
206
|
homepage_uri: https://github.com/Betterment/betterlint
|
|
206
|
-
source_code_uri: https://github.com/Betterment/betterlint/tree/v1.
|
|
207
|
-
changelog_uri: https://github.com/Betterment/betterlint/blob/v1.
|
|
207
|
+
source_code_uri: https://github.com/Betterment/betterlint/tree/v1.30.0
|
|
208
|
+
changelog_uri: https://github.com/Betterment/betterlint/blob/v1.30.0/CHANGELOG.md
|
|
208
209
|
bug_tracker_uri: https://github.com/Betterment/betterlint/issues
|
|
209
|
-
documentation_uri: https://www.rubydoc.info/gems/betterlint/1.
|
|
210
|
+
documentation_uri: https://www.rubydoc.info/gems/betterlint/1.30.0
|
|
210
211
|
rubygems_mfa_required: 'true'
|
|
211
212
|
default_lint_roller_plugin: Betterlint::Plugin
|
|
212
213
|
rdoc_options: []
|
|
@@ -223,7 +224,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
223
224
|
- !ruby/object:Gem::Version
|
|
224
225
|
version: '0'
|
|
225
226
|
requirements: []
|
|
226
|
-
rubygems_version: 4.0.
|
|
227
|
+
rubygems_version: 4.0.21
|
|
227
228
|
specification_version: 4
|
|
228
229
|
summary: Betterment rubocop configuration
|
|
229
230
|
test_files: []
|