synvert-core 1.8.1 → 1.9.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 +8 -0
- data/Gemfile.lock +2 -2
- data/README.md +1 -0
- data/lib/synvert/core/rewriter/instance.rb +11 -6
- data/lib/synvert/core/version.rb +1 -1
- data/spec/synvert/core/rewriter/instance_spec.rb +16 -9
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0bd7dcc7605d1a18cc68ebfba86d5947960bd1320da0b5f7ae41abc8638fed62
|
4
|
+
data.tar.gz: 3023d5fb8a740da0ce0191bdd08f7435cc931e690714d2195391cf03586efa70
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a3c7f43d890a491a7bb3356ec1695a79278a8c19cf61df4f296a1ea6562cbbcfa27764b36cbb22e06f9f27cd53157e2276392bba42856d58212fddb68e92ffac
|
7
|
+
data.tar.gz: 9959f0f8290157b96c83011ef770d59b40b845b236e0f8facf24cb6795cd7a837936a8969e380910df2892604dd25f569c66b9ff0c7aa5649e441b5ddf72b32a
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
synvert-core (1.
|
4
|
+
synvert-core (1.9.1)
|
5
5
|
activesupport (< 7.0.0)
|
6
6
|
erubis
|
7
7
|
node_mutation
|
@@ -49,7 +49,7 @@ GEM
|
|
49
49
|
method_source (1.0.0)
|
50
50
|
minitest (5.16.3)
|
51
51
|
nenv (0.3.0)
|
52
|
-
node_mutation (1.
|
52
|
+
node_mutation (1.4.1)
|
53
53
|
activesupport (< 7.0.0)
|
54
54
|
erubis
|
55
55
|
node_query (1.6.0)
|
data/README.md
CHANGED
@@ -96,3 +96,4 @@ Actions:
|
|
96
96
|
* [replace_with](./Synvert/Core/Rewriter/Instance.html#replace_with-instance_method) - replace the whole code of current node
|
97
97
|
* [warn](./Synvert/Core/Rewriter/Instance.html#warn-instance_method) - warn message
|
98
98
|
* [replace_erb_stmt_with_expr](./Synvert/Core/Rewriter/Instance.html#replace_erb_stmt_with_expr-instance_method) - replace erb stmt code to expr code
|
99
|
+
* [noop](./Synvert/Core/Rewriter/Instance.html#noop-instance_method) - no operation
|
@@ -325,6 +325,11 @@ module Synvert::Core
|
|
325
325
|
@current_mutation.wrap(@current_node, with: with)
|
326
326
|
end
|
327
327
|
|
328
|
+
# Parse +noop dsl.
|
329
|
+
def noop
|
330
|
+
@current_mutation.noop(@current_node)
|
331
|
+
end
|
332
|
+
|
328
333
|
# Parse +warn+ dsl, it creates a {Synvert::Core::Rewriter::Warning} to save warning message.
|
329
334
|
# @example
|
330
335
|
# within_files 'vendor/plugins' do
|
@@ -351,9 +356,9 @@ module Synvert::Core
|
|
351
356
|
def process_file(file_path)
|
352
357
|
puts file_path if Configuration.show_run_process
|
353
358
|
|
354
|
-
@current_file = file_path
|
359
|
+
@current_file = File.join(Configuration.root_path, file_path)
|
355
360
|
while true
|
356
|
-
source = read_source(
|
361
|
+
source = read_source(@current_file)
|
357
362
|
@current_mutation = NodeMutation.new(source)
|
358
363
|
begin
|
359
364
|
node = parse_code(file_path, source)
|
@@ -373,7 +378,7 @@ module Synvert::Core
|
|
373
378
|
result = @current_mutation.process
|
374
379
|
if result.affected?
|
375
380
|
@rewriter.add_affected_file(file_path)
|
376
|
-
write_source(
|
381
|
+
write_source(@current_file, result.new_source)
|
377
382
|
end
|
378
383
|
break unless result.conflicted?
|
379
384
|
rescue Parser::SyntaxError
|
@@ -387,11 +392,11 @@ module Synvert::Core
|
|
387
392
|
#
|
388
393
|
# @param file_path [String]
|
389
394
|
def test_file(file_path)
|
390
|
-
@current_file = file_path
|
391
|
-
source = read_source(
|
395
|
+
@current_file = File.join(Configuration.root_path, file_path)
|
396
|
+
source = read_source(@current_file)
|
392
397
|
@current_mutation = NodeMutation.new(source)
|
393
398
|
begin
|
394
|
-
node = parse_code(
|
399
|
+
node = parse_code(@current_file, source)
|
395
400
|
|
396
401
|
process_with_node(node) do
|
397
402
|
instance_eval(&@block)
|
data/lib/synvert/core/version.rb
CHANGED
@@ -176,6 +176,13 @@ module Synvert::Core
|
|
176
176
|
instance.wrap with: 'module Foobar'
|
177
177
|
end
|
178
178
|
|
179
|
+
it 'parses noop' do
|
180
|
+
instance.current_mutation = double
|
181
|
+
instance.current_node = double
|
182
|
+
expect(instance.current_mutation).to receive(:noop).with(instance.current_node)
|
183
|
+
instance.noop
|
184
|
+
end
|
185
|
+
|
179
186
|
it 'parses warn' do
|
180
187
|
expect(Rewriter::Warning).to receive(:new).with(instance, 'foobar')
|
181
188
|
instance.warn 'foobar'
|
@@ -206,8 +213,8 @@ module Synvert::Core
|
|
206
213
|
end
|
207
214
|
EOS
|
208
215
|
expect(Dir).to receive(:glob).with('spec/**/*_spec.rb').and_return(['spec/models/post_spec.rb'])
|
209
|
-
expect(File).to receive(:read).with('spec/models/post_spec.rb', encoding: 'UTF-8').and_return(input)
|
210
|
-
expect(File).to receive(:write).with('spec/models/post_spec.rb', output)
|
216
|
+
expect(File).to receive(:read).with('./spec/models/post_spec.rb', encoding: 'UTF-8').and_return(input)
|
217
|
+
expect(File).to receive(:write).with('./spec/models/post_spec.rb', output)
|
211
218
|
instance.process
|
212
219
|
end
|
213
220
|
|
@@ -231,8 +238,8 @@ module Synvert::Core
|
|
231
238
|
end
|
232
239
|
EOS
|
233
240
|
expect(Dir).to receive(:glob).with('spec/spec_helper.rb').and_return(['spec/spec_helper.rb'])
|
234
|
-
expect(File).to receive(:read).with('spec/spec_helper.rb', encoding: 'UTF-8').and_return(input)
|
235
|
-
expect(File).not_to receive(:write).with('spec/spec_helper.rb', output)
|
241
|
+
expect(File).to receive(:read).with('./spec/spec_helper.rb', encoding: 'UTF-8').and_return(input)
|
242
|
+
expect(File).not_to receive(:write).with('./spec/spec_helper.rb', output)
|
236
243
|
instance.process
|
237
244
|
end
|
238
245
|
|
@@ -258,9 +265,9 @@ module Synvert::Core
|
|
258
265
|
end
|
259
266
|
EOS
|
260
267
|
expect(Dir).to receive(:glob).with('spec/**/*_spec.rb').and_return(['spec/models/post_spec.rb']).twice
|
261
|
-
expect(File).to receive(:read).with('spec/models/post_spec.rb', encoding: 'UTF-8').and_return(input)
|
262
|
-
expect(File).to receive(:write).with('spec/models/post_spec.rb', output)
|
263
|
-
expect(File).to receive(:read).with('spec/models/post_spec.rb', encoding: 'UTF-8').and_return(output)
|
268
|
+
expect(File).to receive(:read).with('./spec/models/post_spec.rb', encoding: 'UTF-8').and_return(input)
|
269
|
+
expect(File).to receive(:write).with('./spec/models/post_spec.rb', output)
|
270
|
+
expect(File).to receive(:read).with('./spec/models/post_spec.rb', encoding: 'UTF-8').and_return(output)
|
264
271
|
instance.process
|
265
272
|
instance.process
|
266
273
|
expect(rewriter.affected_files).to be_include('spec/models/post_spec.rb')
|
@@ -285,7 +292,7 @@ module Synvert::Core
|
|
285
292
|
end
|
286
293
|
EOS
|
287
294
|
expect(Dir).to receive(:glob).with('spec/**/*_spec.rb').and_return(['spec/models/post_spec.rb'])
|
288
|
-
expect(File).to receive(:read).with('spec/models/post_spec.rb', encoding: 'UTF-8').and_return(input)
|
295
|
+
expect(File).to receive(:read).with('./spec/models/post_spec.rb', encoding: 'UTF-8').and_return(input)
|
289
296
|
results = instance.test
|
290
297
|
expect(results[0].file_path).to eq 'spec/models/post_spec.rb'
|
291
298
|
expect(results[0].actions).to eq [
|
@@ -309,7 +316,7 @@ module Synvert::Core
|
|
309
316
|
end
|
310
317
|
EOS
|
311
318
|
expect(Dir).to receive(:glob).with('spec/spec_helper.rb').and_return(['spec/spec_helper.rb'])
|
312
|
-
expect(File).to receive(:read).with('spec/spec_helper.rb', encoding: 'UTF-8').and_return(input)
|
319
|
+
expect(File).to receive(:read).with('./spec/spec_helper.rb', encoding: 'UTF-8').and_return(input)
|
313
320
|
result = instance.test
|
314
321
|
expect(result[0].file_path).to eq 'spec/spec_helper.rb'
|
315
322
|
expect(result[0].actions).to eq []
|
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.9.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: 2022-09-
|
11
|
+
date: 2022-09-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|