Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Major restructuring for fixing the linting workflow errors and module style code writing. #266

Merged
merged 38 commits into from Feb 18, 2021

Conversation

tjgurwara99
Copy link
Member

@tjgurwara99 tjgurwara99 commented Feb 17, 2021

Apologies for this big PR but I thought I should try and fix the automated issues that this repository faces.

I have refactored quite a lot of code in order for this repository to work the way I think the Go implementation is meant to be. For example, you can work with any function in this repository as long as you do go get GitHub.com/tjgurwara99/Go. The go mod file should be changed so that people can use go get command with TheAlgorithm handle. This particular feature helps avoid the presence of repeated code - however, there are still quite a lot of functions like max, min etc being redeclared locally in each package. Maintainer's should consider adding a proper contribution guidelines file which may explain how people should go about making the code more modular.

As I said before I have restructured quite a lot of things in this repository and there are a lot of test files missing. Once I get time, I will try and write some more tests for the repository. But so far with all the tests that exists, there are no issues except for the strings/sbom submodule test and cipher/rsa submodule - I believe that the implementations are incorrect, but I didn't have time to check properly. All the automated linting tests with golangci-lint are running without any issues (thus we don't need any || true) in the workflow files.

Also note that there are some files that were completely written as a main module which makes go test go crazy so I have decided to comment the code out for now and as soon as I get some time, I will try and convert them into functions and write tests so that the whole repository management can be completely automated. There are quick fixes which can sometime cause issues long term but I didn't want to cause any issues for the repository so I refrained from doing that.

Hope it helps the maintainers 😄

I also wanted to ask the maintainers if the commented out code can be removed (the files where there are some tests and the main function that is commented out is not required)?

tjgurwara99 and others added 29 commits February 17, 2021 01:26
…r that appears in tests goes away. TODO: Maybe implement it with interfaces.
… are no clashes with the definition of Nodes - can be simplified using an interface
…t already existed in the math directory which I updated in the previous commit
@@ -3,10 +3,10 @@
package rot13

import (
"TheAlgorithms/Go/ciphers/caesar"
"github.com/tjgurwara99/Go/ciphers/caesar"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"github.com/tjgurwara99/Go/ciphers/caesar"
"github.com/TheAlgorithm/Go/ciphers/caesar"


n := p * q
// func main() {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do let me know if you think that the main function that have been commented out should be removed completely.

I kept them here because I think they are useful for making new test cases, but a lot of them already have test files so I wasn't sure I should completely remove these blocks.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it should be removed completely.

// "fmt"
// )

// func main() {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is now redundant except for maybe using this to make test cases the way it's developer meant for it to be used.

@@ -1,11 +1,13 @@
package main
package rsacipher
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This package fails the automated tests for the encryption and decryption. I thought it was failing because the implementation of modular exponentiation was incorrect but the test for modular exponentiation passes without issues so I'm actually not sure what the problem is. My current theory is that the inverse exponentiation function is incorrect but I did't try to test it.

@@ -1,10 +1,10 @@
package main
package bigrsacipher
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test for this file passes but because of the automated command in the golangtest.yml file, this folder is also skipped because it shares the same prefix as rsa folder.

@@ -0,0 +1,104 @@
package singlylinkedlist

// TODO not needed because there is already an implementation of SingleLinkedList
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment is self-explanatory

@@ -1,3 +1,5 @@
module TheAlgorithms/Go
module github.com/tjgurwara99/Go
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
module github.com/tjgurwara99/Go
module github.com/TheAlgorithms/Go

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The benefit of this can be seen in the rot13.go file in the cipher directory

}//end of monteCarlo
fmt.Println(monteCarlo(2<<18, cpus))
}
// func main() {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you can see this is fully a main module and would create a lot of conflicts. If I get some time this week, will rewrite it similar to other files.

@vedantmamgain
Copy link
Contributor

LGTM

@vedantmamgain vedantmamgain merged commit 7ea2964 into TheAlgorithms:master Feb 18, 2021
@cclauss
Copy link
Member

cclauss commented Feb 18, 2021

Congratulations! This is a huge step forward. My only regret is that we have a ton of code that does not pass golangci-lint. The original goal was that we could successfully run the linter on all code in the repo like we do for other TheAlgorithms language repos. Is golangci-lint the linter that we should be using for Go code? How can we get the entire codebase to pass the linter? Please review #198 and https://github.com/TheAlgorithms/Go/issues to see what can be closed or updated.

All the automated linting tests with golangci-lint are running without any issues (thus we don't need any || true) in the workflow files.

It looks like this PR comments out those lines instead of running them with || true. --> #267

@tjgurwara99
Copy link
Member Author

closes: #198

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants