rubocop-sorbet 0.2.0 → 0.3.0

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: 9ad80ed7bb1d6485194f669d289efba935cecb7adff45f542ba8ada36171a57f
4
- data.tar.gz: f2129cc057c628df84b40e4ba24d376624fa6ad3e3b7a27025a53e0f5862c422
3
+ metadata.gz: 6740f039852d221e50f5f80f77f899a35135dfc91f19ded44e3cc909e9ba85f4
4
+ data.tar.gz: 518ecd83900a4e20548bd22b659b9853ed5742429195344ec224e29e7d127986
5
5
  SHA512:
6
- metadata.gz: 4c493e9d0aa2718629cfba7c84a8c7ec530bb5b942c273d10b8893594ef7f2cb219227e7499a0981f400d7b10f0cef986adba8c0ad480c90d84ff8c14e5ceda1
7
- data.tar.gz: 5b8d8d04a8b6a77feeb11929d6a4a55804dac5f7eeccf2ed47f0b7ed0dac1b30f08cefa030d59ea623e9fe907a01f0e48ab933f6476d86bf729b0597dcc7130c
6
+ metadata.gz: 2b73e591e2137443e2485c596295446270a86685dc1d185ba5e2f98615b9618ed9b5c0b979d563ae18611fb9184023803de62a01db810d6ed2a0fd6475eaa840
7
+ data.tar.gz: eb57d0b9971e242fb9fb42e238487339e70c463c54a121dd1b4d1c7599459ffae0cdf1628801c1c280fed5f379a13fd2699329e1833c21a98423a6f94ad4e357
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rubocop-sorbet (0.2.0)
4
+ rubocop-sorbet (0.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2019 Ufuk Kayserilioglu
3
+ Copyright (c) 2019 Shopify
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
@@ -0,0 +1,81 @@
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
12
+ #
13
+ # # bad
14
+ # # (start of file)
15
+ # class Foo; end
16
+ #
17
+ # # bad
18
+ # # (start of file)
19
+ # # typed: no
20
+ #
21
+ # # good
22
+ # # (start of file)
23
+ # # typed: true
24
+ class ValidSorbetSigil < RuboCop::Cop::Cop
25
+ def investigate(processed_source)
26
+ return if processed_source.tokens.empty?
27
+
28
+ sorbet_sigil_line = sorbet_typed_sigil_comment(processed_source)
29
+
30
+ if sorbet_sigil_line.nil?
31
+ token = processed_source.tokens.first
32
+
33
+ add_offense(
34
+ token,
35
+ location: token.pos,
36
+ message: 'No Sorbet sigil found in file. ' \
37
+ 'Try a `typed: false` to start (you can also use `rubocop -a` to automatically add this).'
38
+ )
39
+ else
40
+ strictness = sorbet_typed_strictness(sorbet_sigil_line)
41
+ return if valid_sorbet_strictness?(strictness)
42
+
43
+ add_offense(
44
+ sorbet_sigil_line,
45
+ location: sorbet_sigil_line.pos,
46
+ message: "Invalid Sorbet sigil `#{strictness}`."
47
+ )
48
+ end
49
+ end
50
+
51
+ def autocorrect(_node)
52
+ lambda do |corrector|
53
+ return unless sorbet_typed_sigil_comment(processed_source).nil?
54
+
55
+ token = processed_source.tokens.first
56
+
57
+ corrector.insert_before(token.pos, "# typed: false\n")
58
+ end
59
+ end
60
+
61
+ private
62
+
63
+ SORBET_SIGIL_REGEX = /#\s+typed:\s+([\w]+)/
64
+
65
+ def sorbet_typed_sigil_comment(processed_source)
66
+ processed_source.tokens
67
+ .take_while { |token| token.type == :tCOMMENT }
68
+ .find { |token| SORBET_SIGIL_REGEX.match?(token.text) }
69
+ end
70
+
71
+ def valid_sorbet_strictness?(strictness)
72
+ %w(ignore false true strict strong).include?(strictness)
73
+ end
74
+
75
+ def sorbet_typed_strictness(sigil_line)
76
+ sigil_line.text.match(SORBET_SIGIL_REGEX)&.captures&.first
77
+ end
78
+ end
79
+ end
80
+ end
81
+ 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.2.0'
9
- spec.authors = ['Ufuk Kayserilioglu']
10
- spec.email = ['ufuk.kayserilioglu@shopify.com']
8
+ spec.version = '0.3.0'
9
+ spec.authors = ['Ufuk Kayserilioglu', 'Alan Wu', 'Alexandre Terrasa', 'Peter Zhu']
10
+ spec.email = ['rails@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.2.0
4
+ version: 0.3.0
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-07-16 00:00:00.000000000 Z
12
15
  dependencies:
13
16
  - !ruby/object:Gem::Dependency
14
17
  name: rspec
@@ -54,7 +57,7 @@ dependencies:
54
57
  version: '0.57'
55
58
  description:
56
59
  email:
57
- - ufuk.kayserilioglu@shopify.com
60
+ - rails@shopify.com
58
61
  executables: []
59
62
  extensions: []
60
63
  extra_rdoc_files: []
@@ -64,7 +67,6 @@ files:
64
67
  - ".shopify-build/VERSION"
65
68
  - ".shopify-build/rubocop-sorbet.yml"
66
69
  - ".travis.yml"
67
- - CODE_OF_CONDUCT.md
68
70
  - Gemfile
69
71
  - Gemfile.lock
70
72
  - LICENSE.txt
@@ -84,6 +86,7 @@ files:
84
86
  - lib/rubocop/cop/sorbet/keyword_argument_ordering.rb
85
87
  - lib/rubocop/cop/sorbet/parameters_ordering_in_signature.rb
86
88
  - lib/rubocop/cop/sorbet/signature_build_order.rb
89
+ - lib/rubocop/cop/sorbet/valid_sorbet_sigil.rb
87
90
  - lib/rubocop_sorbet.rb
88
91
  - rubocop-sorbet.gemspec
89
92
  - shipit.yml
data/CODE_OF_CONDUCT.md DELETED
@@ -1,74 +0,0 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
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
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.
11
-
12
- ## Our Standards
13
-
14
- Examples of behavior that contributes to creating a positive environment
15
- include:
16
-
17
- * Using welcoming and inclusive language
18
- * Being respectful of differing viewpoints and experiences
19
- * Gracefully accepting constructive criticism
20
- * Focusing on what is best for the community
21
- * Showing empathy towards other community members
22
-
23
- Examples of unacceptable behavior by participants include:
24
-
25
- * The use of sexualized language or imagery and unwelcome sexual attention or
26
- advances
27
- * Trolling, insulting/derogatory comments, and personal or political attacks
28
- * Public or private harassment
29
- * Publishing others' private information, such as a physical or electronic
30
- address, without explicit permission
31
- * Other conduct which could reasonably be considered inappropriate in a
32
- professional setting
33
-
34
- ## Our Responsibilities
35
-
36
- Project maintainers are responsible for clarifying the standards of acceptable
37
- behavior and are expected to take appropriate and fair corrective action in
38
- response to any instances of unacceptable behavior.
39
-
40
- Project maintainers have the right and responsibility to remove, edit, or
41
- reject comments, commits, code, wiki edits, issues, and other contributions
42
- that are not aligned to this Code of Conduct, or to ban temporarily or
43
- permanently any contributor for other behaviors that they deem inappropriate,
44
- threatening, offensive, or harmful.
45
-
46
- ## Scope
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.
54
-
55
- ## Enforcement
56
-
57
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
- reported by contacting the project team at ufuk@paralaus.com. All
59
- complaints will be reviewed and investigated and will result in a response that
60
- is deemed necessary and appropriate to the circumstances. The project team is
61
- obligated to maintain confidentiality with regard to the reporter of an incident.
62
- Further details of specific enforcement policies may be posted separately.
63
-
64
- Project maintainers who do not follow or enforce the Code of Conduct in good
65
- faith may face temporary or permanent repercussions as determined by other
66
- members of the project's leadership.
67
-
68
- ## Attribution
69
-
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]
72
-
73
- [homepage]: http://contributor-covenant.org
74
- [version]: http://contributor-covenant.org/version/1/4/