puppet-lint-recurse_file-check 0.1.1 → 0.2.0

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: 66fff1c8a9e9dfe7ef77a0f08cca144a6868e683e6211dae569ff4aeed75800f
4
- data.tar.gz: 366aa2da1673bfa501b7d7376b116e5c2e74e59f3439891677aff81d67b23bc7
3
+ metadata.gz: 7c6c735a24e0dd891461df7b40c7e807d39029c5cf2b12a0e697da29c1d197d4
4
+ data.tar.gz: 23cf243f5f520573574d1bed25f20a05594a16fd13a0a3b37c46ee6675604959
5
5
  SHA512:
6
- metadata.gz: 289e1e3b2f56e73eea3f9ccd445b09c558a7fb200cf6841f54fd63ddbd8a313fc7345681ba64e3f4e6ca2492a7171e7ed7913a66171ac314ccf5f0a5f806a1e8
7
- data.tar.gz: b0258ad6c28ccecf07bfed77c3710a79c2b1dcd9039c722e7c1fc686be11b48d3ce5c53bf510384d7ca9f5544e55384361d9c6bb7478e9fbea7a839bf479a25f
6
+ metadata.gz: db3ed6c3cf8dacecce87a06b1f2c7e01a45c5c642a8d6537789c73d455bc751d0ec682b6fe64f6b72dccb5779f29c5a54f7f82a18d45ed2c9b3253233efbbc8b
7
+ data.tar.gz: 7fbbf9ab4dc8874f6c64d190b5b7f0a999c291abd4e39aba0512e5df7001f223de54fd2c164405e51d85f4ba0e461eb97c3776a5f48aa9ca540cf4aea91af29c
data/.gitignore CHANGED
@@ -1,6 +1,7 @@
1
1
  /.bundle/
2
2
  /vendor/gems/
3
3
  /Gemfile.lock
4
+ /Gemfile.local
4
5
  pkg/
5
6
  .ruby-*
6
7
  puppet-lint-*.gem
data/.rubocop.yml ADDED
@@ -0,0 +1,37 @@
1
+ ---
2
+ require:
3
+ - rubocop-rake
4
+ - rubocop-rspec
5
+ AllCops:
6
+ NewCops: disable
7
+ DisplayCopNames: true
8
+ Include:
9
+ - "**/*.rb"
10
+ - "*.gemspec"
11
+ Exclude:
12
+ - bin/*
13
+ - ".vendor/**/*"
14
+ - "**/Gemfile"
15
+ - "**/Rakefile"
16
+ - pkg/**/*
17
+ - spec/fixtures/**/*
18
+ - vendor/**/*
19
+ - "**/Puppetfile"
20
+ - "**/Vagrantfile"
21
+ - "**/Guardfile"
22
+ Gemspec/RequiredRubyVersion:
23
+ Enabled: false
24
+ Metrics/MethodLength:
25
+ Enabled: false
26
+ Metrics/BlockLength:
27
+ Enabled: false
28
+ RSpec/DescribeClass:
29
+ Enabled: false
30
+ RSpec/MultipleExpectations:
31
+ Max: 4
32
+ Metrics/AbcSize:
33
+ Enabled: false
34
+ Metrics/CyclomaticComplexity:
35
+ Enabled: false
36
+ Metrics/PerceivedComplexity:
37
+ Enabled: false
data/Gemfile CHANGED
@@ -1,17 +1,25 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  gemspec
4
6
 
5
7
  group :test do
6
- gem 'rake', '~> 10.0'
7
- gem 'rspec-its', '~> 1.0'
8
- gem 'rspec-collection_matchers', '~> 1.0'
9
- gem 'rspec', '~> 3.0'
10
8
  gem 'json'
9
+ gem 'rake', '>= 12.3.3'
10
+ gem 'rspec', '>= 3.0'
11
+ gem 'rspec-collection_matchers', '>= 1.0'
12
+ gem 'rspec-its', '>= 1.0'
11
13
  gem 'rubocop'
12
- gem 'simplecov', :require => false
14
+ gem 'rubocop-rspec'
15
+ gem 'rubocop-rake'
16
+ gem 'simplecov', require: false
13
17
  end
14
18
 
15
19
  group :development do
16
- gem 'github_changelog_generator', :require => false if RUBY_VERSION >= '2.2.2'
20
+ gem 'github_changelog_generator', require: false if RUBY_VERSION >= '2.2.2'
21
+ end
22
+
23
+ if File.file?('Gemfile.local') && File.readable?('Gemfile.local')
24
+ eval(File.read('Gemfile.local'), binding)
17
25
  end
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rspec/core/rake_task'
2
4
  require 'rubocop/rake_task'
3
5
 
@@ -7,4 +9,4 @@ RuboCop::RakeTask.new(:rubocop) do |t|
7
9
  t.options = ['--display-cop-names']
8
10
  end
9
11
 
10
- task :default => :spec
12
+ task default: :spec
@@ -1,26 +1,46 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Public: Check the tokens of each File resource instance for a recurse
2
4
  # true parameter and if found, record a warning about the potential
3
5
  # performance impact.
4
6
  #
5
7
  # https://puppet.com/docs/puppet/latest/types/file.html#file-attribute-recurse
6
8
  PuppetLint.new_check(:recurse_file) do
7
-
8
9
  def check
9
10
  resource_indexes.each do |resource|
10
11
  next unless resource[:type].value == 'file'
11
12
 
12
- resource[:param_tokens].select { |param_token|
13
- param_token.value == 'recurse'
14
- }.each do |param_token|
15
- value_token = param_token.next_code_token.next_code_token
13
+ param_tokens = resource[:param_tokens].select do |param_token|
14
+ %w[recurse max_files].include? param_token.value
15
+ end
16
+
17
+ recurse = param_tokens.find do |t|
18
+ t.value == 'recurse' and %w[true remote].include? t.next_code_token.next_code_token.value
19
+ end
20
+
21
+ next if recurse.nil?
16
22
 
17
- next unless value_token.value == 'true'
23
+ max_files = param_tokens.find do |t|
24
+ t.value == 'max_files'
25
+ end
26
+
27
+ if max_files.nil?
28
+ value_token = recurse.next_code_token.next_code_token
29
+ notify(
30
+ :warning,
31
+ message: 'Unbounded recurse file resources can cause decreased performance. See "max_files"',
32
+ line: value_token.line,
33
+ column: value_token.column,
34
+ token: value_token
35
+ )
36
+ elsif ['0', '-1'].include? max_files.next_code_token.next_code_token.value
37
+ value_token = max_files.next_code_token.next_code_token
18
38
  notify(
19
39
  :warning,
20
- :message => 'recurse file resources can cause decreased performance',
21
- :line => value_token.line,
22
- :column => value_token.column,
23
- :token => value_token
40
+ message: 'Disabling warnings in recurse file resources using "max_files" is not recommended',
41
+ line: value_token.line,
42
+ column: value_token.column,
43
+ token: value_token
24
44
  )
25
45
  end
26
46
  end
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Gem::Specification.new do |s|
2
4
  s.name = 'puppet-lint-recurse_file-check'
3
- s.version = '0.1.1'
5
+ s.version = '0.2.0'
4
6
  s.homepage = 'https://github.com/jarretlavallee/puppet-lint-recurse_file-check'
5
7
  s.license = 'MIT'
6
8
  s.author = 'Jarret Lavallee'
@@ -8,9 +10,7 @@ Gem::Specification.new do |s|
8
10
  s.files = `git ls-files`.split("\n")
9
11
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
10
12
  s.summary = 'puppet-lint recurse_file check'
11
- s.description = <<-EOF
12
- Extends puppet-lint to ensure file resources do not have recurse enabled.
13
- EOF
13
+ s.description = 'Extends puppet-lint to ensure file resources do not have recurse enabled.'
14
14
 
15
- s.add_dependency 'puppet-lint', '>= 1.1', '< 3.0'
15
+ s.add_dependency 'puppet-lint', '>= 1.1', '< 3.0'
16
16
  end
@@ -1,39 +1,86 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe 'recurse_file' do
4
- let(:msg) { 'recurse file resources can cause decreased performance' }
6
+ let(:msg) { 'Unbounded recurse file resources can cause decreased performance. See "max_files"' }
7
+ let(:maxfilesmsg) { 'Disabling warnings in recurse file resources using "max_files" is not recommended' }
8
+
9
+ context 'when recurse is enabled' do
10
+ let(:code) { "file { 'foo': recurse => true }" }
11
+
12
+ it 'detects a single problem' do
13
+ expect(problems).to have(1).problem
14
+ end
15
+
16
+ it 'creates a warning' do
17
+ expect(problems).to contain_warning(msg).on_line(1).in_column(26)
18
+ end
19
+ end
20
+
21
+ context 'when recurse is remote' do
22
+ let(:code) { "file { 'foo': recurse => 'remote' }" }
23
+
24
+ it 'detects a single problem' do
25
+ expect(problems).to have(1).problem
26
+ end
27
+
28
+ it 'creates a warning' do
29
+ expect(problems).to contain_warning(msg).on_line(1).in_column(26)
30
+ end
31
+ end
5
32
 
6
- context 'recurse is enabled' do
7
- let(:code) { "file { 'foo': recurse => true }" }
33
+ context 'when recurse is enabled with max_files set to a number' do
34
+ let(:code) { "file { 'foo': recurse => 'remote', max_files => 10 }" }
8
35
 
9
- it 'should only detect a single problem' do
10
- expect(problems).to have(1).problem
11
- end
36
+ it 'does not detect any problems' do
37
+ expect(problems).to have(0).problem
38
+ end
39
+ end
40
+
41
+ context 'when recurse is enabled with max_files set to "0"' do
42
+ let(:code) { "file { 'foo': recurse => 'remote', max_files => 0 }" }
43
+
44
+ it 'detects a single problem' do
45
+ expect(problems).to have(1).problem
46
+ end
12
47
 
13
- it 'should create a warning' do
14
- expect(problems).to contain_warning(msg).on_line(1).in_column(26)
15
- end
48
+ it 'creates a warning' do
49
+ expect(problems).to contain_warning(maxfilesmsg).on_line(1).in_column(49)
16
50
  end
51
+ end
52
+
53
+ context 'when recurse is enabled with max_files set to "-1"' do
54
+ let(:code) { "file { 'foo': recurse => 'remote', max_files => '-1' }" }
17
55
 
18
- context 'recurse is disabled' do
19
- let(:code) { "file { 'foo': recurse => false }" }
56
+ it 'detects a single problem' do
57
+ expect(problems).to have(1).problem
58
+ end
20
59
 
21
- it 'should not detect any problems' do
22
- expect(problems).to have(0).problems
23
- end
60
+ it 'creates a warning' do
61
+ expect(problems).to contain_warning(maxfilesmsg).on_line(1).in_column(49)
24
62
  end
63
+ end
25
64
 
26
- context 'recurse is not defined' do
27
- let(:code) { "file { 'foo': }" }
65
+ context 'when recurse is disabled' do
66
+ let(:code) { "file { 'foo': recurse => false }" }
28
67
 
29
- it 'should not detect any problems' do
30
- expect(problems).to have(0).problems
31
- end
68
+ it 'does not detect any problems' do
69
+ expect(problems).to have(0).problems
32
70
  end
71
+ end
33
72
 
34
- context 'multi body file recurse selector' do
35
- let(:code) do
36
- <<-END
73
+ context 'when recurse is not defined' do
74
+ let(:code) { "file { 'foo': }" }
75
+
76
+ it 'does not detect any problems' do
77
+ expect(problems).to have(0).problems
78
+ end
79
+ end
80
+
81
+ context 'with multi body file recurse selector' do
82
+ let(:code) do
83
+ <<-MANIFEST
37
84
  file {
38
85
  '/tmp/foo1':
39
86
  ensure => $foo ? { default => absent },
@@ -43,17 +90,17 @@ describe 'recurse_file' do
43
90
  '/tmp/foo3':
44
91
  recurse => true;
45
92
  }
46
- END
47
- end
93
+ MANIFEST
94
+ end
48
95
 
49
- it 'should detect 3 problems' do
50
- expect(problems).to have(3).problems
51
- end
96
+ it 'detects 3 problems' do
97
+ expect(problems).to have(3).problems
98
+ end
52
99
 
53
- it 'should create three warnings' do
54
- expect(problems).to contain_warning(sprintf(msg)).on_line(4).in_column(26)
55
- expect(problems).to contain_warning(sprintf(msg)).on_line(6).in_column(26)
56
- expect(problems).to contain_warning(sprintf(msg)).on_line(8).in_column(26)
57
- end
100
+ it 'creates three warnings' do
101
+ expect(problems).to contain_warning(sprintf(msg)).on_line(4).in_column(26)
102
+ expect(problems).to contain_warning(sprintf(msg)).on_line(6).in_column(26)
103
+ expect(problems).to contain_warning(sprintf(msg)).on_line(8).in_column(26)
58
104
  end
105
+ end
59
106
  end
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet-lint'
2
4
 
3
5
  PuppetLint::Plugins.load_spec_helper
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet-lint-recurse_file-check
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jarret Lavallee
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-09 00:00:00.000000000 Z
11
+ date: 2021-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: puppet-lint
@@ -30,14 +30,14 @@ dependencies:
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '3.0'
33
- description: " Extends puppet-lint to ensure file resources do not have recurse
34
- enabled.\n"
33
+ description: Extends puppet-lint to ensure file resources do not have recurse enabled.
35
34
  email: jarret.lavallee@gmail.com
36
35
  executables: []
37
36
  extensions: []
38
37
  extra_rdoc_files: []
39
38
  files:
40
39
  - ".gitignore"
40
+ - ".rubocop.yml"
41
41
  - ".travis.yml"
42
42
  - Gemfile
43
43
  - LICENSE
@@ -51,7 +51,7 @@ homepage: https://github.com/jarretlavallee/puppet-lint-recurse_file-check
51
51
  licenses:
52
52
  - MIT
53
53
  metadata: {}
54
- post_install_message:
54
+ post_install_message:
55
55
  rdoc_options: []
56
56
  require_paths:
57
57
  - lib
@@ -66,9 +66,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
66
  - !ruby/object:Gem::Version
67
67
  version: '0'
68
68
  requirements: []
69
- rubyforge_project:
70
- rubygems_version: 2.7.6
71
- signing_key:
69
+ rubygems_version: 3.1.4
70
+ signing_key:
72
71
  specification_version: 4
73
72
  summary: puppet-lint recurse_file check
74
73
  test_files: