@@ -75,40 +75,46 @@ export class Formatter {
7575 const filepath = filepathMatch [ 1 ]
7676 args . push ( `--filename=${ filepathMatch [ 1 ] } ` )
7777
78- const editorconfigProperties = await editorconfig . parse ( filepath )
79- logger . debug (
80- `Shfmt: found .editorconfig properties: ${ JSON . stringify (
81- editorconfigProperties ,
82- ) } `,
83- )
84-
85- const editorconfigShfmtConfig : Record < string , any > = { }
86- editorconfigShfmtConfig . binaryNextLine = editorconfigProperties . binary_next_line
87- editorconfigShfmtConfig . caseIndent = editorconfigProperties . switch_case_indent
88- editorconfigShfmtConfig . funcNextLine = editorconfigProperties . function_next_line
89- editorconfigShfmtConfig . keepPadding = editorconfigProperties . keep_padding
90- // --simplify is not supported via .editorconfig
91- editorconfigShfmtConfig . spaceRedirects = editorconfigProperties . space_redirects
92- editorconfigShfmtConfig . languageDialect = editorconfigProperties . shell_variant
93-
94- // if we have any shfmt-specific options in .editorconfig, use the config in .editorconfig and
95- // ignore the language server config (this is similar to shfmt's approach of using either
96- // .editorconfig or command line flags, but not both)
97- if (
98- editorconfigShfmtConfig . binaryNextLine !== undefined ||
99- editorconfigShfmtConfig . caseIndent !== undefined ||
100- editorconfigShfmtConfig . funcNextLine !== undefined ||
101- editorconfigShfmtConfig . keepPadding !== undefined ||
102- editorconfigShfmtConfig . spaceRedirects !== undefined ||
103- editorconfigShfmtConfig . languageDialect !== undefined
104- ) {
78+ if ( ! lspShfmtConfig ?. ignoreEditorconfig ) {
79+ const editorconfigProperties = await editorconfig . parse ( filepath )
10580 logger . debug (
106- 'Shfmt: detected shfmt properties in .editorconfig - ignoring language server shfmt config' ,
81+ `Shfmt: found .editorconfig properties: ${ JSON . stringify (
82+ editorconfigProperties ,
83+ ) } `,
10784 )
108- activeShfmtConfig = { ...editorconfigShfmtConfig }
85+
86+ const editorconfigShfmtConfig : Record < string , any > = { }
87+ editorconfigShfmtConfig . binaryNextLine = editorconfigProperties . binary_next_line
88+ editorconfigShfmtConfig . caseIndent = editorconfigProperties . switch_case_indent
89+ editorconfigShfmtConfig . funcNextLine = editorconfigProperties . function_next_line
90+ editorconfigShfmtConfig . keepPadding = editorconfigProperties . keep_padding
91+ // --simplify is not supported via .editorconfig
92+ editorconfigShfmtConfig . spaceRedirects = editorconfigProperties . space_redirects
93+ editorconfigShfmtConfig . languageDialect = editorconfigProperties . shell_variant
94+
95+ // if we have any shfmt-specific options in .editorconfig, use the config in .editorconfig and
96+ // ignore the language server config (this is similar to shfmt's approach of using either
97+ // .editorconfig or command line flags, but not both)
98+ if (
99+ editorconfigShfmtConfig . binaryNextLine !== undefined ||
100+ editorconfigShfmtConfig . caseIndent !== undefined ||
101+ editorconfigShfmtConfig . funcNextLine !== undefined ||
102+ editorconfigShfmtConfig . keepPadding !== undefined ||
103+ editorconfigShfmtConfig . spaceRedirects !== undefined ||
104+ editorconfigShfmtConfig . languageDialect !== undefined
105+ ) {
106+ logger . debug (
107+ 'Shfmt: detected shfmt properties in .editorconfig - ignoring language server shfmt config' ,
108+ )
109+ activeShfmtConfig = { ...editorconfigShfmtConfig }
110+ } else {
111+ logger . debug (
112+ 'Shfmt: no shfmt properties found in .editorconfig - using language server shfmt config' ,
113+ )
114+ }
109115 } else {
110116 logger . debug (
111- 'Shfmt: no shfmt properties found in .editorconfig - using language server shfmt config' ,
117+ 'Shfmt: configured to ignore .editorconfig - using language server shfmt config' ,
112118 )
113119 }
114120 }
@@ -124,7 +130,8 @@ export class Formatter {
124130 if ( activeShfmtConfig ?. keepPadding ) args . push ( '-kp' ) // --keep-padding
125131 if ( activeShfmtConfig ?. simplifyCode ) args . push ( '-s' ) // --simplify
126132 if ( activeShfmtConfig ?. spaceRedirects ) args . push ( '-sr' ) // --space-redirects
127- if ( activeShfmtConfig ?. languageDialect ) args . push ( `-ln=${ activeShfmtConfig . languageDialect } ` ) // --language-dialect
133+ if ( activeShfmtConfig ?. languageDialect )
134+ args . push ( `-ln=${ activeShfmtConfig . languageDialect } ` ) // --language-dialect
128135
129136 return args
130137 }
0 commit comments