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 +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +26 -0
- data/lib/ruby-next/language.rb +8 -0
- data/lib/ruby-next/language/bootsnap.rb +2 -0
- data/lib/ruby-next/language/runtime.rb +2 -0
- data/lib/ruby-next/language/setup.rb +8 -0
- data/lib/ruby-next/rubocop.rb +46 -0
- data/lib/ruby-next/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae8ccdf6dc524052fe864e962362b7da9dd6ce804d03b8cde765ed8010f8c9ea
|
4
|
+
data.tar.gz: ad015bedd5ca0a48e0f50f27f9b3c78235c3326e99a65d4f4ae1f9adac0aaa2b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 10eb9b82b0dd65188fe311d0a3bbe1950c148b6d94ed548a59d3b0ced0e41e077e1183315c3cbc2c351def0ee6ac16a2095f49cc425952ab6d276221766f8856
|
7
|
+
data.tar.gz: c65ff2bda5a24e47cd3ee13b80059c50dfdb05a9051c3ae782d8cfabdf9f32b0b936110751cdf65920ac00850e5448c04f606f7870d22c2b02d93692f24c0699
|
data/CHANGELOG.md
CHANGED
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
|
data/lib/ruby-next/language.rb
CHANGED
@@ -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)
|
@@ -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
|
data/lib/ruby-next/version.rb
CHANGED
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.
|
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
|