GithubHelp home page GithubHelp logo

joffref / genz Goto Github PK

View Code? Open in Web Editor NEW
7.0 7.0 3.0 139 KB

✨ Never write toil/boilerplate go code again! ✨

Home Page: https://pkg.go.dev/github.com/Joffref/genz

License: Apache License 2.0

Makefile 1.03% Go 98.97%
generator go golang tool

genz's Introduction

Hi there 👋

I'm Mathis Joffre, I'm 22 years old and I'm an apprentice engineer currently interested in Network, system administration, and software engineering.

  • 🔭 I’m currently working on 5GCoreNetSDK, it is an open source student project that provides a set of APIs to access or provide services in 5G Core Network.
  • 👯 I’m looking to collaborate on open source project
  • 📫 How to reach me: on Linkedin or GitHub

genz's People

Contributors

arthurmelton avatar joffref avatar leorolland avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

genz's Issues

[Feature]: parse methods comments

Contact Details

No response

What is the feature?

I want to be able to get comments of the Methods, the same as for Attributes.
TODO in code here

What is the solution?

?

Why is this important?

core feature of GenZ
to be able to read comments on methods

What are the alternatives?

No response

What is the impact?

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

[Feature]: get the aliased name of an imported type

Contact Details

No response

What is the feature?

I want to get the package name qualifier following the aliased name I gave in the parsed go input

What is the solution?

A solution happened!

Why is this important?

A reason happened!

What are the alternatives?

An alternative happened!

What is the impact?

An impact happened!

Code of Conduct

  • I agree to follow this project's Code of Conduct

[Feature]: Provide a way to test templates

Contact Details

No response

What is the feature?

The main idea is to be able to test the generated code against an expected output. Moreover, we should be able to test the behavior of templates against common scenarios, in order to prevent regression.

What is the solution?

Let's define it together!

Why is this important?

This could be a huge blocker for company-grade solutions wanting to use GenZ as they are not able to test templates to avoid regression.

What are the alternatives?

No response

What is the impact?

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

[Feature]: Parse Interfaces

What is the feature?

We should be able to parse interfaces, and thus generate code from them, such as mock or anything else (just for examples).

Let's say we expose the following attributes :

  • Name (string): Name of the interface
  • Comments ([]string): List comments above the interface.
  • Methods ([]Methods): Methods that express this interface.
  • SubInterfaces ([]self): Interfaces that compose this interface. (Maybe optional for now)

Why is this important?

It might be a great asset to differentiate from other tools.

Code of Conduct

  • I agree to follow this project's Code of Conduct

[Enhancement]: Cannot test a Type with the same name as the parsed type because of name overlapping

Contact Details

No response

What is the problem?

We cannot generate a Type with the same name as the parsed type because of name overlapping.

Ex.

package main

type Human struct {
	//+required
	Firstname string
	//+required
	Lastname string
	Age uint
}

Template

package main

type {{ .Type.InternalName }}) struct {}

if you want genz tests, you will have both human.go and expected.go in the same package, with the name Human overlapping

What is the solution?

Quickfix https://github.com/Joffref/genz/tree/expected-in-dir

Why is this important?

No response

What are the alternatives?

to discuss

What is the impact?

blocker for some cases

Code of Conduct

  • I agree to follow this project's Code of Conduct

[Bug]: Unable to create issues for features/enhancements

Contact Details

No response

What happened?

[Bug]: Unable to create issues for features/enhancements

Version

beta

Relevant log output

No response

Template

No response

Config

No response

File

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

[Enhancement]: Improve readme

Contact Details

No response

What is the problem?

README has to explain the tool's installation, design, and usage.

What is the solution?

No response

Why is this important?

That's the first impression our tool is giving to people.

What are the alternatives?

No response

What is the impact?

Huge I hope <3

Code of Conduct

  • I agree to follow this project's Code of Conduct

[Feature]: Import template using HTTP

Contact Details

No response

What is the feature?

Be able to specify, an HTTP URL instead of a path for a template.

What is the solution?

Parse template argument to check if it starts https://. If it is true, let's download it in tmp dir and run genz with this template.

Why is this important?

No response

What are the alternatives?

No response

What is the impact?

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

[Feature]: Parse methods

Contact Details

No response

What is the feature?

Parse type methods into parser.Method struct

What is the solution?

No response

Why is this important?

No response

What are the alternatives?

No response

What is the impact?

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

[Enhancement]: Consume GenZ as code - Proposal WIP

Contact Details

No response

What is the problem?

At the moment GenZ uses a template to render go code. GenZ workflow could be described as follows:

flowchart LR
  parser[Parse Go code] ---> object[GenZ parsed element]
  generator[GenZ generator] --->|Consume|object 
  generator --->|Inject ParsedElement|Template
  Template --->|Generate| code[Go code]

There are some caveats with this approach:

  • Template is hard to write as there are no common linting solutions or syntax checkers.

What is the solution?

On viable solution could be to expose a fluent API, to write Go code with Go code. It ensures syntax consistency, flexibility, and hardened testing.

API Definition

Code object

// ...
Code(buffer, "name").
	WithHeader("My Header").
	WithHeaders([]string{"line 1", "line 2"}).
	WithImport("test").
	WithImports([]string{"hello", "world"}).
	WithNamedImport("b", "bob")
	WithNamedImports(map[string]string{
	  "t": "toto"
	}).Generate()
// ...
// My Header
// line 1
// line 2
package name

import (
   "test"
   "hello"
   "world"
   b "bob"
   t "toto"
)

Declaration

A declaration is defined as the following interface:

type Declaration interface {
	Generate() string
}
// ...
Code(buffer, "name").
  WithDeclaration(MyDeclaration).
  WithDeclarations([]Declaration{MyDeclarationOne, MyDeclarationTwo}).
  Generate()
// ...

Function Declaration

// ...
FuncDecl("HelloWorld").
	WithDoc("HelloWorld does blabla").
	WithReceiver("m", "MyReceiver", true).
	WithParameter("name", "string").
        WithParamaters(map[string]string{
		"world": "string",
		"n": "int"
	}).
	WithReturn("string").
        WithReturns([]string{"int", "error"}).
        WithBody(`return "", 0, nil`).
	Generate()
// ...
// HelloWorld does blabla
func (m *MyReceiver) HelloWorld(name string, world string, n int) (string, int, error) {
	return "", 0, nil
}

Struct Declaration

// ...
StructDecl("MyStruct").
	WithDoc("A comment").
	WithAttribute("integer" "int", "json:int").
        WithAttributes(??).
	Generate()
// ...
// A comment
type MyStruct struct {
	integer int `json: int`
        hello func() string
}

Interface Declaration

Why is this important?

A reason happened!

What are the alternatives?

An alternative happened!

What is the impact?

An impact happened!

Code of Conduct

  • I agree to follow this project's Code of Conduct

[Feature]: Parse struct tags

What is the feature?

GenZ should be able to parse struct tags. For instance:

type Human struct {
    name string `json: name`
}

name in this struct should be retrieved using this syntax (or equivalent): .Attributes[0].Tags["json"]

  • I agree to follow this project's Code of Conduct

[Enhancement]: Display errored test/file on genz test comparison

Contact Details

No response

What is the problem?

Actual output when running genz tests (via make test-examples) doesn't give information about the context on failure.

▶  genz(refacto-generator-to-parse-1-type-only) $ make test-examples
genz test -directory ./examples/ -v
genz: genz test ./examples/
running test in examples/1_validator/test
genz: generating template for type Human
genz: generated buffer (716 bytes)
genz: gofmt-ing buffer
genz: wrote human_validator.gen.go (580 bytes)
running test in examples/2_getters/test
genz: generating template for type Car
genz: generated buffer (142 bytes)
genz: gofmt-ing buffer
genz: wrote car.gen.go (122 bytes)
?   	github.com/Joffref/genz/examples/2_getters/test	[no test files]
running test in examples/3_tests/tests/0_no_getter
genz: generating template for type Car
genz: generated buffer (19 bytes)
genz: gofmt-ing buffer
genz: wrote car.gen.go (13 bytes)
?   	github.com/Joffref/genz/examples/3_tests/tests/0_no_getter	[no test files]
running test in examples/3_tests/tests/1_1_getter
genz: generating template for type Car
genz: generated buffer (75 bytes)
genz: gofmt-ing buffer
genz: wrote car.gen.go (66 bytes)
=== RUN   TestCarGetModel
--- PASS: TestCarGetModel (0.00s)
PASS
ok  	github.com/Joffref/genz/examples/3_tests/tests/1_1_getter	(cached)
genz: Difference between expected.go and generated file:
  []uint8(
  	"""
  	... // 22 identical lines
  		// WORK IN PROGRESS
  	
- 		// map[_0:+>18 _1:<99]
+ 		// map[_0:&#43;&gt;18 _1:&lt;99]
  	
  		return nil
  	... // 2 identical lines
  	"""
  )

make: *** [Makefile:23: test-examples] Error 1

What is the solution?

I guess we can have a best output to read the results

  1. Getting PASS at the end of unit tests execution even with a failure is a bit tricky because we could understand everything went well, (or is that me ?)
  2. I see that somewhere I got a diff genz: Difference between expected.go and generated file: but there is no information about the concerned directory or test name (I suggest to print the directory and the test name)
  3. (bonus) Maybe we can have a summary at the end ?

Why is this important?

Because currently it's hard to determine where a test did not match

What are the alternatives?

no idea

What is the impact?

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

[Enhancement]: Document exposed attributes to template

Contact Details

No response

What is the problem?

There is no documentation on parsed attributes.

What is the solution?

No response

Why is this important?

No response

What are the alternatives?

No response

What is the impact?

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

[Enhancement]: zero value behind a Type

Contact Details

No response

What is the problem?

I want to be able to express the zero value behind a Type

What is the solution?

No response

Why is this important?

No response

What are the alternatives?

No response

What is the impact?

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

[Bug]: Attribute Type returns all path to type

Contact Details

No response

What happened?

Exemple

type Car struct {
	tires []Tire
}

type Tire struct{}

Will have it's tires .Type value equal to github.com/Joffref/genz/examples/getters/test.Tire in template
We only want "Tire".

Version

beta

Relevant log output

No response

Template

No response

Config

No response

File

parser.go

Code of Conduct

  • I agree to follow this project's Code of Conduct

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.