-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Labels
P3A lower priority bug or feature requestA lower priority bug or feature requestarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.devexp-linterIssues with the analyzer's support for the linter packageIssues with the analyzer's support for the linter packagelinter-lint-proposallinter-status-pendingtype-enhancementA request for a change that isn't a bugA request for a change that isn't a bug
Description
bin_files_must_export_main
Could also be called:
no_libraries_in_binexecutable_without_main
Description
Dart files in bin/ should export a main function that can serve as entrypoint for an executable.
Details
Files in the bin/ folder can be executed using dart run in your package, or any package that has a dependency on your package. Private scripts should be placed in tool/ and private libraries should be placed in lib/src/.
See package layout conventions.
Kind
This aims to guard against errors.
Bad Examples
# bin/foo.dart
const myFoo = 42;Good Examples
# bin/foo.dart
void main() {
print('hello world');
}or
# bin/foo.dart
// You can export 'main' from a library, that's okay too.
export 'package:foo/src/foo.dart' show main;Discussion
dart run foowill runbin/foo.dartfrompackage:foo(requires thatpackage :foois either a dependency or the name of the root package).dart run foo:barwill runbin/bar.dartfrompackage:foo.dart pub global run foowill runbin/foo.dartfrompackage:foo.- The
executablessection inpubspec.yamloffers the creation of binstubs for files inbin/. - pana will assign packages with files in
bin/ashas:executable.
It could be argued that this lint should only be enabled for packages that have a version and doesn't feature publish_to: none in the pubspec.yaml.
Though, there is no reason for other packages / apps to put libraries in bin/, this folder should be reserved for executables.
Motiviation
- Package layout convention
has:executablesearch tag on pub.dev- This is granted by pana analysis.
- We want packages that match this tag to have executable files in
bin/. - We could make a check for this in pana, and score on this basis. But it's probably better UX to give a lint directly in the editor. That way authors will know it sooner rather than later.
sigurdm, srawlins and isoos
Metadata
Metadata
Assignees
Labels
P3A lower priority bug or feature requestA lower priority bug or feature requestarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.devexp-linterIssues with the analyzer's support for the linter packageIssues with the analyzer's support for the linter packagelinter-lint-proposallinter-status-pendingtype-enhancementA request for a change that isn't a bugA request for a change that isn't a bug