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

proposal: `package_import_contains_dot_dot` #3939

Open srawlins opened 1 year ago

srawlins commented 1 year ago

package_import_contains_dot_dot

Description

A package import shouldn't contain '..'.

It is a bad practice for a package import to reference anything outside the given package, or more generally, it is bad practice for a package import to contain a "..". For example, a source file should not contain a directive such as import 'package:foo/../some.dart'.

Details

This rule replaces the current HintCode named package_import_contains_dot_dot. As part of removing the notion of "hints," https://github.com/dart-lang/sdk/issues/50796, we want to move package_import_contains_dot_dot to the linter.

Kind

"bad practice"? haha, maybe errors...

Bad Examples

import 'package:foo/../tool/foo.dart';

Good Examples

import '../tool/foo.dart';

Discussion

Discussion checklist

pq commented 1 year ago

See: https://github.com/dart-lang/sdk/issues/48042. If we aren't currently producing this diagnostic, we might consider dropping it?

srawlins commented 1 year ago

Oh wow great catch! I agree, maybe just drop it :)