diff --git a/.changeset/breezy-bags-provide.md b/.changeset/breezy-bags-provide.md new file mode 100644 index 00000000..7867aeaf --- /dev/null +++ b/.changeset/breezy-bags-provide.md @@ -0,0 +1,5 @@ +--- +"prettier-plugin-sh": minor +--- + +feat: `switchCaseIndent` and `spaceRedirects`'s default value has been changed to be `true` diff --git a/.changeset/pretty-numbers-dance.md b/.changeset/pretty-numbers-dance.md new file mode 100644 index 00000000..ef59ffc2 --- /dev/null +++ b/.changeset/pretty-numbers-dance.md @@ -0,0 +1,5 @@ +--- +"prettier-plugin-sh": minor +--- + +feat: declare all possible options for plugin-sh diff --git a/.changeset/sweet-students-end.md b/.changeset/sweet-students-end.md new file mode 100644 index 00000000..94685d9b --- /dev/null +++ b/.changeset/sweet-students-end.md @@ -0,0 +1,6 @@ +--- +"prettier-plugin-pkg": minor +"prettier-plugin-sql": minor +--- + +chore: rebuild via esbuild, update node lts version diff --git a/packages/sh/src/index.ts b/packages/sh/src/index.ts index a8cc6170..50ba58c1 100644 --- a/packages/sh/src/index.ts +++ b/packages/sh/src/index.ts @@ -1,5 +1,11 @@ import sh, { LangVariant, Node, Pos } from 'mvdan-sh' -import { AstPath, ParserOptions, Plugin, RequiredOptions } from 'prettier' +import { + IntSupportOption, + ParserOptions, + PathSupportOption, + Plugin, + RequiredOptions, +} from 'prettier' import { languages } from './languages' @@ -21,7 +27,7 @@ export interface ShOptions extends RequiredOptions { functionNextLine: boolean } -export type ShParserOptions = ParserOptions & ShOptions +export type ShParserOptions = ParserOptions & ShOptions export interface ShParseError { Filename: string @@ -31,8 +37,7 @@ export interface ShParseError { Error(): void } -export default { - name: 'prettier-plugin-sh', +const ShPlugin: Plugin = { languages, parsers: { sh: { @@ -66,21 +71,21 @@ export default { } }, astFormat: 'sh', - locStart: (node: Node) => node.Pos().Offset(), - locEnd: (node: Node) => node.End().Offset(), + locStart: node => node.Pos().Offset(), + locEnd: node => node.End().Offset(), }, }, printers: { sh: { print: ( - path: AstPath, + path, { useTabs, tabWidth, indent = useTabs ? 0 : tabWidth, binaryNextLine = true, - switchCaseIndent, - spaceRedirects, + switchCaseIndent = true, + spaceRedirects = true, keepPadding, minify, functionNextLine, @@ -99,4 +104,106 @@ export default { .Print(path.getValue()), }, }, -} as Plugin + options: { + keepComments: { + since: '0.1.0', + category: 'Output', + type: 'boolean', + default: true, + description: + 'KeepComments makes the parser parse comments and attach them to nodes, as opposed to discarding them.', + }, + stopAt: { + since: '0.1.0', + category: 'Config', + type: 'path', + description: [ + 'StopAt configures the lexer to stop at an arbitrary word, treating it as if it were the end of the input. It can contain any characters except whitespace, and cannot be over four bytes in size.', + 'This can be useful to embed shell code within another language, as one can use a special word to mark the delimiters between the two.', + 'As a word, it will only apply when following whitespace or a separating token. For example, StopAt("$$") will act on the inputs "foo $$" and "foo;$$", but not on "foo \'$$\'".', + 'The match is done by prefix, so the example above will also act on "foo $$bar".', + ].join('\n'), + } as PathSupportOption, + variant: { + since: '0.1.0', + category: 'Config', + type: 'choice', + default: undefined, + choices: [ + { + value: 0, // LangVariant.LangBash, + description: 'Bash', + }, + { + value: 1, // LangVariant.LangPOSIX, + description: 'POSIX', + }, + { + value: 2, // LangVariant.LangMirBSDKorn, + description: 'MirBSDKorn', + }, + ], + description: + 'Variant changes the shell language variant that the parser will accept.', + }, + indent: { + since: '0.1.0', + category: 'Format', + type: 'int', + description: + 'Indent sets the number of spaces used for indentation. If set to 0, tabs will be used instead.', + } as IntSupportOption, + binaryNextLine: { + since: '0.1.0', + category: 'Output', + type: 'boolean', + default: true, + description: + 'BinaryNextLine will make binary operators appear on the next line when a binary command, such as a pipe, spans multiple lines. A backslash will be used.', + }, + switchCaseIndent: { + since: '0.1.0', + category: 'Format', + type: 'boolean', + default: true, + description: + 'SwitchCaseIndent will make switch cases be indented. As such, switch case bodies will be two levels deeper than the switch itself.', + }, + spaceRedirects: { + since: '0.1.0', + category: 'Format', + type: 'boolean', + default: true, + description: + "SpaceRedirects will put a space after most redirection operators. The exceptions are '>&', '<&', '>(', and '<('.", + }, + keepPadding: { + since: '0.1.0', + category: 'Format', + type: 'boolean', + default: false, + description: [ + 'KeepPadding will keep most nodes and tokens in the same column that they were in the original source. This allows the user to decide how to align and pad their code with spaces.', + 'Note that this feature is best-effort and will only keep the alignment stable, so it may need some human help the first time it is run.', + ].join('\n'), + }, + minify: { + since: '0.1.0', + category: 'Output', + type: 'boolean', + default: false, + description: + 'Minify will print programs in a way to save the most bytes possible. For example, indentation and comments are skipped, and extra whitespace is avoided when possible.', + }, + functionNextLine: { + since: '0.1.0', + category: 'Format', + type: 'boolean', + default: false, + description: + "FunctionNextLine will place a function's opening braces on the next line.", + }, + }, +} + +export default ShPlugin diff --git a/packages/sql/src/index.ts b/packages/sql/src/index.ts index 1eff27e3..da61d2ef 100644 --- a/packages/sql/src/index.ts +++ b/packages/sql/src/index.ts @@ -58,7 +58,7 @@ const SqlPlugin: Plugin = { options: { formatter: { since: '0.1.0', - category: 'Format', + category: 'Config', type: 'choice', default: SQL_FORMATTER, description: 'Choose which formatter to be used', @@ -136,7 +136,7 @@ const SqlPlugin: Plugin = { }, linesBetweenQueries: { since: '0.1.0', - category: 'Output', + category: 'Format', type: 'int', default: 2, description: