bake-modernize 0.62.0 → 0.63.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: 7b8c84fb38c24a7df3e697bde00f9e28d5725ff4435c36bc1943c3f3d9639e57
4
- data.tar.gz: b1b37a9bb7567882ef2bf29ea5341e2f655a71753bfdb8ae83ef8932b492fc4a
3
+ metadata.gz: f1285a821430d0892953c2d45e86f8e5d11fe8d27d8212614ddb87914599370c
4
+ data.tar.gz: f1c4f3edb34b0bbecc4b5cada2286f2572173db3d168d21aa0fd8193dcb60b79
5
5
  SHA512:
6
- metadata.gz: bcf556c3cc4c36c933fb83cec422ab2d11571ba92d548574f076caad8a6bc7738f501490edea101fb9420ea66d1ad6e76da47d0b1bc14424d115a443195d394b
7
- data.tar.gz: 141b31cac4965846e143316b60065c32ad8a282d4e82c9d63287ebbf4be83f488ae90fcea489fb3e4a59c7c5d9eb01a2b0a3a569ff939e9c16ae2c59e3da9fb1
6
+ metadata.gz: f75c658d10774d709155f72b2933bcd818cad028d2cff2c80071b1b09f46e9caa3fccc82e3503d988d29d410dd08027887d4bba51d6ace5a5abd4931d2b08434
7
+ data.tar.gz: 35962d24b690a376da309acf3608817cee9340e1d330cf11a589153c445387e1a4e9e390d6b0836b021e5bb9f212878c7eb4a60bcdeedacb28fdce7ca23b0252
checksums.yaml.gz.sig CHANGED
@@ -1 +1,4 @@
1
- `����J?0��zp��s���z���6q�K �S�����Z[��$ɧ����ߌ3Q9���A��ϐɘ���;�\7i����m�W?��g�$�Z��n�Q�E�H�N��-؆j(�j��j���14����[�%��15��f�젓]/6�˾c�ԣ�s��� 2��͇ �dwb��p
1
+ 'O�v���Ej6ޗZjR�XKy���ښK�ݖr���b4�$_op�2��&m^՝B����y�)�&~W�9y߭�x+�
2
+ �����������1� ^a�u)�]��C�c�O'�)%�> ����F7��߈�����H.��MU2 �vri��}S⃯M�B����m0T��˦.���`���z�"�q��V1_5���B�?�g� �!�3{���~��+�Q
3
+ d_��f1�#}u�j�T藯�����2 ���V�\m ���
4
+ 9G4֎P1ݨ�cL� ��B��;$휕B��_8�v_�������E���S@|�o��h�Ir��)����
@@ -66,50 +66,7 @@ private
66
66
 
67
67
  def update_source_file_authors(authorship, path, modifications)
68
68
  copyrights = authorship.copyrights_for_modifications(modifications)
69
-
70
- input = File.readlines(path)
71
- output = []
72
-
73
- if input.first =~ /^\#!/
74
- output.push input.shift
75
- end
76
-
77
- # Drop any old copyright statements.
78
- while input.first =~ /Copyright/i
79
- input.shift
80
- end
81
-
82
- if input.first =~ /^\#.*?\:/
83
- output.push input.shift
84
- if input.first.chomp.empty?
85
- input.shift
86
- end
87
- output << "\n"
88
- end
89
-
90
- # Remove any existing license:
91
- while input.first =~ /^#.*$/
92
- input.shift
93
- end
94
-
95
- # Remove any empty lines:
96
- while input.first&.chomp&.empty?
97
- input.shift
98
- end
99
-
100
- output << "# Released under the MIT License.\n"
101
-
102
- copyrights.each do |copyright|
103
- output << "# #{copyright.statement}\n"
104
- end
105
-
106
- output << "\n"
107
-
108
- output.concat(input)
109
-
110
- File.open(path, "w") do |file|
111
- file.puts(output)
112
- end
69
+ Bake::Modernize::License::SourceFile.update(path, copyrights: copyrights.map(&:statement))
113
70
  end
114
71
 
115
72
  def remove_license(readme_path)
@@ -12,6 +12,55 @@ module Bake
12
12
  module License
13
13
  GIT_BLAME_IGNORE_REVS = ".git-blame-ignore-revs"
14
14
 
15
+ # Updates Ruby source headers without removing documentation comments.
16
+ class SourceFile
17
+ MAGIC_COMMENT = /\A#\s*(?:-\*-\s*)?(?:coding|encoding|frozen_string_literal|warn_indent|shareable_constant_value)\s*[:=]/i
18
+ LICENSE_COMMENT = /\A#\s*(?:Released under\b|Copyright\b|SPDX-License-Identifier:)/i
19
+
20
+ # Replace the license and copyright header for a Ruby source file.
21
+ # @parameter path [String] The source file path.
22
+ # @parameter copyrights [Array(String)] The copyright statements to write.
23
+ def self.update(path, copyrights:)
24
+ input = File.readlines(path)
25
+ prefix = []
26
+
27
+ prefix << input.shift if input.first&.start_with?("#!")
28
+ while input.first&.match?(MAGIC_COMMENT)
29
+ prefix << input.shift
30
+ end
31
+
32
+ # Keep the complete leading comment block, removing only known license metadata.
33
+ documentation = []
34
+ while line = input.first
35
+ break unless line.match?(/\A\s*#/) || line.strip.empty?
36
+
37
+ input.shift
38
+ next if line.match?(LICENSE_COMMENT)
39
+
40
+ documentation << line
41
+ end
42
+
43
+ while documentation.first&.strip&.empty?
44
+ documentation.shift
45
+ end
46
+ while documentation.last&.strip&.empty?
47
+ documentation.pop
48
+ end
49
+
50
+ output = prefix.dup
51
+ output << "\n" if output.any?
52
+ output << "# Released under the MIT License.\n"
53
+ copyrights.each do |copyright|
54
+ output << "# #{copyright}\n"
55
+ end
56
+ output << "\n"
57
+ output.concat(documentation)
58
+ output.concat(input)
59
+
60
+ File.write(path, output.join)
61
+ end
62
+ end
63
+
15
64
  # Represents revisions to skip when analyzing authorship.
16
65
  class SkipList
17
66
  # Load the skip list from a directory.
@@ -5,6 +5,6 @@
5
5
 
6
6
  module Bake
7
7
  module Modernize
8
- VERSION = "0.62.0"
8
+ VERSION = "0.63.0"
9
9
  end
10
10
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bake-modernize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.62.0
4
+ version: 0.63.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
metadata.gz.sig CHANGED
Binary file