synvert-core 1.17.0 → 1.18.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: dd4c09ec590b3d1bce36465a50c319c4530aa2d28c08906fa008f33e72cccc55
4
- data.tar.gz: 5591fd4d4a992ac99d5d523b958d7aa4e2caf56deaa5203dc8cf4ad537c3be32
3
+ metadata.gz: 036a5a2a642e96b611185e400b4f458be77f2622c3ef996bdac4bc0cbda1df70
4
+ data.tar.gz: 51ec847622d9018176f4dceb51a2a9ac623c1129abea3012d6e2faab650ee7f2
5
5
  SHA512:
6
- metadata.gz: 5c24a6a380ad2b418639b834818100c8ebcb19255e33c78a19b99b299d2cf6ad24024a0e6d4543d205bee939f53646f3180db257cad05c96bb011334849e79ec
7
- data.tar.gz: 1025d6ebfab92f0a04d939aa57b5e2170e957fec465d7996b36abc5f4e334996f615e5cfc5b7db0b9a9ae076de2eac3108fa6e7a7446640b5de1fd4929fc48a5
6
+ metadata.gz: 6c739ddf2691480f5d53fe0033eb24a5c0e784116fec98eff71a58d1d1745a853790121a89979b32624fcb65ea104b837a744b9353fde8ef74ef227433e9be7f
7
+ data.tar.gz: 95ad1ab6a96a33f0299aa012f7731915a7af3794b805b5e5743ddd2d11c48e29dc34019773a3948b96db94aea814d928558c0ee0409a750dae3e85c6d503ec67
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.18.1 (2023-02-05)
4
+
5
+ * Fix glob with only paths
6
+
7
+ ## 1.18.0 (2023-02-01)
8
+
9
+ * Remove `todo` dsl
10
+ * Update `parser_node_ext` to 0.9.0
11
+
3
12
  ## 1.17.0 (2023-01-21)
4
13
 
5
14
  * Add `add_action` dsl
data/Gemfile.lock CHANGED
@@ -1,19 +1,19 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- synvert-core (1.17.0)
4
+ synvert-core (1.18.1)
5
5
  activesupport (< 7.0.0)
6
6
  erubis
7
7
  node_mutation (>= 1.8.2)
8
8
  node_query (>= 1.12.0)
9
9
  parallel
10
10
  parser
11
- parser_node_ext (>= 0.6.1)
11
+ parser_node_ext (>= 0.9.0)
12
12
 
13
13
  GEM
14
14
  remote: https://rubygems.org/
15
15
  specs:
16
- activesupport (6.1.7.1)
16
+ activesupport (6.1.7.2)
17
17
  concurrent-ruby (~> 1.0, >= 1.0.2)
18
18
  i18n (>= 1.6, < 2)
19
19
  minitest (>= 5.1)
@@ -21,7 +21,7 @@ GEM
21
21
  zeitwerk (~> 2.3)
22
22
  ast (2.4.2)
23
23
  coderay (1.1.3)
24
- concurrent-ruby (1.1.10)
24
+ concurrent-ruby (1.2.0)
25
25
  diff-lcs (1.5.0)
26
26
  erubis (2.7.0)
27
27
  fakefs (1.8.0)
@@ -59,7 +59,7 @@ GEM
59
59
  parallel (1.22.1)
60
60
  parser (3.2.0.0)
61
61
  ast (~> 2.4.1)
62
- parser_node_ext (0.6.1)
62
+ parser_node_ext (0.10.0)
63
63
  parser
64
64
  pry (0.14.1)
65
65
  coderay (~> 1.1)
@@ -83,7 +83,7 @@ GEM
83
83
  rspec-support (3.10.3)
84
84
  shellany (0.0.1)
85
85
  thor (1.2.1)
86
- tzinfo (2.0.5)
86
+ tzinfo (2.0.6)
87
87
  concurrent-ruby (~> 1.0)
88
88
  zeitwerk (2.6.6)
89
89
 
data/README.md CHANGED
@@ -69,7 +69,6 @@ DSLs are as follows
69
69
  * [remove_file](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter.html#remove_file-instance_method) - remove a file
70
70
  * [helper_method](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter.html#helper_method-instance_method) - define a helper method
71
71
  * [add_snippet](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter.html#add_snippet-instance_method) - call another rewriter
72
- * [todo](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter.html#todo-instance_method) - set todo
73
72
  * [redo_until_no_change](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter.html#redo_until_no_change-instance_method) - run the snippet until no change
74
73
 
75
74
  Scopes:
@@ -93,7 +92,8 @@ Actions:
93
92
  * [insert_after](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#insert_after-instance_method) - insert the code next to the current node
94
93
  * [insert_before](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#insert_before-instance_method) - insert the code previous to the current node
95
94
  * [replace](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#replace-instance_method) - replace the code of specified child nodes
96
- * [delete](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#delete-instance_method) - delete the code specified child nodes
95
+ * [delete](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#delete-instance_method) - delete the code in specified child nodes
96
+ * [remove](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#remove-instance_method) - remove the whole code of current node
97
97
  * [wrap](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#wrap-instance_method) - wrap the current node with code
98
98
  * [replace_with](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#replace_with-instance_method) - replace the whole code of current node
99
99
  * [warn](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#warn-instance_method) - warn message
@@ -330,28 +330,6 @@ module Synvert::Core
330
330
  @helpers << { name: name, block: block }
331
331
  end
332
332
 
333
- # It sets todo of the rewriter.
334
- # Or get todo.
335
- # @example
336
- # Synvert::Rewriter.new 'rails', 'upgrade_3_2_to_4_0' do
337
- # todo <<~EOS
338
- # 1. Rails 4.0 no longer supports loading plugins from vendor/plugins. You must replace any plugins by extracting them to gems and adding them to your Gemfile. If you choose not to make them gems, you can move them into, say, lib/my_plugin/* and add an appropriate initializer in config/initializers/my_plugin.rb.
339
- # 2. Make the following changes to your Gemfile.
340
- # gem 'sass-rails', '~> 4.0.0'
341
- # gem 'coffee-rails', '~> 4.0.0'
342
- # gem 'uglifier', '>= 1.3.0'
343
- # EOS
344
- # end
345
- # @param todo [String] rewriter todo.
346
- # @return [String] rewriter todo.
347
- def todo(todo = nil)
348
- if todo
349
- @todo = todo
350
- else
351
- @todo
352
- end
353
- end
354
-
355
333
  # Rerun the snippet until no change.
356
334
  # @example
357
335
  # Synvert::Rewriter.new 'ruby', 'nested_class_definition' do
@@ -369,46 +347,16 @@ module Synvert::Core
369
347
  # @yieldparam file_path [String] file path.
370
348
  def handle_one_file(file_patterns)
371
349
  if Configuration.number_of_workers > 1
372
- Parallel.map(get_file_paths(file_patterns), in_processes: Configuration.number_of_workers) do |file_path|
350
+ Parallel.map(Utils.glob(file_patterns), in_processes: Configuration.number_of_workers) do |file_path|
373
351
  yield(file_path)
374
352
  end
375
353
  else
376
- get_file_paths(file_patterns).map do |file_path|
354
+ Utils.glob(file_patterns).map do |file_path|
377
355
  yield(file_path)
378
356
  end
379
357
  end
380
358
  end
381
359
 
382
- # Get file paths.
383
- # @return [Array<String>] file paths
384
- def get_file_paths(file_patterns)
385
- Dir.chdir(Configuration.root_path) do
386
- only_paths = Configuration.only_paths.size > 0 ? Configuration.only_paths : ["."]
387
- only_paths.flat_map do |only_path|
388
- file_patterns.flat_map do |file_pattern|
389
- pattern = only_path == "." ? file_pattern : File.join(only_path, file_pattern)
390
- Dir.glob(pattern)
391
- end
392
- end - get_skip_files
393
- end
394
- end
395
-
396
- # Get skip files.
397
- # @return [Array<String>] skip files
398
- def get_skip_files
399
- Configuration.skip_paths.flat_map do |skip_path|
400
- if File.directory?(skip_path)
401
- Dir.glob(File.join(skip_path, "**/*"))
402
- elsif File.file?(skip_path)
403
- [skip_path]
404
- elsif skip_path.end_with?("**") || skip_path.end_with?("**/")
405
- Dir.glob(File.join(skip_path, "*"))
406
- else
407
- Dir.glob(skip_path)
408
- end
409
- end
410
- end
411
-
412
360
  def merge_test_results(results)
413
361
  @test_results += results.select { |result| result.affected? }
414
362
  end
@@ -27,6 +27,18 @@ module Synvert::Core
27
27
  end
28
28
  end
29
29
 
30
+ # Glob file paths.
31
+ # @param file_patterns [Array<String>] file patterns
32
+ # @return [Array<String>] file paths
33
+ def glob(file_patterns)
34
+ Dir.chdir(Configuration.root_path) do
35
+ all_files = file_patterns.flat_map do |file_pattern|
36
+ Dir.glob(file_pattern)
37
+ end
38
+ filter_only_paths(all_files) - get_skip_files
39
+ end
40
+ end
41
+
30
42
  private
31
43
 
32
44
  def is_valid_url?(url)
@@ -65,6 +77,32 @@ module Synvert::Core
65
77
 
66
78
  url.sub('//github.com/', '//raw.githubusercontent.com/').sub('/blob/', '/')
67
79
  end
80
+
81
+ # Filter only paths with `Configuration.only_paths`.
82
+ # @return [Array<String>] filtered file paths
83
+ def filter_only_paths(all_files)
84
+ return all_files if Configuration.only_paths.size == 0
85
+
86
+ Configuration.only_paths.flat_map do |only_path|
87
+ all_files.filter { |file_path| file_path.starts_with?(only_path) }
88
+ end
89
+ end
90
+
91
+ # Get skip files.
92
+ # @return [Array<String>] skip files
93
+ def get_skip_files
94
+ Configuration.skip_paths.flat_map do |skip_path|
95
+ if File.directory?(skip_path)
96
+ Dir.glob(File.join(skip_path, "**/*"))
97
+ elsif File.file?(skip_path)
98
+ [skip_path]
99
+ elsif skip_path.end_with?("**") || skip_path.end_with?("**/")
100
+ Dir.glob(File.join(skip_path, "*"))
101
+ else
102
+ Dir.glob(skip_path)
103
+ end
104
+ end
105
+ end
68
106
  end
69
107
  end
70
108
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Synvert
4
4
  module Core
5
- VERSION = '1.17.0'
5
+ VERSION = '1.18.1'
6
6
  end
7
7
  end
@@ -86,7 +86,7 @@ module Synvert::Core
86
86
  end
87
87
 
88
88
  it 'delegates process to instances if if_ruby matches' do
89
- expect(Dir).to receive(:glob).with('config/routes.rb').and_return(['config/routes.rb'])
89
+ expect(Utils).to receive(:glob).with(['config/routes.rb']).and_return(['config/routes.rb'])
90
90
  expect(File).to receive(:exist?).with('./.ruby-version').and_return(true)
91
91
  expect(File).to receive(:read).with('./.ruby-version').and_return('2.0.0')
92
92
  expect_any_instance_of(Rewriter::Instance).to receive(:process)
@@ -112,7 +112,7 @@ module Synvert::Core
112
112
  end
113
113
 
114
114
  it 'delegates process to instances if if_gem matches' do
115
- expect(Dir).to receive(:glob).with('config/routes.rb').and_return(['config/routes.rb'])
115
+ expect(Utils).to receive(:glob).with(['config/routes.rb']).and_return(['config/routes.rb'])
116
116
  expect_any_instance_of(Rewriter::GemSpec).to receive(:match?).and_return(true)
117
117
  expect_any_instance_of(Rewriter::Instance).to receive(:process)
118
118
  rewriter =
@@ -125,7 +125,7 @@ module Synvert::Core
125
125
  end
126
126
 
127
127
  it 'delegates process to instances if if_ruby and if_gem do not exist' do
128
- expect(Dir).to receive(:glob).with('config/routes.rb').and_return(['config/routes.rb'])
128
+ expect(Utils).to receive(:glob).with(['config/routes.rb']).and_return(['config/routes.rb'])
129
129
  expect_any_instance_of(Rewriter::Instance).to receive(:process)
130
130
  rewriter =
131
131
  Rewriter.new 'group', 'name' do
@@ -256,15 +256,6 @@ module Synvert::Core
256
256
  expect(instance.dynamic_helper('arg1', 'arg2')).to eq 'dynamic result'
257
257
  end
258
258
 
259
- it 'parses todo' do
260
- rewriter =
261
- Rewriter.new 'group', 'name' do
262
- todo "this rewriter doesn't do blah blah blah"
263
- end
264
- rewriter.process
265
- expect(rewriter.todo).to eq "this rewriter doesn't do blah blah blah"
266
- end
267
-
268
259
  it 'parses redo_until_no_change' do
269
260
  rewriter =
270
261
  Rewriter.new 'group', 'name' do
@@ -53,5 +53,30 @@ module Synvert::Core
53
53
  end
54
54
  end
55
55
  end
56
+
57
+ describe '.glob' do
58
+ before do
59
+ Configuration.only_paths = []
60
+ Configuration.skip_paths = []
61
+ end
62
+
63
+ it 'gets all files' do
64
+ expect(Dir).to receive(:glob).with('**/*.rb').and_return(['app/models/post.rb', 'app/controllers/posts_controller.rb'])
65
+ expect(described_class.glob(['**/*.rb'])).to eq(['app/models/post.rb', 'app/controllers/posts_controller.rb'])
66
+ end
67
+
68
+ it 'filters only paths' do
69
+ Configuration.only_paths = ['app/models']
70
+ expect(Dir).to receive(:glob).with('**/*.rb').and_return(['app/models/post.rb', 'app/controllers/posts_controller.rb'])
71
+ expect(described_class.glob(['**/*.rb'])).to eq(['app/models/post.rb'])
72
+ end
73
+
74
+ it 'skip files' do
75
+ Configuration.skip_paths = ['app/controllers/**/*']
76
+ expect(Dir).to receive(:glob).with('**/*.rb').and_return(['app/models/post.rb', 'app/controllers/posts_controller.rb'])
77
+ expect(Dir).to receive(:glob).with('app/controllers/**/*').and_return(['app/controllers/posts_controller.rb'])
78
+ expect(described_class.glob(['**/*.rb'])).to eq(['app/models/post.rb'])
79
+ end
80
+ end
56
81
  end
57
82
  end
@@ -24,6 +24,6 @@ Gem::Specification.new do |spec|
24
24
  spec.add_runtime_dependency "node_query", ">= 1.12.0"
25
25
  spec.add_runtime_dependency "node_mutation", ">= 1.8.2"
26
26
  spec.add_runtime_dependency "parser"
27
- spec.add_runtime_dependency "parser_node_ext", ">= 0.6.1"
27
+ spec.add_runtime_dependency "parser_node_ext", ">= 0.9.0"
28
28
  spec.add_runtime_dependency "parallel"
29
29
  end
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.17.0
4
+ version: 1.18.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-01-21 00:00:00.000000000 Z
11
+ date: 2023-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - ">="
88
88
  - !ruby/object:Gem::Version
89
- version: 0.6.1
89
+ version: 0.9.0
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
- version: 0.6.1
96
+ version: 0.9.0
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: parallel
99
99
  requirement: !ruby/object:Gem::Requirement