Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to override header formatting #612

Closed
jbarreiros opened this issue Apr 27, 2021 · 3 comments
Closed

Unable to override header formatting #612

jbarreiros opened this issue Apr 27, 2021 · 3 comments

Comments

@jbarreiros
Copy link
Contributor

jbarreiros commented Apr 27, 2021

Hi, messing around with the latest 3.0-rc.8 release.

Creating a custom format that will output some HTML to be included in a project as a Twig file. In Twig, comments look like:

{# I'm a comment #}

The full header would be expected to look like:

{#
    Do not edit directly
    Generated on [date]
#}

The issue I'm noticing is that the fileHeader() function accepts a formatting option, but it appears to ultimately be ignored.

For example:

// myCustomFormat.js
const header = fileHeader({ file, formatting: { prefix: '  ', header: '{#', footer: '#}' } });

The current logic appears to always overwrite the prefix, header and footer properties.

@jbarreiros
Copy link
Contributor Author

I'm open to creating an MR, but wasn't sure my idea for fixing this is all that great. The only thing I can think of is:

let {prefix, lineSeparator, header, footer} = Object.assign({}, defaultFormatting);

if (/* formattting object is not empty */) {
   let {prefix, lineSeparator, header, footer} = Object.assign({}, defaultFormatting, formatting);
   // The potentially annoying part here is that "header" and "footer" probably need to include
   // lineSeparator in their value. E.g. "footer: '\nEND\n'"
} else {
   // existing logic
}

@dbanksdesign
Copy link
Member

Good catch. Sloppy logic on my part, and also lack of unit tests... Let me know your thoughts on #614. I just moved the default formatting options to the defaultFormatting object and removed the final else. Now it works as you would expect, but I might be missing a use case or something...

dbanksdesign added a commit that referenced this issue May 3, 2021
Fixes #612 
Formatting options in the `fileHeader` format helper function were being overridden by the default formatting options.
@dbanksdesign
Copy link
Member

This is now fixed and released in 3.0.0-rc.9! I added a test with your use-case to make sure it worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants