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

proposal: file_import_inside_lib_references_file_outside #4103

Open
1 of 5 tasks
srawlins opened this issue Mar 2, 2023 · 1 comment
Open
1 of 5 tasks

proposal: file_import_inside_lib_references_file_outside #4103

srawlins opened this issue Mar 2, 2023 · 1 comment
Labels
lint-proposal P3 A lower priority bug or feature request status-pending type-enhancement A request for a change that isn't a bug

Comments

@srawlins
Copy link
Member

srawlins commented Mar 2, 2023

file_import_inside_lib_references_file_outside

Description

This rule was originally proposed (and implemented?) as an analyzer Hint, but the implementation is either gone or never existed, and this is more a style recommendation so should be a Lint rule.

Details

The YAML definition of the Hint was the following:

  FILE_IMPORT_INSIDE_LIB_REFERENCES_FILE_OUTSIDE:
    problemMessage: "A file in the 'lib' directory shouldn't import a file outside the 'lib' directory."
    correctionMessage: "Try removing the import, or moving the imported file inside the 'lib' directory."
    comment: |-
      It is a bad practice for a source file in a package "lib" directory
      hierarchy to traverse outside that directory hierarchy. For example, a
      source file in the "lib" directory should not contain a directive such as
      `import '../web/some.dart'` which references a file outside the lib
      directory.

Kind

Style

Bad Examples

Relative imports from lib/ that go outside lib/.

// in lib/foo.dart:

import '../bin/bar.dart';

Good Examples

Relative imports from lib/ that don't go outside lib/.

// in lib/foo.dart:

import 'bar.dart';

Relative imports from outside lib/.

// in test/foo.dart:

import '../tool/bar.dart';

Discussion

Discussion checklist

  • List any existing rules this proposal modifies, complements, overlaps or conflicts with.
  • List any relevant issues (reported here, the SDK Tracker, or elsewhere).
  • If there's any prior art (e.g., in other linters), please add references here.
  • If this proposal corresponds to Effective Dart or Flutter Style Guide advice, please call it out. (If there isn't any corresponding advice, should there be?)
  • If this proposal is motivated by real-world examples, please provide as many details as you can. Demonstrating potential impact is especially valuable.
@srawlins
Copy link
Member Author

srawlins commented Mar 2, 2023

FWIW, I am proposing this primarily as due diligence in deleting the (not implemented) analyzer Hint. But also I would support this rule. I don't see it happen much, but it's a legitimate request, helpful for new users (as our lib/ setup is bespoke).

copybara-service bot pushed a commit to dart-lang/sdk that referenced this issue Mar 2, 2023
…NCES_FILE_* rules

Lint replacement suggested at
dart-lang/linter#4103

Bug: #50796
Change-Id: I2578c91af3f66a816d67bb0e9ecfa22802febf94
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/286345
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
@pq pq added the P3 A lower priority bug or feature request label May 22, 2023
@srawlins srawlins added the type-enhancement A request for a change that isn't a bug label Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lint-proposal P3 A lower priority bug or feature request status-pending type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

2 participants