rubocop-sorbet 0.0.2 → 0.3.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/.github/probots.yml +3 -0
- data/CODE_OF_CONDUCT.md +18 -15
- data/Gemfile.lock +1 -1
- data/LICENSE.txt +1 -1
- data/README.md +3 -1
- data/config/default.yml +3 -0
- data/dev.yml +3 -2
- data/lib/rubocop/cop/sorbet/constants_from_strings.rb +1 -1
- data/lib/rubocop/cop/sorbet/signature_build_order.rb +1 -0
- data/lib/rubocop/cop/sorbet/valid_sorbet_sigil.rb +102 -0
- data/lib/rubocop_sorbet.rb +1 -0
- data/rubocop-sorbet.gemspec +3 -3
- metadata +10 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7baa291ded0aa343c64c841b2d03cf91d52ad07071883a680f8b725297d0d8e9
|
4
|
+
data.tar.gz: 95e36584da91cccee6423d2d65fcc061ea74e1abfc51c4c5fb1a18f8b1878e62
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d3772bb095eed330fbab2f2ff723f932bc4b40a175738532e043c6fbb66c9c2116a9435b4b210cf2b0f59dc3b8be889da976293db38f6e42f583be9dd8ddb26
|
7
|
+
data.tar.gz: 04a54d3d285223f71d48f4a164ec69124ce9b45d74eba3c7232abd6388e9638acb3e8fada94f2f88533432e51077d03952037d1828850261e623797dacd7b9a5
|
data/.github/probots.yml
ADDED
data/CODE_OF_CONDUCT.md
CHANGED
@@ -3,11 +3,11 @@
|
|
3
3
|
## Our Pledge
|
4
4
|
|
5
5
|
In the interest of fostering an open and welcoming environment, we as
|
6
|
-
contributors and maintainers pledge to
|
6
|
+
contributors and maintainers pledge to make participation in our project and
|
7
7
|
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
-
size, disability, ethnicity, gender identity and expression,
|
9
|
-
|
10
|
-
orientation.
|
8
|
+
size, disability, ethnicity, sex characteristics, gender identity and expression,
|
9
|
+
level of experience, education, socio-economic status, nationality, personal
|
10
|
+
appearance, race, religion, or sexual identity and orientation.
|
11
11
|
|
12
12
|
## Our Standards
|
13
13
|
|
@@ -23,7 +23,7 @@ include:
|
|
23
23
|
Examples of unacceptable behavior by participants include:
|
24
24
|
|
25
25
|
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
-
advances
|
26
|
+
advances
|
27
27
|
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
28
|
* Public or private harassment
|
29
29
|
* Publishing others' private information, such as a physical or electronic
|
@@ -45,17 +45,17 @@ threatening, offensive, or harmful.
|
|
45
45
|
|
46
46
|
## Scope
|
47
47
|
|
48
|
-
This Code of Conduct applies
|
49
|
-
|
50
|
-
representing a project or community include using an official
|
51
|
-
address, posting via an official social media account, or acting
|
52
|
-
representative at an online or offline event. Representation of
|
53
|
-
further defined and clarified by project maintainers.
|
48
|
+
This Code of Conduct applies within all project spaces, and it also applies when
|
49
|
+
an individual is representing the project or its community in public spaces.
|
50
|
+
Examples of representing a project or community include using an official
|
51
|
+
project e-mail address, posting via an official social media account, or acting
|
52
|
+
as an appointed representative at an online or offline event. Representation of
|
53
|
+
a project may be further defined and clarified by project maintainers.
|
54
54
|
|
55
55
|
## Enforcement
|
56
56
|
|
57
57
|
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
-
reported by contacting the project team at
|
58
|
+
reported by contacting the project team at opensource@shopify.com. All
|
59
59
|
complaints will be reviewed and investigated and will result in a response that
|
60
60
|
is deemed necessary and appropriate to the circumstances. The project team is
|
61
61
|
obligated to maintain confidentiality with regard to the reporter of an incident.
|
@@ -68,7 +68,10 @@ members of the project's leadership.
|
|
68
68
|
## Attribution
|
69
69
|
|
70
70
|
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
-
available at
|
71
|
+
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
|
72
|
+
|
73
|
+
[homepage]: https://www.contributor-covenant.org
|
74
|
+
|
75
|
+
For answers to common questions about this code of conduct, see
|
76
|
+
https://www.contributor-covenant.org/faq
|
72
77
|
|
73
|
-
[homepage]: http://contributor-covenant.org
|
74
|
-
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile.lock
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Rubocop-Sorbet
|
2
2
|
|
3
|
+
[](https://travis-ci.org/Shopify/rubocop-sorbet)
|
4
|
+
|
3
5
|
A collection of Rubocop rules for Sorbet.
|
4
6
|
|
5
7
|
## Installation
|
@@ -29,7 +31,7 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/Shopif
|
|
29
31
|
|
30
32
|
## License
|
31
33
|
|
32
|
-
The gem is available as open source under the terms of the [MIT License](https://
|
34
|
+
The gem is available as open source under the terms of the [MIT License](https://github.com/Shopify/rubocop-sorbet/blob/master/LICENSE.txt).
|
33
35
|
|
34
36
|
## Code of Conduct
|
35
37
|
|
data/config/default.yml
ADDED
data/dev.yml
CHANGED
@@ -43,7 +43,7 @@ module RuboCop
|
|
43
43
|
add_offense(
|
44
44
|
node,
|
45
45
|
location: :selector,
|
46
|
-
message: "Don't use `#{node.method_name}`, it
|
46
|
+
message: "Don't use `#{node.method_name}`, it makes the code harder to understand, less editor-friendly, " \
|
47
47
|
"and impossible to analyze. Replace `#{node.method_name}` with a case/when or a hash."
|
48
48
|
)
|
49
49
|
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rubocop'
|
4
|
+
|
5
|
+
module RuboCop
|
6
|
+
module Cop
|
7
|
+
module Sorbet
|
8
|
+
# This cop checks that every Ruby file contains a valid Sorbet sigil.
|
9
|
+
# Adapted from: https://gist.github.com/clarkdave/85aca4e16f33fd52aceb6a0a29936e52
|
10
|
+
#
|
11
|
+
# @example RequireSigilOnAllFiles: false (default)
|
12
|
+
#
|
13
|
+
# # bad
|
14
|
+
# # (start of file)
|
15
|
+
# # typed: no
|
16
|
+
#
|
17
|
+
# # good
|
18
|
+
# # (start of file)
|
19
|
+
# class Foo; end
|
20
|
+
#
|
21
|
+
# # good
|
22
|
+
# # (start of file)
|
23
|
+
# # typed: true
|
24
|
+
#
|
25
|
+
# @example RequireSigilOnAllFiles: true
|
26
|
+
#
|
27
|
+
# # bad
|
28
|
+
# # (start of file)
|
29
|
+
# class Foo; end
|
30
|
+
#
|
31
|
+
# # bad
|
32
|
+
# # (start of file)
|
33
|
+
# # typed: no
|
34
|
+
#
|
35
|
+
# # good
|
36
|
+
# # (start of file)
|
37
|
+
# # typed: true
|
38
|
+
class ValidSorbetSigil < RuboCop::Cop::Cop
|
39
|
+
def investigate(processed_source)
|
40
|
+
return if processed_source.tokens.empty?
|
41
|
+
|
42
|
+
sorbet_sigil_line = sorbet_typed_sigil_comment(processed_source)
|
43
|
+
|
44
|
+
if sorbet_sigil_line.nil?
|
45
|
+
token = processed_source.tokens.first
|
46
|
+
|
47
|
+
if require_sorbet_sigil_on_all_files?
|
48
|
+
add_offense(
|
49
|
+
token,
|
50
|
+
location: token.pos,
|
51
|
+
message: 'No Sorbet sigil found in file. ' \
|
52
|
+
'Try a `typed: false` to start (you can also use `rubocop -a` to automatically add this).'
|
53
|
+
)
|
54
|
+
end
|
55
|
+
else
|
56
|
+
strictness = sorbet_typed_strictness(sorbet_sigil_line)
|
57
|
+
return if valid_sorbet_strictness?(strictness)
|
58
|
+
|
59
|
+
add_offense(
|
60
|
+
sorbet_sigil_line,
|
61
|
+
location: sorbet_sigil_line.pos,
|
62
|
+
message: "Invalid Sorbet sigil `#{strictness}`."
|
63
|
+
)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def autocorrect(_node)
|
68
|
+
lambda do |corrector|
|
69
|
+
return unless require_sorbet_sigil_on_all_files?
|
70
|
+
return unless sorbet_typed_sigil_comment(processed_source).nil?
|
71
|
+
|
72
|
+
token = processed_source.tokens.first
|
73
|
+
|
74
|
+
corrector.insert_before(token.pos, "# typed: false\n")
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
|
80
|
+
def require_sorbet_sigil_on_all_files?
|
81
|
+
!!cop_config['RequireSigilOnAllFiles']
|
82
|
+
end
|
83
|
+
|
84
|
+
SORBET_SIGIL_REGEX = /#\s+typed:\s+([\w]+)/
|
85
|
+
|
86
|
+
def sorbet_typed_sigil_comment(processed_source)
|
87
|
+
processed_source.tokens
|
88
|
+
.take_while { |token| token.type == :tCOMMENT }
|
89
|
+
.find { |token| SORBET_SIGIL_REGEX.match?(token.text) }
|
90
|
+
end
|
91
|
+
|
92
|
+
def valid_sorbet_strictness?(strictness)
|
93
|
+
%w(ignore false true strict strong).include?(strictness)
|
94
|
+
end
|
95
|
+
|
96
|
+
def sorbet_typed_strictness(sigil_line)
|
97
|
+
sigil_line.text.match(SORBET_SIGIL_REGEX)&.captures&.first
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
data/lib/rubocop_sorbet.rb
CHANGED
@@ -9,3 +9,4 @@ require_relative 'rubocop/cop/sorbet/forbid_superclass_const_literal'
|
|
9
9
|
require_relative 'rubocop/cop/sorbet/forbid_include_const_literal'
|
10
10
|
require_relative 'rubocop/cop/sorbet/parameters_ordering_in_signature'
|
11
11
|
require_relative 'rubocop/cop/sorbet/keyword_argument_ordering'
|
12
|
+
require_relative 'rubocop/cop/sorbet/valid_sorbet_sigil'
|
data/rubocop-sorbet.gemspec
CHANGED
@@ -5,9 +5,9 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = 'rubocop-sorbet'
|
8
|
-
spec.version = '0.
|
9
|
-
spec.authors = ['Ufuk Kayserilioglu']
|
10
|
-
spec.email = ['
|
8
|
+
spec.version = '0.3.2'
|
9
|
+
spec.authors = ['Ufuk Kayserilioglu', 'Alan Wu', 'Alexandre Terrasa', 'Peter Zhu']
|
10
|
+
spec.email = ['ruby@shopify.com']
|
11
11
|
|
12
12
|
spec.summary = 'Automatic Sorbet code style checking tool.'
|
13
13
|
spec.homepage = 'https://github.com/shopify/rubocop-sorbet'
|
metadata
CHANGED
@@ -1,14 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-sorbet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ufuk Kayserilioglu
|
8
|
+
- Alan Wu
|
9
|
+
- Alexandre Terrasa
|
10
|
+
- Peter Zhu
|
8
11
|
autorequire:
|
9
12
|
bindir: exe
|
10
13
|
cert_chain: []
|
11
|
-
date: 2019-
|
14
|
+
date: 2019-09-18 00:00:00.000000000 Z
|
12
15
|
dependencies:
|
13
16
|
- !ruby/object:Gem::Dependency
|
14
17
|
name: rspec
|
@@ -54,11 +57,12 @@ dependencies:
|
|
54
57
|
version: '0.57'
|
55
58
|
description:
|
56
59
|
email:
|
57
|
-
-
|
60
|
+
- ruby@shopify.com
|
58
61
|
executables: []
|
59
62
|
extensions: []
|
60
63
|
extra_rdoc_files: []
|
61
64
|
files:
|
65
|
+
- ".github/probots.yml"
|
62
66
|
- ".gitignore"
|
63
67
|
- ".rubocop.yml"
|
64
68
|
- ".shopify-build/VERSION"
|
@@ -73,6 +77,7 @@ files:
|
|
73
77
|
- bin/console
|
74
78
|
- bin/rspec
|
75
79
|
- bin/setup
|
80
|
+
- config/default.yml
|
76
81
|
- dev.yml
|
77
82
|
- lib/rubocop-sorbet.rb
|
78
83
|
- lib/rubocop/cop/sorbet/allow_incompatible_override.rb
|
@@ -84,6 +89,7 @@ files:
|
|
84
89
|
- lib/rubocop/cop/sorbet/keyword_argument_ordering.rb
|
85
90
|
- lib/rubocop/cop/sorbet/parameters_ordering_in_signature.rb
|
86
91
|
- lib/rubocop/cop/sorbet/signature_build_order.rb
|
92
|
+
- lib/rubocop/cop/sorbet/valid_sorbet_sigil.rb
|
87
93
|
- lib/rubocop_sorbet.rb
|
88
94
|
- rubocop-sorbet.gemspec
|
89
95
|
- shipit.yml
|
@@ -108,8 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
114
|
- !ruby/object:Gem::Version
|
109
115
|
version: '0'
|
110
116
|
requirements: []
|
111
|
-
|
112
|
-
rubygems_version: 2.7.6
|
117
|
+
rubygems_version: 3.0.3
|
113
118
|
signing_key:
|
114
119
|
specification_version: 4
|
115
120
|
summary: Automatic Sorbet code style checking tool.
|