Skip to content

Commit 82835c7

Browse files
nwalters512JounQin
andauthored
fix(sh): exclude ShellSession language (#416)
Co-authored-by: JounQin <[email protected]>
1 parent e6b9b70 commit 82835c7

4 files changed

Lines changed: 27 additions & 10 deletions

File tree

‎.changeset/light-pots-remain.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"prettier-plugin-sh": minor
3+
---
4+
5+
fix(sh): exclude `ShellSession` language

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"@vitejs/plugin-react-swc": "^3.7.0",
4848
"@vitest/coverage-istanbul": "^1.0.4",
4949
"github-markdown-css": "^5.4.0",
50-
"linguist-languages": "^7.27.0",
50+
"linguist-languages": "^7.29.0",
5151
"lodash": "^4.17.21",
5252
"prettier": "^3.2.4",
5353
"prettier-plugin-autocorrect": "workspace:*",

‎pnpm-lock.yaml‎

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

‎scripts/languages.ts‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ const EXTRA_SH_LANGUAGES: SupportLanguage[] = [
3636
},
3737
]
3838

39-
const getSupportLanguages = (
39+
const getSupportedLanguages = (
4040
parser: 'autocorrect' | 'sh' | 'sql' | 'toml',
4141
aceModes: string[],
42+
excludeNames?: string[],
4243
) =>
4344
Object.values(LinguistLanguages).reduce<SupportLanguage[]>(
4445
(
@@ -55,6 +56,9 @@ const getSupportLanguages = (
5556
if (!aceModes.includes('all') && !aceModes.includes(aceMode)) {
5657
return acc
5758
}
59+
if (excludeNames?.includes(name)) {
60+
return acc
61+
}
5862
acc.push({
5963
name,
6064
aceMode,
@@ -74,7 +78,7 @@ fs.writeFileSync(
7478
`import { SupportLanguage } from 'prettier'
7579
7680
export const languages = ${JSON.stringify(
77-
getSupportLanguages('autocorrect', ['all']),
81+
getSupportedLanguages('autocorrect', ['all']),
7882
null,
7983
2,
8084
)} as SupportLanguage[]`,
@@ -86,7 +90,15 @@ fs.writeFileSync(
8690
8791
export const languages = ${JSON.stringify(
8892
[
89-
...getSupportLanguages('sh', ['dockerfile', 'gitignore', 'sh']),
93+
...getSupportedLanguages(
94+
'sh',
95+
['dockerfile', 'gitignore', 'sh'],
96+
[
97+
// `ShellSession` includes both commands and output. We can't reliably
98+
// format the latter, so we exclude this language entirely.
99+
'ShellSession',
100+
],
101+
),
90102
...EXTRA_SH_LANGUAGES,
91103
],
92104
null,
@@ -99,7 +111,7 @@ fs.writeFileSync(
99111
`import { SupportLanguage } from 'prettier'
100112
101113
export const languages = ${JSON.stringify(
102-
[...getSupportLanguages('sql', ['sql', 'pgsql'])],
114+
[...getSupportedLanguages('sql', ['sql', 'pgsql'])],
103115
null,
104116
2,
105117
)} as SupportLanguage[]`,
@@ -110,7 +122,7 @@ fs.writeFileSync(
110122
`import { SupportLanguage } from 'prettier'
111123
112124
export const languages = ${JSON.stringify(
113-
[...getSupportLanguages('toml', ['toml'])],
125+
[...getSupportedLanguages('toml', ['toml'])],
114126
null,
115127
2,
116128
)} as SupportLanguage[]`,

0 commit comments

Comments
 (0)