Showing 22 of 80 total issues
File parser_test.go
has 678 lines of code (exceeds 500 allowed). Consider refactoring. Open
package args_test
import (
"os"
ArgParser
has 34 methods (exceeds 20 allowed). Consider refactoring. Open
type ArgParser struct {
Command *Rule
EnvPrefix string
Description string
Name string
Options
has 32 methods (exceeds 20 allowed). Consider refactoring. Open
type Options struct {
log StdLogger
parser *ArgParser
values map[string]Value
}
Function main
has 106 lines of code (exceeds 50 allowed). Consider refactoring. Open
func main() {
var conf Config
// Create the parser with program name 'example'
// and environment variables prefixed with APP_
Method ArgParser.Watch
has a Cognitive Complexity of 36 (exceeds 20 allowed). Consider refactoring. Open
func (self *ArgParser) Watch(backend Backend, callBack func(*ChangeEvent, error)) WatchCancelFunc {
var isRunning sync.WaitGroup
var once sync.Once
done := make(chan struct{})
- 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
RuleModifier
has 25 methods (exceeds 20 allowed). Consider refactoring. Open
type RuleModifier struct {
rule *Rule
parser *ArgParser
}
Function WatchFile
has a Cognitive Complexity of 32 (exceeds 20 allowed). Consider refactoring. Open
func WatchFile(path string, interval time.Duration, callBack func(error)) (WatchCancelFunc, error) {
var isRunning sync.WaitGroup
fsWatch, err := fsnotify.NewWatcher()
if err != nil {
return nil, err
- 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 ArgParser.parseUntil
has a Cognitive Complexity of 28 (exceeds 20 allowed). Consider refactoring. Open
func (self *ArgParser) parseUntil(terminator string) (*Options, error) {
self.idx = 0
// Sanity Check
if len(self.rules) == 0 {
- 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 ArgParser.ValidateRules
has a Cognitive Complexity of 26 (exceeds 20 allowed). Consider refactoring. Open
func (self *ArgParser) ValidateRules() error {
var greedyRule *Rule
for idx, rule := range self.rules {
// Duplicate rule check
next := idx + 1
- 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
Function WatchFile
has 54 lines of code (exceeds 50 allowed). Consider refactoring. Open
func WatchFile(path string, interval time.Duration, callBack func(error)) (WatchCancelFunc, error) {
var isRunning sync.WaitGroup
fsWatch, err := fsnotify.NewWatcher()
if err != nil {
return nil, err
Method Rule.ComputedValue
has 8 return statements (exceeds 4 allowed). Open
func (self *Rule) ComputedValue(values *Options) (interface{}, error) {
if self.Count != 0 {
self.Value = self.Count
}
Method Rule.Match
has 7 return statements (exceeds 4 allowed). Open
func (self *Rule) Match(args []string, idx *int) (bool, error) {
name := self.Name
var matched bool
if self.HasFlag(IsConfig) {
Avoid deeply nested control flow statements. Open
goto Retry
Avoid deeply nested control flow statements. Open
goto Retry
Method ArgParser.parseUntil
has 6 return statements (exceeds 4 allowed). Open
func (self *ArgParser) parseUntil(terminator string) (*Options, error) {
self.idx = 0
// Sanity Check
if len(self.rules) == 0 {
Function StringToMap
has 6 return statements (exceeds 4 allowed). Open
func StringToMap(value string) (map[string]string, error) {
tokenizer := NewKeyValueTokenizer(value)
result := make(map[string]string)
var lvalue, rvalue, expression string
Function castStringSlice
has 5 return statements (exceeds 4 allowed). Open
func castStringSlice(name string, dest interface{}, value interface{}) (interface{}, error) {
// If our destination is nil, init a new slice
if dest == nil {
dest = make([]string, 0)
}
Method Rule.GenerateUsage
has 5 return statements (exceeds 4 allowed). Open
func (self *Rule) GenerateUsage() string {
switch {
case self.Flags&IsOption != 0:
if self.HasFlag(IsRequired) {
return fmt.Sprintf("%s", self.Aliases[0])
Function castBool
has 5 return statements (exceeds 4 allowed). Open
func castBool(name string, dest interface{}, value interface{}) (interface{}, error) {
// If value is nil, return the type default
if value == nil {
return false, nil
}
Function castStringMap
has 5 return statements (exceeds 4 allowed). Open
func castStringMap(name string, dest interface{}, value interface{}) (interface{}, error) {
// If our destination is nil, init a new slice
if dest == nil {
dest = make(map[string]string, 0)
}