From e2ffb348ab41d9847201c06fffd9a966289683d0 Mon Sep 17 00:00:00 2001 From: Jake Brady Date: Fri, 4 Aug 2023 09:59:26 -0700 Subject: [PATCH 1/3] match SIGIL_REGEX behavior to sorbet sigil parsing --- lib/rubocop/cop/sorbet/sigils/valid_sigil.rb | 2 +- spec/rubocop/cop/sorbet/sigils/valid_sigil_spec.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/rubocop/cop/sorbet/sigils/valid_sigil.rb b/lib/rubocop/cop/sorbet/sigils/valid_sigil.rb index 13b7d11f..0963d8be 100644 --- a/lib/rubocop/cop/sorbet/sigils/valid_sigil.rb +++ b/lib/rubocop/cop/sorbet/sigils/valid_sigil.rb @@ -51,7 +51,7 @@ def autocorrect(_node) protected STRICTNESS_LEVELS = ["ignore", "false", "true", "strict", "strong"] - SIGIL_REGEX = /^\s*#\s+typed:(?:\s+([\w]+))?/ + SIGIL_REGEX = /^\s*#\s+typed:(?:\s+([\S]+))?/ # extraction diff --git a/spec/rubocop/cop/sorbet/sigils/valid_sigil_spec.rb b/spec/rubocop/cop/sorbet/sigils/valid_sigil_spec.rb index cecd1500..f0b92d5a 100644 --- a/spec/rubocop/cop/sorbet/sigils/valid_sigil_spec.rb +++ b/spec/rubocop/cop/sorbet/sigils/valid_sigil_spec.rb @@ -42,6 +42,15 @@ class Foo; end ^^^^^^^^^^^^^^^ Invalid Sorbet sigil `foobar`. class Foo; end RUBY + end + + it "enforces whitespase surrounding valid strictness levels" do + expect_offense(<<~RUBY) + # Hello world! + # typed: true# rubocop:todo Sorbet/StrictSigil + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Invalid Sorbet sigil `true#`. + class Foo; end + RUBY end end From 817a6ab24d6288a47c01af75bd7c0503dac85afd Mon Sep 17 00:00:00 2001 From: Jake Brady Date: Fri, 4 Aug 2023 10:35:26 -0700 Subject: [PATCH 2/3] use [[:blank:]] over \s Co-authored-by: Ufuk Kayserilioglu --- lib/rubocop/cop/sorbet/sigils/valid_sigil.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rubocop/cop/sorbet/sigils/valid_sigil.rb b/lib/rubocop/cop/sorbet/sigils/valid_sigil.rb index 0963d8be..c62a5732 100644 --- a/lib/rubocop/cop/sorbet/sigils/valid_sigil.rb +++ b/lib/rubocop/cop/sorbet/sigils/valid_sigil.rb @@ -51,7 +51,7 @@ def autocorrect(_node) protected STRICTNESS_LEVELS = ["ignore", "false", "true", "strict", "strong"] - SIGIL_REGEX = /^\s*#\s+typed:(?:\s+([\S]+))?/ + SIGIL_REGEX = /^[[:blank:]]*#[[:blank:]]+typed:(?:[[:blank:]]+([\S]+))?/ # extraction From f92d3ba2f9ed4498b518a5924269f3ab4f0b4e7d Mon Sep 17 00:00:00 2001 From: Jake Brady Date: Fri, 4 Aug 2023 10:36:58 -0700 Subject: [PATCH 3/3] fix trailing whitespace --- spec/rubocop/cop/sorbet/sigils/valid_sigil_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/rubocop/cop/sorbet/sigils/valid_sigil_spec.rb b/spec/rubocop/cop/sorbet/sigils/valid_sigil_spec.rb index f0b92d5a..cf75de32 100644 --- a/spec/rubocop/cop/sorbet/sigils/valid_sigil_spec.rb +++ b/spec/rubocop/cop/sorbet/sigils/valid_sigil_spec.rb @@ -42,7 +42,7 @@ class Foo; end ^^^^^^^^^^^^^^^ Invalid Sorbet sigil `foobar`. class Foo; end RUBY - end + end it "enforces whitespase surrounding valid strictness levels" do expect_offense(<<~RUBY)