You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
File.read(GENERATED_CODE_PATH).each_line do |line|
60
60
line.gsub!('\\', '\\\\\\\\')
@@ -100,59 +100,30 @@ end
100
100
101
101
## Guidelines for generated code
102
102
103
-
### Rust
103
+
Generally speaking, we aim to have generated code follow the same standards as handwritten code, except when doing so would add significant complexity to the code generator. Below are some additional language-specific considerations.
104
104
105
-
Generated Rust code should aim to follow the same [guidelines](#rust-style-guide) as handwritten code, with the possible exception of the line length limit.
105
+
### Rust
106
106
107
-
To ensure that generated code will pass Rust and [Clippy](https://github.com/rust-lang/rust-clippy) lint checks now and in the future, it disables the lint checks as follows:
107
+
Typical is designed to be invoked by a [Cargo build script](https://doc.rust-lang.org/cargo/reference/build-scripts.html). See the [example project](https://github.com/stepchowfun/typical/tree/main/examples/rust) for how to set that up. The user is expected to create a dedicated source file which locally disables lint checks for that file and then includes the generated code as follows:
However, our policy is that generated code should pass all checks in `clippy::all`, `clippy::pedantic`, and `warnings`, with the following exemptions:
114
-
115
-
```rust
116
-
#![allow(
117
-
clippy::cast_possible_truncation,
118
-
clippy::identity_op,
119
-
clippy::let_unit_value,
120
-
clippy::match_single_binding,
121
-
clippy::module_name_repetitions,
122
-
clippy::no_effect,
123
-
clippy::similar_names,
124
-
clippy::too_many_lines,
125
-
clippy::unit_arg,
126
-
clippy::useless_conversion,
127
-
dead_code,
128
-
unused_variables,
129
-
)]
130
-
```
131
-
132
-
This isn't currently enforced by any CI check. The list of exempt checks can be amended as needed to accommodate future developments, but such amendments must be justified.
133
111
134
-
To ensure that generated code doesn't cause code formatting checks to fail, the generated code also disables [Rustfmt](https://github.com/rust-lang/rustfmt) for all top-level constructs as follows:
135
-
136
-
```rust
137
-
#[rustfmt::skip]
112
+
include!(concat!(env!("OUT_DIR"), "/types.rs"));
138
113
```
139
114
140
-
Our policy is that generated code should be formatted in the same style as handwritten code when doing so doesn't add significant complexity to the code generator, although this is also not enforced by any CI check. The formatting of handwritten code is enforced by Rustfmt in a CI check.
115
+
Note that the [Rust integration test](https://github.com/stepchowfun/typical/tree/main/integration_tests/rust) disables specific checks rather than all of them to help us keep track of which checks we are violating.
141
116
142
117
### TypeScript
143
118
144
-
Generated Rust code should aim to follow the same standards as handwritten code, with the possible exception of the line length limit.
145
-
146
-
To ensure that generated code will pass [ESLint](https://eslint.org/) checks now and in the future, it disables ESLint as follows:
119
+
To ensure it will pass formatting checks now and in the future, the generated code should disable [Prettier](https://prettier.io/) for all top-level constructs as follows:
147
120
148
121
```typescript
149
-
//eslint-disable
122
+
//prettier-ignore
150
123
```
151
124
152
-
To ensure that generated code doesn't cause code formatting checks to fail, the it also disables [Prettier](https://prettier.io/)for all top-level constructs as follows:
125
+
To ensure it will pass lint checks now and in the future, the generated code should disable [ESLint](https://eslint.org/)at the file level as follows:
153
126
154
127
```typescript
155
-
//prettier-ignore
128
+
//eslint-disable
156
129
```
157
-
158
-
Our policy is that generated code should be formatted in the same style as handwritten code when doing so doesn't add significant complexity to the code generator, although this is also not enforced by any CI check. The formatting of handwritten code is enforced by Prettier in a CI check.
Refer to the [example Rust project](https://github.com/stepchowfun/typical/tree/main/examples/rust) for how to automate this with a [Cargo build script](https://doc.rust-lang.org/cargo/reference/build-scripts.html).
52
+
51
53
The client and server can then use the generated code to serialize and deserialize messages for mutual communication. If the client and server are written in different languages, you can generate code for each language.
52
54
53
55
Note that Typical only does serialization and deserialization. It has nothing to do with service meshes, encryption, authentication, or authorization, but it can be used together with those technologies.
To run this demonstration, first [install Typical](https://github.com/stepchowfun/typical#installation-instructions) and [Rust](https://www.rust-lang.org/tools/install) if you haven't already. Then run the following command in this directory:
4
+
5
+
```sh
6
+
cargo run
7
+
```
8
+
9
+
Note that you don't need to run Typical directly, since there's a [build script](https://github.com/stepchowfun/typical/blob/main/examples/rust/build.rs) that automates it for you.
0 commit comments