diff_test 0.4.0 → 0.6.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: ddeb2f4b0a8c3b760e6a548aecfe8fb72a0d4ae78d1e6234f6813729bca18d82
4
- data.tar.gz: 23680b38854d9e07fb0d9c7fb982055653efe70aa6b4cc9c4e17e5d10168b172
3
+ metadata.gz: daf439f9e7a37880a1c7e407b1f83c53bef5c95ef758cdcdbb39a60dcc96826a
4
+ data.tar.gz: 75589fb13675ac87b4782bd21596050de5e603683dddad4c0f6a1e0b60dbe50d
5
5
  SHA512:
6
- metadata.gz: f9cdc48a24aeedd64dcab7ca29fb5db7495270c185fb9a3cfc172af12f499111a59bc8efecb787c5b32c6ba4e4cb77946bb7a7153ea27d084da5c6a235bbeb68
7
- data.tar.gz: c655b85c2c21d5be0f1c1df04130ed996119f6a3a5213ef8ab7fb23b6d3bc7d4632ec2ae67d6013da6c2814c481ed5f8b51a5878c722069af2cd4e3730c32ae9
6
+ metadata.gz: 7de494d4d7ed09e9227f1fd9e1c62564cdcaa2a3eaa9579593f6e3adf1fdda0285bd91e0b2aa011e5f688c8f3971b15ae2dab58ab57350d7dea5d41095407467
7
+ data.tar.gz: ef8e2f4d679ddf3abdcb58a36ee16c186b2f86f8caa3d360cf43c9de91588f29973500d339b649359bf89ef76e1acdc1354b1fe74c5b44c823c037cc67d48cc3
@@ -23,9 +23,15 @@ module DiffTest
23
23
  comment = coffee ? '#' : '//'
24
24
  safe_method_call = coffee ? '?' : '?.'
25
25
 
26
- annotation = "#{comment} Automatically added by DiffTest\n(globalThis || window)?.diffTestTrackJsFile#{safe_method_call}(\"#{file_path}\");\n#{comment} Automatically added by DiffTest\n"
26
+ typescript = file_path.end_with?('ts') || file_path.end_with?('tsx')
27
27
 
28
- annotation + content
28
+ disable_lint_comments = ""
29
+ disable_lint_comments += "#{comment} @ts-ignore\n" if typescript
30
+ disable_lint_comments += "#{comment} prettier-ignore\n"
31
+ disable_lint_comments += "#{comment} eslint-disable-next-line\n"
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
+ insert_at_first_non_comment_line_str(content, annotation)
29
35
  end
30
36
 
31
37
  UNANNOTATE_REGEX = /(\/\/|#) Automatically added by DiffTest.*?(\/\/|#) Automatically added by DiffTest\n/m
@@ -37,6 +43,62 @@ module DiffTest
37
43
  def self.annotated?(content)
38
44
  content.include?('diffTestTrackJsFile')
39
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
40
102
  end
41
103
  end
42
104
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DiffTest
4
- VERSION = "0.4.0"
4
+ VERSION = "0.6.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diff_test
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Owais
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-04-13 00:00:00.000000000 Z
11
+ date: 2025-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty