synvert-core 1.19.0 → 1.21.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/Gemfile.lock +3 -3
- data/README.md +6 -0
- data/lib/synvert/core/configuration.rb +14 -1
- data/lib/synvert/core/rewriter/instance.rb +21 -1
- data/lib/synvert/core/version.rb +1 -1
- data/spec/synvert/core/rewriter/instance_spec.rb +39 -0
- data/synvert-core-ruby.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df27af331a60def04866041f84ae64b9fe15555996ec2289015eb2c97d965f68
|
4
|
+
data.tar.gz: '092e9456741b2b43516146756ba738f6997a5252ba03dff226bde042333b4bf4'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 05aea1fff55d3a96596dc54de49db457ffe4fac87677bc9dada1d8af4ec6f45397b586207a0e8214fbbedbeed42f58a4fe92934a6095a610c834332632c1901a
|
7
|
+
data.tar.gz: ed6ab4c13e2aa0f406de8f4eff041f4fdb39ba37430902284994eb7ed303352bb4a1b459416a73fd049196646eed95bd332721a7f9b9f6da8dcf6a119fdb25e2
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 1.21.0 (2023-02-08)
|
4
|
+
|
5
|
+
* Add `Configuration#tab_width`
|
6
|
+
* Add `Instance#add_leading_spaces`
|
7
|
+
|
8
|
+
## 1.20.0 (2023-02-08)
|
9
|
+
|
10
|
+
* Add `Configuration#single_quote`
|
11
|
+
* Add `Instance#wrap_with_quotes`
|
12
|
+
|
3
13
|
## 1.19.0 (2023-02-06)
|
4
14
|
|
5
15
|
* Remove `Instance#query_adapter`
|
data/Gemfile.lock
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
synvert-core (1.
|
4
|
+
synvert-core (1.21.0)
|
5
5
|
activesupport (< 7.0.0)
|
6
6
|
erubis
|
7
|
-
node_mutation (>= 1.
|
7
|
+
node_mutation (>= 1.9.0)
|
8
8
|
node_query (>= 1.12.0)
|
9
9
|
parallel
|
10
10
|
parser
|
@@ -50,7 +50,7 @@ GEM
|
|
50
50
|
method_source (1.0.0)
|
51
51
|
minitest (5.17.0)
|
52
52
|
nenv (0.3.0)
|
53
|
-
node_mutation (1.
|
53
|
+
node_mutation (1.9.0)
|
54
54
|
erubis
|
55
55
|
node_query (1.12.0)
|
56
56
|
notiffany (0.1.3)
|
data/README.md
CHANGED
@@ -101,6 +101,12 @@ Actions:
|
|
101
101
|
* [noop](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#noop-instance_method) - no operation
|
102
102
|
* [add_action](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#add_action-instance_method) - add custom action
|
103
103
|
|
104
|
+
Others:
|
105
|
+
|
106
|
+
* [wrap_with_quotes](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#wrap_with_quotes-instance_method) - wrap string code with single or doulbe quotes
|
107
|
+
* [add_leading_spaces](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#add_leading_spaces-instance_method) - add leading spaces before the string code
|
108
|
+
|
109
|
+
|
104
110
|
Attributes:
|
105
111
|
|
106
112
|
* [file_path](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#file_path-instance_method) - current file path
|
@@ -9,7 +9,9 @@ module Synvert::Core
|
|
9
9
|
# @!attribute [w] only_paths
|
10
10
|
# @!attribute [w] show_run_process
|
11
11
|
# @!attribute [w] number_of_workers
|
12
|
-
|
12
|
+
# @!attribute [w] single_quote
|
13
|
+
# @!attribute [w] tab_width
|
14
|
+
attr_writer :root_path, :skip_paths, :only_paths, :show_run_process, :number_of_workers, :single_quote, :tab_width
|
13
15
|
|
14
16
|
# Get the path.
|
15
17
|
#
|
@@ -45,6 +47,17 @@ module Synvert::Core
|
|
45
47
|
def number_of_workers
|
46
48
|
@number_of_workers || 1
|
47
49
|
end
|
50
|
+
|
51
|
+
# Use single quote or double quote.
|
52
|
+
#
|
53
|
+
# @return [Boolean] true if use single quote, default is true
|
54
|
+
def single_quote
|
55
|
+
@single_quote.nil? ? true : @single_quote
|
56
|
+
end
|
57
|
+
|
58
|
+
def tab_width
|
59
|
+
@tab_width || 2
|
60
|
+
end
|
48
61
|
end
|
49
62
|
end
|
50
63
|
end
|
@@ -22,7 +22,7 @@ module Synvert::Core
|
|
22
22
|
if rewriter.options[:strategy] == Strategy::ALLOW_INSERT_AT_SAME_POSITION
|
23
23
|
strategy |= NodeMutation::Strategy::ALLOW_INSERT_AT_SAME_POSITION
|
24
24
|
end
|
25
|
-
NodeMutation.configure({ strategy: strategy })
|
25
|
+
NodeMutation.configure({ strategy: strategy, tab_width: Configuration.tab_width })
|
26
26
|
rewriter.helpers.each { |helper| singleton_class.send(:define_method, helper[:name], &helper[:block]) }
|
27
27
|
end
|
28
28
|
|
@@ -410,6 +410,26 @@ module Synvert::Core
|
|
410
410
|
@rewriter.add_warning Rewriter::Warning.new(self, message)
|
411
411
|
end
|
412
412
|
|
413
|
+
# Wrap str string with single or doulbe quotes based on Configuration.single_quote.
|
414
|
+
# @param str [String]
|
415
|
+
# @return [String] quoted string
|
416
|
+
def wrap_with_quotes(str)
|
417
|
+
quote = Configuration.single_quote ? "'" : '"';
|
418
|
+
another_quote = Configuration.single_quote ? '"' : "'";
|
419
|
+
if str.include?(quote) && !str.include?(another_quote)
|
420
|
+
return "#{another_quote}#{str}#{another_quote}"
|
421
|
+
end
|
422
|
+
escaped_str = str.gsub(quote) { |char| '\\' + quote }
|
423
|
+
quote + escaped_str + quote
|
424
|
+
end
|
425
|
+
|
426
|
+
# Add leading spaces before the str according to Configuration.tab_width.
|
427
|
+
# @param str [String]
|
428
|
+
# @return [String]
|
429
|
+
def add_leading_spaces(str)
|
430
|
+
" " * Configuration.tab_width + str;
|
431
|
+
end
|
432
|
+
|
413
433
|
private
|
414
434
|
|
415
435
|
# Read file source.
|
data/lib/synvert/core/version.rb
CHANGED
@@ -361,5 +361,44 @@ module Synvert::Core
|
|
361
361
|
expect(instance.current_node).to eq node1
|
362
362
|
end
|
363
363
|
end
|
364
|
+
|
365
|
+
describe '#wrap_with_quotes' do
|
366
|
+
context 'Configuration.single_quote = true' do
|
367
|
+
it 'wraps with single quotes' do
|
368
|
+
expect(instance.wrap_with_quotes('foobar')).to eq "'foobar'"
|
369
|
+
end
|
370
|
+
|
371
|
+
it 'wraps with double quotes if it contains single quote' do
|
372
|
+
expect(instance.wrap_with_quotes("foo'bar")).to eq '"foo\'bar"'
|
373
|
+
end
|
374
|
+
|
375
|
+
it 'wraps with signle quotes and escapes single quote' do
|
376
|
+
expect(instance.wrap_with_quotes("foo'\"bar")).to eq "'foo\\'\"bar'"
|
377
|
+
end
|
378
|
+
end
|
379
|
+
|
380
|
+
context 'Configuration.single_quote = false' do
|
381
|
+
before { Configuration.single_quote = false }
|
382
|
+
after { Configuration.single_quote = true }
|
383
|
+
|
384
|
+
it 'wraps with double quotes' do
|
385
|
+
expect(instance.wrap_with_quotes('foobar')).to eq '"foobar"'
|
386
|
+
end
|
387
|
+
|
388
|
+
it 'wraps with single quotes if it contains double quote' do
|
389
|
+
expect(instance.wrap_with_quotes('foo"bar')).to eq "'foo\"bar'"
|
390
|
+
end
|
391
|
+
|
392
|
+
it 'wraps with double quotes and escapes double quote' do
|
393
|
+
expect(instance.wrap_with_quotes("foo'\"bar")).to eq '"foo\'\\"bar"'
|
394
|
+
end
|
395
|
+
end
|
396
|
+
end
|
397
|
+
|
398
|
+
describe '#add_leading_spaces' do
|
399
|
+
it 'adds leading spaces' do
|
400
|
+
expect(instance.add_leading_spaces('foo')).to eq ' foo';
|
401
|
+
end
|
402
|
+
end
|
364
403
|
end
|
365
404
|
end
|
data/synvert-core-ruby.gemspec
CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_runtime_dependency "activesupport", "< 7.0.0"
|
23
23
|
spec.add_runtime_dependency "erubis"
|
24
24
|
spec.add_runtime_dependency "node_query", ">= 1.12.0"
|
25
|
-
spec.add_runtime_dependency "node_mutation", ">= 1.
|
25
|
+
spec.add_runtime_dependency "node_mutation", ">= 1.9.0"
|
26
26
|
spec.add_runtime_dependency "parser"
|
27
27
|
spec.add_runtime_dependency "parser_node_ext", ">= 0.9.0"
|
28
28
|
spec.add_runtime_dependency "parallel"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: synvert-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.21.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Huang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-02-
|
11
|
+
date: 2023-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 1.
|
61
|
+
version: 1.9.0
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 1.
|
68
|
+
version: 1.9.0
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: parser
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|