google / google/json_serializable.dart

Support configurable line length (page width) for generated files

Open
#1,530 1 comment 0 reactions 0 assignees View on GitHub
State: blocked
Dominant language
Dart
Stars
1.6k
Forks
461
Avg merge
45m
Merged PRs (30d)
1

Description

**Issue**

Currently, json_serializable generates Dart files using a fixed default line length of 80 characters. This value is hard-coded in the code generation process, and there is no way to configure it via build.yaml, annotations, or any other mechanism.

However, many projects and organizations follow their own internal code formatting standards for instance, using a wider or narrower line length (e.g., 100, 120, or 150 characters). Since the generated files are formatted at a fixed width, these projects have to manually reformat generated code after each build or live with inconsistent formatting between generated and manually written code.

This limitation reduces developer productivity, clutters diffs, and introduces noise in version control systems when automated formatters re-wrap the generated code.

**Proposal**

Add support for configurable line length (page width) for generated files.

This could be implemented by introducing a configuration option, such as:

```yaml
# build.yaml
targets:
$default:
builders:
json_serializable:
options:
line_length: 120

```

Alternatively, the configuration could also be exposed through a JsonSerializable annotation parameter for finer control per file/class:
```dart
@JsonSerializable(lineLength: 120)
class Example { ... }
```

This change would:
1. Improve integration with custom formatter settings and organizational code style guides.
2. Avoid redundant diffs caused by formatter rewrites.
3. Allow teams to align generated code with their overall formatting standards.

If accepted, I’d be happy to help with a PR implementing this feature.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.