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

refactor: Cleanup Linter Complaints and Setup Makefile #63

Merged
merged 9 commits into from
Dec 7, 2021

Conversation

shahzadlone
Copy link
Member

@shahzadlone shahzadlone commented Nov 30, 2021

DESCRIPTION:

This PR sets up a Makefile workflow and resolves the cries from these following Go Linters (around 150 linter errors):
- deadcode
- gosimple
- govet
- ineffassign
- staticcheck
- structcheck
- typecheck
- unused
- varcheck

ISSUE:

Started from #42 but added alot more goodies.

BEFORE-MERGE:

Since a lot of dead code had to be edited out, I predict lots of breakage if new features are merged that make use of any of that code that was commented (without syncing with this branch). So really ensure even after there are no conflicts that nothing broke.
Needs a very thorough review to ensure I haven't done any BAD GO THINGS while resolving these linter errors.
Would prefer like @AndrewSisley suggested to also delete as much code as possible rather than having comments before the merge.

TODO:

There are tons more linters we can now very easily add with our configuration file (.golangci.sourceinc.yaml). Some good ones that I think we can add soon are:

  • errcheck
  • wrapcheck
  • errorlint
  • gci
  • exportloopref
  • megacheck
  • govet
  • wsl
  • nilerr
  • nilnil

NOTES:

There are some nolint:<linter-to-ignore> style placed to suppress the linter that we should eventually address. These can also be quickly found if you run make lint:todo command (and have ripgrep installed).

conflicts (so that auto-merge doesn't mess things up).
Merge branch 'develop' into lone/feature/linters-and-nice-to-haves

Tests still failing, still investigating.
@todo
Copy link

todo bot commented Nov 30, 2021

Handle collection name from @collection directive

// // @todo: Handle collection name from @collection directive
// Name: name,
// Type: obj,
// Args: gql.FieldConfigArgument{
// "filter": newArgConfig(config.filter),
// },


This comment was generated by todo based on a todo comment in be4c24b in #63. cc @sourcenetwork.

Copy link
Contributor

@AndrewSisley AndrewSisley left a comment

Choose a reason for hiding this comment

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

Looks good to me - thanks for the cleanup :) Just have a couple of minor comments on specific lines, plus the below:

  1. I would much prefer the deletion of unused code instead of commenting it out, in most cases you seem to be making the problem worse in a sense by adding an an extra line of eye-space describing that it is commented out because it is unused.
  2. Having to declare new names for every error variable within a scope doesn't seem ideal, and feels like a waste of mental energy when writing, and needless code clutter when reading - however this feels like it is potentially useful due to a Go 'quirk' allowing multiple variables with the same name (instead of the usual overwrite the existing variable in most langs I've worked with). Is this ever a problem with errors and we want to enforce the lint-rule, or is it safe to disable this one? (or is the lint rule getting me confused and Go behaves like a normal lang here, and the lint is about mutation or something?)

db/db.go Outdated Show resolved Hide resolved
db/collection_update.go Show resolved Hide resolved
@sourcenetwork sourcenetwork deleted a comment from todo bot Nov 30, 2021
@sourcenetwork sourcenetwork deleted a comment from todo bot Nov 30, 2021
@sourcenetwork sourcenetwork deleted a comment from todo bot Nov 30, 2021
@sourcenetwork sourcenetwork deleted a comment from todo bot Nov 30, 2021
@shahzadlone
Copy link
Member Author

shahzadlone commented Nov 30, 2021

Thanks for the review @AndrewSisley, responding to your comment here.

Looks good to me - thanks for the cleanup :) Just have a couple of minor comments on specific lines, plus the below:
I would much prefer the deletion of unused code instead of commenting it out, in most cases you seem to be making the problem worse in a sense by adding an an extra line of eye-space describing that it is commented out because it is unused.

I am on the same same page about deletion of unused code instead of commenting it out, I did that for now as It is a big batch of removal for lots of unused code spanning many files and there could perhaps be some important unused code that we may want for reference (sometimes it's easier to have some code as comments rather than to look at past git history). Will be nice if @jsimnz can point out code that I commented out that he would like to keep for reference, this way before the PR gets merged I can delete that code. Another reason I was hesitant to delete code straight away was if there was any partial implementation that was being worked on and somehow got merged into develop (which we should absolutely avoid in the future). The extra line of describing why the comment was there is only for the draft PR review to help understand why a comment was made, rest assured those can also be removed before the merge.

Having to declare new names for every error variable within a scope doesn't seem ideal, and feels like a waste of mental energy when writing, and needless code clutter when reading - however this feels like it is potentially useful due to a Go 'quirk' allowing multiple variables with the same name (instead of the usual overwrite the existing variable in most langs I've worked with). Is this ever a problem with errors and we want to enforce the lint-rule, or is it safe to disable this one? (or is the lint rule getting me confused and Go behaves like a normal lang here, and the lint is about mutation or something?)

Absolutely, I found that this was only an issue for 2 of the linters which now may have been disabled, it was referring to ineffectual assignment in GO if you are curious as to what it was. Another one had issues overwriting only when inside a nested block, which I am also guessing was due to some GO quirk. I changed and played with lots of different linters, I think the ones we have now shouldn't annoy us with issues like this anymore. If they do, let me know and we can have a chat and configure the linter rules again.

@AndrewSisley
Copy link
Contributor

Ahh I wouldnt worry about partial implementations here - you are deleting full declarations, not parts of function so the compiler will flag anything pretty safely I think. But fair enough :) I can be quite heavy-handed with this kind of stuff lol

Nice - thanks for that effort plus info (re error stuff) :)

Copy link
Member

@jsimnz jsimnz left a comment

Choose a reason for hiding this comment

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

just a few changes.... :D

api/http/api.go Outdated Show resolved Hide resolved
cli/defradb/cmd/query.go Show resolved Hide resolved
cli/defradb/cmd/start.go Show resolved Hide resolved
db/fetcher/dag.go Outdated Show resolved Hide resolved
db/fetcher/fetcher.go Outdated Show resolved Hide resolved
query/graphql/schema/generate.go Outdated Show resolved Hide resolved
query/graphql/schema/generate.go Outdated Show resolved Hide resolved
query/graphql/schema/generate.go Outdated Show resolved Hide resolved
query/graphql/schema/generate_test.go Outdated Show resolved Hide resolved
query/graphql/schema/manager.go Outdated Show resolved Hide resolved
@jsimnz jsimnz linked an issue Dec 2, 2021 that may be closed by this pull request
2) Resolve new linter errors from the merge with parents.
3) Resolved the conflicts from: Merge branch 'develop' into lone/feature/linters-and-nice-to-haves
@todo
Copy link

todo bot commented Dec 4, 2021

paramaterize ns/suffix

// @todo paramaterize ns/suffix
func newBaseCRDT(store core.DSReaderWriter, namespace ds.Key) baseCRDT {
return baseCRDT{
store: store,


This comment was generated by todo based on a todo comment in 8ccafae in #63. cc @sourcenetwork.

@todo
Copy link

todo bot commented Dec 4, 2021

Expand delta metadata (investigate if needed)

// @todo: Expand delta metadata (investigate if needed)
type LWWRegDelta struct {
Priority uint64
Data []byte


This comment was generated by todo based on a todo comment in 8ccafae in #63. cc @sourcenetwork.

@todo
Copy link

todo bot commented Dec 4, 2021

check if NonNull is possible here

// @todo: check if NonNull is possible here
//case *gql.NonNull:
// get subtype
}


This comment was generated by todo based on a todo comment in 8ccafae in #63. cc @sourcenetwork.

are surpressed are the ones that are unused code / dead-code.
@shahzadlone shahzadlone marked this pull request as ready for review December 4, 2021 03:36
@sourcenetwork sourcenetwork deleted a comment from todo bot Dec 4, 2021
@sourcenetwork sourcenetwork deleted a comment from todo bot Dec 4, 2021
@sourcenetwork sourcenetwork deleted a comment from todo bot Dec 4, 2021
@sourcenetwork sourcenetwork deleted a comment from todo bot Dec 4, 2021
@sourcenetwork sourcenetwork deleted a comment from todo bot Dec 4, 2021
@sourcenetwork sourcenetwork deleted a comment from todo bot Dec 4, 2021
@sourcenetwork sourcenetwork deleted a comment from todo bot Dec 4, 2021
@sourcenetwork sourcenetwork deleted a comment from todo bot Dec 4, 2021
Copy link
Member

@jsimnz jsimnz left a comment

Choose a reason for hiding this comment

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

lgtm

@shahzadlone shahzadlone merged commit 97a2d7c into develop Dec 7, 2021
@shahzadlone shahzadlone deleted the lone/feature/linters-and-nice-to-haves branch December 10, 2021 17:24
@orpheuslummis orpheuslummis mentioned this pull request Jan 29, 2022
shahzadlone added a commit to shahzadlone/defradb that referenced this pull request Feb 23, 2024
)

* Linter and Makefile setup.

* Change go-cross-build.sh script to be executable.

* All default linters errors resolved.
Some todo's needed to temporarily bybass some linter errors.

* Comment line-wise instead of block-wise, to ensure that we can get merge
conflicts (so that auto-merge doesn't mess things up).

* Fix the txn.go bug

* Clean up all other @todo linter errors. Now the only linter errors that
are surpressed are the ones that are unused code / dead-code.
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.

Add Linter for Proper Error Handling
3 participants