Skip to content

Commit

Permalink
Rename things to capture T::Sig and T::Helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Brushett committed Mar 11, 2021
1 parent 1424112 commit 1810d4f
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ Sorbet/FalseSigil:
- db/**/*.rb
- script/**/*

Sorbet/ForbidExtendTSigInShims:
Description: 'Forbid the use of `extend T::Sig` in RBI shims'
Sorbet/ForbidExtendTSigHelpersInShims:
Description: 'Forbid the use of `extend T::Sig` and `extend T::Helpers` in RBI shims'
Enabled: true
VersionAdded: '0.86'
Include:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ module RuboCop
module Cop
module Sorbet
# This cop ensures RBI shims do not include a call to extend T::Sig
# or to extend T::Helpers
#
# @example
#
# # bad
# module SomeModule
# extend T::Sig
# extend T::Helpers
#
# sig { returns(String) }
# def foo; end
Expand All @@ -20,7 +22,7 @@ module Sorbet
# sig { returns(String) }
# def foo; end
# end
class ForbidExtendTSigInShims < RuboCop::Cop::Cop
class ForbidExtendTSigHelpersInShims < RuboCop::Cop::Cop
include RangeHelp

MSG = 'Extending T::Sig or T::Helpers in a shim is unnecessary'
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/sorbet_cops.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true
require_relative 'sorbet/binding_constants_without_type_alias'
require_relative 'sorbet/constants_from_strings'
require_relative 'sorbet/forbid_extend_t_sig_in_shims'
require_relative 'sorbet/forbid_extend_t_sig_helpers_in_shims'
require_relative 'sorbet/forbid_superclass_const_literal'
require_relative 'sorbet/forbid_include_const_literal'
require_relative 'sorbet/forbid_untyped_struct_props'
Expand Down
2 changes: 1 addition & 1 deletion manual/cops.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ In the following section you find all available cops:
* [Sorbet/EnforceSigilOrder](cops_sorbet.md#sorbetenforcesigilorder)
* [Sorbet/EnforceSignatures](cops_sorbet.md#sorbetenforcesignatures)
* [Sorbet/FalseSigil](cops_sorbet.md#sorbetfalsesigil)
* [Sorbet/ForbidExtendTSigInShims](cops_sorbet.md#sorbetforbidextendtsiginshims)
* [Sorbet/ForbidExtendTSigHelpersInShims](cops_sorbet.md#sorbetforbidextendtsighelpersinshims)
* [Sorbet/ForbidIncludeConstLiteral](cops_sorbet.md#sorbetforbidincludeconstliteral)
* [Sorbet/ForbidSuperclassConstLiteral](cops_sorbet.md#sorbetforbidsuperclassconstliteral)
* [Sorbet/ForbidUntypedStructProps](cops_sorbet.md#sorbetforbiduntypedstructprops)
Expand Down
4 changes: 3 additions & 1 deletion manual/cops_sorbet.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,20 +171,22 @@ SuggestedStrictness | `true` | Boolean
Include | `**/*.rb`, `**/*.rbi`, `**/*.rake`, `**/*.ru` | Array
Exclude | `bin/**/*`, `db/**/*.rb`, `script/**/*` | Array

## Sorbet/ForbidExtendTSigInShims
## Sorbet/ForbidExtendTSigHelpersInShims

Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
--- | --- | --- | --- | ---
Enabled | Yes | Yes | 0.86 | -

This cop ensures RBI shims do not include a call to extend T::Sig
or to extend T::Helpers

### Examples

```ruby
# bad
module SomeModule
extend T::Sig
extend T::Helpers

sig { returns(String) }
def foo; end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require 'spec_helper'

RSpec.describe(RuboCop::Cop::Sorbet::ForbidExtendTSigInShims, :config) do
RSpec.describe(RuboCop::Cop::Sorbet::ForbidExtendTSigHelpersInShims, :config) do
subject(:cop) { described_class.new(config) }

describe('offences') do
Expand Down Expand Up @@ -36,7 +36,7 @@ def foo; end
end

describe('no offences') do
it 'does not add an offence to uses of extend that are not T::Sig' do
it 'does not add an offence to uses of extend that are not T::Sig or T::Helpers' do
expect_no_offenses(<<~RBI)
module MyModule
extend ActiveSupport::Concern
Expand Down

0 comments on commit 1810d4f

Please sign in to comment.