-
Notifications
You must be signed in to change notification settings - Fork 131
Make generated files // swift-format-ignore #738
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
Comments
Sounds good. Are we happy for it to be behind a config option for those that do want to include the generated files in their format? |
This is probably the better solution although we could have something in the meanwhile. |
I agree that swift-format would benefit from ignore support in its own config file. You’re right that the reusable GitHub workflows have support for this already, but I don’t think we can expect that all adopters use these. @weissi presumably you don’t use the reusable script since you filed the issue? |
Correct, not using those. I'm fine with a configuration option to turn on/off |
That'd be fine with me, I'd just make sure it's not tied to swift-format. Maybe a "top-level-comments" property, then users can specify "swift-format-ignore". |
@MahdiBM wrote:
I'm less inclined to make this super generalisable. Seems like an odd thing for folks to be inserting arbitrary things at the top of the generated file and, while I would be sympathetic to not wanting to over-index on one tool if we had an ecosystem of tens of linters, Sounds like @FranzBusch agrees (#738 (comment)) and if Swift Protobuf is doing this, then I'm inclined for us to. What do others think. I know I originally suggested we make this configurable but maybe we should just add the comment(s) unilaterally? Any objections? |
I wish See this about possibility of support for other formatters in sourcekit-lsp. |
If we're really against just hardcoding it, then I guess an additionalFileComments:
- "swift-format-ignore-file"
- "swiftlint:disable all"
- "mumble mumble mumble" // swift-format-ignore-file
// swiftlint:disable all
// mumble mumble mumble We haven't had many requests for it, so as long as there's a way to it, for those that want it, I'm pretty flexible on how. |
Users want the ability to add custom comments to generated files. One concrete use case is adding directives like `swift-format-ignore-file` and `swiftlint:disable all` to prevent these tools from processing generated code. - Added `additionalFileComments` property to `Config` and `UserConfig` structs - Modified `FileTranslator` to include additional comments along with the do-not-edit comment - Added CLI support with `--additional-file-comment` option - Added config tests to confirm the option propagates and the default is empty - Added snippet tests to validate the actual rendering - Updated documentation with examples and usage instructions Users can now configure additional comments to be added to generated files using either the config file or a command line option. Fixes apple#738. - Added unit tests for `Config` - Added snippet tests for rendering - Manual tests of generator using config and CLI on real OpenAPI doc: ```console % swift run swift-openapi-generator generate openapi-documents/petstore.yaml \ --mode types \ --output-directory test-output-cli \ --additional-file-comment "hello world" \ --additional-file-comment "testing, testing, 1, 2, 3" Build of product 'swift-openapi-generator' complete! (3.27s) Swift OpenAPI Generator is running with the following configuration: - OpenAPI document path: /Users/Si/work/code/swift-openapi-workspace/packages/swift-openapi-generator/openapi-documents/petstore.yaml - Configuration path: <none> - Generator modes: types - Access modifier: internal - Naming strategy: defensive - Name overrides: <none> - Feature flags: <none> - Output file names: Types.swift - Output directory: /Users/Si/work/code/swift-openapi-workspace/packages/swift-openapi-generator/test-output-cli - Diagnostics output path: <none - logs to stderr> - Current directory: /Users/Si/work/code/swift-openapi-workspace/packages/swift-openapi-generator - Plugin source: <none> - Is dry run: false - Additional imports: <none> - Additional file comments: hello world, testing, testing, 1, 2, 3 Writing data to file Types.swift... % head -5 test-output-cli/Types.swift // Generated by swift-openapi-generator, do not modify. // hello world // testing, testing, 1, 2, 3 @_spi(Generated) import OpenAPIRuntime ```
Description
I have generated files & swift-format. I don't want the formatter to reformat the generated code though. So it'd be awesome if it could generate a line with
// swift-format-ignore
which will disable formatting for that file.Reproduction
N/a
Package version(s)
All
Expected behavior
No formatting
Environment
All
Additional information
No response
The text was updated successfully, but these errors were encountered: