@@ -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
133132end
0 commit comments