Giter Site home page Giter Site logo

gofor's Introduction

Go For - Range Copy - Editing

A GoLand plugin to help developers detect an edge case: editing a range assigned variable.

Motivation

Go dictates range clause to copy collection before iterating.

Consider the following go code

package main
import "fmt"
type Editable struct{ i int }

func pumpUp(e *Editable)  {
 e.i = 100
}

func main() {
 es := []Editable { { i : 1 }, { i : 2 }, { i : 3 }, { i : 4 } }
 for _, e := range es {
 	pumpUp(&e)
 }
 fmt.Printf("%v", es)
}

below outlines the output in Go, Swift, Objective-C, Java (keeping the semantics same)

Language Output
Go [{1} {2} {3} {4}]
Swift [{100} {100} {100} {100}]
Java [{100} {100} {100} {100}]
Objective-C [{100} {100} {100} {100}]

This plugin tries to catch such use cases and highlight them for the developer to reconsider the logic

Supported

  1. Detect usages of pointer references of assigned variable in a for block
  2. Detect editable method references of assigned variable in the block

To be supported

  1. Assigned variable is predeclared before the range clause
  2. Direct assignment of the struct's properties

* please see issues for more

Output

Highlighted Text

References

Assigned Variable = e in the above go for block

Gradle Scan: https://scans.gradle.com/s/vywyvtekrzqfg Gradle Scan

Reference: Plugin Extension Points in IntelliJ SDK Docs

gofor's People

Contributors

ravivooda avatar

Watchers

 avatar  avatar  avatar

gofor's Issues

Remove debug logs from the project

Specifically, need to remove 'PsiViewer:201.6251.22-EAP-SNAPSHOT.1' from the build.Gradle file. This is only needed for my debugging purposes

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.