Skip to content
This repository has been archived by the owner on Nov 20, 2024. It is now read-only.

add lint use_string_in_part_of_directives #3567

Merged
merged 2 commits into from
Aug 2, 2022

Conversation

a14n
Copy link
Contributor

@a14n a14n commented Aug 1, 2022

Description

From effective dart:

DO use strings in part of directives.

BAD:

part of my_library;

GOOD:

part of '../../my_library.dart';

Fixes dart-lang/sdk#58777

@coveralls
Copy link

coveralls commented Aug 1, 2022

Coverage Status

Coverage decreased (-0.08%) to 95.663% when pulling 2051f94 on a14n:use_string_in_part_of_directives into 7d51bf6 on dart-lang:main.

@@ -0,0 +1,68 @@
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you consider migrating this test to the reflective_test_loader style? These run faster and are easier to debug.

FWIW ConditionalUriDoesNotExistTest and PreferConstConstructorsTest are examples of tests that uses this style for tests that require multiple files.

(Aside: we should really write up some docs for this... 😬 )

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this rule I need several files. I don't find example dealing with multiple files. Do you have an example of such case?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure!

In this case newFile2 creates a.dart which is imported by the test file in assertNoDiagnostics.

  test_deferred_arg() async {
    newFile2('$testPackageLibPath/a.dart', '''
class A {
  const A();
}

const aa = A();
''');

    await assertNoDiagnostics(r'''
import 'a.dart' deferred as a;

class B {
  const B(Object a);
}

main() {
  var b = B(a.aa);
  print(b);
}   
''');
  }

You can call newFile2 multiple times with different library names ($testPackageLibPath/b.dart etc.) to get more libraries to import into your test file if needed.

I need to run out for a but but if you get stuck, feel free to share how far you get and I'm happy to take a look.

Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your help. Tests are now migrated. PTAL

Copy link
Member

@pq pq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super. Thanks!

@pq pq merged commit 7e1703b into dart-lang:main Aug 2, 2022
@a14n a14n deleted the use_string_in_part_of_directives branch August 2, 2022 14:03
mockturtl added a commit to mockturtl/tidy that referenced this pull request Aug 10, 2022
copybara-service bot pushed a commit to dart-lang/sdk that referenced this pull request Aug 23, 2023
* add lint use_string_in_part_of_directives

* migrate test to reflective_test_loader style
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"Strings in part of directives" Effective Dart guideline does not have a lint
3 participants