Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use_late_for_private_fields_and_variables triggering strangely with part files #4946

Closed
FMorschel opened this issue Apr 19, 2024 · 1 comment
Assignees
Labels
P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@FMorschel
Copy link
Contributor

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.

@bwilkerson bwilkerson added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) P2 A bug or feature request we're likely to work on labels Apr 19, 2024
@FMorschel FMorschel changed the title use_late_for_private_fields_and_variables triggering stragely with part files use_late_for_private_fields_and_variables triggering strangely with part files Apr 19, 2024
copybara-service bot pushed a commit to dart-lang/sdk that referenced this issue May 17, 2024
This primarily takes the form of adding an ErrorReporter field to
LinterContextUnit. In addition, we make the getter access to
`Linter.reporter` protected, to prevent lint rule authors from trying
to call `rule.reporter.reportError` with a temporary AnalysisError
that attempts to point to a specific source. The _setter_ for
`Linter.reporter` remains public, as it is generally set by the
framework.

Some other changes are made in order to facilitate this:

* Remove LinterAnalysis.linterUnit, no longer needed.
* Remove LinterContextUnit2, no longer needed.
* Correct the tests for avoid_private_typedef_functions and
  use_late_for_private_fields_and_variables. These tests did not
  correctly test declarations of typedefs or variables _in_ part
  files.

Fixes dart-lang/linter#4946
Fixes dart-lang/linter#2921

Change-Id: I77c14ab6e56f369417a27f5f5227d6ec11486c3f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/366405
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
@srawlins srawlins self-assigned this May 17, 2024
@srawlins
Copy link
Member

Fixed with dart-lang/sdk@bca7663

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

3 participants