From 9a370a7f0f64463549cf8877c8bbe7ceb7cd5833 Mon Sep 17 00:00:00 2001 From: Shuhei Hayashibara Date: Sat, 22 Jul 2023 19:37:49 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20add=20option=20`--wrap-a?= =?UTF-8?q?ttributes-min-attrs`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 5 +++-- src/cli.ts | 6 ++++++ src/formatter.ts | 3 +++ src/main.ts | 1 + src/runtimeConfig.ts | 2 ++ 5 files changed, 15 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6b5f8864..cf0304af 100755 --- a/README.md +++ b/README.md @@ -181,6 +181,7 @@ $ blade-formatter -c -d resources/**/*.blade.php --wrap-line-length, --wrap The length of line wrap size [default: 120] --wrap-attributes, --wrap-atts The way to wrap attributes. [auto|force|force-aligned|force-expand-multiline|aligned-multiple|preserve|preserve-aligned] [string] [default: "auto"] + -M, --wrap-attributes-min-attrs Minimum number of html tag attributes for force wrap attribute options. Wrap the first attribute only if 'force-expand-multiline' is specified in wrap attributes [default: "2"] --sort-tailwindcss-classes Sort tailwindcss classes [boolean] [default: false] --tailwindcss-config-path Specify path of tailwind config [string] [default: null] --sort-html-attributes Sort HTML attributes. [string] [choices: "none", "alphabetical", "code-guide", "idiomatic", "vuejs", "custom"] [default: none] @@ -347,7 +348,7 @@ SyntaxError: Unexpected token 'export' then you should check your nodejs module type is matched with `tailwindcss.config.js`. -### ESM +### ESM `package.json` @@ -363,7 +364,7 @@ export default { } ``` -### CommonJS +### CommonJS `tailwind.config.js` diff --git a/src/cli.ts b/src/cli.ts index e9093892..0340d54d 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -68,6 +68,12 @@ export default async function cli() { description: `The way to wrap attributes.\n[auto|force|force-aligned|force-expand-multiline|aligned-multiple|preserve|preserve-aligned]`, default: 'auto', }) + .option('wrap-attributes-min-attrs', { + type: 'integer', + alias: 'M', + description: `Minimum number of html tag attributes for force wrap attribute options. Wrap the first attribute only if 'force-expand-multiline' is specified in wrap attributes`, + default: '2', + }) .option('sort-tailwindcss-classes', { alias: 'sort-classes', type: 'boolean', diff --git a/src/formatter.ts b/src/formatter.ts index f8291ca9..294aed70 100644 --- a/src/formatter.ts +++ b/src/formatter.ts @@ -244,6 +244,7 @@ export default class Formatter { indent_size: util.optional(this.options).indentSize || 4, wrap_line_length: util.optional(this.options).wrapLineLength || 120, wrap_attributes: util.optional(this.options).wrapAttributes || 'auto', + wrap_attributes_min_attrs: util.optional(this.options).wrapAttributesMinAttrs, end_with_newline: util.optional(this.options).endWithNewline || true, max_preserve_newlines: util.optional(this.options).noMultipleEmptyLines ? 1 : undefined, css: { @@ -1932,6 +1933,7 @@ export default class Formatter { indent_size: util.optional(this.options).indentSize || 4, wrap_line_length: util.optional(this.options).wrapLineLength || 120, wrap_attributes: util.optional(this.options).wrapAttributes || 'auto', + wrap_attributes_min_attrs: util.optional(this.options).wrapAttributesMinAttrs, indent_with_tabs: useTabs, end_with_newline: false, templating: ['php'], @@ -2039,6 +2041,7 @@ export default class Formatter { indent_size: util.optional(this.options).indentSize || 4, wrap_line_length: util.optional(this.options).wrapLineLength || 120, wrap_attributes: util.optional(this.options).wrapAttributes || 'auto', + wrap_attributes_min_attrs: util.optional(this.options).wrapAttributesMinAttrs, end_with_newline: false, templating: ['php'], }; diff --git a/src/main.ts b/src/main.ts index e6d089b4..51b25b15 100644 --- a/src/main.ts +++ b/src/main.ts @@ -34,6 +34,7 @@ export type FormatterOption = { indentSize?: number; wrapLineLength?: number; wrapAttributes?: WrapAttributes; + wrapAttributesMinAttrs?: number; endWithNewline?: boolean; endOfLine?: EndOfLine; useTabs?: boolean; diff --git a/src/runtimeConfig.ts b/src/runtimeConfig.ts index 00063f68..1592b29b 100644 --- a/src/runtimeConfig.ts +++ b/src/runtimeConfig.ts @@ -22,6 +22,7 @@ export interface RuntimeConfig { indentSize?: number; wrapLineLength?: number; wrapAttributes?: WrapAttributes; + wrapAttributesMinAttrs?: number; endWithNewline?: boolean; endOfLine?: EndOfLine; useTabs?: boolean; @@ -76,6 +77,7 @@ export async function readRuntimeConfig(filePath: string | null): Promise