File tree Expand file tree Collapse file tree 5 files changed +27
-0
lines changed Expand file tree Collapse file tree 5 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ describe('ConfigSchema', () => {
1818 "caseIndent": false,
1919 "funcNextLine": false,
2020 "keepPadding": false,
21+ "languageDialect": "auto",
2122 "path": "shfmt",
2223 "simplifyCode": false,
2324 "spaceRedirects": false,
@@ -39,6 +40,7 @@ describe('ConfigSchema', () => {
3940 caseIndent : true ,
4041 funcNextLine : true ,
4142 keepPadding : true ,
43+ languageDialect : 'posix' ,
4244 path : 'myshfmt' ,
4345 simplifyCode : true ,
4446 spaceRedirects : true ,
@@ -64,6 +66,7 @@ describe('ConfigSchema', () => {
6466 "caseIndent": true,
6567 "funcNextLine": true,
6668 "keepPadding": true,
69+ "languageDialect": "posix",
6770 "path": "myshfmt",
6871 "simplifyCode": true,
6972 "spaceRedirects": true,
@@ -99,6 +102,7 @@ describe('getConfigFromEnvironmentVariables', () => {
99102 "caseIndent": false,
100103 "funcNextLine": false,
101104 "keepPadding": false,
105+ "languageDialect": "auto",
102106 "path": "shfmt",
103107 "simplifyCode": false,
104108 "spaceRedirects": false,
@@ -128,6 +132,7 @@ describe('getConfigFromEnvironmentVariables', () => {
128132 "caseIndent": false,
129133 "funcNextLine": false,
130134 "keepPadding": false,
135+ "languageDialect": "auto",
131136 "path": "",
132137 "simplifyCode": false,
133138 "spaceRedirects": false,
@@ -166,6 +171,7 @@ describe('getConfigFromEnvironmentVariables', () => {
166171 "caseIndent": true,
167172 "funcNextLine": false,
168173 "keepPadding": false,
174+ "languageDialect": "auto",
169175 "path": "/path/to/shfmt",
170176 "simplifyCode": false,
171177 "spaceRedirects": false,
Original file line number Diff line number Diff line change @@ -58,6 +58,9 @@ export const ConfigSchema = z.object({
5858 // (Deprecated) Keep column alignment padding.
5959 keepPadding : z . boolean ( ) . default ( false ) ,
6060
61+ // Language dialect to use when parsing (bash/posix/mksh/bats).
62+ languageDialect : z . string ( ) . trim ( ) . default ( 'auto' ) ,
63+
6164 // Simplify code before formatting.
6265 simplifyCode : z . boolean ( ) . default ( false ) ,
6366
@@ -84,6 +87,7 @@ export function getConfigFromEnvironmentVariables(): {
8487 shellcheckPath : process . env . SHELLCHECK_PATH ,
8588 shfmt : {
8689 path : process . env . SHFMT_PATH ,
90+ languageDialect : process . env . SHFMT_LANGUAGE_DIALECT ,
8791 binaryNextLine : toBoolean ( process . env . SHFMT_BINARY_NEXT_LINE ) ,
8892 caseIndent : toBoolean ( process . env . SHFMT_CASE_INDENT ) ,
8993 funcNextLine : toBoolean ( process . env . SHFMT_FUNC_NEXT_LINE ) ,
Original file line number Diff line number Diff line change @@ -62,6 +62,17 @@ describe('formatter', () => {
6262 )
6363 } )
6464
65+ it ( 'should throw when parsing using the wrong language dialect' , async ( ) => {
66+ expect ( async ( ) => {
67+ await getFormattingResult ( {
68+ document : FIXTURE_DOCUMENT . SHFMT ,
69+ shfmtConfig : { languageDialect : 'posix' } ,
70+ } )
71+ } ) . rejects . toThrow (
72+ / S h f m t : e x i t e d w i t h s t a t u s 1 : .* \/ t e s t i n g \/ f i x t u r e s \/ s h f m t .s h : 2 5 : 1 4 : t h e " f u n c t i o n " b u i l t i n e x i s t s i n b a s h ; t r i e d p a r s i n g a s p o s i x / ,
73+ )
74+ } )
75+
6576 it ( 'should format when shfmt is present' , async ( ) => {
6677 const [ result ] = await getFormattingResult ( { document : FIXTURE_DOCUMENT . SHFMT } )
6778 expect ( result ) . toMatchInlineSnapshot ( `
Original file line number Diff line number Diff line change @@ -71,6 +71,7 @@ export class Formatter {
7171 if ( shfmtConfig ?. keepPadding ) args . push ( '-kp' ) // --keep-padding
7272 if ( shfmtConfig ?. simplifyCode ) args . push ( '-s' ) // --simplify
7373 if ( shfmtConfig ?. spaceRedirects ) args . push ( '-sr' ) // --space-redirects
74+ if ( shfmtConfig ?. languageDialect ) args . push ( `-ln=${ shfmtConfig . languageDialect } ` ) // --language-dialect
7475
7576 // If we can determine a local filename, pass that to shfmt to aid language dialect detection
7677 const filePathMatch = document . uri . match ( / ^ f i l e : \/ \/ ( .* ) $ / )
Original file line number Diff line number Diff line change 8383 "default" : " shfmt" ,
8484 "description" : " Controls the executable used for Shfmt formatting. An empty string will disable formatting."
8585 },
86+ "bashIde.shfmt.languageDialect" : {
87+ "type" : " string" ,
88+ "default" : " auto" ,
89+ "description" : " Language dialect to use when parsing (bash/posix/mksh/bats)."
90+ },
8691 "bashIde.shfmt.binaryNextLine" : {
8792 "type" : " boolean" ,
8893 "default" : false ,
You can’t perform that action at this time.
0 commit comments