Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 23fdaa9

Browse files
authored
Merge pull request bash-lsp#1171 from chris-reeves/shfmt-editorconfig-support
Add .editorconfig support for shfmt
2 parents fe93389 + 986548d commit 23fdaa9

File tree

12 files changed

+365
-22
lines changed

12 files changed

+365
-22
lines changed

‎README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,15 @@ there is no `shfmt`-specific configuration variable for this. If your editor is
195195
two-space indents then that's what it will use. If you're using tabs for indentation then `shfmt`
196196
will use that.
197197

198+
The `shfmt` integration also supports configuration via `.editorconfig`. If any `shfmt`-specific
199+
configuration properties are found in `.editorconfig` then the config in `.editorconfig` will be
200+
used and the language server config will be ignored. This follows `shfmt`'s approach of using either
201+
`.editorconfig` or command line flags, but not both. Note that only `shfmt`-specific configuration
202+
properties are read from `.editorconfig` - indentation preferences are still provided by the editor,
203+
so to format using the indentation specified in `.editorconfig` make sure your editor is also
204+
configured to read `.editorconfig`. It is possible to disable `.editorconfig` support and always use
205+
the language server config by setting the "Ignore Editorconfig" configuration variable.
206+
198207
## Logging
199208

200209
The minimum logging level for the server can be adjusted using the `BASH_IDE_LOG_LEVEL` environment variable

‎pnpm-lock.yaml

Lines changed: 30 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎server/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Bash Language Server
22

3+
## 5.4.0
4+
5+
- Add .editorconfig support for shfmt https://github.com/bash-lsp/bash-language-server/pull/1171
6+
37
## 5.3.4
48

59
- Add additonal shfmt formatting config options https://github.com/bash-lsp/bash-language-server/pull/1168

‎server/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "A language server for Bash",
44
"author": "Mads Hartmann",
55
"license": "MIT",
6-
"version": "5.3.4",
6+
"version": "5.4.0",
77
"main": "./out/server.js",
88
"typings": "./out/server.d.ts",
99
"bin": {
@@ -17,6 +17,7 @@
1717
"node": ">=16"
1818
},
1919
"dependencies": {
20+
"editorconfig": "2.0.0",
2021
"fast-glob": "3.3.2",
2122
"fuzzy-search": "3.2.1",
2223
"node-fetch": "2.7.0",

‎server/src/__tests__/config.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ describe('ConfigSchema', () => {
1717
"binaryNextLine": false,
1818
"caseIndent": false,
1919
"funcNextLine": false,
20+
"ignoreEditorconfig": false,
2021
"keepPadding": false,
22+
"languageDialect": "auto",
2123
"path": "shfmt",
2224
"simplifyCode": false,
2325
"spaceRedirects": false,
@@ -38,7 +40,9 @@ describe('ConfigSchema', () => {
3840
binaryNextLine: true,
3941
caseIndent: true,
4042
funcNextLine: true,
43+
ignoreEditorconfig: true,
4144
keepPadding: true,
45+
languageDialect: 'posix',
4246
path: 'myshfmt',
4347
simplifyCode: true,
4448
spaceRedirects: true,
@@ -63,7 +67,9 @@ describe('ConfigSchema', () => {
6367
"binaryNextLine": true,
6468
"caseIndent": true,
6569
"funcNextLine": true,
70+
"ignoreEditorconfig": true,
6671
"keepPadding": true,
72+
"languageDialect": "posix",
6773
"path": "myshfmt",
6874
"simplifyCode": true,
6975
"spaceRedirects": true,
@@ -98,7 +104,9 @@ describe('getConfigFromEnvironmentVariables', () => {
98104
"binaryNextLine": false,
99105
"caseIndent": false,
100106
"funcNextLine": false,
107+
"ignoreEditorconfig": false,
101108
"keepPadding": false,
109+
"languageDialect": "auto",
102110
"path": "shfmt",
103111
"simplifyCode": false,
104112
"spaceRedirects": false,
@@ -127,7 +135,9 @@ describe('getConfigFromEnvironmentVariables', () => {
127135
"binaryNextLine": false,
128136
"caseIndent": false,
129137
"funcNextLine": false,
138+
"ignoreEditorconfig": false,
130139
"keepPadding": false,
140+
"languageDialect": "auto",
131141
"path": "",
132142
"simplifyCode": false,
133143
"spaceRedirects": false,
@@ -165,7 +175,9 @@ describe('getConfigFromEnvironmentVariables', () => {
165175
"binaryNextLine": false,
166176
"caseIndent": true,
167177
"funcNextLine": false,
178+
"ignoreEditorconfig": false,
168179
"keepPadding": false,
180+
"languageDialect": "auto",
169181
"path": "/path/to/shfmt",
170182
"simplifyCode": false,
171183
"spaceRedirects": false,

‎server/src/config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ export const ConfigSchema = z.object({
4646
// Controls the executable used for Shfmt formatting. An empty string will disable formatting
4747
path: z.string().trim().default('shfmt'),
4848

49+
// Ignore shfmt config options in .editorconfig (always use language server config)
50+
ignoreEditorconfig: z.boolean().default(false),
51+
52+
// Language dialect to use when parsing (bash/posix/mksh/bats).
53+
languageDialect: z.enum(['auto', 'bash', 'posix', 'mksh', 'bats']).default('auto'),
54+
4955
// Allow boolean operators (like && and ||) to start a line.
5056
binaryNextLine: z.boolean().default(false),
5157

@@ -84,6 +90,8 @@ export function getConfigFromEnvironmentVariables(): {
8490
shellcheckPath: process.env.SHELLCHECK_PATH,
8591
shfmt: {
8692
path: process.env.SHFMT_PATH,
93+
ignoreEditorconfig: toBoolean(process.env.SHFMT_IGNORE_EDITORCONFIG),
94+
languageDialect: process.env.SHFMT_LANGUAGE_DIALECT,
8795
binaryNextLine: toBoolean(process.env.SHFMT_BINARY_NEXT_LINE),
8896
caseIndent: toBoolean(process.env.SHFMT_CASE_INDENT),
8997
funcNextLine: toBoolean(process.env.SHFMT_FUNC_NEXT_LINE),

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /