Skip to content

proposal: unnecessary_library_directive  #58870

Closed
dart-archive/linter
#3791
@kevmoo

Description

@kevmoo

unnecessary_library_directive

Description

The library directive at the top of...libraries...is generally superfluous – UNLESS it's used to "anchor" a doc comment or an annotation (see #58871).

The use of the "naked" library directives should be avoided.

Details

Not much more than the description.

Kind

Style

Good Examples

// Notice no library directive – not needed!

void main() {}
// Doc comments and/or annotations are a good reason to still use the library directive

/// This is a cool test library
@TestOn('vm')
library; // assuming https://github.com/dart-lang/language/issues/1073 lands with support for no-name library directives

void main() {...}

Bad Examples

// The library directive accomplishes NOTHING!

library pointless.library.here;

void main() {}

Discussion

See dart-lang/language#1073 for the no-name library directive proposal.

Would "conflict" with the following lints. No point in enforcing conventions for names when we want to avoid library directives!

This could likely be added to Effective Dart, I think.

Discussion checklist

  • List any existing rules this proposal modifies, complements, overlaps or conflicts with.
  • List any relevant issues (reported here, the SDK Tracker, or elsewhere).
  • If there's any prior art (e.g., in other linters), please add references here.
  • If this proposal corresponds to Effective Dart or Flutter Style Guide advice, please call it out. (If there isn’t any corresponding advice, should there be?)
  • If this proposal is motivated by real-world examples, please provide as many details as you can. Demonstrating potential impact is especially valuable.

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