Skip to content

Commit 83b8652

Browse files
authored
Merge pull request #286 from glennsarti/fix-puppet-lint
(GH-189) Reset PuppetLint configuration for each call
2 parents fa980bd + c70511b commit 83b8652

File tree

2 files changed

+35
-21
lines changed

2 files changed

+35
-21
lines changed

lib/puppet-languageserver/manifest/validation_provider.rb

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,7 @@ module ValidationProvider
1212
# <String> New Content
1313
# ]
1414
def self.fix_validate_errors(session_state, content)
15-
module_root = session_state.documents.store_root_path
16-
linter_options = nil
17-
if module_root.nil?
18-
linter_options = PuppetLint::OptParser.build
19-
else
20-
Dir.chdir(module_root.to_s) { linter_options = PuppetLint::OptParser.build }
21-
end
22-
linter_options.parse!(['--fix'])
15+
init_puppet_lint(session_state.documents.store_root_path, ['--fix'])
2316

2417
linter = PuppetLint::Checks.new
2518
linter.load_data(nil, content)
@@ -40,19 +33,7 @@ def self.validate(session_state, content, options = {})
4033
# TODO: Need to implement max_problems
4134
problems = 0
4235

43-
module_root = session_state.documents.store_root_path
44-
linter_options = nil
45-
if module_root.nil?
46-
linter_options = PuppetLint::OptParser.build
47-
else
48-
begin
49-
Dir.chdir(module_root.to_s) { linter_options = PuppetLint::OptParser.build }
50-
rescue OptionParser::InvalidOption => e
51-
PuppetLanguageServer.log_message(:error, "(#{name}) Error reading Puppet Lint configuration. Using default: #{e}")
52-
linter_options = PuppetLint::OptParser.build
53-
end
54-
end
55-
linter_options.parse!([])
36+
init_puppet_lint(session_state.documents.store_root_path, [])
5637

5738
begin
5839
linter = PuppetLint::Checks.new
@@ -128,6 +109,24 @@ def self.validate(session_state, content, options = {})
128109

129110
result
130111
end
112+
113+
def self.init_puppet_lint(root_dir, lint_options = [])
114+
linter_options = nil
115+
if root_dir.nil?
116+
linter_options = PuppetLint::OptParser.build
117+
else
118+
begin
119+
Dir.chdir(module_root.to_s) { linter_options = PuppetLint::OptParser.build }
120+
rescue OptionParser::InvalidOption => e
121+
PuppetLanguageServer.log_message(:error, "(#{name}) Error reading Puppet Lint configuration. Using default: #{e}")
122+
linter_options = PuppetLint::OptParser.build
123+
end
124+
end
125+
# Reset the fix flag
126+
PuppetLint.configuration.fix = false
127+
linter_options.parse!(lint_options)
128+
end
129+
private_class_method :init_puppet_lint
131130
end
132131
end
133132
end

spec/languageserver/integration/puppet-languageserver/manifest/validation_provider_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,5 +194,20 @@
194194
end
195195
end
196196
end
197+
198+
describe "Given a complete manifest with validation errors" do
199+
let(:manifest) { "class bad_formatting {\n user { 'username':\n ensure => absent,\n auth_membership => 'false',\n }\n} " }
200+
201+
it "should return errors and warnings even after fix_validate_errors" do
202+
fixes = subject.fix_validate_errors(session_state, manifest)
203+
validation = subject.validate(session_state, manifest)
204+
205+
expect(validation.count).to_not be_zero
206+
207+
validation.each do |problem|
208+
expect([LSP::DiagnosticSeverity::ERROR, LSP::DiagnosticSeverity::WARNING]).to include(problem.severity)
209+
end
210+
end
211+
end
197212
end
198213
end

0 commit comments

Comments
 (0)