elves/elvish

View on GitHub

Showing 221 of 222 total issues

Method writer.UpdateBuffer has a Cognitive Complexity of 34 (exceeds 20 allowed). Consider refactoring.
Open

func (w *writer) UpdateBuffer(bufNoti, buf *Buffer, fullRefresh bool) error {
    if buf.Width != w.curBuf.Width && w.curBuf.Lines != nil {
        // Width change, force full refresh
        w.curBuf.Lines = nil
        fullRefresh = true
Severity: Minor
Found in pkg/cli/term/writer.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

Function highlight has a Cognitive Complexity of 34 (exceeds 20 allowed). Consider refactoring.
Open

func highlight(code string, cfg Config, lateCb func(ui.Text)) (ui.Text, []ui.Text) {
    var tips []ui.Text
    var errorRegions []region

    addDiagError := func(err diag.RangeError) {
Severity: Minor
Found in pkg/edit/highlight/highlight.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

Function suitableMethods has a Cognitive Complexity of 33 (exceeds 20 allowed). Consider refactoring.
Open

func suitableMethods(typ reflect.Type, reportErr bool) map[string]*methodType {
    methods := make(map[string]*methodType)
    for m := 0; m < typ.NumMethod(); m++ {
        method := typ.Method(m)
        mtype := method.Type
Severity: Minor
Found in pkg/rpc/server.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

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

func _() {
    // An "invalid array index" compiler error signifies that the constant values have changed.
    // Re-run the stringer command to generate them again.
    var x [1]struct{}
    _ = x[OpText-0]
Severity: Major
Found in pkg/md/zstring.go and 2 other locations - About 2 hrs to fix
pkg/md/zstring.go on lines 7..24
pkg/parse/zstring.go on lines 7..24

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 199.

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

func _() {
    // An "invalid array index" compiler error signifies that the constant values have changed.
    // Re-run the stringer command to generate them again.
    var x [1]struct{}
    _ = x[BadPrimary-0]
Severity: Major
Found in pkg/parse/zstring.go and 2 other locations - About 2 hrs to fix
pkg/md/zstring.go on lines 7..24
pkg/md/zstring.go on lines 36..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 199.

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

func _() {
    // An "invalid array index" compiler error signifies that the constant values have changed.
    // Re-run the stringer command to generate them again.
    var x [1]struct{}
    _ = x[OpThematicBreak-0]
Severity: Major
Found in pkg/md/zstring.go and 2 other locations - About 2 hrs to fix
pkg/md/zstring.go on lines 36..53
pkg/parse/zstring.go on lines 7..24

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 199.

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 Serve has a Cognitive Complexity of 31 (exceeds 20 allowed). Consider refactoring.
Open

func Serve(sockpath, dbpath string, opts ServeOpts) int {
    logger.Println("pid is", syscall.Getpid())
    logger.Println("going to listen", sockpath)
    listener, err := net.Listen("unix", sockpath)
    if err != nil {
Severity: Minor
Found in pkg/daemon/server.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

Function matchElement has a Cognitive Complexity of 31 (exceeds 20 allowed). Consider refactoring.
Open

func matchElement(segs []Segment, name string) bool {
    if len(segs) == 0 {
        return name == ""
    }
    // If the name start with "." and the first segment is a Wild, only match
Severity: Minor
Found in pkg/glob/glob.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

Function parseCSI has a Cognitive Complexity of 31 (exceeds 20 allowed). Consider refactoring.
Open

func parseCSI(nums []int, last rune, seq string) ui.Key {
    if k, ok := csiSeqByLast[last]; ok {
        if len(nums) == 0 {
            // Unmodified: \e[A (Up)
            return k
Severity: Minor
Found in pkg/cli/term/reader_unix.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

Function parseGetoptOptSpecs has 22 return statements (exceeds 4 allowed).
Open

func parseGetoptOptSpecs(v any) (parsedOptSpecs, error) {
    result := parsedOptSpecs{
        nil, map[*getopt.OptionSpec]string{},
        map[*getopt.OptionSpec]string{}, map[*getopt.OptionSpec]eval.Callable{}}

Severity: Major
Found in pkg/edit/complete_getopt.go - About 2 hrs to fix

    Method Closure.Call has a Cognitive Complexity of 30 (exceeds 20 allowed). Consider refactoring.
    Open

    func (c *Closure) Call(fm *Frame, args []any, opts map[string]any) error {
        // Check number of arguments.
        if c.RestArg != -1 {
            if len(args) < len(c.ArgNames)-1 {
                return errs.ArityMismatch{What: "arguments",
    Severity: Minor
    Found in pkg/eval/closure.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 pprintASTRec has a Cognitive Complexity of 30 (exceeds 20 allowed). Consider refactoring.
    Open

    func pprintASTRec(n Node, wr io.Writer, indent int, leading string) {
        nodeType := reflect.TypeOf((*Node)(nil)).Elem()
    
        var childFields, childrenFields, propertyFields []field
    
    
    Severity: Minor
    Found in pkg/parse/pprint.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 sgrTextToHTML has a Cognitive Complexity of 30 (exceeds 20 allowed). Consider refactoring.
    Open

    func sgrTextToHTML(ttyshot string) string {
        t := ui.ParseSGREscapedText(ttyshot)
    
        var sb strings.Builder
        for i, line := range t.SplitByRune('\n') {
    Severity: Minor
    Found in website/cmd/ttyshot/interp.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 inlineParser.processEmphasis has a Cognitive Complexity of 28 (exceeds 20 allowed). Consider refactoring.
    Open

    func (p *inlineParser) processEmphasis(bottom *delim) {
        var openersBottom [2][3][2]*delim
        for closer := bottom.next; closer != nil; {
            if !closer.canClose {
                closer = closer.next
    Severity: Minor
    Found in pkg/md/inline.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 Parse has a Cognitive Complexity of 28 (exceeds 20 allowed). Consider refactoring.
    Open

    func Parse(s string) Pattern {
        segments := []Segment{}
        add := func(seg Segment) {
            segments = append(segments, seg)
        }
    Severity: Minor
    Found in pkg/glob/parse.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 TestCmd has a Cognitive Complexity of 28 (exceeds 20 allowed). Consider refactoring.
    Open

    func TestCmd(t *testing.T, store storedefs.Store) {
        startSeq, err := store.NextCmdSeq()
        if startSeq != 1 || err != nil {
            t.Errorf("store.NextCmdSeq() => (%v, %v), want (1, nil)",
                startSeq, err)
    Severity: Minor
    Found in pkg/store/storetest/cmd.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 interact has a Cognitive Complexity of 28 (exceeds 20 allowed). Consider refactoring.
    Open

    func interact(ev *eval.Evaler, fds [3]*os.File, cfg *interactCfg) {
        if interactiveRescueShell {
            defer handlePanic()
        }
    
    
    Severity: Minor
    Found in pkg/shell/interact.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 assignOp.exec has a Cognitive Complexity of 27 (exceeds 20 allowed). Consider refactoring.
    Open

    func (op *assignOp) exec(fm *Frame) Exception {
        variables := make([]vars.Var, len(op.lhs.lvalues))
        for i, lvalue := range op.lhs.lvalues {
            variable, err := derefLValue(fm, lvalue)
            if err != nil {
    Severity: Minor
    Found in pkg/eval/compile_lvalue.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 benchmark has a Cognitive Complexity of 27 (exceeds 20 allowed). Consider refactoring.
    Open

    func benchmark(fm *Frame, opts benchmarkOpts, f Callable) error {
        if err := opts.parse(); err != nil {
            return err
        }
    
    
    Severity: Minor
    Found in pkg/eval/builtin_fn_time.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 parse has a Cognitive Complexity of 27 (exceeds 20 allowed). Consider refactoring.
    Open

    func parse(args []string, spec []*OptionSpec, cfg Config) ([]*Option, []string, *Option, bool) {
        var (
            opts       []*Option
            nonOptArgs []string
            // Non-nil only when the last argument was an option with required
    Severity: Minor
    Found in pkg/getopt/getopt.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

    Severity
    Category
    Status
    Source
    Language