func()

in dev-tools/mage/linter.go [136:158]


func (l Linter) LastChange() error {
	mg.Deps(l.Install, l.CheckConfig)

	// get current branch name
	branch, err := sh.Output("git", "rev-parse", "--abbrev-ref", "HEAD")
	if err != nil {
		return fmt.Errorf("failed to get the current branch: %w", err)
	}

	// the linter is supposed to support linting changed diffs only but,
	// for some reason, it simply does not work - does not output any
	// results without linting the whole files, so we have to use `--whole-files`
	// which can lead to some frustration from developers who would like to
	// fix a single line in an existing codebase and the linter would force them
	// into fixing all linting issues in the whole file instead

	if branch == "main" {
		// files changed in the last commit
		return runLinter("--new-from-rev=HEAD~", "--whole-files")
	}

	return runLinter("--new-from-rev=origin/main", "--whole-files")
}