Skip to content

High performance self-hosted photo and video management solution.

6.0 KB
Raw Blame
# This file configures the analyzer, which statically analyzes Dart code to
# check for errors, warnings, and lints.
#
# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
# invoked from the command line by running `flutter analyze`.

# The following line activates a set of recommended lints for Flutter apps,
# packages, and plugins designed to encourage good coding practices.
include: package:flutter_lints/flutter.yaml

formatter:
  page_width: 120

linter:
  # The lint rules applied to this project can be customized in the
  # section below to disable rules from the `package:flutter_lints/flutter.yaml`
  # included above or to enable additional rules. A list of all available lints
  # and their documentation is published at
  # https://dart.dev/tools/linter-rules
  #
  # Instead of disabling a lint rule for the entire project in the
  # section below, it can also be suppressed for a single line of code
  # or a specific dart file by using the `// ignore: name_of_lint` and
  # `// ignore_for_file: name_of_lint` syntax on the line or in the file
  # producing the lint.

  rules:
    # Correctness
    always_declare_return_types: true
    avoid_type_to_string: true
    avoid_unused_constructor_parameters: true
    avoid_void_async: true
    cancel_subscriptions: true
    cast_nullable_to_non_nullable: true
    close_sinks: true
    collection_methods_unrelated_type: true
    deprecated_consistency: true
    deprecated_member_use_from_same_package: true
    discarded_futures: true
    no_adjacent_strings_in_list: true
    no_self_assignments: true
    noop_primitive_operations: true
    only_throw_errors: true
    parameter_assignments: true
    throw_in_finally: true
    tighten_type_of_initializing_formals: true
    unawaited_futures: true
    unnecessary_ignore: true
    unnecessary_null_checks: true
    unnecessary_statements: true
    unrelated_type_equality_checks: true

    # Performance
    avoid_slow_async_io: true
    prefer_const_constructors: true
    prefer_const_declarations: true
    prefer_const_literals_to_create_immutables: true

    # Flutter specific
    avoid_unnecessary_containers: true
    sized_box_for_whitespace: true
    use_build_context_synchronously: true
    use_colored_box: true
    use_decorated_box: true
    use_full_hex_values_for_flutter_colors: true

    # Style
    always_put_control_body_on_new_line: true
    always_use_package_imports: true
    avoid_multiple_declarations_per_line: true
    avoid_print: true
    combinators_ordering: true
    directives_ordering: true
    no_leading_underscores_for_local_identifiers: true
    prefer_final_locals: true
    require_trailing_commas: true
    unnecessary_breaks: true
    unnecessary_parenthesis: true
    use_named_constants: true
    use_super_parameters: true

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
analyzer:
  exclude:
    - generated/openapi/**
    - build/**
    - lib/generated_plugin_registrant.dart
    - lib/**/*.g.dart
    - lib/**/*.drift.dart
    - android/**
    - ios/**
    - web/**
    - windows/**
    - macos/**
    - linux/**

  # NOTE: We explicitly do not use riverpod_lint as there are analyzer version conflicts between
  # our Flutter version and the required old riverpod_lint 2.x
  errors:
    unawaited_futures: warning
    always_put_control_body_on_new_line: warning
    deprecated_member_use_from_same_package: error

dart_code_metrics:
  exclude:
    unused-code:
      - '**/*.g.dart'
      - '**/*.freezed.dart'
      - '**/*.mapper.dart'
      - '**/*.drift.dart'
      - '**/*.gr.dart'
      - 'lib/data/db/main/database.steps.dart'
      # Ideally we wouldn't do this, as this allows for non-column used code, but not complaining
      # about the columns is more important
      - 'lib/data/db/**/table/**'
      - 'lib/widgets/photo_view/**'
      - 'test/drift/**/generated/**'
  rules:
    - banned-usage:
        entries:
          - name: debugPrint
            description: Use dPrint instead of debugPrint for proper tree-shaking in release builds.
            exclude-paths:
              - 'lib/utils/debug_print.dart'
            severity: perf
          - name: tr
            description: 'Use context.t.<key> or StaticTranslations.instance.<key> instead of tr().'
          - type: Locale
            entries:
              - name: toLanguageTag
                description: 'Pass resolvedDateTimeLocale() to DateFormat, not the raw locale. DateFormat throws for locales intl has no date data for (e.g. mi).'
                exclude-paths:
                  - 'lib/main.dart'
          - type: String
            entries:
              - name: tr
                description: 'Use context.t.<key> or StaticTranslations.instance.<key> instead of String.tr().'
              - name: plural
                description: 'Use the generated plural accessor instead of String.plural().'
          - type: Text
            entries:
              - name: tr
                description: 'Use Text(context.t.<key>) instead of Text(<key>).tr().'
    # All rules from "recommended" preset
    # Show potential errors
  #  - avoid-cascade-after-if-null
  #  - avoid-collection-methods-with-unrelated-types
  #  - avoid-duplicate-exports
  #  - avoid-dynamic
  #  - avoid-missing-enum-constant-in-map
  #  - avoid-passing-async-when-sync-expected
  #  - avoid-throw-in-catch-block
    - avoid-unused-parameters
    - prefer-const-border-radius
    - prefer-declaring-const-constructor
    - prefer-switch-expression

    # Riverpod
    - avoid-calling-notifier-members-inside-build
    - avoid-notifier-constructors
    - avoid-nullable-async-value-pattern
    - avoid-public-notifier-properties
    - avoid-ref-inside-state-dispose
    - avoid-ref-read-inside-build
    - avoid-ref-watch-outside-build
    - avoid-unnecessary-consumer-widgets
    - dispose-provided-instances
    - prefer-immutable-provider-arguments
    - use-ref-and-state-synchronously
    - use-ref-read-synchronously