synvert-core 1.20.0 → 1.21.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: d0e41ca1ed27bdc4a8e85f022cab4f220970746e950507c51ca5634dcb0c2f5c
4
- data.tar.gz: bc61e33e6bf1282befa1f6b67944e372d7ba309c4f47b907b6f64fd5fb677a94
3
+ metadata.gz: be7c1313bb5e789a3f3dd489b4e3ef579b9ddd41e4bf65a14b28b96e05b4ddb3
4
+ data.tar.gz: 32f69ddc1ac839e3e1d29addaadc2dc9b7119b0dbec3c4de4bf9ccc533dbe5cc
5
5
  SHA512:
6
- metadata.gz: a1dd19db1a689441e0443c524deb067d8bd6454ae0226f3163180b74fa4633bafb27b97d48c1c7506ff114c96fb40ae94beea6d7ed65740d6eeafaef1bd65cc4
7
- data.tar.gz: bffc0742e22250091392cf453c71e1901920f5f4d8df3cf8d71ae373c351e41c620a2bf62ec3a72f0aac8d6d6f96ef043c81b577f201244c51f52b9cf66de051
6
+ metadata.gz: c0d28b3a39c908abaf543d2e9534827be828db8ab75d1e24d97e1ca9ca3d6ef3fb20dbee9e984cbaedec20b706b1732dbefdd0c45665a65a0bd822223f541dfa
7
+ data.tar.gz: db045c50ecdea16622e9cfc5b72f367336486c3e0f7ee7c8f6e727606638d363fa28bfef297fa8de61327a3d6eece65f33f4d0c0bcf671599fb1cb9b82663d30
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.21.1 (2023-02-10)
4
+
5
+ * Add `tab_size` option to `add_leading_spaces`
6
+
7
+ ## 1.21.0 (2023-02-08)
8
+
9
+ * Add `Configuration#tab_width`
10
+ * Add `Instance#add_leading_spaces`
11
+
3
12
  ## 1.20.0 (2023-02-08)
4
13
 
5
14
  * Add `Configuration#single_quote`
data/Gemfile.lock CHANGED
@@ -1,10 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- synvert-core (1.20.0)
4
+ synvert-core (1.21.1)
5
5
  activesupport (< 7.0.0)
6
6
  erubis
7
- node_mutation (>= 1.8.2)
7
+ node_mutation (>= 1.9.0)
8
8
  node_query (>= 1.12.0)
9
9
  parallel
10
10
  parser
@@ -50,14 +50,14 @@ GEM
50
50
  method_source (1.0.0)
51
51
  minitest (5.17.0)
52
52
  nenv (0.3.0)
53
- node_mutation (1.8.2)
53
+ node_mutation (1.9.0)
54
54
  erubis
55
55
  node_query (1.12.0)
56
56
  notiffany (0.1.3)
57
57
  nenv (~> 0.1)
58
58
  shellany (~> 0.0)
59
59
  parallel (1.22.1)
60
- parser (3.2.0.0)
60
+ parser (3.2.1.0)
61
61
  ast (~> 2.4.1)
62
62
  parser_node_ext (0.10.0)
63
63
  parser
data/README.md CHANGED
@@ -104,6 +104,7 @@ Actions:
104
104
  Others:
105
105
 
106
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
107
108
 
108
109
 
109
110
  Attributes:
@@ -10,7 +10,8 @@ module Synvert::Core
10
10
  # @!attribute [w] show_run_process
11
11
  # @!attribute [w] number_of_workers
12
12
  # @!attribute [w] single_quote
13
- attr_writer :root_path, :skip_paths, :only_paths, :show_run_process, :number_of_workers, :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
14
15
 
15
16
  # Get the path.
16
17
  #
@@ -53,6 +54,10 @@ module Synvert::Core
53
54
  def single_quote
54
55
  @single_quote.nil? ? true : @single_quote
55
56
  end
57
+
58
+ def tab_width
59
+ @tab_width || 2
60
+ end
56
61
  end
57
62
  end
58
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
 
@@ -423,6 +423,14 @@ module Synvert::Core
423
423
  quote + escaped_str + quote
424
424
  end
425
425
 
426
+ # Add leading spaces before the str according to Configuration.tab_width.
427
+ # @param str [String]
428
+ # @param tab_size [Integer] tab size
429
+ # @return [String]
430
+ def add_leading_spaces(str, tab_size: 1)
431
+ " " * Configuration.tab_width * tab_size + str;
432
+ end
433
+
426
434
  private
427
435
 
428
436
  # Read file source.
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Synvert
4
4
  module Core
5
- VERSION = '1.20.0'
5
+ VERSION = '1.21.1'
6
6
  end
7
7
  end
@@ -394,5 +394,12 @@ module Synvert::Core
394
394
  end
395
395
  end
396
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
+ expect(instance.add_leading_spaces('foo', tab_size: 2)).to eq ' foo';
402
+ end
403
+ end
397
404
  end
398
405
  end
@@ -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.8.2"
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.20.0
4
+ version: 1.21.1
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-08 00:00:00.000000000 Z
11
+ date: 2023-02-10 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.8.2
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.8.2
68
+ version: 1.9.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: parser
71
71
  requirement: !ruby/object:Gem::Requirement