rubocop-sorbet 0.3.7 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/.github/CODEOWNERS +2 -0
  3. data/.github/probots.yml +1 -1
  4. data/.github/stale.yml +20 -0
  5. data/.gitignore +0 -2
  6. data/.rspec +3 -0
  7. data/.rubocop.yml +2 -12
  8. data/.travis.yml +3 -1
  9. data/Gemfile +6 -7
  10. data/Gemfile.lock +27 -42
  11. data/README.md +64 -6
  12. data/Rakefile +34 -5
  13. data/config/default.yml +143 -2
  14. data/lib/rubocop-sorbet.rb +9 -1
  15. data/lib/rubocop/cop/sorbet/binding_constants_without_type_alias.rb +24 -1
  16. data/lib/rubocop/cop/sorbet/forbid_extend_t_sig_helpers_in_shims.rb +53 -0
  17. data/lib/rubocop/cop/sorbet/forbid_include_const_literal.rb +0 -40
  18. data/lib/rubocop/cop/sorbet/forbid_superclass_const_literal.rb +0 -17
  19. data/lib/rubocop/cop/sorbet/forbid_untyped_struct_props.rb +58 -0
  20. data/lib/rubocop/cop/sorbet/one_ancestor_per_line.rb +75 -0
  21. data/lib/rubocop/cop/sorbet/sigils/enforce_sigil_order.rb +11 -1
  22. data/lib/rubocop/cop/sorbet/signatures/enforce_signatures.rb +19 -10
  23. data/lib/rubocop/cop/sorbet/signatures/parameters_ordering_in_signature.rb +14 -6
  24. data/lib/rubocop/cop/sorbet/signatures/signature_build_order.rb +22 -3
  25. data/lib/rubocop/cop/sorbet/single_line_rbi_class_module_definitions.rb +46 -0
  26. data/lib/rubocop/cop/sorbet_cops.rb +25 -0
  27. data/lib/rubocop/sorbet.rb +15 -0
  28. data/lib/rubocop/sorbet/inject.rb +20 -0
  29. data/lib/rubocop/sorbet/version.rb +6 -0
  30. data/manual/cops.md +32 -0
  31. data/manual/cops_sorbet.md +424 -0
  32. data/rubocop-sorbet.gemspec +18 -18
  33. data/service.yml +1 -1
  34. data/tasks/cops_documentation.rake +317 -0
  35. metadata +26 -12
  36. data/lib/rubocop_sorbet.rb +0 -22
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 064c7d818d231c638d6b7e4a12d840506bc7dc6aa4381e95d05aea33a45979c4
4
- data.tar.gz: ea038c407cebb75af61397ee08e9df6e51531c2697fb92845e3111219cf5b0db
3
+ metadata.gz: 3e0aff98c220979881dd8ed739d626d9eb20713733126374a4a5a3221504d416
4
+ data.tar.gz: 66e46df2c63d59ca390edcfc2478467bb0c56b659009e5484ca7275c30f36b45
5
5
  SHA512:
6
- metadata.gz: 3692612ec3ecf2181768c8239752907bd99b6068ff7cc3c56602d338c20f93e5e3ddb04bf33186cc4dc8fd9eb32bfe791cfeb53d40ade27880d2c8fe6a7c46f5
7
- data.tar.gz: 41a0f6f1546653a087ac2eb1c8217e5c5fa9c8be5c3ac736ef917c671c39c7df90c85dcbe1b0b6466fd84bbcfd86ceb9783f32974dfbb80e152e98fd483b3a0b
6
+ metadata.gz: fc247fceacb30871f63f3172d181a93d2775b57674ded60539615435e04ccdf95480047b5450784e689de1a42980b4cddb661214b7177645a33e50aef06fd765
7
+ data.tar.gz: 170d0f7f005f94412839046bd959420364f86c0fb5d668a58c4ab65c80b6a6fe55d7a054e3e356b03e56b070e8fec076cfec03df76f38de856046baae9802a71
@@ -0,0 +1,2 @@
1
+ # Request a review from @Shopify/sorbet when a new PR is created
2
+ * @Shopify/sorbet
data/.github/probots.yml CHANGED
@@ -1,3 +1,3 @@
1
1
  enabled:
2
2
  - cla
3
-
3
+ - probot-stale
data/.github/stale.yml ADDED
@@ -0,0 +1,20 @@
1
+ # Number of days of inactivity before an issue becomes stale
2
+ daysUntilStale: 30
3
+ # Number of days of inactivity before a stale issue is closed
4
+ daysUntilClose: 7
5
+ # Issues with these labels will never be considered stale
6
+ exemptLabels:
7
+ - pinned
8
+ - security
9
+ # Label to use when marking an issue as stale
10
+ staleLabel: stale
11
+ # Comment to post when marking an issue as stale. Set to `false` to disable
12
+ markComment: >
13
+ This PR has been automatically marked as stale because it has not had
14
+ recent activity. It will be closed if no further activity occurs. Thank you
15
+ for your contributions.
16
+ # Comment to post when closing a stale issue. Set to `false` to disable
17
+ closeComment: false
18
+ #
19
+ only: pulls
20
+ #
data/.gitignore CHANGED
@@ -6,5 +6,3 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
-
10
- .rubocop-https--*
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml CHANGED
@@ -1,23 +1,13 @@
1
1
  # This file strictly follows the rules defined in the Ruby style guide:
2
2
  # http://shopify.github.io/ruby-style-guide/
3
- inherit_from:
4
- - https://shopify.github.io/ruby-style-guide/rubocop.yml
3
+ inherit_gem:
4
+ rubocop-shopify: rubocop.yml
5
5
 
6
6
  AllCops:
7
7
  TargetRubyVersion: 2.5
8
8
  Exclude:
9
9
  - vendor/**/*
10
10
 
11
- Naming/AccessorMethodName:
12
- Enabled: false
13
-
14
- require:
15
- - rubocop-sorbet
16
-
17
11
  Naming/FileName:
18
12
  Exclude:
19
13
  - lib/rubocop-sorbet.rb
20
-
21
- Lint/HandleExceptions:
22
- Exclude:
23
- - Rakefile
data/.travis.yml CHANGED
@@ -3,7 +3,9 @@ sudo: false
3
3
  language: ruby
4
4
  cache: bundler
5
5
  rvm:
6
- - 2.6.2
6
+ - 2.5
7
+ - 2.6
8
+ - 2.7
7
9
  before_install: gem install bundler -v 1.17.3
8
10
  script:
9
11
  - bundle exec rubocop --config .rubocop.yml
data/Gemfile CHANGED
@@ -1,11 +1,10 @@
1
1
  # frozen_string_literal: true
2
-
3
- source('https://rubygems.org')
4
- git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
5
-
6
- group(:deployment) do
7
- gem('package_cloud', '~> 0.3.05')
8
- end
2
+ source "https://rubygems.org"
9
3
 
10
4
  # Specify your gem's dependencies in rubocop-sorbet.gemspec
11
5
  gemspec
6
+
7
+ gem "rake", ">= 12.3.3"
8
+ gem "rspec"
9
+ gem "rubocop-shopify", require: false
10
+ gem "yard", "~> 0.9"
data/Gemfile.lock CHANGED
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rubocop-sorbet (0.3.7)
4
+ rubocop-sorbet (0.6.0)
5
+ rubocop
5
6
 
6
7
  GEM
7
8
  remote: https://rubygems.org/
@@ -15,38 +16,18 @@ GEM
15
16
  adamantium (~> 0.2.0)
16
17
  equalizer (~> 0.0.9)
17
18
  diff-lcs (1.3)
18
- domain_name (0.5.20190701)
19
- unf (>= 0.0.5, < 1.0.0)
20
19
  equalizer (0.0.11)
21
- highline (1.6.20)
22
- http-cookie (1.0.3)
23
- domain_name (~> 0.5)
24
20
  ice_nine (0.11.2)
25
- jaro_winkler (1.5.3)
26
- json_pure (1.8.1)
27
21
  memoizable (0.4.2)
28
22
  thread_safe (~> 0.3, >= 0.3.1)
29
- mime-types (3.2.2)
30
- mime-types-data (~> 3.2015)
31
- mime-types-data (3.2019.0331)
32
- netrc (0.11.0)
33
- package_cloud (0.3.05)
34
- highline (= 1.6.20)
35
- json_pure (= 1.8.1)
36
- rainbow (= 2.2.2)
37
- rest-client (~> 2.0)
38
- thor (~> 0.18)
39
- parallel (1.17.0)
40
- parser (2.6.3.0)
23
+ parallel (1.19.1)
24
+ parser (2.7.1.3)
41
25
  ast (~> 2.4.0)
42
26
  procto (0.0.3)
43
- rainbow (2.2.2)
44
- rake
45
- rake (12.3.2)
46
- rest-client (2.0.2)
47
- http-cookie (>= 1.0.2, < 2.0)
48
- mime-types (>= 1.16, < 4.0)
49
- netrc (~> 0.8)
27
+ rainbow (3.0.0)
28
+ rake (13.0.1)
29
+ regexp_parser (1.7.0)
30
+ rexml (3.2.4)
50
31
  rspec (3.8.0)
51
32
  rspec-core (~> 3.8.0)
52
33
  rspec-expectations (~> 3.8.0)
@@ -60,38 +41,42 @@ GEM
60
41
  diff-lcs (>= 1.2.0, < 2.0)
61
42
  rspec-support (~> 3.8.0)
62
43
  rspec-support (3.8.2)
63
- rubocop (0.72.0)
64
- jaro_winkler (~> 1.5.1)
44
+ rubocop (0.85.0)
65
45
  parallel (~> 1.10)
66
- parser (>= 2.6)
46
+ parser (>= 2.7.0.1)
67
47
  rainbow (>= 2.2.2, < 4.0)
48
+ regexp_parser (>= 1.7)
49
+ rexml
50
+ rubocop-ast (>= 0.0.3)
68
51
  ruby-progressbar (~> 1.7)
69
- unicode-display_width (>= 1.4.0, < 1.7)
52
+ unicode-display_width (>= 1.4.0, < 2.0)
53
+ rubocop-ast (0.0.3)
54
+ parser (>= 2.7.0.1)
55
+ rubocop-shopify (1.0.3)
56
+ rubocop (~> 0.85.0)
70
57
  ruby-progressbar (1.10.1)
71
- thor (0.20.3)
72
58
  thread_safe (0.3.6)
73
- unf (0.1.4)
74
- unf_ext
75
- unf_ext (0.0.7.6)
76
- unicode-display_width (1.6.0)
77
- unparser (0.4.5)
59
+ unicode-display_width (1.7.0)
60
+ unparser (0.4.7)
78
61
  abstract_type (~> 0.0.7)
79
62
  adamantium (~> 0.2.0)
80
63
  concord (~> 0.1.5)
81
64
  diff-lcs (~> 1.3)
82
65
  equalizer (~> 0.0.9)
83
- parser (~> 2.6.3)
66
+ parser (>= 2.6.5)
84
67
  procto (~> 0.0.2)
68
+ yard (0.9.25)
85
69
 
86
70
  PLATFORMS
87
71
  ruby
88
72
 
89
73
  DEPENDENCIES
90
- package_cloud (~> 0.3.05)
91
- rspec (~> 3.7)
92
- rubocop (~> 0.57)
74
+ rake (>= 12.3.3)
75
+ rspec
76
+ rubocop-shopify
93
77
  rubocop-sorbet!
94
- unparser (~> 0.4.2)
78
+ unparser
79
+ yard (~> 0.9)
95
80
 
96
81
  BUNDLED WITH
97
82
  1.17.3
data/README.md CHANGED
@@ -6,29 +6,87 @@ A collection of Rubocop rules for Sorbet.
6
6
 
7
7
  ## Installation
8
8
 
9
- Add this line to your application's Gemfile:
9
+ Just install the `rubocop-sorbet` gem
10
+
11
+ ```sh
12
+ gem install rubocop-sorbet
13
+ ```
14
+ or, if you use `Bundler`, add this line your application's `Gemfile`:
10
15
 
11
16
  ```ruby
12
- gem 'rubocop-sorbet'
17
+ gem 'rubocop-sorbet', require: false
13
18
  ```
14
19
 
15
- And then execute:
20
+ ## Usage
16
21
 
17
- $ bundle
22
+ You need to tell RuboCop to load the Sorbet extension. There are three ways to do this:
18
23
 
19
- ## Usage
24
+ ### RuboCop configuration file
25
+
26
+ Put this into your `.rubocop.yml`:
27
+
28
+ ```yaml
29
+ require: rubocop-sorbet
30
+ ```
20
31
 
21
- And add this to your `.rubocop.yml` file:
32
+ Alternatively, use the following array notation when specifying multiple extensions:
22
33
 
23
34
  ```yaml
24
35
  require:
36
+ - rubocop-other-extension
25
37
  - rubocop-sorbet
26
38
  ```
27
39
 
40
+ Now you can run `rubocop` and it will automatically load the RuboCop Sorbet cops together with the standard cops.
41
+
42
+ ### Command line
43
+
44
+ ```sh
45
+ rubocop --require rubocop-sorbet
46
+ ```
47
+
48
+ ### Rake task
49
+
50
+ ```ruby
51
+ RuboCop::RakeTask.new do |task|
52
+ task.requires << 'rubocop-sorbet'
53
+ end
54
+ ```
55
+
56
+ ## The Cops
57
+ All cops are located under [`lib/rubocop/cop/sorbet`](lib/rubocop/cop/sorbet), and contain examples/documentation.
58
+
59
+ In your `.rubocop.yml`, you may treat the Sorbet cops just like any other cop. For example:
60
+
61
+ ```yaml
62
+ Sorbet/FalseSigil:
63
+ Exclude:
64
+ - lib/example.rb
65
+ ```
66
+
67
+ ## Documentation
68
+
69
+ You can read about each cop supplied by RuboCop Sorbet in [the manual](manual/cops.md).
70
+
71
+ ## Compatibility
72
+
73
+ Sorbet cops support the following versions:
74
+
75
+ - Sorbet >= 0.5
76
+ - Ruby >= 2.5
77
+
28
78
  ## Contributing
29
79
 
30
80
  Bug reports and pull requests are welcome on GitHub at https://github.com/Shopify/rubocop-sorbet. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
31
81
 
82
+ To contribute a new cop, please use the supplied generator like this:
83
+
84
+ ```sh
85
+ bundle exec rake new_cop[Sorbet/NewCopName]
86
+ ```
87
+
88
+ which will create a skeleton cop, a skeleton spec, an entry in the default config file and will require the new cop so that it is properly exported from the gem.
89
+
32
90
  ## License
33
91
 
34
92
  The gem is available as open source under the terms of the [MIT License](https://github.com/Shopify/rubocop-sorbet/blob/master/LICENSE.txt).
data/Rakefile CHANGED
@@ -2,10 +2,39 @@
2
2
 
3
3
  require('bundler/gem_tasks')
4
4
 
5
- begin
6
- require('rspec/core/rake_task')
7
- RSpec::Core::RakeTask.new(:spec)
8
- rescue LoadError
5
+ Dir['tasks/**/*.rake'].each { |t| load t }
6
+
7
+ require 'rubocop/rake_task'
8
+ require 'rspec/core/rake_task'
9
+
10
+ RSpec::Core::RakeTask.new(:spec) do |spec|
11
+ spec.pattern = FileList['spec/**/*_spec.rb']
9
12
  end
10
13
 
11
- task(default: :spec)
14
+ task(default: %i[
15
+ documentation_syntax_check
16
+ generate_cops_documentation
17
+ spec
18
+ ])
19
+
20
+ desc('Generate a new cop with a template')
21
+ task :new_cop, [:cop] do |_task, args|
22
+ require 'rubocop'
23
+
24
+ cop_name = args.fetch(:cop) do
25
+ warn 'usage: bundle exec rake new_cop[Department/Name]'
26
+ exit!
27
+ end
28
+
29
+ github_user = %x(git config github.user).chop
30
+ github_user = 'Shopify' if github_user.empty?
31
+
32
+ generator = RuboCop::Cop::Generator.new(cop_name, github_user)
33
+
34
+ generator.write_source
35
+ generator.write_spec
36
+ generator.inject_require(root_file_path: 'lib/rubocop/cop/sorbet_cops.rb')
37
+ generator.inject_config(config_file_path: 'config/default.yml')
38
+
39
+ puts generator.todo
40
+ end
data/config/default.yml CHANGED
@@ -1,6 +1,147 @@
1
- Sorbet/ValidSigil:
1
+ inherit_mode:
2
+ merge:
3
+ - Exclude
4
+
5
+ Sorbet/AllowIncompatibleOverride:
6
+ Description: 'Disallows using `.override(allow_incompatible: true)`.'
7
+ Enabled: true
8
+ VersionAdded: 0.2.0
9
+
10
+ Sorbet/BindingConstantWithoutTypeAlias:
11
+ Description: >-
12
+ Disallows binding the return value of `T.any`, `T.all`, `T.enum`
13
+ to a constant directly. To bind the value, one must use `T.type_alias`.
14
+ Enabled: true
15
+ VersionAdded: 0.2.0
16
+
17
+ Sorbet/CheckedTrueInSignature:
18
+ Description: 'Disallows the usage of `checked(true)` in signatures.'
19
+ Enabled: true
20
+ VersionAdded: 0.2.0
21
+
22
+ Sorbet/ConstantsFromStrings:
23
+ Description: >-
24
+ Forbids constant access through meta-programming.
25
+
26
+ For example, things like `constantize` or `const_get`
27
+ are forbidden.
2
28
  Enabled: true
3
- EnforcedStyle: typed_files
29
+ VersionAdded: 0.2.0
30
+
31
+ Sorbet/EnforceSigilOrder:
32
+ Description: 'Ensures that Sorbet sigil comes first in a file.'
33
+ Enabled: true
34
+ VersionAdded: 0.3.4
4
35
 
5
36
  Sorbet/EnforceSignatures:
37
+ Description: 'Ensures all methods have a valid signature.'
38
+ Enabled: false
39
+ VersionAdded: 0.3.4
40
+
41
+ Sorbet/FalseSigil:
42
+ Description: 'All files must be at least at strictness `false`.'
43
+ Enabled: true
44
+ VersionAdded: 0.3.3
45
+ SuggestedStrictness: true
46
+ Include:
47
+ - "**/*.rb"
48
+ - "**/*.rbi"
49
+ - "**/*.rake"
50
+ - "**/*.ru"
51
+ Exclude:
52
+ - bin/**/*
53
+ - db/**/*.rb
54
+ - script/**/*
55
+
56
+ Sorbet/ForbidExtendTSigHelpersInShims:
57
+ Description: 'Forbid the use of `extend T::Sig` and `extend T::Helpers` in RBI shims'
58
+ Enabled: true
59
+ VersionAdded: '0.6.0'
60
+ Include:
61
+ - "**/*.rbi"
62
+
63
+ Sorbet/ForbidIncludeConstLiteral:
64
+ Description: 'Forbids include of non-literal constants.'
65
+ Enabled: false
66
+ VersionAdded: 0.2.0
67
+ VersionChanged: 0.5.0
68
+
69
+ Sorbet/ForbidSuperclassConstLiteral:
70
+ Description: 'Forbid superclasses which are non-literal constants.'
71
+ Enabled: false
72
+ VersionAdded: 0.2.0
73
+ VersionChanged: 0.5.0
74
+
75
+ Sorbet/ForbidUntypedStructProps:
76
+ Description: >-
77
+ Disallows use of `T.untyped` or `T.nilable(T.untyped)` as a
78
+ prop type for `T::Struct` subclasses.
79
+ Enabled: true
80
+ VersionAdded: 0.4.0
81
+
82
+ Sorbet/HasSigil:
83
+ Description: 'Makes the Sorbet typed sigil mandatory in all files.'
84
+ Enabled: false
85
+ VersionAdded: 0.3.3
86
+
87
+ Sorbet/IgnoreSigil:
88
+ Description: 'All files must be at least at strictness `ignore`.'
89
+ Enabled: false
90
+ VersionAdded: 0.3.3
91
+
92
+ Sorbet/KeywordArgumentOrdering:
93
+ Description: >-
94
+ Enforces a compatible keyword arguments with Sorbet.
95
+
96
+ All keyword arguments must be at the end of the parameters
97
+ list, and all keyword arguments with a default value must be
98
+ after those without default values.
99
+ Enabled: true
100
+ VersionAdded: 0.2.0
101
+
102
+ Sorbet/OnedAncestorPerLine:
103
+ Description: 'Enforces one ancestor per call to requires_ancestor'
104
+ Enabled: false
105
+ VersionAdded: '0.6.0'
106
+
107
+ Sorbet/ParametersOrderingInSignature:
108
+ Description: 'Enforces same parameter order between a method and its signature.'
109
+ Enabled: true
110
+ VersionAdded: 0.2.0
111
+
112
+ Sorbet/SignatureBuildOrder:
113
+ Description: >-
114
+ Enforces the order of parts in a signature.
115
+
116
+ The order is first inheritance related builders,
117
+ then params, then return and finally the modifier
118
+ such as: `abstract.params(...).returns(...).soft`.'
119
+ Enabled: true
120
+ VersionAdded: 0.3.0
121
+
122
+ Sorbet/SingleLineRbiClassModuleDefinitions:
123
+ Description: 'Empty class and module definitions in RBI must be on a single line.'
124
+ Enabled: false
125
+ VersionAdded: '0.6.0'
126
+ Include:
127
+ - "**/*.rbi"
128
+
129
+ Sorbet/StrictSigil:
130
+ Description: 'All files must be at least at strictness `strict`.'
131
+ Enabled: false
132
+ VersionAdded: 0.3.3
133
+
134
+ Sorbet/StrongSigil:
135
+ Description: 'All files must be at least at strictness `strong`.'
136
+ Enabled: false
137
+ VersionAdded: 0.3.3
138
+
139
+ Sorbet/TrueSigil:
140
+ Description: 'All files must be at least at strictness `true`.'
141
+ Enabled: false
142
+ VersionAdded: 0.3.3
143
+
144
+ Sorbet/ValidSigil:
145
+ Description: 'All files must have a valid sigil.'
6
146
  Enabled: true
147
+ VersionAdded: 0.3.3