puppet-lint-stdlib_deprecations 0.0.1 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8a262b62431245584e7002db4fda277fc2da95f538cb7ec5a15388eb7a9b4899
4
- data.tar.gz: 5865cc5c09fdc7b435f3c58ed9e666a5f5d36495fe055a9f7a4e6beffb30475a
3
+ metadata.gz: 5a09ec5fb006b9366fa223352f54f94bb678eb624956ad7c4958afe31b6b91cf
4
+ data.tar.gz: 9e0948a038b35fc8bc23ec15dba874f6a88465c1fab452cfde315027a475ddeb
5
5
  SHA512:
6
- metadata.gz: 582cbea7a8ad8e649396e986eb77769ab26dabcfb89c5922d38adf41871c46ef6e6a27e7e860e6fdea207ee494fc70c199cda883a4f5350cd4b80c190957f273
7
- data.tar.gz: 0d2d3e2058bc22c4c59116cbe520c54b2823bfbf3dc8f887f6ce319d86d9e88c55238fe038b6c238151297e767f628625047c0d3dcfbfe6ce62ecf40f62443ea
6
+ metadata.gz: 2964fb07f8f6a70f87c9b1207118e53d6f9e8495d0dca3628deca13eac6ca629c2aa61b241c457219d5277f63071a4a9400bb90bb2c10beb08f2f2a9f6f3b41c
7
+ data.tar.gz: 16171c1f001742c9b266ab7501c6cbafc76717e84d84562486bf7089ee745539df4695cf9d7b9449652ca995974005f2d8db0585fadc520f69049a0e446ab39f
data/README.md CHANGED
@@ -1,2 +1,164 @@
1
1
  # puppet-lint-stdlib_deprecations
2
- A puppet-lint plugin to detect puppetlabs-stdlib deprecations including removed and non-namespaced functions and datatypes.
2
+
3
+ [![ci](https://github.com/puppetlabs/puppet-lint-stdlib_deprecations/actions/workflows/nightly.yml/badge.svg)](https://github.com/puppetlabs/puppet-strings/actions/workflows/nightly.yml)
4
+ [![Gem Version](https://badge.fury.io/rb/puppet-lint-stdlib_deprecations.svg)](https://badge.fury.io/rb/puppet-lint-stdlib_deprecations)
5
+ [![Code Owners](https://img.shields.io/badge/owners-DevX--team-blue)](https://github.com/puppetlabs/puppet-lint-stdlib_deprecations/blob/main/CODEOWNERS)
6
+
7
+ A puppet-lint plugin to detect [puppetlabs/stdlib](https://forge.puppet.com/modules/puppetlabs/stdlib) deprecations including removed and non-namespaced functions and datatypes.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your modules's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'puppet-lint-stdlib_deprecations'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ ```bash
20
+ bundle install
21
+ ```
22
+
23
+ Or install it with:
24
+
25
+ ```bash
26
+ gem install puppet-lint-stdlib_deprecations
27
+ ```
28
+
29
+ ## Checks
30
+
31
+ This plugin includes two checks.
32
+
33
+ ### stdlib_deprecated_functions
34
+
35
+ Scans your puppet code for instances of removed and non-namespaced functions in `puppetlabs/stdlib` v9.0.0+. The plugin will only flag functions removed, that do not have an exact replcacement in core Puppet (for example, `upcase` or `chomp`).
36
+
37
+ ```puppet
38
+ class example_module::agent (
39
+ String $ipaddress = '127.0.0.1'
40
+ ) {
41
+ $chomped = chomp('hello\n')
42
+
43
+ if is_ip_address($ipaddress) {
44
+ notice("${ipaddress} is an ipaddress!")
45
+ }
46
+
47
+ $size = size('hello')
48
+
49
+ $escaped = batch_escape('echo "hello world"')
50
+ }
51
+ ```
52
+
53
+ The above manifest will result in this console output:
54
+
55
+ ```bash
56
+ puppet-lint path/to/file.pp
57
+
58
+ ERROR: Deprecated function found: 'is_ip_address' on line 6 (check: stdlib_deprecated_functions)
59
+ ERROR: Deprecated function found: 'size'. Use length() instead. on line 10 (check: stdlib_deprecated_functions)
60
+ WARNING: Deprecated function found: 'batch_escape'. Use stdlib::batch_escape instead. on line 12 (check: stdlib_deprecated_functions)
61
+ ```
62
+
63
+ Notice, there is no output for the `chomp(..)` function call as there is a direct replacement in core Puppet, meaning the function will continue to work as expected.
64
+
65
+ * `is_ip_address` is flagged as an error, as this will require manual intervention from the user to update this instance to a suitable replacement.
66
+ * `size` is also flagged as an error was replaced by `length()` which is shipped with Puppet.
67
+ * `batch_escape` omits a warning, this is because the function call will continue to work (until later removed from [puppetlabs/stdlib](https://forge.puppet.com/modules/puppetlabs/stdlib)), as 'under the hood' puppet will call the namespaced function.
68
+
69
+ For functions which have a namespaced counterpart (like `batch_escape`) we can make use of puppet-lint's autocorrect functionality to automate the process of updating these function calls.
70
+
71
+ ```puppet
72
+ class example_module::agent (
73
+ String $ipaddress = ''
74
+ ) {
75
+ ...
76
+ $escaped = batch_escape('echo "hello world"')
77
+ }
78
+ ```
79
+
80
+ ```bash
81
+ puppet-lint --fix path/to/file.pp
82
+ ...
83
+ FIXED: Deprecated function found: 'batch_escape'. Use stdlib::batch_escape instead. on line 12 (check: stdlib_deprecated_functions)
84
+ ...
85
+ ```
86
+
87
+ And the updated code will look like:
88
+
89
+ ```puppet
90
+ class example_module::agent (
91
+ String $ipaddress = ''
92
+ ) {
93
+ ...
94
+ $escaped = stdlib::batch_escape('echo "hello world"')
95
+ }
96
+ ```
97
+
98
+ To disable this check, you can add `--no-stdlib_deprecated_functions-check` to your puppet-lint command line.
99
+
100
+ ```bash
101
+ puppet-lint --no-stdlib_deprecated_functions-check path/to/file.pp
102
+ ```
103
+
104
+ Or if you're calling puppet-lint via a Raketask, add this to your Rakefile:
105
+
106
+ ```ruby
107
+ PuppetLint.configuration.send('disable_stdlib_deprecated_functions')
108
+ ```
109
+
110
+ ### stdlib_deprecated_datatypes
111
+
112
+ Checks for instances of the removed `Stdlib::Compat` datatypes in your manifests.
113
+
114
+ ```puppet
115
+ class example_module::agent (
116
+ String $ip = '127.0.0.1',
117
+ ) {
118
+ if ($ip =~ Stdlib::Compat::Ipv4) {
119
+ notice("${ip} is an ip address!")
120
+ }
121
+ }
122
+ ```
123
+
124
+ When running this check, puppet-lint will flag this instance of `Stdlib::Compat::Ip_address` as an error.
125
+
126
+ ```bash
127
+ puppet-lint /path/to/file.pp
128
+
129
+ ERROR: Removed data type found: 'Stdlib::Compat::Ipv4' on line 4 (check: stdlib_deprecated_datatypes)
130
+ ```
131
+
132
+ What you should now use:
133
+
134
+ ```puppet
135
+ class example_module::agent (
136
+ String $ip = '127.0.0.1',
137
+ ) {
138
+ if ($ip =~ Stdlib::IP::Address) {
139
+ notice("${ip} is an ip address!")
140
+ }
141
+ }
142
+ ```
143
+
144
+ Again, to disable this check you can add `--no-stdlib_deprecated_datatypes-check` to your puppet-lint command line.
145
+
146
+ ```bash
147
+ puppet-lint --no-stdlib_deprecated_datatypes-check /path/to/file.pp
148
+ ```
149
+
150
+ Or by adding this line to your Rakefile (if calling the puppet-lint rake task).
151
+
152
+ ```ruby
153
+ PuppetLint.configuration.send('disable_stdlib_deprecated_datatypes')
154
+ ```
155
+
156
+ ## License
157
+
158
+ This codebase is licensed under Apache 2.0. However, the open source dependencies included in this codebase might be subject to other software licenses such as AGPL, GPL2.0, and MIT.
159
+
160
+ ## Development
161
+
162
+ If you run into an issue with this plugin or would like to request a feature you can raise a PR with your suggested changes. Keep in mind that this gem runs automated testing using GitHub Actions and we generally expect new contributions to pass these tests, as well as add additional testing in case of new features.
163
+
164
+ Alternatively, you can raise a Github issue with a feature request or bug reports. Every other Tuesday the DevX team holds office hours in the Puppet Community Slack, where you can ask questions about this and any other supported tools. This session runs at 15:00 (GMT) for about an hour.
@@ -3,9 +3,9 @@
3
3
  # Public: A puppet-lint custom check to detect deprecated functions.
4
4
  DEPRECATED_FUNCTIONS_VAR_TYPES = Set[:FUNCTION_NAME]
5
5
 
6
- # These functions have been removed in stdlib 9.x.
6
+ # These functions have been removed/scheduled for removal in stdlib 9.x.
7
7
  REMOVED_FUNCTIONS = %w[
8
- is_absolute_path type3x private is_bool validate_bool
8
+ is_absolute_path type3x private is_bool validate_legacy validate_bool
9
9
  is_string validate_string is_integer validate_integer is_hash
10
10
  is_float validate_hash absolute_path validate_re validate_slength
11
11
  is_ipv6_address validate_ipv6_address is_ipv4_address validate_ipv4_address
@@ -19,7 +19,8 @@ REPLACED_FUNCTIONS = {
19
19
  'size' => 'length()',
20
20
  'sprintf_hash' => 'sprintf()',
21
21
  'hash' => 'Puppets built-in Hash.new()',
22
- 'has_key' => 'appropriate Puppet match expressions'
22
+ 'has_key' => '"if \'key\' in $my_hash"',
23
+ 'validate_legacy' => 'Puppet data types to validate parameters'
23
24
  }.freeze
24
25
 
25
26
  # These functions have been namespaced in stdlib 9.x.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class StdlibDeprecations
4
- VERSION ||= '0.0.1'
4
+ VERSION ||= '0.0.3'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet-lint-stdlib_deprecations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-27 00:00:00.000000000 Z
11
+ date: 2024-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: puppet-lint