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

makes generated imports look more normal #298

Merged
merged 3 commits into from
Nov 10, 2022
Merged

Conversation

dimitropoulos
Copy link
Contributor

The rationale for this change is that we should take the opportunity, when it arises, to make generated code look natural and typical (if possible). While this isn't a logical change, it's hopefully worthwhile in the pursuit of making the generated outputs feel more normal.

Here's an example:

- import {Message, proto3} from "@bufbuild/protobuf";
+ import { Message, proto3 } from "@bufbuild/protobuf";

Note that this falls in line with Prettier's default as well. In fact, that's how I found it. I was generating code and trying to aim for a final output that matched prettier's default formatting and this was the only thing that I wasn't able to make match as a downstream consumer of protobuf-es.

by searching for:
```
import( type)? \{(\S)(.*)(\S)\}
```

and replacing with
```
import$1 { $2$3$4 }
```
Copy link
Member

@timostamm timostamm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the diligent update, including the docs ❤️

Looks like we missed the single mjs file in the formatter setup. Do you mind fixing it while you're at it?

packages/protobuf-bench/report.mjs Show resolved Hide resolved
@dimitropoulos dimitropoulos merged commit 049cb9e into main Nov 10, 2022
@dimitropoulos dimitropoulos deleted the dimitri/imports branch November 10, 2022 21:56
@smaye81 smaye81 mentioned this pull request Nov 23, 2022
smaye81 added a commit that referenced this pull request Nov 23, 2022
This release includes the following:

## Enhancements
* Add a toJSON method to messages by @smaye81 in #306
* Add an unpack function to `google.protobuf.Any` by @smaye81 in #303
* Make generated imports look more normal by @dimitropoulos in #298
⚠️ Note that as a result of this PR, import statements in your
generated code will contain diffs when generated with `v0.3.0` as the
import statements will have spaces added. For example:
   ```diff
   - import {FooMessage} from './foo_message_pb.js';
   + import { FooMessage } from './foo_message_pb.js';
   ```
* Add print function with tagged template literal by @yukukotani in #279
* Enhance the `Any.is` function by @smaye81 in #294
* Make wrappers more lenient by @timostamm in #291

## Bugfixes
* Fix map equality by @calebdoxsey in #305
* Make `tsNocheck` work correctly by @yukukotani in #275

## New Contributors
@calebdoxsey made their first contribution in #305
@yukukotani made their first contributions in #275 and #279
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

Successfully merging this pull request may close these issues.

2 participants