kaizen-ai / kaizenflow

KaizenFlow is a framework for Bayesian reasoning and AI/ML stream computing
GNU General Public License v3.0
110 stars 76 forks source link

Create a Docker script to clean up / format Solidity #10

Closed gpsaggese closed 1 year ago

gpsaggese commented 1 year ago

We want to extend our beloved linter also to work with Solidity

Maybe we can become with a simple script to lint / format, before adding this to the main flow

Some promising links:

Step 1:

Step 2:

Step 3:

gpsaggese commented 1 year ago

Assigned to @Jingyun-li

gpsaggese commented 1 year ago

@tamriq can you re-route to one of the team members?

samarth9008 commented 1 year ago

@gpsaggese @tamriq

I understand the overall goal for this issue that we are building a linter for solidity but I have few questions.

1) From my understanding, I will have to create a script which will run prettier and ethlint and from the reference of the ctags.sh it should run inside a docker container. Am I right about this?

2) Are there any reference for setting up our python linter? I hope I will get some more clear idea from that too.

3) What will the end file looks like and how should I test it?

gpsaggese commented 1 year ago

Switched to @samarth9008

@gpsaggese @tamriq

I understand the overall goal for this issue that we are building a linter for solidity but I have few questions.

  1. From my understanding, I will have to create a script which will run prettier and ethlint and from the reference of the ctags.sh it should run inside a docker container. Am I right about this?

You need to write a script exactly like ctags.sh called dev_scripts/lint_solidity.sh but changing the container and the script to run. dev_scripts/lint_solidity.sh

  1. Are there any reference for setting up our python linter? I hope I will get some more clear idea from that too.

There is a bug about sharing our Python linter (https://github.com/cryptokaizen/cmamp/issues/4192), but that's a complicated system

  1. What will the end file looks like and how should I test it?

dev_scripts/lint_solidity.sh has the same structure as ctags.sh Once that script runs the files passed to the script are transformed in place (e.g., they are going to be beautified and then issues are going to be found).

No need to test this transformation.

Let's start iterating (quickly and baby steps) and things are going to be clearer.

samarth9008 commented 1 year ago

@gpsaggese

Okay understood the concept. I am able to run the script for single files. However, for multiple files input from command lines, I am looping through the arguments but facing an error in that saying that loop variable(arg): unbound variable. I am working on it now. All code is pushed over here.

https://github.com/sorrentum/sorrentum/blob/Issue10_Create_a_Docker_script_to_clean_up/format_Solidity/dev_scripts/lint_solidity.sh

samarth9008 commented 1 year ago

@gpsaggese

What I have realised from this error is, since we are creating another script /run_linter.sh inside the main lint_solidity.sh which will run the linter on the files passed as a command line arguments inside the container. When we run the file lint_solidity.sh, first it will build a docker image and the environment variables. Then it will create a script file run_linter.sh. While creating that script, its loop variable arg which will read the command line arguments, will require a value. Since these values will be passed once we run the script inside the container and when it executes the run_linter.sh and not during the execution of lint_solidity.sh. So the execution will stop and it will not move forward. Also assigning the default value to arg variable will override the arg variable inside the for loop and the loop will not execute with the right files.

I hope you have understood the error.

We can also try inputting the whole command line argument (The strings of files) as input to the prettier and solium. It works perfectly fine with the prettier but solium does not support multiple files input.

One solution I have found is instead of supplying each files on the command line, Can we supply the directory on the command line which contains our *.sol files? Directory support is provided for both of them.

Code: https://github.com/sorrentum/sorrentum/blob/Issue10_Create_a_Docker_script_to_clean_up/format_Solidity/dev_scripts/lint_solidity.sh

gpsaggese commented 1 year ago

1) I understand the problem and your solution works fine. Good job.

2) It's better to provide the list of files since if you want to lint an entire dir you can compose with bash

lint_solidity.sh $(find $DIR -name "*.sol")

We can also make the script smarter with something like

if [[ -d $DIR ]]; then

Lint dir.

... elif

Lint all passed files

...



3) Let's do a PR so we can review and merge and you can move to the next bug.
samarth9008 commented 1 year ago

Found a better solution which will satisfy the requirements for passing the file names on command line

1) Created a temporary directory which will copy all the file names passed as command args.

2) Since prettier will accept multi-file inputs, we will pass $@ to it and changes will happen at the permanent location.

3) The ethlint will lint the code on temporary directory and will present any errors on the terminal.

4) The temporary directory will then be deleted and any error which were displayed by the ethlint can be solved on the permanent location.

Created a PR of this.