thrawn01/args

View on GitHub

Showing 80 of 80 total issues

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

Similar blocks of code found in 3 locations. Consider refactoring.
Open

    Describe("RuleModifier.StoreInt()", func() {
        It("Should ensure value supplied is assigned to passed value", func() {
            parser := args.NewParser()
            var value int
            parser.AddOption("--power-level").StoreInt(&value)
Severity: Major
Found in rule_modifier_test.go and 2 other locations - About 1 hr to fix
rule_modifier_test.go on lines 177..189
rule_modifier_test.go on lines 190..202

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 162.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 3 locations. Consider refactoring.
Open

    Describe("RuleModifier.StoreStr()", func() {
        It("Should ensure value supplied is assigned to passed value", func() {
            parser := args.NewParser()
            var value string
            parser.AddOption("--power-level").StoreStr(&value)
Severity: Major
Found in rule_modifier_test.go and 2 other locations - About 1 hr to fix
rule_modifier_test.go on lines 144..156
rule_modifier_test.go on lines 177..189

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 162.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 3 locations. Consider refactoring.
Open

    Describe("RuleModifier.StoreString()", func() {
        It("Should ensure value supplied is assigned to passed value", func() {
            parser := args.NewParser()
            var value string
            parser.AddOption("--power-level").StoreString(&value)
Severity: Major
Found in rule_modifier_test.go and 2 other locations - About 1 hr to fix
rule_modifier_test.go on lines 144..156
rule_modifier_test.go on lines 190..202

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 162.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

        It("Should add a new group", func() {
            parser := args.NewParser()
            parser.AddOption("--power-level").Count()
            parser.AddOption("--hostname").InGroup("database")
            opt, err := parser.Parse(&cmdLine)
Severity: Major
Found in rule_modifier_test.go and 1 other location - About 1 hr to fix
parser_test.go on lines 539..547

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 157.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

        It("Should add a new group", func() {
            parser := args.NewParser()
            parser.AddOption("--power-level").Count()
            parser.InGroup("database").AddOption("--hostname")
            opt, err := parser.Parse(&cmdLine)
Severity: Major
Found in parser_test.go and 1 other location - About 1 hr to fix
rule_modifier_test.go on lines 45..53

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 157.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

        It("Should ensure value supplied is true when argument is seen", func() {
            parser := args.NewParser()
            var debug bool
            parser.AddOption("--debug").StoreTrue(&debug)

Severity: Major
Found in rule_modifier_test.go and 1 other location - About 1 hr to fix
rule_modifier_test.go on lines 216..226

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 146.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

        It("Should ensure value supplied is false when argument is NOT seen", func() {
            parser := args.NewParser()
            var debug bool
            parser.AddOption("--debug").StoreTrue(&debug)

Severity: Major
Found in rule_modifier_test.go and 1 other location - About 1 hr to fix
rule_modifier_test.go on lines 204..214

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 146.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

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

Similar blocks of code found in 2 locations. Consider refactoring.
Open

        It("Should allow multiple iterations of the same argument to create a map", func() {
            parser := args.NewParser()
            parser.AddOption("--map").IsStringMap()

            cmdLine := []string{"--map", "blue=bell", "--map", "cat=dog", "--map", "dad=boy"}
Severity: Major
Found in parser_test.go and 1 other location - About 1 hr to fix
parser_test.go on lines 341..357

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 141.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

        It("Should allow multiple iterations of the same argument to create a map with JSON", func() {
            parser := args.NewParser()
            parser.AddOption("--map").IsStringMap()

            cmdLine := []string{
Severity: Major
Found in parser_test.go and 1 other location - About 1 hr to fix
parser_test.go on lines 281..293

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 141.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

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

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

            It("Should fetch 'bind' value from backend", func() {
                parser := args.NewParser()
                parser.SetLog(log)
                parser.AddConfig("--bind")
    
    
    Severity: Major
    Found in backends_test.go and 1 other location - About 1 hr to fix
    backends_test.go on lines 140..149

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 131.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

        It("Should return an error if config option not found in the backend", func() {
            parser := args.NewParser()
            parser.SetLog(log)
            parser.AddConfig("--missing")
    
    
    Severity: Major
    Found in backends_test.go and 1 other location - About 1 hr to fix
    backends_test.go on lines 114..123

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 131.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    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

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

                It("Should provide string value", func() {
                    parser := args.NewParser()
                    parser.AddOption("--power-level").IsString()
        
                    cmdLine := []string{"--power-level", "over-ten-thousand"}
        Severity: Minor
        Found in rule_modifier_test.go and 1 other location - About 45 mins to fix
        rule_modifier_test.go on lines 114..122

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 115.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        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

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                    It("Should ensure value supplied is an integer", func() {
                        parser := args.NewParser()
                        parser.AddOption("--power-level").IsInt()
            
                        cmdLine := []string{"--power-level", "10000"}
            Severity: Minor
            Found in rule_modifier_test.go and 1 other location - About 45 mins to fix
            rule_modifier_test.go on lines 158..166

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 115.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Severity
            Category
            Status
            Source
            Language