gopatch icon indicating copy to clipboard operation
gopatch copied to clipboard

Add feature to support linting #19

Open lverma14 opened this issue 2 years ago • 2 comments

Functionality to list matches without modifying the target files.

User comments could be caught during the linting phase instead of their manual detection during the code review process. For example:

- if err != nil {
-     return err
-   }
-   return nil

Could be replaced by

+ return err

Current gopatch -p functionality completely modifies the target file and outputs nothing to the command line. There is no context on what is happening, what changes have been made or whether they have been made. This pull request extends gopatch to list matches and also display description comments if they exist, to give more context on what the patch does.
Now -l flag turns on lint mode. Associating -l with call to the preview function which prints patch description comments and displays the matches. Otheriwse, (-l = false) associated with call to modify function which applied patch & modifies.

Components Changed: Go.mod : added pkg/diff Go.sum : added pkg/diff main.go: added modify and preview functions and lint flag

For reading description comments: internal/engine/change.go : adding comments to change struct internal/parse/change.go : read comment while parsing internal/parse/ast.go : adding comments to change struct internal/parse/section/section.go : read description comments Main.go : modify apply to return comments

Added Test files for main_test.go

lverma14 avatar Aug 08 '22 02:08 lverma14

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Aug 08 '22 02:08 CLAassistant

Thanks @mindaugasrukas! Made all the changes you mentioned

lverma14 avatar Aug 08 '22 22:08 lverma14

LGTM

mindaugasrukas avatar Aug 11 '22 23:08 mindaugasrukas

Codecov Report

Merging #64 (7b1b2b7) into main (3851876) will increase coverage by 0.11%. The diff coverage is 81.48%.

:exclamation: Current head 7b1b2b7 differs from pull request most recent head b7f9960. Consider uploading reports for the commit b7f9960 to get more accurate results

@@            Coverage Diff             @@
##             main      #64      +/-   ##
==========================================
+ Coverage   86.43%   86.54%   +0.11%     
==========================================
  Files          38       38              
  Lines        2034     2051      +17     
==========================================
+ Hits         1758     1775      +17     
  Misses        221      221              
  Partials       55       55              
Impacted Files Coverage Δ
internal/parse/ast.go 50.00% <ø> (ø)
main.go 65.08% <77.27%> (+2.66%) :arrow_up:
internal/engine/change.go 82.00% <100.00%> (+0.36%) :arrow_up:
internal/parse/change.go 55.55% <100.00%> (+5.55%) :arrow_up:
internal/parse/section/section.go 98.79% <100.00%> (+0.04%) :arrow_up:

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more

codecov-commenter avatar Aug 18 '22 20:08 codecov-commenter