Skip to content

Support configurable line length (page width) for generated files #1530

@yashj6294

Description

@yashj6294

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:

# 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:

@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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions