Skip to content

Commit 8529224

Browse files
committed
Allow annotating models and routes using sorbet's static checks
See https://sorbet.org/docs/static
1 parent 5d01c41 commit 8529224

File tree

5 files changed

+26
-5
lines changed

5 files changed

+26
-5
lines changed

.rubocop_todo.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,7 @@ Style/StderrPuts:
768768
Style/StringConcatenation:
769769
Exclude:
770770
- 'lib/annotate/annotate_models.rb'
771+
- 'lib/annotate/annotate_routes/helpers.rb'
771772

772773
# Offense count: 57
773774
# Cop supports --auto-correct.
@@ -817,4 +818,4 @@ Style/TrailingCommaInArrayLiteral:
817818
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
818819
# URISchemes: http, https
819820
Layout/LineLength:
820-
Max: 264
821+
Max: 245

lib/annotate/annotate_models.rb

+9-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,15 @@ module AnnotateModels
3939
}
4040
}.freeze
4141

42-
MAGIC_COMMENT_MATCHER = Regexp.new(/(^#\s*encoding:.*(?:\n|r\n))|(^# coding:.*(?:\n|\r\n))|(^# -\*- coding:.*(?:\n|\r\n))|(^# -\*- encoding\s?:.*(?:\n|\r\n))|(^#\s*frozen_string_literal:.+(?:\n|\r\n))|(^# -\*- frozen_string_literal\s*:.+-\*-(?:\n|\r\n))/).freeze
42+
MAGIC_COMMENT_MATCHER = Regexp.new(
43+
'(^#\s*encoding:.*(?:\n|\r\n))' \
44+
+ '|(^# coding:.*(?:\n|\r\n))' \
45+
+ '|(^# -\*- coding:.*(?:\n|\r\n))' \
46+
+ '|(^# -\*- encoding\s?:.*(?:\n|\r\n))' \
47+
+ '|(^#\s*frozen_string_literal:.+(?:\n|\r\n))' \
48+
+ '|(^# -\*- frozen_string_literal\s*:.+-\*-(?:\n|\r\n))' \
49+
+ '|(^#\s*typed:.+(?:\n|\r\n))'
50+
).freeze
4351

4452
class << self
4553
def annotate_pattern(options = {})

lib/annotate/annotate_routes/helpers.rb

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
module AnnotateRoutes
22
module Helpers
3-
MAGIC_COMMENT_MATCHER = Regexp.new(/(^#\s*encoding:.*)|(^# coding:.*)|(^# -\*- coding:.*)|(^# -\*- encoding\s?:.*)|(^#\s*frozen_string_literal:.+)|(^# -\*- frozen_string_literal\s*:.+-\*-)/).freeze
3+
MAGIC_COMMENT_MATCHER = Regexp.new(
4+
'(^#\s*encoding:.*)' \
5+
+ '|(^# coding:.*)' \
6+
+ '|(^# -\*- coding:.*)' \
7+
+ '|(^# -\*- encoding\s?:.*)' \
8+
+ '|(^#\s*frozen_string_literal:.+)' \
9+
+ '|(^# -\*- frozen_string_literal\s*:.+-\*-)' \
10+
+ '|(^#\s*typed:.*)'
11+
).freeze
412

513
class << self
614
# TODO: write the method doc using ruby rdoc formats

spec/lib/annotate/annotate_models_spec.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
"# frozen_string_literal: true\n# encoding: utf-8",
1919
'# frozen_string_literal: true',
2020
'#frozen_string_literal: false',
21-
'# -*- frozen_string_literal : true -*-'
21+
'# -*- frozen_string_literal : true -*-',
22+
'#typed: false',
23+
'# typed: true'
2224
].freeze unless const_defined?(:MAGIC_COMMENTS)
2325

2426
def mock_index(name, params = {})

spec/lib/annotate/annotate_routes_spec.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
"# frozen_string_literal: true\n# encoding: utf-8",
2121
'# frozen_string_literal: true',
2222
'#frozen_string_literal: false',
23-
'# -*- frozen_string_literal : true -*-'
23+
'# -*- frozen_string_literal : true -*-',
24+
'#typed: false',
25+
'# typed: true'
2426
].freeze unless const_defined?(:MAGIC_COMMENTS)
2527

2628
let :stubs do

0 commit comments

Comments
 (0)