dart-lang / linter

Linter for Dart.
https://dart.dev/tools/linter-rules
BSD 3-Clause "New" or "Revised" License
628 stars 172 forks source link

`use_late_for_private_fields_and_variables` triggering strangely with part files #4946

Closed FMorschel closed 1 month ago

FMorschel commented 2 months ago

Describe the issue I got back to work in this package I've created. And I've added the use_late_for_private_fields_and_variables to the analysis_options.yaml file:

linter:
  rules:
    use_late_for_private_fields_and_variables: true

To Reproduce In that project, the lib/src/floating_overlay.dart file is the main file for some part files.

Currently, my parts are (in this specific order):

part 'floating_overlay_controller.dart';
part 'floating_overlay_cursor.dart';
part 'floating_overlay_offset.dart';
part 'floating_overlay_scale.dart';
part 'floating_overlay_data.dart';
part 'reposition.dart';
part 'rescale.dart';
part 'cursor_resizing.dart';
part 'size_extension.dart';
part 'cursor_border_side.dart';

And that is triggering on a random part of a variable inside an enum declaration (inside lib/src/cursor_border_side.dart line 29).

  bottom(
    cursor: SystemMouseCursors.resizeUpDown,
    height: _defaultWidth,
    bottomDistance: 0,
    leftDistance: _defaultWidth, // <- triggering on `_defaultWi` not the full variable name. Also, I don't think that is what is trying to trigger.
    rightDistance: _defaultWidth,
  ),

Now when I change the part files order inside floating_overlay.dart so that cursor_border_side.dart is not the last file in my parts (alphabetical sorting):

part 'cursor_border_side.dart';
part 'cursor_resizing.dart';
part 'floating_overlay_controller.dart';
part 'floating_overlay_cursor.dart';
part 'floating_overlay_data.dart';
part 'floating_overlay_offset.dart';
part 'floating_overlay_scale.dart';
part 'reposition.dart';
part 'rescale.dart';
part 'size_extension.dart';

It now triggers on size_extension.dart line 18 (a comment):

  /// Returns this size clamped to be in the range lowerLimit-upperLimit.
  ///
  /// The arguments lowerLimit and upperLimit must form a valid range where
  /// `(lowerLimit.height < upperLimit.height) && (lowerLimit.width <              /// triggering here only `it.width <` text.
  /// upperLimit.width)`.
  Size clamp(Size lowerLimit, Size upperLimit) {

Expected behavior To trigger on the right file (if there is actually a file where that happens, of course). And to take into account the reordering of parts in the file that it's a part of.

Additional context Nothing else.

srawlins commented 1 month ago

Fixed with https://github.com/dart-lang/sdk/commit/bca76630256a901d751cb11907923ed48789f3be