Skip to content

Commit

Permalink
fix: 🐛 error when --extra-liners option passed at 1st argument
Browse files Browse the repository at this point in the history
  • Loading branch information
shufo committed Aug 11, 2023
1 parent 878d5e0 commit de46752
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ $ blade-formatter -c -d resources/**/*.blade.php
--sort-html-attributes Sort HTML attributes. [string] [choices: "none", "alphabetical", "code-guide", "idiomatic", "vuejs", "custom"] [default: none]
--custom-html-attributes-order Comma separated custom HTML attributes order. To enable this you must specify sort html attributes option as `custom`. You can use regex for attribute names. [string] [default: null]
--no-single-quote Use double quotes instead of single quotes for php expression. [boolean] [default: false]
--extra-liners Comma separated list of tags that should have an extra newline before them. [string] (default: ['head', 'body', '/html'])
-E, --extra-liners Comma separated list of tags that should have an extra newline before them. [string] [default: "head,body,/html"]
--no-multiple-empty-lines Merge multiple blank lines into a single blank line [boolean] [default: false]
--no-php-syntax-check Disable PHP sytnax checking [boolean] [default: false]
-p, --progress Print progress [boolean] [default: false]
Expand Down
10 changes: 7 additions & 3 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,13 @@ export default async function cli() {
.option('extra-liners', {
alias: 'E',
type: 'string',
description:
'Comma separated list of tags that should have an extra newline before them (defaults to [head,body,/html]).',
default: null,
description: 'Comma separated list of tags that should have an extra newline before them.',
default: 'head,body,/html',
nullable: true,
coerce(formats) {
// Make sure we support comma-separated syntax: --extra-liners head,body
return _.flatten(_.flatten([formats]).map((format) => format.split(',')));
},
})
.option('no-multiple-empty-lines', {
type: 'boolean',
Expand Down
4 changes: 3 additions & 1 deletion src/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ export default class Formatter {
indent_inner_html: util.optional(this.options).indentInnerHtml || false,
end_with_newline: util.optional(this.options).endWithNewline || true,
max_preserve_newlines: util.optional(this.options).noMultipleEmptyLines ? 1 : undefined,
extra_liners: util.optional(this.options).extraLiners || ['head', 'body', '/html'],
extra_liners: util.optional(this.options).extraLiners,
css: {
end_with_newline: false,
},
Expand Down Expand Up @@ -1937,6 +1937,7 @@ export default class Formatter {
wrap_attributes: util.optional(this.options).wrapAttributes || 'auto',
wrap_attributes_min_attrs: util.optional(this.options).wrapAttributesMinAttrs,
indent_inner_html: util.optional(this.options).indentInnerHtml || false,
extra_liners: util.optional(this.options).extraLiners,
indent_with_tabs: useTabs,
end_with_newline: false,
templating: ['php'],
Expand Down Expand Up @@ -2046,6 +2047,7 @@ export default class Formatter {
wrap_attributes: util.optional(this.options).wrapAttributes || 'auto',
wrap_attributes_min_attrs: util.optional(this.options).wrapAttributesMinAttrs,
indent_inner_html: util.optional(this.options).indentInnerHtml || false,
extra_liners: util.optional(this.options).extraLiners,
end_with_newline: false,
templating: ['php'],
};
Expand Down
10 changes: 9 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,15 @@ class BladeFormatter {

try {
const options = await readRuntimeConfig(configFile);
this.options = _.merge(this.options, options);

this.options = _.mergeWith(this.options, options, (obj, src) => {
if (!_.isNil(src)) {
return src;
}

return obj;
});

this.runtimeConfigCache = this.options;

if (this.options.sortTailwindcssClasses) {
Expand Down
2 changes: 1 addition & 1 deletion src/runtimeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export async function readRuntimeConfig(filePath: string | null): Promise<Runtim
noMultipleEmptyLines: { type: 'boolean', nullable: true },
noPhpSyntaxCheck: { type: 'boolean', nullable: true },
noSingleQuote: { type: 'boolean', nullable: true },
extraLiners: { type: 'array', nullable: true, items: { type: 'string' }, default: [] },
extraLiners: { type: 'array', nullable: true, items: { type: 'string' }, default: ['head', 'body', '/html'] },
},
additionalProperties: true,
};
Expand Down

0 comments on commit de46752

Please sign in to comment.