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

Disable Header Should Prevent Any Extra Output #706

Open
TheMaverickProgrammer opened this issue Apr 29, 2024 · 5 comments
Open

Disable Header Should Prevent Any Extra Output #706

TheMaverickProgrammer opened this issue Apr 29, 2024 · 5 comments

Comments

@TheMaverickProgrammer
Copy link

Dart SDK version: 3.0.4 (stable) (Wed Jun 7 14:55:32 2023 +0000) on "windows_x64"

I'm using a custom builder to generate JSON from some annotations used in another program. You can think of it like Protobuf. This is working fine but I was surprised that using a header value of an empty string still produced the auto-generated message in the output .json file, which is not compliant to the .json spec. My work-around at the moment is just to trim the file contents after the last line but it seems counter-intuitive to have to do this at all.

Example:

Builder yarnJsonBuilder(BuilderOptions options) => LibraryBuilder(
    YarnGenerator(),
    generatedExtension: '.yarn.json',
    formatOutput: (code) => code
        .split(
            r'// **************************************************************************')
        .last
        .trim(),
    header: '');

// ...
@jakemac53
Copy link
Contributor

jakemac53 commented Apr 29, 2024

This package is only intended for generating Dart files from Dart files, and it assumes it is safe to put Dart comments in the code. These comments are meant to separate the sections of the file generated from different generators, and tell you which generator produced the following output, which is different from the header which just goes at the top of the file.

@TheMaverickProgrammer
Copy link
Author

I'd kindly request to consider emphasizing the exclusivity with dartlang then because the fact source_gen can support many output file extensions (and not just dart/part files), plus the way the docs were worded, led me to think it could be used to generate anything we wanted and not just Dart source files.

Otherwise, it works great. Thank you for helping me.

@jakemac53
Copy link
Contributor

Fwiw it would likely be quite possible to support your use case as well (maybe all you need is some option to not output these comments). I was more just trying to explain what was happening, based on the Dart->Dart assumptions, than shutting the door entirely on this use case :).

It isn't likely something we could prioritize at this time, so you might be best served just forking the package for the time being. Or, you could work on a pull request. We do require tests etc for pull requests though so keep in mind that it would be more work than just the actual feature implementation.

@TheMaverickProgrammer
Copy link
Author

Roger. I assume these are the minimal necessary steps:
https://github.com/dart-lang/sdk/blob/main/CONTRIBUTING.md

Leaving this here to reference for myself.

@jakemac53
Copy link
Contributor

https://github.com/dart-lang/sdk/blob/main/CONTRIBUTING.md

Working in the SDK is a lot more complicated than this repo. Our CONTRIBUTING.md is pretty boilerplatey so it doesn't have much useful information (other than the info about the CLA). But, you can develop this repo just like any other git repo, no special steps.

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