rubocop-sorbet 0.0.2 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aceacd9544f68f9fa77c04eb851f4b9c950ae807bcd6acba40343930e1e09c60
4
- data.tar.gz: 32568e235724593175627d5e27bf08fde7465bd0faaadf130f24928336ffa80c
3
+ metadata.gz: 7baa291ded0aa343c64c841b2d03cf91d52ad07071883a680f8b725297d0d8e9
4
+ data.tar.gz: 95e36584da91cccee6423d2d65fcc061ea74e1abfc51c4c5fb1a18f8b1878e62
5
5
  SHA512:
6
- metadata.gz: 7c373c8ab61cb4801f0e15acc68d959d4b5dcc517a958083067b30461f3d6d1095b4c57ebf65e6e0c84ae5c50c2bfa3f8a5dc3c43809020315a5f02c1e82107f
7
- data.tar.gz: fc0e8c2beaae55bd7d041c26c18d4bb33fe12531e024ac99ade345bd4854c7196a3717af0f605408f4f9b50ab6dd77db368862c946547063b853980f4de5831b
6
+ metadata.gz: 2d3772bb095eed330fbab2f2ff723f932bc4b40a175738532e043c6fbb66c9c2116a9435b4b210cf2b0f59dc3b8be889da976293db38f6e42f583be9dd8ddb26
7
+ data.tar.gz: 04a54d3d285223f71d48f4a164ec69124ce9b45d74eba3c7232abd6388e9638acb3e8fada94f2f88533432e51077d03952037d1828850261e623797dacd7b9a5
@@ -0,0 +1,3 @@
1
+ enabled:
2
+ - cla
3
+
@@ -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 making participation in our project and
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, level of experience,
9
- nationality, personal appearance, race, religion, or sexual identity and
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 both within project spaces and in public spaces
49
- when an individual is representing the project or its community. Examples of
50
- representing a project or community include using an official project e-mail
51
- address, posting via an official social media account, or acting as an appointed
52
- representative at an online or offline event. Representation of a project may be
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 ufuk@paralaus.com. All
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 [http://contributor-covenant.org/version/1/4][version]
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/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rubocop-sorbet (0.0.2)
4
+ rubocop-sorbet (0.3.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2019 Ufuk Kayserilioglu
3
+ Copyright (c) 2019-present, Shopify Inc.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Rubocop-Sorbet
2
2
 
3
+ [![Build Status](https://travis-ci.org/Shopify/rubocop-sorbet.svg?branch=master)](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://opensource.org/licenses/MIT).
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
 
@@ -0,0 +1,3 @@
1
+ Sorbet/ValidSorbetSigil:
2
+ Enabled: true
3
+ EnforcedStyle: typed_files
data/dev.yml CHANGED
@@ -6,5 +6,6 @@ up:
6
6
  - ruby: "2.5.5"
7
7
  - "bundler"
8
8
 
9
- test:
10
- run: "bin/rspec"
9
+ commands:
10
+ test: "bin/rspec"
11
+ style: "bundle exec rubocop"
@@ -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 make the code harder to understand, less editor-friendly " \
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
@@ -24,6 +24,7 @@ module RuboCop
24
24
  :overridable,
25
25
  :soft,
26
26
  :checked,
27
+ :on_failure,
27
28
  ].each_with_index.to_h.freeze
28
29
 
29
30
  def_node_matcher(:signature?, <<~PATTERN)
@@ -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
@@ -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'
@@ -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.0.2'
9
- spec.authors = ['Ufuk Kayserilioglu']
10
- spec.email = ['ufuk.kayserilioglu@shopify.com']
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.0.2
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-07-15 00:00:00.000000000 Z
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
- - ufuk.kayserilioglu@shopify.com
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
- rubyforge_project:
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.