Summary
file-length counts every line in the file. Doc comments and blank lines count
the same as code. A file with many comments gets a warning when its code is well
below the limit.
Is this intentional? The answer decides whether this is a documentation change or
a code change.
This report also describes an off-by-one error in the same count. See the last
section.
Example
A 224-line script reports this:
res://critter/critter.gd:1: File exceeds 200 lines (225)
The file contains:
| Line type |
Count |
doc comment (##) |
43 |
comment (#) |
2 |
| blank |
58 |
| code |
121 |
| total |
224 |
The file exceeds a 200-line limit with 121 lines of code.
Code
In addons/gdscript-linter/analyzer/code-analyzer.gd:
# line 77
var file_result = FileResultClass.create(file_path, lines.size())
# line 274
var line_count := lines.size()
# line 307
func _check_file_length(file_path: String, line_count: int) -> void:
lines comes from content.split("\n"), so the count includes every line.
Options
If the behavior is intentional, the documentation can state it. The names
file_lines_soft and file_lines_hard read like limits on code.
If the behavior is not intentional, there are four options:
- Document the current behavior and change nothing.
- Remove blank lines from the count.
- Remove blank lines and comment-only lines from
file-length. Keep the full
count for the "total lines" statistic in the report.
- Add a second limit for code lines. Keep
file-length as it is.
I can send a pull request for the option you prefer.
Off-by-one error
The count is one too high for a file that ends with a newline.
"extends Node\nvar a := 1\n".split("\n")
# -> ["extends Node", "var a := 1", ""]
The example above reports 225 lines. The editor shows 224 lines. A file at the
limit gets a warning one line early.
The fix is to drop one empty element at the end before the count. This changes
every file-length count by one. A pinned exception at an exact boundary moves
with it.
Tell me if you want this as a separate issue.
Environment
- Addon version 3.3.0
- Godot 4.7.1.stable.mono
- I reproduced this with the CLI (
analyze-cli.gd), not the editor dock
Summary
file-lengthcounts every line in the file. Doc comments and blank lines countthe same as code. A file with many comments gets a warning when its code is well
below the limit.
Is this intentional? The answer decides whether this is a documentation change or
a code change.
This report also describes an off-by-one error in the same count. See the last
section.
Example
A 224-line script reports this:
The file contains:
##)#)The file exceeds a 200-line limit with 121 lines of code.
Code
In
addons/gdscript-linter/analyzer/code-analyzer.gd:linescomes fromcontent.split("\n"), so the count includes every line.Options
If the behavior is intentional, the documentation can state it. The names
file_lines_softandfile_lines_hardread like limits on code.If the behavior is not intentional, there are four options:
file-length. Keep the fullcount for the "total lines" statistic in the report.
file-lengthas it is.I can send a pull request for the option you prefer.
Off-by-one error
The count is one too high for a file that ends with a newline.
The example above reports 225 lines. The editor shows 224 lines. A file at the
limit gets a warning one line early.
The fix is to drop one empty element at the end before the count. This changes
every
file-lengthcount by one. A pinned exception at an exact boundary moveswith it.
Tell me if you want this as a separate issue.
Environment
analyze-cli.gd), not the editor dock