Showing 247 of 615 total issues
Method User.Apply
has 61 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func (u *User) Apply(context.Context) (resource.TaskStatus, error) {
// lookup the user by name
// ErrUnsupported is returned if the system is not supported
// Lookup returns user.UnknownUserError if the user is not found
userByName, nameErr := u.system.Lookup(u.Username)
Function TestRetryUntil
has 61 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func TestRetryUntil(t *testing.T) {
t.Parallel()
defer logging.HideLogs(t)()
t.Run("sets retry count", func(t *testing.T) {
Function TestVGApply
has 61 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func TestVGApply(t *testing.T) {
t.Run("single device", func(t *testing.T) {
lvm, m := testhelpers.MakeFakeLvmEmpty()
m.On("CreateVolumeGroup", mock.Anything, mock.Anything).Return(nil)
Function Nodes
has 61 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func Nodes(ctx context.Context, root string, verify bool) (*graph.Graph, error) {
logger := logging.GetLogger(ctx).WithField("function", "Nodes")
toLoad := []*source{{"root", root, root}}
Method Printer.Show
has a Cognitive Complexity of 27 (exceeds 20 allowed). Consider refactoring. Open
Open
func (p Printer) Show(ctx context.Context, g *graph.Graph) (string, error) {
outputBuffer := new(bytes.Buffer)
write := func(s Renderable) { outputBuffer.WriteString(s.String()) }
subgraphs := makeSubgraphMap()
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method Renderer.lookup
has 60 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func (r *Renderer) lookup(name string) (string, error) {
g := r.Graph()
// fully-qualified graph name
fqgn := graph.SiblingID(r.ID, name)
Function dependencyWalk
has 14 return statements (exceeds 4 allowed). Open
Open
func dependencyWalk(rctx context.Context, g *Graph, cb WalkFunc) error {
// the basic idea of this implementation is that we want to defer schedule
// children of any given node until after that node's non-child dependencies
// are satisfied. We're going to have a couple major components of this.
// First, a scheduler/latch to make sure we don't schedule work more than
Function TestLoadSwitch
has 58 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func TestLoadSwitch(t *testing.T) {
var sampleStatement = `
switch "named-switch" {
case "eq 1 0" "a" {
task.query "foo" {
Method Group.Check
has 13 return statements (exceeds 4 allowed). Open
Open
func (g *Group) Check(context.Context, resource.Renderer) (resource.TaskStatus, error) {
var (
groupByGid *user.Group
gidErr error
groupByNewName *user.Group
Function TestDependencyResolverResolvesGroupDependencies
has a Cognitive Complexity of 26 (exceeds 20 allowed). Consider refactoring. Open
Open
func TestDependencyResolverResolvesGroupDependencies(t *testing.T) {
t.Parallel()
defer logging.HideLogs(t)()
t.Run("intra-module", func(t *testing.T) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method Server.Listen
has 56 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func (s *Server) Listen(ctx context.Context, addr *url.URL) error {
logger := logging.GetLogger(ctx).WithField("addr", addr)
// set up a context within the waitgroup
wg, ctx := errgroup.WithContext(ctx)
Function TestPreparer
has 56 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func TestPreparer(t *testing.T) {
users := []*user.User{fakeUser("1", "1", "user-1")}
groups := []*user.Group{fakeGroup("1", "group-1")}
t.Run("implements-resource", func(t *testing.T) {
assert.Implements(t, (*resource.Resource)(nil), new(owner.Preparer))
Function TestApply
has 55 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func TestApply(t *testing.T) {
t.Parallel()
defer logging.HideLogs(t)()
newWait := func() *wait.Wait {
Function getFailedReason
has 55 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func getFailedReason(u *Unit) (string, error) {
err := errors.New("unable to determine cause of failure: no properties available")
var reason string
switch u.Type {
case UnitTypeService:
Function expandSwitchMacro
has 55 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func expandSwitchMacro(data []byte, current *source, n *parse.Node, g *graph.Graph) (*graph.Graph, error) {
if !control.IsSwitchNode(n) {
return g, nil
}
switchObj, err := control.NewSwitch(n, data)
Method Server.Listen
has 12 return statements (exceeds 4 allowed). Open
Open
func (s *Server) Listen(ctx context.Context, addr *url.URL) error {
logger := logging.GetLogger(ctx).WithField("addr", addr)
// set up a context within the waitgroup
wg, ctx := errgroup.WithContext(ctx)
Function TestCopyToFinalDest
has 12 return statements (exceeds 4 allowed). Open
Open
func TestCopyToFinalDest(t *testing.T) {
t.Parallel()
t.Run("no duplicates", func(t *testing.T) {
destDir, err := ioutil.TempDir("", "destDir_unarchive")
Function TestEvaluateDuplicates
has 12 return statements (exceeds 4 allowed). Open
Open
func TestEvaluateDuplicates(t *testing.T) {
t.Parallel()
t.Run("no duplicates", func(t *testing.T) {
destDir, err := ioutil.TempDir("", "destDir_unarchive")
Function TestHandlesContext
has 54 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func TestHandlesContext(t *testing.T) {
t.Parallel()
t.Run("Check", func(t *testing.T) {
t.Parallel()
Function TestApplyOwnershipDiff
has 54 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func TestApplyOwnershipDiff(t *testing.T) {
users := []*user.User{
fakeUser("1", "1", "user-1"),
fakeUser("2", "2", "user-2"),
}