thrawn01/args

View on GitHub

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"

Severity: Minor
Found in parser_test.go - About 6 hrs to fix

    ArgParser has 34 methods (exceeds 20 allowed). Consider refactoring.
    Open

    type ArgParser struct {
        Command              *Rule
        EnvPrefix            string
        Description          string
        Name                 string
    Severity: Minor
    Found in parser.go - About 4 hrs to fix

      Options has 32 methods (exceeds 20 allowed). Consider refactoring.
      Open

      type Options struct {
          log    StdLogger
          parser *ArgParser
          values map[string]Value
      }
      Severity: Minor
      Found in options.go - About 4 hrs to fix

        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_
        Severity: Major
        Found in examples/demo/demo.go - About 3 hrs to fix

          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{})
          
          
          Severity: Minor
          Found in backends.go - About 2 hrs to fix

          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
          }
          Severity: Minor
          Found in rule_modifier.go - About 2 hrs to fix

            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
            Severity: Minor
            Found in watchfile.go - About 2 hrs to fix

            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 {
            Severity: Minor
            Found in parser.go - About 1 hr to fix

            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
            Severity: Minor
            Found in parser.go - About 1 hr to fix

            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
            Severity: Minor
            Found in watchfile.go - About 1 hr to fix

              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
                  }
              
              
              Severity: Major
              Found in rules.go - About 50 mins to fix

                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) {
                Severity: Major
                Found in rules.go - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                                          goto Retry
                  Severity: Major
                  Found in backends.go - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                                            goto Retry
                    Severity: Major
                    Found in backends.go - About 45 mins to fix

                      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 {
                      Severity: Major
                      Found in parser.go - About 40 mins to fix

                        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
                        Severity: Major
                        Found in args.go - About 40 mins to fix

                          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)
                              }
                          Severity: Major
                          Found in args.go - About 35 mins to fix

                            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])
                            Severity: Major
                            Found in rules.go - About 35 mins to fix

                              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
                                  }
                              Severity: Major
                              Found in args.go - About 35 mins to fix

                                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)
                                    }
                                Severity: Major
                                Found in args.go - About 35 mins to fix
                                  Severity
                                  Category
                                  Status
                                  Source
                                  Language