puppet-lint-stdlib_deprecations 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8a262b62431245584e7002db4fda277fc2da95f538cb7ec5a15388eb7a9b4899
4
+ data.tar.gz: 5865cc5c09fdc7b435f3c58ed9e666a5f5d36495fe055a9f7a4e6beffb30475a
5
+ SHA512:
6
+ metadata.gz: 582cbea7a8ad8e649396e986eb77769ab26dabcfb89c5922d38adf41871c46ef6e6a27e7e860e6fdea207ee494fc70c199cda883a4f5350cd4b80c190957f273
7
+ data.tar.gz: 0d2d3e2058bc22c4c59116cbe520c54b2823bfbf3dc8f887f6ce319d86d9e88c55238fe038b6c238151297e767f628625047c0d3dcfbfe6ce62ecf40f62443ea
data/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # puppet-lint-stdlib_deprecations
2
+ A puppet-lint plugin to detect puppetlabs-stdlib deprecations including removed and non-namespaced functions and datatypes.
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Public: A puppet-lint custom check to detect removed deprecated compatibility data types.
4
+
5
+ DEPRECATED_DATATYPES_VAR_TYPES = [:CLASSREF].freeze
6
+
7
+ PuppetLint.new_check(:stdlib_deprecated_datatypes) do
8
+ def check
9
+ tokens.select { |x| DEPRECATED_DATATYPES_VAR_TYPES.include?(x.type) }.each do |token|
10
+ next unless token.value.include?('Stdlib::Compat::')
11
+
12
+ message = "Removed data type found: '#{token.value}'"
13
+
14
+ notify :error, {
15
+ message: message,
16
+ line: token.line,
17
+ column: token.column,
18
+ token: token,
19
+ fact_name: token.value
20
+ }
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Public: A puppet-lint custom check to detect deprecated functions.
4
+ DEPRECATED_FUNCTIONS_VAR_TYPES = Set[:FUNCTION_NAME]
5
+
6
+ # These functions have been removed in stdlib 9.x.
7
+ REMOVED_FUNCTIONS = %w[
8
+ is_absolute_path type3x private is_bool validate_bool
9
+ is_string validate_string is_integer validate_integer is_hash
10
+ is_float validate_hash absolute_path validate_re validate_slength
11
+ is_ipv6_address validate_ipv6_address is_ipv4_address validate_ipv4_address
12
+ is_ip_address validate_ip_address size sprintf_hash is_email_address
13
+ is_mac_address is_domain_name is_function_available hash has_key is_array
14
+ ].freeze
15
+
16
+ # Subset of REMOVED_FUNCTIONS that have been replaced with an alternative.
17
+ REPLACED_FUNCTIONS = {
18
+ 'private' => 'assert_private()',
19
+ 'size' => 'length()',
20
+ 'sprintf_hash' => 'sprintf()',
21
+ 'hash' => 'Puppets built-in Hash.new()',
22
+ 'has_key' => 'appropriate Puppet match expressions'
23
+ }.freeze
24
+
25
+ # These functions have been namespaced in stdlib 9.x.
26
+ NAMESPACED_FUNCTIONS = %w[
27
+ batch_escape ensure_packages fqdn_rand_string has_interface_with merge
28
+ os_version_gte parsehocon parsepson powershell_escape seeded_rand
29
+ seeded_rand_string shell_escape to_json to_json_pretty to_python to_ruby
30
+ to_toml to_yaml type_of validate_domain_name validate_email_address
31
+ ].freeze
32
+
33
+ PuppetLint.new_check(:stdlib_deprecated_functions) do
34
+ def check
35
+ tokens.select { |x| DEPRECATED_FUNCTIONS_VAR_TYPES.include?(x.type) }.each do |token|
36
+ if REMOVED_FUNCTIONS.include?(token.value)
37
+ removed_function_detected = true
38
+ elsif NAMESPACED_FUNCTIONS.include?(token.value)
39
+ namespaced_function_detected = true
40
+ else
41
+ next
42
+ end
43
+
44
+ message = "Deprecated function found: '#{token.value}'"
45
+ message += ". Use stdlib::#{token.value} instead." if namespaced_function_detected
46
+ message += ". Use #{REPLACED_FUNCTIONS[token.value]} instead." if REPLACED_FUNCTIONS.include?(token.value)
47
+
48
+ notify_log_level = removed_function_detected ? :error : :warning
49
+ notify notify_log_level, {
50
+ message: message,
51
+ line: token.line,
52
+ column: token.column,
53
+ token: token,
54
+ fact_name: token.value
55
+ }
56
+ end
57
+ end
58
+
59
+ # only applicable for namespaced functions
60
+ def fix(problem)
61
+ raise PuppetLint::NoFix unless NAMESPACED_FUNCTIONS.include?(problem[:token].value)
62
+
63
+ problem[:token].value = "stdlib::#{problem[:token].value}"
64
+ end
65
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class StdlibDeprecations
4
+ VERSION ||= '0.0.1'
5
+ end
@@ -0,0 +1,92 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe 'stdlib_deprecated_datatypes' do
6
+ context 'when scanning puppet code for deprecated compat datatypes' do
7
+ let(:code) { 'Stdlib::Compat::String' }
8
+ let(:report) { /Removed data type found: 'Stdlib::Compat::String'/ }
9
+
10
+ it 'does detect a problem' do
11
+ expect(problems.size).to eq(1)
12
+ end
13
+
14
+ it 'throws an error' do
15
+ expect(problems).to include(a_hash_including(kind: /error/))
16
+ end
17
+
18
+ it 'contains the specific warning message' do
19
+ expect(problems).to include(a_hash_including(message: report))
20
+ end
21
+ end
22
+
23
+ context 'when scanning puppet code for multiple deprecated compat datatypes' do
24
+ let(:code) { 'Stdlib::Compat::String, Stdlib::Compat::Array' }
25
+ let(:string_report) { /Removed data type found: 'Stdlib::Compat::String'/ }
26
+ let(:array_report) { /Removed data type found: 'Stdlib::Compat::Array'/ }
27
+
28
+ it 'does detect a problem' do
29
+ expect(problems.size).to eq(2)
30
+ end
31
+
32
+ it 'throws an error' do
33
+ expect(problems).to include(a_hash_including(kind: /error/))
34
+ end
35
+
36
+ it 'contains the specific String warning message' do
37
+ expect(problems).to include(a_hash_including(message: string_report))
38
+ end
39
+
40
+ it 'contains the specific Array warning message' do
41
+ expect(problems).to include(a_hash_including(message: array_report))
42
+ end
43
+ end
44
+
45
+ context 'when scanning puppet code for non-deprecated datatypes' do
46
+ let(:code) { 'String' }
47
+
48
+ it 'does not detect a problem' do
49
+ expect(problems).to be_empty
50
+ end
51
+ end
52
+
53
+ context 'when scanning puppet code for a mixture of deprecated and non-depreacted data types' do
54
+ let(:code) { 'String, Stdlib::Compat::String' }
55
+ let(:report) { /Removed data type found: 'Stdlib::Compat::String'/ }
56
+
57
+ it 'does detect a problem' do
58
+ expect(problems.size).to eq(1)
59
+ end
60
+
61
+ it 'throws an error' do
62
+ expect(problems).to include(a_hash_including(kind: /error/))
63
+ end
64
+
65
+ it 'contains the specific warning message' do
66
+ expect(problems).to include(a_hash_including(message: report))
67
+ end
68
+ end
69
+
70
+ context 'when scanning puppet code for deprecated compat datatypes with a code block' do
71
+ let(:code) do
72
+ <<~PUPPETCODE
73
+ class foo (
74
+ Stdlib::Compat::String $bar = 'foobar',
75
+ ){}
76
+ PUPPETCODE
77
+ end
78
+ let(:report) { /Removed data type found: 'Stdlib::Compat::String'/ }
79
+
80
+ it 'does detect a problem' do
81
+ expect(problems.size).to eq(1)
82
+ end
83
+
84
+ it 'throws an error' do
85
+ expect(problems).to include(a_hash_including(kind: /error/))
86
+ end
87
+
88
+ it 'contains the specific warning message' do
89
+ expect(problems).to include(a_hash_including(message: report))
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,327 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe 'stdlib_deprecated_functions' do
6
+ let(:generic_report) { /Deprecated function found:/ }
7
+
8
+ # Testing the stdlib_deprecated_functions check without autofix
9
+ context 'when testing puppet code with fix disabled and' do
10
+ context 'with one removed stdlib function present' do
11
+ let(:code) { "is_absolute_path('foo')" }
12
+
13
+ it 'does detect a problem' do
14
+ expect(problems.size).to eq(1)
15
+ end
16
+
17
+ it 'throws an error' do
18
+ expect(problems).to include(a_hash_including(kind: /error/))
19
+ end
20
+
21
+ it 'contains the specific warning message' do
22
+ expect(problems).to include(a_hash_including(message: generic_report))
23
+ end
24
+ end
25
+
26
+ context 'with one namespaced stdlib function present' do
27
+ let(:code) { "to_json('foo')" }
28
+
29
+ it 'does detect a problem' do
30
+ expect(problems.size).to eq(1)
31
+ end
32
+
33
+ it 'throws a warning' do
34
+ expect(problems).to include(a_hash_including(kind: /warning/))
35
+ end
36
+
37
+ it 'contains the specific warning message' do
38
+ expect(problems).to include(a_hash_including(message: generic_report))
39
+ end
40
+ end
41
+
42
+ context 'with a non-deprecated stdlib function present' do
43
+ let(:code) { "basename('/path/to/file')" }
44
+
45
+ it 'does not flag a problem' do
46
+ expect(problems.size).to eq(0)
47
+ end
48
+
49
+ it 'does not warn the user about deprecations' do
50
+ expect(problems).not_to include(a_hash_including(message: generic_report))
51
+ end
52
+ end
53
+
54
+ context 'with a wrongly written deprecated stdlib function present' do
55
+ let(:code) { "to_jron('foo')" }
56
+
57
+ it 'does not flag a problem' do
58
+ expect(problems.size).to eq(0)
59
+ end
60
+ end
61
+
62
+ context 'with multiple removed functions present' do
63
+ let(:code) { "is_absolute_path('foo')\nis_integer('foo')" }
64
+
65
+ it 'does detect multiple problems' do
66
+ expect(problems.size).to eq(2)
67
+ end
68
+
69
+ it 'throws an error' do
70
+ expect(problems).to include(a_hash_including(kind: /error/))
71
+ end
72
+
73
+ it 'does not throw a warning' do
74
+ expect(problems).not_to include(a_hash_including(kind: /warning/))
75
+ end
76
+
77
+ it 'contains the specific warning message' do
78
+ expect(problems).to include(a_hash_including(message: generic_report))
79
+ end
80
+ end
81
+
82
+ context 'with multiple namespaced functions present' do
83
+ let(:code) { "to_json('foo')\nto_yaml('foo')" }
84
+
85
+ it 'does detect multiple problems' do
86
+ expect(problems.size).to eq(2)
87
+ end
88
+
89
+ it 'throws a warning' do
90
+ expect(problems).to include(a_hash_including(kind: /warning/))
91
+ end
92
+
93
+ it 'does not throw an error' do
94
+ expect(problems).not_to include(a_hash_including(kind: /error/))
95
+ end
96
+
97
+ it 'contains the specific warning message' do
98
+ expect(problems).to include(a_hash_including(message: generic_report))
99
+ end
100
+ end
101
+
102
+ context 'with multiple mixed functions present' do
103
+ let(:code) { "is_absolute_path('foo')\nto_yaml('foo')" }
104
+
105
+ it 'does detect multiple problems' do
106
+ expect(problems.size).to eq(2)
107
+ end
108
+
109
+ it 'throws an error' do
110
+ expect(problems).to include(a_hash_including(kind: /error/))
111
+ end
112
+
113
+ it 'throws a warning' do
114
+ expect(problems).to include(a_hash_including(kind: /warning/))
115
+ end
116
+
117
+ it 'contains the specific warning message' do
118
+ expect(problems).to include(a_hash_including(message: generic_report))
119
+ end
120
+ end
121
+
122
+ context 'with a mix of deprecated and non-deprecated functions present' do
123
+ let(:code) { "is_absolute_path('foo')\nbasename('foo')" }
124
+
125
+ it 'does detect a problem' do
126
+ expect(problems.size).to eq(1)
127
+ end
128
+
129
+ it 'throws an error' do
130
+ expect(problems).to include(a_hash_including(kind: /error/))
131
+ end
132
+
133
+ it 'contains the specific warning message' do
134
+ expect(problems).to include(a_hash_including(message: generic_report))
135
+ end
136
+ end
137
+ end
138
+
139
+ # Testing the stdlib_deprecated_functions check with autofix
140
+ context 'when testing puppet code with fix enabled and' do
141
+ before do
142
+ PuppetLint.configuration.fix = true
143
+ end
144
+
145
+ after do
146
+ PuppetLint.configuration.fix = false
147
+ end
148
+
149
+ context 'with one non-replaceable removed stdlib function present' do
150
+ let(:code) { "is_absolute_path('foo')" }
151
+
152
+ it 'does detect a problem' do
153
+ expect(problems.size).to eq(1)
154
+ end
155
+
156
+ it 'throws an error' do
157
+ expect(problems).to include(a_hash_including(kind: /error/))
158
+ end
159
+
160
+ it 'does not fix the problem' do
161
+ expect(problems).not_to include(a_hash_including(kind: /fixed/))
162
+ end
163
+
164
+ it 'contains the specific warning message' do
165
+ expect(problems).to include(a_hash_including(message: generic_report))
166
+ end
167
+ end
168
+
169
+ context 'with one namespaced stdlib function present' do
170
+ let(:code) { "to_json('foo')" }
171
+ let(:fixedcode) { "stdlib::to_json('foo')" }
172
+
173
+ it 'does detect a problem' do
174
+ expect(problems.size).to eq(1)
175
+ end
176
+
177
+ it 'fixes the problem' do
178
+ expect(problems).to include(a_hash_including(kind: /fixed/))
179
+ end
180
+
181
+ it 'fixes the code' do
182
+ expect(manifest).to eq(fixedcode)
183
+ end
184
+
185
+ it 'contains the specific warning message' do
186
+ expect(problems).to include(a_hash_including(message: generic_report))
187
+ end
188
+ end
189
+
190
+ context 'with a non-deprecated stdlib function present' do
191
+ let(:code) { "basename('/path/to/file')" }
192
+
193
+ it 'does not flag a problem' do
194
+ expect(problems.size).to eq(0)
195
+ end
196
+
197
+ it 'does not warn the user about deprecations' do
198
+ expect(problems).not_to include(a_hash_including(message: generic_report))
199
+ end
200
+
201
+ it 'does not fix anything' do
202
+ expect(problems).not_to include(a_hash_including(kind: /fixed/))
203
+ end
204
+ end
205
+
206
+ context 'with a wrongly written deprecated stdlib function present' do
207
+ let(:code) { "to_jron('foo')" }
208
+
209
+ it 'does not flag a problem' do
210
+ expect(problems.size).to eq(0)
211
+ end
212
+
213
+ it 'does not fix anything' do
214
+ expect(problems).not_to include(a_hash_including(kind: /fixed/))
215
+ end
216
+ end
217
+
218
+ context 'with multiple namespaced functions present' do
219
+ let(:code) { "to_json('foo')\nto_yaml('foo')" }
220
+ let(:fixedcode) { "stdlib::to_json('foo')\nstdlib::to_yaml('foo')" }
221
+
222
+ it 'does detect multiple problems' do
223
+ expect(problems.size).to eq(2)
224
+ end
225
+
226
+ it 'fixes the problems' do
227
+ expect(problems).to include(a_hash_including(kind: /fixed/))
228
+ end
229
+
230
+ it 'does not avoid fixing the problems' do
231
+ expect(problems).not_to include(a_hash_including(kind: /warning/))
232
+ end
233
+
234
+ it 'fixes the code' do
235
+ expect(manifest).to eq(fixedcode)
236
+ end
237
+ end
238
+
239
+ context 'with multiple mixed functions present' do
240
+ let(:code) { "is_absolute_path('foo')\nto_yaml('foo')" }
241
+ let(:fixedcode) { "is_absolute_path('foo')\nstdlib::to_yaml('foo')" }
242
+
243
+ it 'does detect multiple problems' do
244
+ expect(problems.size).to eq(2)
245
+ end
246
+
247
+ it 'fixes the problems' do
248
+ expect(problems).to include(a_hash_including(kind: /fixed/))
249
+ end
250
+
251
+ it 'does not fix the unfixable problem' do
252
+ expect(problems).to include(a_hash_including(kind: /error/))
253
+ end
254
+
255
+ it 'fixes the code' do
256
+ expect(manifest).to eq(fixedcode)
257
+ end
258
+ end
259
+
260
+ context 'with the replaceable function size() present' do
261
+ # rubocop: disable Layout/LineLength
262
+ let(:code) { "size('foo')" }
263
+
264
+ it 'does detect a problem' do
265
+ expect(problems.size).to eq(1)
266
+ end
267
+
268
+ it 'offers an alternative' do
269
+ expect(problems).to include(a_hash_including(message: "Deprecated function found: 'size'. Use length() instead.", kind: :error))
270
+ end
271
+ end
272
+
273
+ context 'with the replaceable function hash() present' do
274
+ let(:code) { "hash('foo')" }
275
+
276
+ it 'does detect a problem' do
277
+ expect(problems.size).to eq(1)
278
+ end
279
+
280
+ it 'offers an alternative' do
281
+ expect(problems).to include(a_hash_including(message: "Deprecated function found: 'hash'. Use Puppets built-in Hash.new() instead.", kind: :error))
282
+ end
283
+ end
284
+
285
+ context 'with the replaceable function sprintf_hash() present' do
286
+ let(:code) { "sprintf_hash('foo')" }
287
+
288
+ it 'does detect a problem' do
289
+ expect(problems.size).to eq(1)
290
+ end
291
+
292
+ it 'offers an alternative' do
293
+ expect(problems).to include(a_hash_including(message: "Deprecated function found: 'sprintf_hash'. Use sprintf() instead.", kind: :error))
294
+ end
295
+ end
296
+
297
+ context 'with the replaceable function private() present' do
298
+ let(:code) { "private('foo')" }
299
+
300
+ it 'does detect a problem' do
301
+ expect(problems.size).to eq(1)
302
+ end
303
+
304
+ it 'offers an alternative' do
305
+ expect(problems).to include(a_hash_including(message: "Deprecated function found: 'private'. Use assert_private() instead.", kind: :error))
306
+ end
307
+ end
308
+
309
+ context 'with multiple replaceable functions present' do
310
+ let(:code) { "size('foo')\nsprintf_hash('foo')\nprivate('foo')" }
311
+ let(:fixedcode) { "length('foo')\nsprintf('foo')\nassert_private('foo')" }
312
+
313
+ it 'does detect multiple problems' do
314
+ expect(problems.size).to eq(3)
315
+ end
316
+
317
+ it 'offers an alternative for size' do
318
+ expect(problems).to include(a_hash_including(message: "Deprecated function found: 'size'. Use length() instead.", kind: :error))
319
+ end
320
+
321
+ it 'offers an alternative for private' do
322
+ expect(problems).to include(a_hash_including(message: "Deprecated function found: 'private'. Use assert_private() instead.", kind: :error))
323
+ end
324
+ # rubocop: enable Layout/LineLength
325
+ end
326
+ end
327
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rspec'
4
+ require 'simplecov'
5
+ require 'puppet-lint'
6
+ require 'rspec/its'
7
+
8
+ if ENV['COVERAGE'] == 'yes'
9
+ require 'simplecov'
10
+ require 'simplecov-console'
11
+
12
+ SimpleCov.formatters = [
13
+ SimpleCov::Formatter::HTMLFormatter,
14
+ SimpleCov::Formatter::Console
15
+ ]
16
+
17
+ SimpleCov.start do
18
+ track_files 'lib/puppet-lint/**/*.rb'
19
+ add_filter 'lib/puppet-lint/plugins/version.rb'
20
+ add_filter '/spec'
21
+ end
22
+ end
23
+
24
+ PuppetLint::Plugins.load_spec_helper
25
+
26
+ # Additional RSpec configuration
27
+ RSpec.configure do |c|
28
+ # Example configuration
29
+ c.mock_with :rspec
30
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: puppet-lint-stdlib_deprecations
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Puppet, Inc.
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-08-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: puppet-lint
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
27
+ description: |2
28
+ Helps to detect deprecated, removed and non-namespaced puppetlabs-stdlib functions and datatypes during your upgrade to puppetlabs-stdlib 9.x,
29
+ and puppet 8.
30
+ email:
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - LICENSE
36
+ - README.md
37
+ - lib/puppet-lint/plugins/stdlib_deprecated_datatypes.rb
38
+ - lib/puppet-lint/plugins/stdlib_deprecated_functions.rb
39
+ - lib/puppet-lint/plugins/version.rb
40
+ - spec/puppet-lint/plugins/stdlib_deprecated_datatypes_spec.rb
41
+ - spec/puppet-lint/plugins/stdlib_deprecated_functions_spec.rb
42
+ - spec/spec_helper.rb
43
+ homepage: https://github.com/puppetlabs/puppet-lint-stdlib_deprecations
44
+ licenses:
45
+ - Apache-2.0
46
+ metadata:
47
+ rubygems_mfa_required: 'true'
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '2.7'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubygems_version: 3.1.6
64
+ signing_key:
65
+ specification_version: 4
66
+ summary: A puppet-lint plugin to aid your puppetlabs-stdlib 9.x upgrade.
67
+ test_files: []