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: `avoid_mixing_comment_identifiers` #4997

Open Pante opened 1 week ago

Pante commented 1 week ago

avoid_mixing_comment_identifiers

Description

It is possible to accidentally mix dartdoc comments and normal comments. This is especially true when you have a long chunk of documentation. Ideally the lint will be able to identify such erroneous usage of //s in the middle of ///s.

/// Applies a theme to descendant widgets.
///
/// A theme configures the colors and typographic choices of Forui widgets. The actual configuration is stored in
/// a [FThemeData]. Descendant widgets obtain the current theme's [FThemeData] via either [ThemeBuildContext.theme],
/// or [FTheme.of]. When a widget uses either, it is automatically rebuilt if the theme later changes.
///
/// ```dart
/// class Parent extends StatelessWidget {
///   @override
///   Widget build(BuildContext context) => FTheme(
///      data: FThemes.zinc.light,
///      child: Child(),
///    );
///  }
/// 
//  class Child extends StatelessWidget { // <-- This line will not be included in the generated Dartdocs.
///    @override
///    Widget build(BuildContext context) {
///      final FThemeData theme = context.theme;
///      final FThemeData sameTheme = FTheme.of(context);
///      return const Placeholder();
///    }
///  }
/// ```

Details

Give a detailed description that should provide context and motivation. Ideally this could be used directly in the rule's documentation.

Kind

Bad Examples

Add a few examples that demonstrate where this lint should fire.

Good Examples

Add a few examples that demonstrate a “good” adoption of this lint’s principle.

Discussion

Add any other motivation or useful context here.

srawlins commented 1 week ago

Yikes, I think this is a great idea. I'm a bit fearful to see what existing issues this catches...

I'll add one suggestion though: if the comment starts with ignore: (so, // ignore:), allow it; if there is a static issue with a line in the middle of a big doc comment, the only way to ignore the individual line is to add a // comment precisely as shown above.