rubocop-sorbet 0.3.3 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/CODEOWNERS +2 -0
- data/.github/probots.yml +1 -1
- data/.github/stale.yml +20 -0
- data/.gitignore +0 -2
- data/.rspec +3 -0
- data/.rubocop.yml +2 -12
- data/.travis.yml +3 -1
- data/Gemfile +6 -7
- data/Gemfile.lock +26 -41
- data/README.md +64 -6
- data/Rakefile +34 -5
- data/config/default.yml +124 -1
- data/lib/rubocop-sorbet.rb +9 -1
- data/lib/rubocop/cop/sorbet/binding_constants_without_type_alias.rb +21 -2
- data/lib/rubocop/cop/sorbet/forbid_untyped_struct_props.rb +58 -0
- data/lib/rubocop/cop/sorbet/sigils/enforce_sigil_order.rb +105 -0
- data/lib/rubocop/cop/sorbet/sigils/valid_sigil.rb +29 -4
- data/lib/rubocop/cop/sorbet/{allow_incompatible_override.rb → signatures/allow_incompatible_override.rb} +0 -0
- data/lib/rubocop/cop/sorbet/{checked_true_in_signature.rb → signatures/checked_true_in_signature.rb} +3 -8
- data/lib/rubocop/cop/sorbet/signatures/enforce_signatures.rb +135 -0
- data/lib/rubocop/cop/sorbet/{keyword_argument_ordering.rb → signatures/keyword_argument_ordering.rb} +4 -9
- data/lib/rubocop/cop/sorbet/{parameters_ordering_in_signature.rb → signatures/parameters_ordering_in_signature.rb} +17 -14
- data/lib/rubocop/cop/sorbet/{signature_build_order.rb → signatures/signature_build_order.rb} +6 -12
- data/lib/rubocop/cop/sorbet/signatures/signature_cop.rb +28 -0
- data/lib/rubocop/cop/sorbet_cops.rb +22 -0
- data/lib/rubocop/sorbet.rb +15 -0
- data/lib/rubocop/sorbet/inject.rb +20 -0
- data/lib/rubocop/sorbet/version.rb +6 -0
- data/manual/cops.md +29 -0
- data/manual/cops_sorbet.md +340 -0
- data/rubocop-sorbet.gemspec +18 -18
- data/tasks/cops_documentation.rake +317 -0
- metadata +31 -17
- data/lib/rubocop_sorbet.rb +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed85b2aa8c9315734700e66a95850b31448f0564044857f05a8b9ffcaaa8bd69
|
4
|
+
data.tar.gz: 29fbbd4eef2a6039dd1f15247d6a39c05575de00cfd3a9ec2b8a3e5258628f27
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a69d768ccb20841020b531c5befae05d4279b7483e26c266f61214d8702fdb67419187db6ff8f9a8bd8973113aa9861e9ef9f0295a4157397023f6e8d6cdeaab
|
7
|
+
data.tar.gz: 3c2afa2c95472039e4c95bd81ffa91847a05f0114690d5e89bb5d34f4ad4d303aff4df81e107dcc79c3de146b35834bf8ca5c94595c90b5d2b6d4c1e096bb5e2
|
data/.github/CODEOWNERS
ADDED
data/.github/probots.yml
CHANGED
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
data/.rspec
ADDED
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
|
-
|
4
|
-
-
|
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
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.0"
|
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.
|
4
|
+
rubocop-sorbet (0.4.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
|
-
|
30
|
-
|
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 (
|
44
|
-
rake
|
27
|
+
rainbow (3.0.0)
|
45
28
|
rake (12.3.2)
|
46
|
-
|
47
|
-
|
48
|
-
mime-types (>= 1.16, < 4.0)
|
49
|
-
netrc (~> 0.8)
|
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.
|
64
|
-
jaro_winkler (~> 1.5.1)
|
44
|
+
rubocop (0.85.0)
|
65
45
|
parallel (~> 1.10)
|
66
|
-
parser (>= 2.
|
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, <
|
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
|
-
|
74
|
-
|
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 (
|
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
|
-
|
91
|
-
rspec
|
92
|
-
rubocop
|
74
|
+
rake (~> 12.0)
|
75
|
+
rspec
|
76
|
+
rubocop-shopify
|
93
77
|
rubocop-sorbet!
|
94
|
-
unparser
|
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
|
-
|
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
|
-
|
20
|
+
## Usage
|
16
21
|
|
17
|
-
|
22
|
+
You need to tell RuboCop to load the Sorbet extension. There are three ways to do this:
|
18
23
|
|
19
|
-
|
24
|
+
### RuboCop configuration file
|
25
|
+
|
26
|
+
Put this into your `.rubocop.yml`:
|
27
|
+
|
28
|
+
```yaml
|
29
|
+
require: rubocop-sorbet
|
30
|
+
```
|
20
31
|
|
21
|
-
|
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
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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:
|
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,3 +1,126 @@
|
|
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.
|
28
|
+
Enabled: true
|
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
|
35
|
+
|
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/ForbidIncludeConstLiteral:
|
57
|
+
Description: 'Forbids include of non-literal constants.'
|
58
|
+
Enabled: true
|
59
|
+
VersionAdded: 0.2.0
|
60
|
+
|
61
|
+
Sorbet/ForbidSuperclassConstLiteral:
|
62
|
+
Description: 'Forbid superclasses which are non-literal constants.'
|
63
|
+
Enabled: true
|
64
|
+
VersionAdded: 0.2.0
|
65
|
+
|
66
|
+
Sorbet/ForbidUntypedStructProps:
|
67
|
+
Description: >-
|
68
|
+
Disallows use of `T.untyped` or `T.nilable(T.untyped)` as a
|
69
|
+
prop type for `T::Struct` subclasses.
|
70
|
+
Enabled: true
|
71
|
+
VersionAdded: 0.4.0
|
72
|
+
|
73
|
+
Sorbet/HasSigil:
|
74
|
+
Description: 'Makes the Sorbet typed sigil mandatory in all files.'
|
75
|
+
Enabled: false
|
76
|
+
VersionAdded: 0.3.3
|
77
|
+
|
78
|
+
Sorbet/IgnoreSigil:
|
79
|
+
Description: 'All files must be at least at strictness `ignore`.'
|
80
|
+
Enabled: false
|
81
|
+
VersionAdded: 0.3.3
|
82
|
+
|
83
|
+
Sorbet/KeywordArgumentOrdering:
|
84
|
+
Description: >-
|
85
|
+
Enforces a compatible keyword arguments with Sorbet.
|
86
|
+
|
87
|
+
All keyword arguments must be at the end of the parameters
|
88
|
+
list, and all keyword arguments with a default value must be
|
89
|
+
after those without default values.
|
90
|
+
Enabled: true
|
91
|
+
VersionAdded: 0.2.0
|
92
|
+
|
93
|
+
Sorbet/ParametersOrderingInSignature:
|
94
|
+
Description: 'Enforces same parameter order between a method and its signature.'
|
95
|
+
Enabled: true
|
96
|
+
VersionAdded: 0.2.0
|
97
|
+
|
98
|
+
Sorbet/SignatureBuildOrder:
|
99
|
+
Description: >-
|
100
|
+
Enforces the order of parts in a signature.
|
101
|
+
|
102
|
+
The order is first inheritance related builders,
|
103
|
+
then params, then return and finally the modifier
|
104
|
+
such as: `abstract.params(...).returns(...).soft`.'
|
105
|
+
Enabled: true
|
106
|
+
VersionAdded: 0.3.0
|
107
|
+
|
108
|
+
Sorbet/StrictSigil:
|
109
|
+
Description: 'All files must be at least at strictness `strict`.'
|
110
|
+
Enabled: false
|
111
|
+
VersionAdded: 0.3.3
|
112
|
+
|
113
|
+
Sorbet/StrongSigil:
|
114
|
+
Description: 'All files must be at least at strictness `strong`.'
|
115
|
+
Enabled: false
|
116
|
+
VersionAdded: 0.3.3
|
117
|
+
|
118
|
+
Sorbet/TrueSigil:
|
119
|
+
Description: 'All files must be at least at strictness `true`.'
|
120
|
+
Enabled: false
|
121
|
+
VersionAdded: 0.3.3
|
122
|
+
|
1
123
|
Sorbet/ValidSigil:
|
124
|
+
Description: 'All files must have a valid sigil.'
|
2
125
|
Enabled: true
|
3
|
-
|
126
|
+
VersionAdded: 0.3.3
|