synvert-core 2.1.2 → 2.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a46f27187479785039c353bc33688eb5528d2d6591485d5e55efd43f2f6cd817
4
- data.tar.gz: 1b96464e513f2a8b3beb3421eb021e1efd5c41045698aa4eb26fbaa0b94703d3
3
+ metadata.gz: a8de6e08c31aaa4768912559d7192f5eb447a5f7e4110f09b8bac0363e0df253
4
+ data.tar.gz: 57eb0b68bf973e02a83589ea9ae6b06b955aa07cd4400000604845f10cd8e4c3
5
5
  SHA512:
6
- metadata.gz: b5b68e153d26a3bac0a6b2ced72b2cd33b7b3b05159f7932c49b9fdb20822561d17c6d13aca805b21ae3bbeb156ed479845c531755ce1d5e53f78e15bc5c2068
7
- data.tar.gz: b1978636d9eb02f79f8f92eaba1cd702d2be8748a42deb7d5c34645dd28e388b1d99471a826e0d0ce17571a2c8fe71dab32545fe5f0c4f6dc77ec54ea1edbe96
6
+ metadata.gz: 167371f72e5abf567047a57b9af8ac7765b34f9ffff99092094cf92635dd54345cc6dac800b928ab16223aa5ed003c4d16464f3b856810a822b19a65ee038a25
7
+ data.tar.gz: 31248d3db71575585065e364e5130d6313474d6df3e86bf3667b451b3a9ffdceea7a125bc8c995faf8162bc367f7571320187f5404d78e84836e4aa0c81b09d3
@@ -0,0 +1,29 @@
1
+ name: Close stale issues
2
+
3
+ on:
4
+ schedule:
5
+ - cron: '0 0 * * *' # Runs at 00:00 UTC every day
6
+
7
+ jobs:
8
+ stale:
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - uses: actions/stale@v9
12
+ with:
13
+ # Issues
14
+ stale-issue-message: 'This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.'
15
+ close-issue-message: 'This issue was closed because it has been stale for 30 days with no activity.'
16
+ days-before-issue-stale: 60
17
+ days-before-issue-close: 30
18
+
19
+ # Pull Requests
20
+ stale-pr-message: 'This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.'
21
+ close-pr-message: 'This pull request was closed because it has been stale for 30 days with no activity.'
22
+ days-before-pr-stale: 60
23
+ days-before-pr-close: 30
24
+
25
+ # General settings
26
+ exempt-issue-labels: 'pinned,security'
27
+ exempt-pr-labels: 'pinned,security'
28
+ stale-issue-label: 'stale'
29
+ stale-pr-label: 'stale'
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 2.2.1 (2024-12-27)
4
+
5
+ * Raise error to notify user instance method should not be called in rewriter
6
+
7
+ ## 2.2.0 (2024-07-20)
8
+
9
+ * Remove `save_data` and `load_data` dsls
10
+
3
11
  ## 2.1.2 (2024-07-17)
4
12
 
5
13
  * Update `parser_node_ext` to 1.4.2
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- synvert-core (2.1.2)
5
- activesupport
4
+ synvert-core (2.2.1)
5
+ activesupport (= 7.1.3.4)
6
6
  node_mutation (>= 1.24.4)
7
7
  node_query (>= 1.15.4)
8
8
  node_visitor (>= 1.1.0)
@@ -29,9 +29,9 @@ GEM
29
29
  tzinfo (~> 2.0)
30
30
  ast (2.4.2)
31
31
  base64 (0.2.0)
32
- bigdecimal (3.1.8)
32
+ bigdecimal (3.1.9)
33
33
  coderay (1.1.3)
34
- concurrent-ruby (1.3.3)
34
+ concurrent-ruby (1.3.4)
35
35
  connection_pool (2.4.1)
36
36
  diff-lcs (1.5.1)
37
37
  drb (2.2.1)
@@ -52,36 +52,36 @@ GEM
52
52
  guard (~> 2.1)
53
53
  guard-compat (~> 1.1)
54
54
  rspec (>= 2.99.0, < 4.0)
55
- i18n (1.14.5)
55
+ i18n (1.14.6)
56
56
  concurrent-ruby (~> 1.0)
57
57
  listen (3.9.0)
58
58
  rb-fsevent (~> 0.10, >= 0.10.3)
59
59
  rb-inotify (~> 0.9, >= 0.9.10)
60
60
  lumberjack (1.2.10)
61
61
  method_source (1.1.0)
62
- minitest (5.24.1)
63
- mutex_m (0.2.0)
62
+ minitest (5.25.4)
63
+ mutex_m (0.3.0)
64
64
  nenv (0.3.0)
65
65
  node_mutation (1.24.4)
66
- node_query (1.15.4)
66
+ node_query (1.16.0)
67
67
  node_visitor (1.1.0)
68
68
  notiffany (0.1.3)
69
69
  nenv (~> 0.1)
70
70
  shellany (~> 0.0)
71
- parallel (1.25.1)
72
- parser (3.3.4.0)
71
+ parallel (1.26.3)
72
+ parser (3.3.6.0)
73
73
  ast (~> 2.4.1)
74
74
  racc
75
75
  parser_node_ext (1.4.2)
76
76
  parser
77
77
  prettier_print (1.2.1)
78
- prism (0.30.0)
78
+ prism (1.3.0)
79
79
  prism_ext (0.4.2)
80
80
  prism
81
81
  pry (0.14.2)
82
82
  coderay (~> 1.1)
83
83
  method_source (~> 1.0)
84
- racc (1.8.0)
84
+ racc (1.8.1)
85
85
  rake (13.0.6)
86
86
  rb-fsevent (0.11.2)
87
87
  rb-inotify (0.10.1)
data/README.md CHANGED
@@ -78,8 +78,6 @@ DSLs are as follows
78
78
  * [add_snippet](https://synvert-hq.github.io/synvert-core-ruby/Synvert/Core/Rewriter.html#add_snippet-instance_method) - call another rewriter
79
79
  * [call_helper](https://synvert-hq.github.io/synvert-core-ruby/Synvert/Core/Rewriter.html#call_helper-instance_method) - call a shared rewriter
80
80
  * [with_configurations](https://synvert-hq.github.io/synvert-core-ruby/Synvert/Core/Rewriter.html#with_configurations-instance_method) - execute a block of code with temporary configurations
81
- * [save_data](https://synvert-hq.github.io/synvert-core-ruby/Synvert/Core/Rewriter.html#save_data-instance_method) - save data
82
- * [load_data](https://synvert-hq.github.io/synvert-core-ruby/Synvert/Core/Rewriter.html#load_data-instance_method) - load data
83
81
 
84
82
  Scopes:
85
83
 
@@ -15,6 +15,15 @@ module Synvert::Core
15
15
  class Rewriter::Instance
16
16
  include Rewriter::Helper
17
17
 
18
+ DSL_METHODS = %i[
19
+ within_node with_node find_node goto_node
20
+ if_exist_node unless_exist_node
21
+ append prepend insert insert_after insert_before replace delete remove wrap replace_with warn replace_erb_stmt_with_expr noop group add_action
22
+ add_callback
23
+ wrap_with_quotes add_leading_spaces
24
+ file_path node mutation_adapter
25
+ ].freeze
26
+
18
27
  # Initialize an Instance.
19
28
  #
20
29
  # @param rewriter [Synvert::Core::Rewriter]
@@ -416,20 +416,19 @@ module Synvert::Core
416
416
  Configuration.with_temporary_configurations(configurations, &block)
417
417
  end
418
418
 
419
- # Saves data with a given key and value.
420
- #
421
- # @param key [Symbol] the key to identify the data
422
- # @param value [Object] the value to be saved
423
- def save_data(key, value)
424
- Synvert::Core.instance_variable_set("@#{key}", value)
419
+ # Raise error to notify user instance method should not be called in Rewriter.
420
+ (Rewriter::Instance::DSL_METHODS - %i[group]).each do |method|
421
+ define_method(method) do |**|
422
+ raise NoMethodError, "#{method} must be called within within_files or within_file block."
423
+ end
425
424
  end
426
425
 
427
- # Loads data with the given key.
428
- #
429
- # @param key [Symbol] the key of the data to be loaded
430
- # @return [Object] the data loaded
431
- def load_data(key)
432
- Synvert::Core.instance_variable_get("@#{key}")
426
+ def group
427
+ if block_given?
428
+ raise NoMethodError, 'group must be called within rewriter block.'
429
+ else
430
+ @group
431
+ end
433
432
  end
434
433
 
435
434
  private
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Synvert
4
4
  module Core
5
- VERSION = '2.1.2'
5
+ VERSION = '2.2.1'
6
6
  end
7
7
  end
@@ -91,6 +91,21 @@ module Synvert::Core
91
91
  expect(File.read("code.rb")).to eq output
92
92
  end
93
93
  end
94
+
95
+ it 'does not rewrite the file if within_files is not called' do
96
+ rewriter =
97
+ Rewriter.new('group', 'name') do
98
+ with_node node_type: 'class', name: 'Foobar' do
99
+ replace :name, with: 'Synvert'
100
+ end
101
+ end
102
+ input = "class Foobar\nend"
103
+ output = "class Synvert\nend"
104
+ FakeFS do
105
+ File.write("code.rb", input)
106
+ expect { rewriter.process }.to raise_error(NoMethodError, 'with_node must be called within within_files or within_file block.')
107
+ end
108
+ end
94
109
  end
95
110
 
96
111
  describe '#test' do
@@ -346,11 +361,10 @@ module Synvert::Core
346
361
  it 'eval helper by name' do
347
362
  block_receiver = nil
348
363
  block_options = {}
349
- helper =
350
- Synvert::Helper.new 'helper' do |options|
351
- block_receiver = self.class.name
352
- block_options = options
353
- end
364
+ Synvert::Helper.new 'helper' do |options|
365
+ block_receiver = self.class.name
366
+ block_options = options
367
+ end
354
368
  rewriter =
355
369
  Rewriter.new 'group', 'rewriter' do
356
370
  call_helper('helper', foo: 'bar')
@@ -395,18 +409,6 @@ module Synvert::Core
395
409
  expect(instance.dynamic_helper('arg1', 'arg2')).to eq 'dynamic result'
396
410
  end
397
411
 
398
- it 'parses save_data and load_data' do
399
- data = nil
400
- rewriter =
401
- Rewriter.new 'group', 'name' do
402
- hash = { foo: 'bar' }
403
- save_data :object, hash
404
- data = load_data :object
405
- end
406
- rewriter.process
407
- expect(data).to eq({ foo: 'bar' })
408
- end
409
-
410
412
  describe 'class methods' do
411
413
  before :each do
412
414
  Rewriter.clear
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
20
  spec.require_paths = ["lib"]
21
21
 
22
- spec.add_runtime_dependency "activesupport"
22
+ spec.add_runtime_dependency "activesupport", '7.1.3.4' # to support ruby 2.7
23
23
  spec.add_runtime_dependency "node_query", ">= 1.15.4"
24
24
  spec.add_runtime_dependency "node_mutation", ">= 1.24.4"
25
25
  spec.add_runtime_dependency "node_visitor", ">= 1.1.0"
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: synvert-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2
4
+ version: 2.2.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: 2024-07-17 00:00:00.000000000 Z
11
+ date: 2024-12-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 7.1.3.4
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: '0'
26
+ version: 7.1.3.4
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: node_query
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -172,6 +172,7 @@ extensions: []
172
172
  extra_rdoc_files: []
173
173
  files:
174
174
  - ".github/workflows/main.yml"
175
+ - ".github/workflows/stale.yml"
175
176
  - ".gitignore"
176
177
  - ".rspec"
177
178
  - ".vscode/settings.json"
@@ -249,7 +250,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
249
250
  - !ruby/object:Gem::Version
250
251
  version: '0'
251
252
  requirements: []
252
- rubygems_version: 3.5.14
253
+ rubygems_version: 3.5.22
253
254
  signing_key:
254
255
  specification_version: 4
255
256
  summary: convert ruby code to better syntax.