-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from Shopify/at-rbi
Ensure RBI files are always under `sorbet/rbi`
- Loading branch information
Showing
10 changed files
with
141 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
31 changes: 31 additions & 0 deletions
31
lib/rubocop/cop/sorbet/rbi/forbid_rbi_outside_of_sorbet_dir.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# frozen_string_literal: true | ||
|
||
module RuboCop | ||
module Cop | ||
module Sorbet | ||
# This cop makes sure that RBI files are always located under sorbet/rbi/. | ||
# | ||
# @example | ||
# # bad | ||
# lib/some_file.rbi | ||
# other_file.rbi | ||
# | ||
# # good | ||
# sorbet/rbi/some_file.rbi | ||
# sorbet/rbi/any/path/for/file.rbi | ||
class ForbidRBIOutsideOfSorbetDir < RuboCop::Cop::Cop | ||
include RangeHelp | ||
|
||
PATH_REGEXP = %r{sorbet/rbi} | ||
|
||
def investigate(processed_source) | ||
add_offense( | ||
nil, | ||
location: source_range(processed_source.buffer, 1, 0), | ||
message: "RBI files are only accepted in the sorbet/rbi/ directory." | ||
) unless processed_source.file_path =~ PATH_REGEXP | ||
end | ||
end | ||
end | ||
end | ||
end |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
32 changes: 32 additions & 0 deletions
32
spec/rubocop/cop/sorbet/rbi/forbid_rbi_outside_of_sorbet_dir_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
RSpec.describe(RuboCop::Cop::Sorbet::ForbidRBIOutsideOfSorbetDir, :config) do | ||
subject(:cop) { described_class.new(config) } | ||
|
||
let(:source) { 'print 1' } | ||
let(:processed_source) { parse_source(source) } | ||
|
||
before do | ||
allow(processed_source.buffer).to(receive(:name).and_return(filename)) | ||
_investigate(cop, processed_source) | ||
end | ||
|
||
context 'with an .rbi file outside of sorbet/' do | ||
let(:filename) { 'some/dir/file.rbi' } | ||
|
||
it 'makes offense if an RBI file is outside of the sorbet/ directory' do | ||
expect(cop.offenses.size).to(eq(1)) | ||
expect(cop.messages).to(eq(['RBI files are only accepted in the sorbet/rbi/ directory.'])) | ||
end | ||
end | ||
|
||
context 'with an .rbi file inside of sorbet/' do | ||
let(:filename) { 'sorbet/rbi/ome/dir/file.rbi' } | ||
|
||
it 'makes no offense if an RBI file is inside the sorbet/ directory' do | ||
expect(cop.offenses.empty?).to(be(true)) | ||
end | ||
end | ||
end |
File renamed without changes.