Skip to content

add AZG012: separate the steps of a longer function body with blank lines - #71

Open
katbyte wants to merge 2 commits into
mainfrom
kt/azg012-blank-line-between-steps
Open

katbyte wants to merge 2 commits into
mainfrom
kt/azg012-blank-line-between-steps

Conversation

@katbyte

@katbyte katbyte commented Oct 9, 2026

Copy link
Copy Markdown
Owner

A new rule, AZG012, that reports an if, for, switch or select in a longer function body run straight into the statement after it, with a fix that inserts the blank line.

Why: a body reads as a sequence of steps: get something, check it, use it. The block that ends one step and the statement that starts the next need a blank line between them or a twenty-line loop body reads as one undifferentiated run. This is the judgement #70 applied by hand across the repo, turned into a check so it holds for new code.

Steps run together. In a body of more than five statements spanning more than ten lines, a block followed on the very next line by another statement is reported at that statement. A comment on that line belongs to the next step, so the report and the blank go before the comment.

 		if !ok || runs[fn] != nil {
 			continue
 		}
+
 		rest := strings.TrimPrefix(fn.Name(), "TestAcc")

Things that are fine as they are. A short body is one group and gets nothing: five statements or fewer, or ten lines or fewer, both adjustable through the statements and lines options. Two one-line ifs in a row read as a set of guards and stay together. A literal assignment that closes with a brace does not end a step. Nothing is reported before a case, and never where a blank line already is.

Files the earlier pass skipped. #70 left out AZP002.go, AZT003.go and lib/tf/registration.go because #67 and #68 rewrite them. The rule runs on this repo, so those three get the same blank lines here through the rule's own fix. Whichever of #67, #68 and this lands last takes a trivial rebase, since the insertions are identical.

The rule is enabled on this repo through the existing enable: [AZG] setting, and the tree is clean under it. Fixable with -fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant