filesize

package module
v0.1.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 24, 2026 License: MIT Imports: 6 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Documentation

Overview

Package filesize provides a go/analysis analyzer that reports source files longer than a configured number of lines.

File length is a proxy for how much one file is being asked to do, and it is the constraint that other rules only detect indirectly. A 1:1 test-layout rule, for instance, notices an oversized source only once somebody has already worked around it by splitting the tests — the symptom, one step removed and long after the fact. Measuring the file itself catches the cause.

The default limit is deliberately loose rather than aspirational: measured across a real fleet the median Go file was 54 lines and the 95th percentile 285, so 300 flags the genuine outliers without reshaping ordinary code. A repository with a different profile sets -max.

Test files are not judged. Not because tests deserve less care, but because LENGTH specifically says nothing true about them: the number of tests a function needs is set by its branches rather than by its own length, so one boundary, three error paths and a table of cases legitimately cost many times the source they cover, and a rule written against source growth reads that as a defect when it is the coverage requirement being met. Correctness rules still apply to test code exactly as they apply to source; length is the only property tests are excused from, and that exemption is the owner's decision rather than this analyzer's inference.

The exemption is decided by the file's name, and the name is what makes it unforgeable — not any sentence here. isTest applies strings.HasSuffix(name, "_test.go"), which is the expression go/build itself applies when deciding which files it compiles into the test binary alone, so acquiring the marker IS being dropped from the package build and no spelling buys the silence without paying for it. The claim is deliberately no wider than that: the go tool also compiles a generated _testmain.go into the test binary alone, and this rule does not spare it, because a generated file is the framework's exemption to apply rather than this one's.

Generated files are not this analyzer's concern: the yze framework drops findings in files carrying the standard generated marker before they are reported, so a machine-authored parser or protobuf stub is never counted.

Index

Constants

View Source
const ErrInvalidMaxLines errs.Const = "-max must be a line count of at least one"

ErrInvalidMaxLines reports a -max that is not a bound.

The flag took any int. `-max=0` and `-max=-5` were accepted and reported every file in the module "over the -5-line limit" -- a sentence naming a limit nothing can meet, in a rule whose whole remedy is to split a file until it fits. That is not a bound on length, it is a demand no file can satisfy, and it prints nonsense while making it.

Refused here for the same reason and in the same shape as ptrrecv's ErrInvalidMaxCopy, which is the sibling this flag should have matched from the start: a value nothing can honour is refused rather than stored.

The other direction is deliberately NOT decided here. Raising the limit until the rule reports nothing is a disablement channel, and ptrrecv's doc says how far such a bound may move is the owner's to set. This refuses what is meaningless; what is merely permissive is a policy nobody has ratified.

Variables

View Source
var Analyzer = newAnalyzer()

Analyzer reports files longer than the configured limit.

View Source
var Registration = goyze.Registration{
	Precision:  goyze.PrecisionExact,
	Name:       "filesize",
	Categories: []goyze.Category{"structure", "maintainability"},
	URL:        "https://docs.gomatic.dev/yze/filesize",
	Analyzer:   Analyzer,
}

Registration declares this analyzer to the yze framework.

It deliberately declares NO TestScope, and that is a decision rather than an omission. TestScopeAll asks the driver to filter nothing, which is exactly right here: report has already refused every test file, so there is nothing left for a second filter to remove and something it would wrongly remove. go-yze decides a source-only rule's drop from the RESOLVED position path — outOfScope reads Diagnostic.Path, which convert.go takes from fset.Position — and fset.Position applies //line directives. So `//line zz_test.go:1` on the first line of an ordinary source file, one that go/build still compiles into the package and any importer still links, makes that driver drop a finding this analyzer correctly emitted. isTest reads token.File.Name(), which no directive rewrites.

Declaring the scope would therefore buy no silence this analyzer does not already produce correctly, and one it must not produce: a forgeable escape costing a single comment, standing beside an unforgeable one that costs being compiled out of the package. The rule stays where its matcher cannot be rewritten by the file it is judging.

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址