Skip to content

var-naming: improve underscore detection with _test package #1314

Open
@ccoVeille

Description

@ccoVeille

A package name like this one would be accepted by the code

  • foo_bar_test

The current code is like this

// Package names need slightly different handling than other names.
	if strings.Contains(walker.fileAst.Name.Name, "_") && !strings.HasSuffix(walker.fileAst.Name.Name, "_test") {
		walker.onFailure(lint.Failure{
			Failure:    "don't use an underscore in package name",
			Confidence: 1,
			Node:       walker.fileAst.Name,
			Category:   lint.FailureCategoryNaming,
		})
	}

Source: https://github.com/mgechev/revive/blob/57ed899d0ce6ab78ad51cb83e67d2d9d32873eb2/rule/var_naming.go#L80-90

So anything that contains more than a _ and and with _test is accepted.

I think about using (pseudo-code)

  • strings.CutSufix(packageName, "_test")
  • then check if it was present
  • then strings.Contains(packageNameWithoutTestSuffix, "_")

Originally posted by @ccoVeille in #1312 (comment)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions