Skip to content

Enable disallow patterns to match as/show/hide clauses in import directives #3

@fujidaiti

Description

@fujidaiti

Example use cases

Always use the prefix 'math' for dart:math

When using the dart:math library, we should always use the prefix 'math' for imports.

rules:
  - target: "**"
    disallow: dart:math
    exclude_disallow: { path: dart:math, as: math } # <---- NEW SYNTAX
    reason: Always use the prefix 'math' for dart:math.
import 'dart:math'; // Not allowed
import 'dart:math' as m; // Not allowed
import 'dart:math' as math; // Allowed

Enforce the use of a custom logger instead of the built-in log function

rules:
  - target: "**"
    exclude_target: lib/common/logger.dart
    disallow: dart:developer
    exclude_disallow: { path: dart:developer, hide: log } # <----- NEW SYNTAX
    reason: |
      Always use lib/common/logger.dart instead of the built-in log function. 
      If you need to import dart:developer, try hiding the log function from the import.
// lib/main.dart

import 'dart:developer'; // Not allowed
import 'dart:developer' as dev; // Not allowed
import 'dart:developer' hide log; // Allowed
// lib/common/logger.dart

import 'dart:developer'; // Exceptionally allowed

class Logger {
  void info(String message) {
    log('[$DateTime.now().toIso8601String()] $message');
  }
}

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions