Rules / Complexity / max-lines-for-file

max-lines-for-file

lint/complexity/max-lines-for-file
recommended
Same as max_lines_for_file · Pyramid Lint

Flags a file longer than the configured line limit.

Very long files are hard to navigate and usually mix unrelated responsibilities; splitting them improves readability and review. The rule counts the total lines in the file and reports once, at the top, when the count exceeds the threshold. The diagnostic message states the configured limit.

Options

max_lines (integer, default: 200) — flag files with more than this many lines.

Invalid

example.dartdart
 // File exceeds max_lines_for_file threshold (line count > 75)

class ExcessivelyLongFile {
  /// Line 5
  /// Line 6
  /// Line 7
  /// Line 8
  /// Line 9
  /// Line 10
  void method1() {}
  /// Line 13
  /// Line 14
  /// Line 15
  /// Line 16
  /// Line 17
  /// Line 18
  void method2() {}
  /// Line 21
  /// Line 22
  /// Line 23
  /// Line 24
  /// Line 25
  /// Line 26
  void method3() {}
  /// Line 29
  /// Line 30
  /// Line 31
  /// Line 32
  /// Line 33
  /// Line 34
  void method4() {}
  /// Line 37
  /// Line 38
  /// Line 39
  /// Line 40
  /// Line 41
  /// Line 42
  void method5() {}
  /// Line 45
  /// Line 46
  /// Line 47
  /// Line 48
  /// Line 49
  /// Line 50
  void method6() {}
  /// Line 53
  /// Line 54
  /// Line 55
  /// Line 56
  /// Line 57
  /// Line 58
  void method7() {}
  /// Line 61
  /// Line 62
  /// Line 63
  /// Line 64
  /// Line 65
  /// Line 66
  void method8() {}
  /// Line 69
  /// Line 70
  /// Line 71
  /// Line 72
  /// Line 73
  /// Line 74
  void method9() {}
  /// Line 77
  /// Line 78
  /// Line 79
  /// Line 80
  /// Line 81
  /// Line 82
  void method10() {}
  /// Line 85
  /// Line 86
  /// Line 87
  /// Line 88
  /// Line 89
  /// Line 90
  void method11() {}
  /// Line 93
  /// Line 94
  /// Line 95
  /// Line 96
  /// Line 97
  /// Line 98
  void method12() {}
}
File exceeds the maximum number of lines (60).
1 // File exceeds max_lines_for_file threshold (line count > 75)

Valid

example.dartdart
// This file stays within the max_lines_for_file threshold (under 500 lines)

class ReasonablySizedFile {
  /// A normal sized file
  void method1() {
    print('method 1');
  }

  void method2() {
    print('method 2');
  }

  void method3() {
    print('method 3');
  }

  void method4() {
    print('method 4');
  }

  void method5() {
    print('method 5');
  }

  void method6() {
    print('method 6');
  }

  void method7() {
    print('method 7');
  }

  void method8() {
    print('method 8');
  }

  void method9() {
    print('method 9');
  }

  void method10() {
    print('method 10');
  }
}

// This file is well under the 500-line limit
// It demonstrates good file structure with reasonable number of methods
// and is not overly complex or monolithic

How to configure

Set the severity of max-lines-for-file in your falcon.json:

falcon.jsonjson
{
  "linter": {
    "rules": {
      "complexity": {
        "max-lines-for-file": "error"
      }
    }
  }
}