standard 1.24.2 → 1.25.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 13d481f6982b619853ac364ffa223ddb6c010ea68cd57248c759786119f991a7
4
- data.tar.gz: 3ee49b870ff3d1ffe12bca06c1d0c80ec41e815fe056f476b91f2bb766293196
3
+ metadata.gz: 62f07904722bcfbbb854cb836adab694bb8e8c17462815746c43a9fc7efeec25
4
+ data.tar.gz: eb29fb518070108bb06c5935a674f7e4bc790bdf9ed1fb61f1b4b4c62e981678
5
5
  SHA512:
6
- metadata.gz: e1e0ad0ae158c7659b253f1062693f82cd1691babf12e65237521d005f9c4ce148b53e2905dfa1d1029082133e4852ef0f8c9a46e6917d6860342cf602c0fc64
7
- data.tar.gz: 0d4ad3d30a9652e3536129f0f4733e5b7efb8ccefb699333e83f18a47e4259c2917b7f4507806aa79f4de15b0e7a73f5cf4961fafe86be88cb6c3c97a00a2d6f
6
+ metadata.gz: 6f6a1c87fe29092994d039226b2724372b47d7108a2b10fbb32aa3da6d10c07301a2013553c1532bacc5e3d6a144bc741254c3e80abb14fc8b76704d011b79f9
7
+ data.tar.gz: ac43fa3bda8577a7bbc8b3f5dfb9b8ae949681b0c98da4bdfbd80bdf93ecb8b92e38a16358a935223e5b5c00045893540645eae5b43b8f8bbb6ad9ad0e04c3ed
data/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.25.0
4
+
5
+ * Update rubocop-performance from 1.15.2 to [1.16.0](https://github.com/rubocop/rubocop-performance/releases/tag/v1.16.0)
6
+ * Update rubocop from 1.44.1 to [1.48.1](https://github.com/rubocop/rubocop/releases/tag/v1.48.1)
7
+ * Enabled [Style/DirEmpty](https://docs.rubocop.org/rubocop/cops_style.html#styledirempty)
8
+ * Enabled [Style/RedundantHeredocDelimiterQuotes](https://docs.rubocop.org/rubocop/cops_style.html#styleredundantheredocdelimiterquotes)
9
+
10
+ ## 1.24.3
11
+
12
+ * _Further_ _further_ _further_ improve `--lsp` server to ignore files correctly
13
+
3
14
  ## 1.24.2
4
15
 
5
16
  * _Further_ _further_ improve `--lsp` server to always respond to requests
data/Gemfile.lock CHANGED
@@ -1,10 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- standard (1.24.2)
4
+ standard (1.25.0)
5
5
  language_server-protocol (~> 3.17.0.2)
6
- rubocop (= 1.44.1)
7
- rubocop-performance (= 1.15.2)
6
+ rubocop (= 1.48.1)
7
+ rubocop-performance (= 1.16.0)
8
8
 
9
9
  GEM
10
10
  remote: https://rubygems.org/
@@ -19,9 +19,9 @@ GEM
19
19
  method_source (>= 0.6.7)
20
20
  rake (>= 0.9.2.2)
21
21
  method_source (1.0.0)
22
- minitest (5.17.0)
22
+ minitest (5.18.0)
23
23
  parallel (1.22.1)
24
- parser (3.2.1.0)
24
+ parser (3.2.1.1)
25
25
  ast (~> 2.4.1)
26
26
  pry (0.14.2)
27
27
  coderay (~> 1.1)
@@ -30,22 +30,22 @@ GEM
30
30
  rake (13.0.6)
31
31
  regexp_parser (2.7.0)
32
32
  rexml (3.2.5)
33
- rubocop (1.44.1)
33
+ rubocop (1.48.1)
34
34
  json (~> 2.3)
35
35
  parallel (~> 1.10)
36
36
  parser (>= 3.2.0.0)
37
37
  rainbow (>= 2.2.2, < 4.0)
38
38
  regexp_parser (>= 1.8, < 3.0)
39
39
  rexml (>= 3.2.5, < 4.0)
40
- rubocop-ast (>= 1.24.1, < 2.0)
40
+ rubocop-ast (>= 1.26.0, < 2.0)
41
41
  ruby-progressbar (~> 1.7)
42
42
  unicode-display_width (>= 2.4.0, < 3.0)
43
- rubocop-ast (1.24.1)
44
- parser (>= 3.1.1.0)
45
- rubocop-performance (1.15.2)
43
+ rubocop-ast (1.27.0)
44
+ parser (>= 3.2.1.0)
45
+ rubocop-performance (1.16.0)
46
46
  rubocop (>= 1.7.0, < 2.0)
47
47
  rubocop-ast (>= 0.4.0)
48
- ruby-progressbar (1.11.0)
48
+ ruby-progressbar (1.13.0)
49
49
  simplecov (0.22.0)
50
50
  docile (~> 1.1)
51
51
  simplecov-html (~> 0.11)
data/README.md CHANGED
@@ -200,19 +200,6 @@ community conventions higher than personal style. This might not make sense for
200
200
  place for newbies. Setting up clear, automated contributor expectations makes a
201
201
  project healthier.
202
202
 
203
- ## Usage via RuboCop
204
-
205
- If you only want to use Standard's rules while continuing to use RuboCop's CLI
206
- (for example, to continue using your favorite IDE/tooling/workflow with RuboCop
207
- support), you can configure this in your `.rubocop.yml`:
208
-
209
- ```yaml
210
- require: standard
211
-
212
- inherit_gem:
213
- standard: config/base.yml
214
- ```
215
-
216
203
  ## Who uses Ruby Standard Style?
217
204
 
218
205
  Here are a few examples of Ruby Standard-compliant teams & projects:
@@ -242,6 +229,7 @@ Here are a few examples of Ruby Standard-compliant teams & projects:
242
229
  * [Rebase Interactive](https://www.rebaseinteractive.com/)
243
230
  * [Renuo](https://www.renuo.ch/)
244
231
  * [RubyCI](https://ruby.ci)
232
+ * [Teamtailor](https://www.teamtailor.com/)
245
233
  * [thoughtbot](https://thoughtbot.com/)
246
234
 
247
235
  Does your team use Standard? [Add your name to the list](https://github.com/testdouble/standard/edit/main/README.md)!
@@ -430,7 +418,7 @@ and `rake standard` will also execute the default configuration of the
430
418
  `rubocop-rails` gem without needing to invoke `rubocop` separately.
431
419
 
432
420
  For a slightly more complex example, we could add the
433
- [https://github.com/Betterment/betterlint] gem from our friends at
421
+ [betterlint](https://github.com/Betterment/betterlint) gem from our friends at
434
422
  [Betterment](https://www.betterment.com), first by telling Standard where our
435
423
  configuration file is:
436
424
 
@@ -475,11 +463,25 @@ Standard (like `TargetRubyVersion`) or prevent Standard's own rules from running
475
463
  `extend_config`, note that their resulting RuboCop configurations will be merged
476
464
  in order (i.e. last-in-wins).
477
465
 
478
- If you find that Standard's `extend_config` feature doesn't meet your needs,
479
- Evil Martians also maintains [a regularly updated
466
+ ### Usage via RuboCop
467
+
468
+ If you find that Standard's `extend_config` feature doesn't meet your needs or
469
+ if you only want to use Standard's rules while continuing to use RuboCop's CLI
470
+ (e.g., to continue using your favorite IDE/tooling/workflow with RuboCop
471
+ support) Evil Martians also maintains [a regularly updated
480
472
  guide](https://evilmartians.com/chronicles/rubocoping-with-legacy-bring-your-ruby-code-up-to-standard)
481
473
  on how to configure RuboCop to load and execute Standard's ruleset.
482
474
 
475
+ In short, you can configure this in your `.rubocop.yml` to load Standard's
476
+ ruleset like any other gem:
477
+
478
+ ```yaml
479
+ require: standard
480
+
481
+ inherit_gem:
482
+ standard: config/base.yml
483
+ ```
484
+
483
485
  ## How do I change the output?
484
486
 
485
487
  Standard's built-in formatter is intentionally minimal, printing only unfixed
data/config/base.yml CHANGED
@@ -855,6 +855,9 @@ Metrics/BlockNesting:
855
855
  Metrics/ClassLength:
856
856
  Enabled: false
857
857
 
858
+ Metrics/CollectionLiteralLength:
859
+ Enabled: false
860
+
858
861
  Metrics/CyclomaticComplexity:
859
862
  Enabled: false
860
863
 
@@ -1246,6 +1249,9 @@ Style/DefWithParentheses:
1246
1249
  Style/Dir:
1247
1250
  Enabled: true
1248
1251
 
1252
+ Style/DirEmpty:
1253
+ Enabled: true
1254
+
1249
1255
  Style/DisableCopsWithinSourceCodeDirective:
1250
1256
  Enabled: false
1251
1257
 
@@ -1325,6 +1331,9 @@ Style/ExponentialNotation:
1325
1331
  Style/FetchEnvVar:
1326
1332
  Enabled: false
1327
1333
 
1334
+ Style/FileEmpty:
1335
+ Enabled: false
1336
+
1328
1337
  Style/FileRead:
1329
1338
  Enabled: true
1330
1339
 
@@ -1692,6 +1701,9 @@ Style/RedundantFileExtensionInRequire:
1692
1701
  Style/RedundantFreeze:
1693
1702
  Enabled: true
1694
1703
 
1704
+ Style/RedundantHeredocDelimiterQuotes:
1705
+ Enabled: true
1706
+
1695
1707
  Style/RedundantInitialize:
1696
1708
  Enabled: true
1697
1709
 
data/config/ruby-2.3.yml CHANGED
@@ -5,3 +5,6 @@ AllCops:
5
5
 
6
6
  Style/ComparableClamp:
7
7
  Enabled: false
8
+
9
+ Style/DirEmpty:
10
+ Enabled: false
@@ -1,9 +1,19 @@
1
1
  module Standard
2
2
  module Lsp
3
3
  class Logger
4
+ def initialize
5
+ @puts_onces = []
6
+ end
7
+
4
8
  def puts(message)
5
9
  warn("[server] #{message}")
6
10
  end
11
+
12
+ def puts_once(message)
13
+ return if @puts_onces.include?(message)
14
+ @puts_onces << message
15
+ puts(message)
16
+ end
7
17
  end
8
18
  end
9
19
  end
@@ -30,7 +30,8 @@ module Standard
30
30
  diagnostic_provider: true,
31
31
  execute_command_provider: true,
32
32
  text_document_sync: Proto::Interface::TextDocumentSyncOptions.new(
33
- change: Proto::Constant::TextDocumentSyncKind::FULL
33
+ change: Proto::Constant::TextDocumentSyncKind::FULL,
34
+ open_close: true
34
35
  )
35
36
  )
36
37
  ))
@@ -130,13 +131,17 @@ module Standard
130
131
 
131
132
  private
132
133
 
134
+ def uri_to_path(uri)
135
+ uri.sub(%r{^file://}, "")
136
+ end
137
+
133
138
  def format_file(file_uri)
134
139
  text = @text_cache[file_uri]
135
140
  if text.nil?
136
141
  @logger.puts "Format request arrived before text synchonized; skipping: `#{file_uri}'"
137
142
  []
138
143
  else
139
- new_text = @standardizer.format(text)
144
+ new_text = @standardizer.format(uri_to_path(file_uri), text)
140
145
  if new_text == text
141
146
  []
142
147
  else
@@ -153,7 +158,7 @@ module Standard
153
158
 
154
159
  def diagnostic(file_uri, text)
155
160
  @text_cache[file_uri] = text
156
- offenses = @standardizer.offenses(text)
161
+ offenses = @standardizer.offenses(uri_to_path(file_uri), text)
157
162
 
158
163
  lsp_diagnostics = offenses.map { |o|
159
164
  code = o[:cop_name]
@@ -9,15 +9,11 @@ module Standard
9
9
  SEV = Proto::Constant::DiagnosticSeverity
10
10
 
11
11
  class Server
12
- def self.start(standardizer)
13
- new(standardizer).start
14
- end
15
-
16
- def initialize(standardizer)
17
- @standardizer = standardizer
12
+ def initialize(config)
18
13
  @writer = Proto::Transport::Io::Writer.new($stdout)
19
14
  @reader = Proto::Transport::Io::Reader.new($stdin)
20
15
  @logger = Logger.new
16
+ @standardizer = Standard::Lsp::Standardizer.new(config, @logger)
21
17
  @routes = Routes.new(@writer, @logger, @standardizer)
22
18
  end
23
19
 
@@ -1,49 +1,65 @@
1
1
  require_relative "../runners/rubocop"
2
- require "tempfile"
3
2
 
4
3
  module Standard
5
4
  module Lsp
6
5
  class Standardizer
7
- def initialize(config)
8
- @template_options = config
9
- @runner = Standard::Runners::Rubocop.new
6
+ def initialize(config, logger)
7
+ @config = config
8
+ @logger = logger
9
+ @rubocop_runner = Standard::Runners::Rubocop.new
10
10
  end
11
11
 
12
- def format(text)
13
- run_standard(text, format: true)
12
+ # This abuses the --stdin option of rubocop and reads the formatted text
13
+ # from the options[:stdin] that rubocop mutates. This depends on
14
+ # parallel: false as well as the fact that rubocop doesn't otherwise dup
15
+ # or reassign that options object. Risky business!
16
+ #
17
+ # Reassigning options[:stdin] is done here:
18
+ # https://github.com/rubocop/rubocop/blob/master/lib/rubocop/cop/team.rb#L131
19
+ # Printing options[:stdin]
20
+ # https://github.com/rubocop/rubocop/blob/master/lib/rubocop/cli/command/execute_runner.rb#L95
21
+ # Setting `parallel: true` would break this here:
22
+ # https://github.com/rubocop/rubocop/blob/master/lib/rubocop/runner.rb#L72
23
+ def format(path, text)
24
+ ad_hoc_config = fork_config(path, text, format: true)
25
+ capture_rubocop_stdout(ad_hoc_config)
26
+ ad_hoc_config.rubocop_options[:stdin]
14
27
  end
15
28
 
16
- def offenses(text)
17
- results = run_standard(text, format: false)
18
- JSON.parse(results, symbolize_names: true).dig(:files, 0, :offenses)
29
+ def offenses(path, text)
30
+ results = JSON.parse(
31
+ capture_rubocop_stdout(fork_config(path, text, format: false)),
32
+ symbolize_names: true
33
+ )
34
+ if results[:files].empty?
35
+ @logger.puts_once "Ignoring file, per configuration: #{path}"
36
+ []
37
+ else
38
+ results.dig(:files, 0, :offenses)
39
+ end
19
40
  end
20
41
 
21
42
  private
22
43
 
23
- BASENAME = ["source", ".rb"].freeze
24
- def run_standard(text, format:)
25
- Tempfile.open(BASENAME) do |temp|
26
- temp.write(text)
27
- temp.flush
28
- stdout = capture_rubocop_stdout(make_config(temp.path, format))
29
- format ? File.read(temp.path) : stdout
30
- end
31
- end
32
-
33
- def make_config(file, format)
34
- # Can't make frozen versions of this hash because RuboCop mutates it
35
- o = if format
36
- {autocorrect: true, formatters: [["Standard::Formatter", nil]], parallel: true, todo_file: nil, todo_ignore_files: [], safe_autocorrect: true}
44
+ BASE_OPTIONS = {
45
+ force_exclusion: true,
46
+ parallel: false,
47
+ todo_file: nil,
48
+ todo_ignore_files: []
49
+ }
50
+ def fork_config(path, text, format:)
51
+ options = if format
52
+ {stdin: text, autocorrect: true, formatters: [], safe_autocorrect: true}
37
53
  else
38
- {autocorrect: false, formatters: [["json"]], parallel: true, todo_file: nil, todo_ignore_files: [], format: "json"}
54
+ {stdin: text, autocorrect: false, formatters: [["json"]], format: "json"}
39
55
  end
40
- Standard::Config.new(@template_options.runner, [file], o, @template_options.rubocop_config_store)
56
+ Standard::Config.new(@config.runner, [path], BASE_OPTIONS.merge(options), @config.rubocop_config_store)
41
57
  end
42
58
 
43
59
  def capture_rubocop_stdout(config)
44
60
  redir = StringIO.new
45
61
  $stdout = redir
46
- @runner.call(config)
62
+ @rubocop_runner.call(config)
47
63
  redir.string
48
64
  ensure
49
65
  $stdout = STDOUT
@@ -4,8 +4,7 @@ module Standard
4
4
  module Runners
5
5
  class Lsp
6
6
  def call(config)
7
- standardizer = Standard::Lsp::Standardizer.new(config)
8
- Standard::Lsp::Server.start(standardizer)
7
+ Standard::Lsp::Server.new(config).start
9
8
  end
10
9
  end
11
10
  end
@@ -1,3 +1,3 @@
1
1
  module Standard
2
- VERSION = Gem::Version.new("1.24.2")
2
+ VERSION = Gem::Version.new("1.25.0")
3
3
  end
data/standard.gemspec CHANGED
@@ -19,8 +19,8 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ["lib"]
21
21
 
22
- spec.add_dependency "rubocop", "1.44.1"
23
- spec.add_dependency "rubocop-performance", "1.15.2"
22
+ spec.add_dependency "rubocop", "1.48.1"
23
+ spec.add_dependency "rubocop-performance", "1.16.0"
24
24
 
25
25
  # not semver: first three are lsp protocol version, last is patch
26
26
  spec.add_dependency "language_server-protocol", "~> 3.17.0.2"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: standard
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.24.2
4
+ version: 1.25.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Searls
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-02-10 00:00:00.000000000 Z
11
+ date: 2023-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 1.44.1
19
+ version: 1.48.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 1.44.1
26
+ version: 1.48.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rubocop-performance
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 1.15.2
33
+ version: 1.16.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 1.15.2
40
+ version: 1.16.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: language_server-protocol
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -52,7 +52,7 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 3.17.0.2
55
- description:
55
+ description:
56
56
  email:
57
57
  - searls@gmail.com
58
58
  executables:
@@ -123,7 +123,7 @@ files:
123
123
  homepage: https://github.com/testdouble/standard
124
124
  licenses: []
125
125
  metadata: {}
126
- post_install_message:
126
+ post_install_message:
127
127
  rdoc_options: []
128
128
  require_paths:
129
129
  - lib
@@ -138,8 +138,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
138
  - !ruby/object:Gem::Version
139
139
  version: '0'
140
140
  requirements: []
141
- rubygems_version: 3.3.26
142
- signing_key:
141
+ rubygems_version: 3.1.6
142
+ signing_key:
143
143
  specification_version: 4
144
144
  summary: Ruby Style Guide, with linter & automatic code fixer
145
145
  test_files: []