Skip to content

feat: add include_library option for unnecessary_library_directive rule#14

Merged
BreX900 merged 1 commit intoBreX900:masterfrom
riscait:add-include-library-setting
Jun 2, 2025
Merged

feat: add include_library option for unnecessary_library_directive rule#14
BreX900 merged 1 commit intoBreX900:masterfrom
riscait:add-include-library-setting

Conversation

@riscait
Copy link
Copy Markdown
Contributor

@riscait riscait commented May 31, 2025

Summary

Add include_library option to control whether the library directive is included in generated barrel files.

Background

This addresses the unnecessary_library_directive lint rule that flags library directives as unnecessary in modern Dart. Some projects prefer to omit library directives entirely from their barrel files.

Changes

  • ✅ Add include_library boolean field to LibrarySettings (defaults to true)
  • ✅ When include_library: false, both library directive and docs are omitted (docs are library-specific documentation)
  • ✅ Add comprehensive test coverage for the new functionality
  • ✅ Update README with usage examples and documentation

Usage

index_generator:
  libraries:
    - directory_path: lib
      include_library: false  # Omit library directive
    - directory_path: src
      include_library: true   # Include library directive (default)
      name: my_library

Generated Output Examples

With include_library: true (default behavior)

// GENERATED CODE - DO NOT MODIFY BY HAND

/// Library documentation
library my_library;

export 'file1.dart';
export 'file2.dart';

With include_library: false

// GENERATED CODE - DO NOT MODIFY BY HAND

export 'file1.dart';
export 'file2.dart';

Backward Compatibility

  • ✅ Fully backward compatible - defaults to true to maintain existing behavior
  • ✅ No breaking changes to existing configurations

Testing

  • ✅ Unit tests for LibrarySettings default values
  • ✅ All existing tests pass

@BreX900 BreX900 merged commit c5e42e7 into BreX900:master Jun 2, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants