ruby-next-core 0.5.0 → 0.5.1

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: 18e3905f1324ff7061b59c61aaabd4faf91ff5bcbe2e2896ceda6f2514427b71
4
- data.tar.gz: f87cad7947307e13f3da37624eff499f62ae1b8398f902107c8cc7179ee6a5be
3
+ metadata.gz: ae8ccdf6dc524052fe864e962362b7da9dd6ce804d03b8cde765ed8010f8c9ea
4
+ data.tar.gz: ad015bedd5ca0a48e0f50f27f9b3c78235c3326e99a65d4f4ae1f9adac0aaa2b
5
5
  SHA512:
6
- metadata.gz: 4c2530ece05aa6e2bb8e0437f38f5d198a9a081039101ec03c836a01162a92685c5dc6dc2d90f1608c1466002b1afcca3fdf9ddb36774ff1b47a2d438f7cb0ae
7
- data.tar.gz: cf6f93b2f8f869354e594ee8e5932acd96ecd78201223a6630f74d6fc13423d220459d9524a81266342f23913304f41a30c3face46be1291022e09b2f15caee3
6
+ metadata.gz: 10eb9b82b0dd65188fe311d0a3bbe1950c148b6d94ed548a59d3b0ced0e41e077e1183315c3cbc2c351def0ee6ac16a2095f49cc425952ab6d276221766f8856
7
+ data.tar.gz: c65ff2bda5a24e47cd3ee13b80059c50dfdb05a9051c3ae782d8cfabdf9f32b0b936110751cdf65920ac00850e5448c04f606f7870d22c2b02d93692f24c0699
@@ -2,6 +2,12 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 0.5.1 (2020-03-20)
6
+
7
+ - Add RuboCop integration. ([@palkan][])
8
+
9
+ Adds support for missing node types and fixes some bugs with 2.7.
10
+
5
11
  ## 0.5.0 (2020-03-20)
6
12
 
7
13
  - Add `rewrite` transpiler mode. ([@palkan][])
data/README.md CHANGED
@@ -35,6 +35,7 @@ That's why Ruby Next implements the `master` features as fast as possible.
35
35
  - [Runtime usage](#runtime-usage)
36
36
  - [Bootsnap integration](#using-with-bootsnap)
37
37
  - [`ruby -ruby-next`](#uby-next)
38
+ - [RuboCop](#rubocop)
38
39
  - [Proposed & edge features](#proposed-and-edge-features)
39
40
 
40
41
  ## Overview
@@ -247,6 +248,8 @@ due to the way feature resolving works in Ruby (scanning the `$LOAD_PATH` and ha
247
248
 
248
249
  **NOTE:** `require_relative` should be avoided due to the way we _hijack_ the features loading mechanism.
249
250
 
251
+ If you're using [runtime mode](#runtime-usage) a long with `setup_gem_load_path` (e.g., in tests), the transpiled files are ignored (i.e., we do not modify `$LOAD_PATH`).
252
+
250
253
  \* Ruby Next avoids storing duplicates; instead, only the code for the earlier version is created and is assumed to be used with other versions. For example, if the transpiled code is the same for Ruby 2.5 and Ruby 2.6, only the `.rbnext/2.7/path/to/file.rb` is kept. That's why multiple entries are added to the `$LOAD_PATH` (`.rbnext/2.6` and `.rbnext/2.7` in the specified order for Ruby 2.5 and only `.rbnext/2.7` for Ruby 2.6).
251
254
 
252
255
  ## Runtime usage
@@ -304,6 +307,28 @@ RUBYOPT="-ruby-next" ruby my_ruby_script.rb
304
307
  ruby -ruby-next -e "puts [2, 4, 5].tally"
305
308
  ```
306
309
 
310
+ ## RuboCop
311
+
312
+ Since Ruby Next provides support for features not available in RuboCop yet, you need to add a patch for compatibility.
313
+ In you `.rubocop.yml` add the following:
314
+
315
+ ```yml
316
+ require:
317
+ - ruby-next/rubocop
318
+ ```
319
+
320
+ **NOTE:** You should use `TargetRubyVersion: 2.7`.
321
+
322
+ Alternatively, you can load the patch from the command line by running: `rubocop -r ruby-next/rubocop ...`.
323
+
324
+ Also, when pre-transpiling source code with `ruby-next nextify`, we suggest ignoring the transpiled files:
325
+
326
+ ```yml
327
+ AllCops:
328
+ Exclude:
329
+ - 'lib/.rbnext/**/*'
330
+ ```
331
+
307
332
  ## Proposed and edge features
308
333
 
309
334
  Ruby Next aims to bring edge and proposed features to Ruby community before they (hopefully) reach an official Ruby release.
@@ -380,3 +405,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
380
405
  [unparser]: https://github.com/mbj/unparser
381
406
  [next_parser]: https://github.com/ruby-next/parser
382
407
  [Bootsnap]: https://github.com/Shopify/bootsnap
408
+ [rubocop]: https://github.com/rubocop-hq/rubocop
@@ -82,6 +82,14 @@ module RubyNext
82
82
  mode == :ast
83
83
  end
84
84
 
85
+ def runtime!
86
+ @runtime = true
87
+ end
88
+
89
+ def runtime?
90
+ @runtime
91
+ end
92
+
85
93
  def transform(*args, **kwargs)
86
94
  if mode == :rewrite
87
95
  rewrite(*args, **kwargs)
@@ -4,6 +4,8 @@ require "ruby-next"
4
4
  require "ruby-next/utils"
5
5
  require "ruby-next/language"
6
6
 
7
+ RubyNext::Language.runtime!
8
+
7
9
  # Patch bootsnap to transform source code.
8
10
  # Based on https://github.com/kddeisz/preval/blob/master/lib/preval.rb
9
11
  load_iseq = RubyVM::InstructionSequence.method(:load_iseq)
@@ -9,6 +9,8 @@ require "ruby-next/language/eval"
9
9
 
10
10
  module RubyNext
11
11
  module Language
12
+ runtime!
13
+
12
14
  # Module responsible for runtime transformations
13
15
  module Runtime
14
16
  using RubyNext
@@ -6,6 +6,12 @@ require "ruby-next"
6
6
  module RubyNext
7
7
  module Language
8
8
  class << self
9
+ unless method_defined?(:runtime?)
10
+ def runtime?
11
+ false
12
+ end
13
+ end
14
+
9
15
  def setup_gem_load_path(lib_dir = "lib", rbnext_dir: RUBY_NEXT_DIR)
10
16
  called_from = caller_locations(1, 1).first.path
11
17
  dirname = File.dirname(called_from)
@@ -21,6 +27,8 @@ module RubyNext
21
27
 
22
28
  dirname = File.realpath(dirname)
23
29
 
30
+ return if Language.runtime? && Language.watch_dirs.include?(dirname)
31
+
24
32
  current_index = $LOAD_PATH.index(dirname)
25
33
 
26
34
  raise "Gem's lib is not in the $LOAD_PATH: #{dirname}" if current_index.nil?
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This file contains patches to RuboCop to support
4
+ # edge features and fix some bugs with 2.7 syntax
5
+
6
+ module RuboCop
7
+ module AST
8
+ module Traversal
9
+ # Fixed in https://github.com/rubocop-hq/rubocop/pull/7786
10
+ unless defined?(::RuboCop::AST::CaseMatchNode)
11
+ %i[case_match in_pattern].each do |type|
12
+ module_eval(<<~RUBY, __FILE__, __LINE__ + 1)
13
+ def on_#{type}(node)
14
+ node.children.each { |child| send(:"on_\#{child.type}", child) if child }
15
+ nil
16
+ end
17
+ RUBY
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+ module RuboCop
25
+ module Cop
26
+ # Commissioner class is responsible for processing the AST and delegating
27
+ # work to the specified cops.
28
+ class Commissioner
29
+ def on_meth_ref(node)
30
+ trigger_responding_cops(:on_meth_ref, node)
31
+ end
32
+
33
+ unless method_defined?(:on_numblock)
34
+ def on_numblock(node)
35
+ children = node.children
36
+ child = children[0]
37
+ send(:"on_#{child.type}", child)
38
+ # children[1] is the number of parameters
39
+ return unless (child = children[2])
40
+
41
+ send(:"on_#{child.type}", child)
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubyNext
4
- VERSION = "0.5.0"
4
+ VERSION = "0.5.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-next-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Dementyev
@@ -95,6 +95,7 @@ files:
95
95
  - lib/ruby-next/language/runtime.rb
96
96
  - lib/ruby-next/language/setup.rb
97
97
  - lib/ruby-next/language/unparser.rb
98
+ - lib/ruby-next/rubocop.rb
98
99
  - lib/ruby-next/utils.rb
99
100
  - lib/ruby-next/version.rb
100
101
  - lib/uby-next.rb