spoom 1.0.6 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -36,6 +36,36 @@ module Spoom
36
36
  @allowed_extensions = T.let([], T::Array[String])
37
37
  end
38
38
 
39
+ sig { returns(Config) }
40
+ def copy
41
+ new_config = Sorbet::Config.new
42
+ new_config.paths.concat(@paths)
43
+ new_config.ignore.concat(@ignore)
44
+ new_config.allowed_extensions.concat(@allowed_extensions)
45
+ new_config
46
+ end
47
+
48
+ # Returns self as a string of options that can be passed to Sorbet
49
+ #
50
+ # Example:
51
+ # ~~~rb
52
+ # config = Sorbet::Config.new
53
+ # config.paths << "/foo"
54
+ # config.paths << "/bar"
55
+ # config.ignore << "/baz"
56
+ # config.allowed_extensions << ".rb"
57
+ #
58
+ # puts config.options_string # "/foo /bar --ignore /baz --allowed-extension .rb"
59
+ # ~~~
60
+ sig { returns(String) }
61
+ def options_string
62
+ opts = []
63
+ opts.concat(paths)
64
+ opts.concat(ignore.map { |p| "--ignore #{p}" })
65
+ opts.concat(allowed_extensions.map { |ext| "--allowed-extension #{ext}" })
66
+ opts.join(" ")
67
+ end
68
+
39
69
  class << self
40
70
  extend T::Sig
41
71
 
@@ -4,6 +4,8 @@
4
4
  module Spoom
5
5
  module Sorbet
6
6
  module Errors
7
+ extend T::Sig
8
+
7
9
  # Parse errors from Sorbet output
8
10
  class Parser
9
11
  extend T::Sig
@@ -123,6 +125,7 @@ module Spoom
123
125
  @more = more
124
126
  end
125
127
 
128
+ # By default errors are sorted by location
126
129
  sig { params(other: T.untyped).returns(Integer) }
127
130
  def <=>(other)
128
131
  return 0 unless other.is_a?(Error)
@@ -134,6 +137,11 @@ module Spoom
134
137
  "#{file}:#{line}: #{message} (#{code})"
135
138
  end
136
139
  end
140
+
141
+ sig { params(errors: T::Array[Error]).returns(T::Array[Error]) }
142
+ def self.sort_errors_by_code(errors)
143
+ errors.sort_by { |e| [e.code, e.file, e.line, e.message] }
144
+ end
137
145
  end
138
146
  end
139
147
  end
@@ -11,13 +11,9 @@ require_relative 'lsp/errors'
11
11
  module Spoom
12
12
  module LSP
13
13
  class Client
14
- def initialize(sorbet_cmd, *sorbet_args, path: ".")
14
+ def initialize(sorbet_bin, *sorbet_args, path: ".")
15
15
  @id = 0
16
- Bundler.with_clean_env do
17
- opts = {}
18
- opts[:chdir] = path
19
- @in, @out, @err, @status = Open3.popen3([sorbet_cmd, *sorbet_args].join(" "), opts)
20
- end
16
+ @in, @out, @err, @status = T.unsafe(Open3).popen3(sorbet_bin, *sorbet_args, chdir: path)
21
17
  end
22
18
 
23
19
  def next_id
@@ -56,14 +56,14 @@ module Spoom
56
56
  sig { params(path: T.any(String, Pathname)).returns(T.nilable(String)) }
57
57
  def self.file_strictness(path)
58
58
  return nil unless File.exist?(path)
59
- content = File.read(path)
59
+ content = File.read(path, encoding: Encoding::ASCII_8BIT)
60
60
  strictness_in_content(content)
61
61
  end
62
62
 
63
63
  # changes the sigil in the file at the passed path to the specified new strictness
64
64
  sig { params(path: T.any(String, Pathname), new_strictness: String).returns(T::Boolean) }
65
65
  def self.change_sigil_in_file(path, new_strictness)
66
- content = File.read(path)
66
+ content = File.read(path, encoding: Encoding::ASCII_8BIT)
67
67
  new_content = update_sigil(content, new_strictness)
68
68
 
69
69
  File.write(path, new_content)
@@ -87,7 +87,7 @@ module Spoom
87
87
  extension: String
88
88
  ).returns(T::Array[String])
89
89
  end
90
- def self.files_with_sigil_strictness(directory, strictness, extension = ".rb")
90
+ def self.files_with_sigil_strictness(directory, strictness, extension: ".rb")
91
91
  paths = Dir.glob("#{File.expand_path(directory)}/**/*#{extension}").sort.uniq
92
92
  paths.filter do |path|
93
93
  file_strictness(path) == strictness
@@ -76,6 +76,15 @@ module Spoom
76
76
  Spoom::Git.exec("GIT_COMMITTER_DATE=\"#{date}\" git commit -m '#{message}' --date '#{date}'", path: path)
77
77
  end
78
78
 
79
+ # Run `bundle install` in this project
80
+ sig { returns([T.nilable(String), T.nilable(String), T::Boolean]) }
81
+ def bundle_install
82
+ opts = {}
83
+ opts[:chdir] = path
84
+ out, err, status = Open3.capture3("bundle", "install", opts)
85
+ [out, err, status.success?]
86
+ end
87
+
79
88
  # Run a command with `bundle exec` in this project
80
89
  sig { params(cmd: String, args: String).returns([T.nilable(String), T.nilable(String), T::Boolean]) }
81
90
  def bundle_exec(cmd, *args)
data/lib/spoom/version.rb CHANGED
@@ -1,6 +1,6 @@
1
- # typed: true
1
+ # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Spoom
5
- VERSION = "1.0.6"
5
+ VERSION = "1.1.1"
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spoom
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexandre Terrasa
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-11-19 00:00:00.000000000 Z
11
+ date: 2021-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -70,16 +70,16 @@ dependencies:
70
70
  name: sorbet
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: 0.5.5
75
+ version: 0.5.6347
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: 0.5.5
82
+ version: 0.5.6347
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: thor
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -128,7 +128,6 @@ files:
128
128
  - lib/spoom/cli/helper.rb
129
129
  - lib/spoom/cli/lsp.rb
130
130
  - lib/spoom/cli/run.rb
131
- - lib/spoom/config.rb
132
131
  - lib/spoom/coverage.rb
133
132
  - lib/spoom/coverage/d3.rb
134
133
  - lib/spoom/coverage/d3/base.rb
data/lib/spoom/config.rb DELETED
@@ -1,11 +0,0 @@
1
- # typed: true
2
- # frozen_string_literal: true
3
-
4
- module Spoom
5
- module Config
6
- SORBET_CONFIG = "sorbet/config"
7
- SORBET_GEM_PATH = Gem::Specification.find_by_name("sorbet-static").full_gem_path
8
- SORBET_PATH = (Pathname.new(SORBET_GEM_PATH) / "libexec" / "sorbet").to_s
9
- SPOOM_PATH = (Pathname.new(__FILE__) / ".." / ".." / "..").to_s
10
- end
11
- end