Skip to content

Commit

Permalink
feat: 🎸 add option --wrap-attributes-min-attrs
Browse files Browse the repository at this point in the history
  • Loading branch information
shufo committed Jul 22, 2023
1 parent bc1775e commit 9a370a7
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 2 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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`
Expand All @@ -363,7 +364,7 @@ export default {
}
```
### CommonJS
### CommonJS
`tailwind.config.js`
Expand Down
6 changes: 6 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
3 changes: 3 additions & 0 deletions src/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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'],
Expand Down Expand Up @@ -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'],
};
Expand Down
1 change: 1 addition & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export type FormatterOption = {
indentSize?: number;
wrapLineLength?: number;
wrapAttributes?: WrapAttributes;
wrapAttributesMinAttrs?: number;
endWithNewline?: boolean;
endOfLine?: EndOfLine;
useTabs?: boolean;
Expand Down
2 changes: 2 additions & 0 deletions src/runtimeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface RuntimeConfig {
indentSize?: number;
wrapLineLength?: number;
wrapAttributes?: WrapAttributes;
wrapAttributesMinAttrs?: number;
endWithNewline?: boolean;
endOfLine?: EndOfLine;
useTabs?: boolean;
Expand Down Expand Up @@ -76,6 +77,7 @@ export async function readRuntimeConfig(filePath: string | null): Promise<Runtim
],
nullable: true,
},
wrapAttributesMinAttrs: { type: 'integer', nullable: true, default: 2 },
endWithNewline: { type: 'boolean', nullable: true },
endOfLine: { type: 'string', enum: ['LF', 'CRLF'], nullable: true },
useTabs: { type: 'boolean', nullable: true },
Expand Down

0 comments on commit 9a370a7

Please sign in to comment.