Skip to content

False positive "indentation error" on Dart constructor initializer list continuation lines #205

@Zoti321

Description

@Zoti321

Description

When editing Dart files, indent-rainbow highlights the leading whitespace of continuation lines after a constructor initializer list as an indentation error (e.g. red background), even though the code is valid and commonly produced by dart format.

This happens because Dart style often aligns the next initializer under the first initializer on the previous line, which can result in a non-multiple-of-indent-size number of leading spaces (alignment-based indentation), not a strict hierarchical indent step.

Environment

  • Editor: VS Code / Cursor (please specify)
  • Extension: indent-rainbow (please specify exact extension id + version from marketplace)
  • OS: Windows 10/11 (please specify)

Steps to reproduce

  1. Install indent-rainbow with default settings (or typical "error highlight" enabled).
  2. Create a .dart file with a constructor that uses an initializer list split across two lines, where the second line is indented to align with the first initializer (as dart format does).

Minimal reproducible example (Dart)

class ComicRepositoryImpl {
  ComicRepositoryImpl(
    this._comicDao, {
    required ReadingHistoryRepository readingHistory,
    required SeriesRepository librarySeries,
  }) : _readingHistory = readingHistory,
       _librarySeries = librarySeries;

  final dynamic _comicDao;
  final ReadingHistoryRepository _readingHistory;
  final SeriesRepository _librarySeries;
}

// placeholder types so the snippet parses
class ReadingHistoryRepository {}
class SeriesRepository {}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions