rubocop-safe_migrations 0.0.1 → 0.0.2
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/Gemfile.lock +1 -1
- data/README.md +11 -1
- data/lib/rubocop/cop/safe_migrations_cops.rb +7 -1
- data/lib/rubocop/safe_migrations/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3649ce5cf29e895eb9639963ee1e26d5a57deed878c2dce600699b03c8a4dc62
|
4
|
+
data.tar.gz: 046e3c506c93b0ec04bde54d0a3ec8fa3f190d92678ab68a8e2b931ba717158b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1cf46dd12f6d67b50f83edcab3f49f8f84d5c2ede5612a7ffb31cd9ca8670f346052da4ac66bb38f065fa3f2e0d42908c05482ae6d06189d9358d493d7576d90
|
7
|
+
data.tar.gz: 626594af95804cc4e22f0303b0b1bb984be3e5d0cf50f22ac41d8b88c5f8d65f3b8e0f5e96b4b3efca8f526b0f52fac25c63e615eb66495001a57c28b3d4804f
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -32,6 +32,16 @@ This is more importante to be avoided if you have your deploy pipeline configure
|
|
32
32
|
|
33
33
|
By default, all active record methods that generate update, create or delete queries are checked by the cop, and if used on migrations an offense will be generated.
|
34
34
|
|
35
|
+
To turn some method available to be used on migration, just add it to AllowedMethods config on rubocop.yml, for example:
|
36
|
+
|
37
|
+
```yaml
|
38
|
+
Migration/UpdatingDataInMigration:
|
39
|
+
AllowedMethods:
|
40
|
+
- toggle
|
41
|
+
```
|
42
|
+
|
43
|
+
Using the configuration above, the cop will not add an offense when toggle method is used on migrations.
|
44
|
+
|
35
45
|
## Development
|
36
46
|
|
37
47
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -55,13 +65,13 @@ Everyone interacting in the Rubocop::SafeMigrations project's codebases, issue t
|
|
55
65
|
|
56
66
|
### For Updating data in migration rule
|
57
67
|
- [ ] Adds check to active record update_counters method called on migration
|
68
|
+
- [ ] Adds check to active record create method called on migration
|
58
69
|
- [ ] Adds check to active record create_or_update method called on migration
|
59
70
|
- [ ] Adds check to active record decrement method called on migration
|
60
71
|
- [ ] Adds check to active record increment method called on migration
|
61
72
|
- [ ] Adds check to active record find_or_create method called on migration
|
62
73
|
- [ ] Adds check to string sql execution with updates, inserts or deletions
|
63
74
|
- [ ] Position offense message on the method being called, not in the end of line
|
64
|
-
- [ ] Adds option to be able to whitelist some methods
|
65
75
|
- [ ] Adds option to be able to add custom methods to blacklist
|
66
76
|
|
67
77
|
### For new rules
|
@@ -3,14 +3,20 @@ module RuboCop
|
|
3
3
|
module Cop
|
4
4
|
module Migration
|
5
5
|
class UpdatingDataInMigration < RuboCop::Cop::Cop
|
6
|
-
MSG =
|
6
|
+
MSG = "Updating or manipulating data in migration is unsafe!".freeze
|
7
7
|
|
8
8
|
def on_send(node)
|
9
|
+
return if allowed_methods.include?(node.method_name.to_s)
|
10
|
+
|
9
11
|
add_offense(node) if forbidden_methods.include?(node.method_name)
|
10
12
|
end
|
11
13
|
|
12
14
|
private
|
13
15
|
|
16
|
+
def allowed_methods
|
17
|
+
cop_config["AllowedMethods"] || []
|
18
|
+
end
|
19
|
+
|
14
20
|
def forbidden_methods
|
15
21
|
%i[
|
16
22
|
update
|