Skip to content

Don't require "part file.*.dart" for files in the same directory with the same base name. #60018

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

Open
tylandercasper opened this issue Jan 30, 2025 · 2 comments
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). type-enhancement A request for a change that isn't a bug

Comments

@tylandercasper
Copy link

tylandercasper commented Jan 30, 2025

The problem is that having to manually add "part 'file.g.dart';" to get code generators to work is error prone, confusing and adds even more boiler plate to a simple file.

A similar issue: #60016 got shot down because having to scan every file to see if it's linked to another file would be to expensive.

A good compromise would be to keep the part directive for arbitrary files, but also treating any group of files with a common basename in the same directory as a single shared library. (Basically implicit 'part file')

so
basename.dart
basename.g.dart
basename.freezed.dart
basename.customusercode.dart

would automatically be processed the same as if
basename.dart had "part ..." for each of the extra files.

This gives us the advantage of cleaned up code, but also doesn't add any extra processing time to build runner.

@dart-github-bot
Copy link
Collaborator

Summary: Users find manually adding part directives tedious and error-prone. Proposed solution: automatically include files with the same basename in the same directory, simplifying code generation.

@dart-github-bot dart-github-bot added legacy-area-analyzer Use area-devexp instead. triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. type-enhancement A request for a change that isn't a bug labels Jan 30, 2025
@tylandercasper tylandercasper changed the title Assume "part file.*.dart" for files in the same directory with the same base name. Implicit "part file.*.dart" for files in the same directory with the same base name. Jan 30, 2025
@tylandercasper tylandercasper changed the title Implicit "part file.*.dart" for files in the same directory with the same base name. Don't require "part file.*.dart" for files in the same directory with the same base name. Jan 30, 2025
@lrhn
Copy link
Member

lrhn commented Jan 31, 2025

So a library can choose to say:

library with "subdir/";
...

and then every file in subdir/ is considered a part file of the current file. (Usual rules preventing the same file from being part of more than one library.)

Maybe only every .dart file, but the language has so far not enforced any naming for files, that's just tradition.

Alternatively, library with "basename_"; where all files starting with basename_ in the current directory are parts of the current file.

Might become tricky with when parts can have parts too, but I guess reversed order prefixing can work.
Main library has library of "basename_";, and the basename_part1.dart has part of "basename.dart" with "part1_basename_"; to specify its parts. Should be unique enough.

Can combine the two, library with "parts/basename_"; includes all the files in parts/ starting withbasename_.

I'm definitely sure I don't like including files without saying anything in the file itself. Too fragile and accidental.
Saying very little and having some "*.dart" logic might make sense.
Still potentially error-prone, especially if it can include non-.dart files.

The part file itself would still need to have a part of '../basename.dart directive.

@lrhn lrhn added area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). and removed legacy-area-analyzer Use area-devexp instead. triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. labels Feb 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

3 participants