diff_test 0.5.0 → 0.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fefa1f0ef248be6ac2a0f63d5829ce2b14cd4752990ef4a3914c69aba3279c95
4
- data.tar.gz: ab46b9d095e154cfbf384947105958d62eb1c3573b70c76c15fa1f4d88b0839a
3
+ metadata.gz: 0c9bb00a4ed3e786eeea894db16fc53b880e1cb86a9bc297df003e9697772151
4
+ data.tar.gz: 4060332f4db48744bbe0ac76a6d812c26854dc232331508da5f0f98ce849c0a9
5
5
  SHA512:
6
- metadata.gz: 608734f38df7c5007ece7948f9d987159a1e0a4951d8b11f86625ce6050a9bff8c99db2bc82fd41900e96c5b38b6b36a42120c973b4cbea9273ac40339f733a5
7
- data.tar.gz: 9fcd8f04020676f9ca3e7601f7b9cd9898c986ae684ef63019a9c5538f761093ae6915538ac11b2cd3694d3feed1de1712f69fd04ac9eab20c2bdcfc7ddd864d
6
+ metadata.gz: af7bce53595bdfbfb97c62959bdcb388638b5991d197852ab269e1e9afd61854d28dae7f0771307f497cdf4e1c45a7b8f04bb0a7200ced9f2c91e9bda78f2fcb
7
+ data.tar.gz: 92fcc77616d2a327934f228560b8adfec15f6ff4421c63460d097763f4ad731d2f55617082ed61bf683cb13cb856ef7edcb09127e4cc4aa34ec7f53656dcc114
@@ -30,9 +30,8 @@ module DiffTest
30
30
  disable_lint_comments += "#{comment} prettier-ignore\n"
31
31
  disable_lint_comments += "#{comment} eslint-disable-next-line\n"
32
32
 
33
- annotation = "#{comment} Automatically added by DiffTest\n#{disable_lint_comments}(globalThis || window)?.diffTestTrackJsFile#{safe_method_call}(\"#{file_path}\");\n#{comment} Automatically added by DiffTest\n"
34
-
35
- annotation + content
33
+ annotation = "#{comment} Automatically added by DiffTest\n#{disable_lint_comments};(globalThis || window)?.diffTestTrackJsFile#{safe_method_call}(\"#{file_path}\");\n#{comment} Automatically added by DiffTest\n"
34
+ insert_at_first_non_comment_line_str(content, annotation)
36
35
  end
37
36
 
38
37
  UNANNOTATE_REGEX = /(\/\/|#) Automatically added by DiffTest.*?(\/\/|#) Automatically added by DiffTest\n/m
@@ -44,6 +43,62 @@ module DiffTest
44
43
  def self.annotated?(content)
45
44
  content.include?('diffTestTrackJsFile')
46
45
  end
46
+
47
+ def self.insert_at_first_non_comment_line_str(content, text_to_insert)
48
+ lines = content.lines.map(&:chomp)
49
+
50
+ in_multiline_comment = false
51
+ comment_type = nil
52
+ insert_index = nil
53
+
54
+ lines.each_with_index do |line, idx|
55
+ stripped = line.strip
56
+
57
+ # --- End of multi-line comments
58
+ if in_multiline_comment
59
+ case comment_type
60
+ when :js
61
+ if stripped.include?("*/")
62
+ in_multiline_comment = false
63
+ comment_type = nil
64
+ end
65
+ when :coffee
66
+ if stripped.include?('###')
67
+ in_multiline_comment = false
68
+ comment_type = nil
69
+ end
70
+ end
71
+ next
72
+ end
73
+
74
+ # --- Start of multi-line comments
75
+ if stripped.start_with?('/*')
76
+ in_multiline_comment = true
77
+ comment_type = :js
78
+ next
79
+ elsif stripped.start_with?('###')
80
+ in_multiline_comment = true
81
+ comment_type = :coffee
82
+ next
83
+ end
84
+
85
+ # --- Single-line comments
86
+ if stripped.empty? || stripped.start_with?('//') || stripped.start_with?('#')
87
+ next
88
+ end
89
+
90
+ # --- Found first non-comment line
91
+ insert_index = idx
92
+ break
93
+ end
94
+
95
+ insert_index ||= lines.size
96
+
97
+ new_lines = lines.dup
98
+ new_lines.insert(insert_index, text_to_insert)
99
+
100
+ new_lines.join("\n") + "\n"
101
+ end
47
102
  end
48
103
  end
49
104
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DiffTest
4
- VERSION = "0.5.0"
4
+ VERSION = "0.7.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diff_test
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Owais