winutil icon indicating copy to clipboard operation
winutil copied to clipboard

Code Formatting of Repo - Add Preprocessing to Compilation Process - Introduction of Dev/Build Tools to WinUtil (Although very simple at the moment)

Open og-mrk opened this issue 1 year ago • 7 comments

Type of Change

  • [x] New feature
  • [x] Refactoring

Description

Makes sure all files don't have any trailing whitespace. And by putting in inside a function (the Do-PreProcessing function) it'll be possible in the future to do other things, like replacing Tabs with 4 spaces (the convention that's used the most.. other than Invoke-WPFMicrowin.ps1).

Testing

I ran the script and not only does it compile WinUtil, but also makes sure every file follows specific coding conventions (like having no trailing whitespace)

Additional Information

Not only does it do this preprocessing on other files in the repo.. it also does it on the Compile.ps1 file itself, indicating that PowerShell interpreter makes a Copy of the running script in memory, before actually running said script.. which's somewhat a new discovery (at least for me).

Checklist

  • [x] My code adheres to the coding and style guidelines of the project.
  • [x] I have performed a self-review of my own code.
  • [x] I have commented my code, particularly in hard-to-understand areas.
  • [ ] I have made corresponding changes to the documentation.
  • [x] My changes generate no errors/warnings/merge conflicts.

og-mrk avatar Jul 16 '24 20:07 og-mrk

Nice!

ruxunderscore avatar Jul 16 '24 20:07 ruxunderscore

@ChrisTitusTech Fixed.

Just discarded every change on my branch (HEAD) for every merge conflicts, and for updates.md file, I just added it with git add docs/updates.md to confirm its deletion.

og-mrk avatar Jul 25 '24 21:07 og-mrk

Now a few things happened:

  1. Even after using git for a while.. I got a bit cocky & did something, which I personally thought was quite impossible to do.. which's losing your changes with git 😆, I'll never do a Force Push to any branch without double/triple checking my previous commands, LOL
  2. The deletion of my code (yes, it was gone locally & on remote) was at first.. a bit annoying, had to re-write it from memory (no snippets, screenshots, or anything).. but thankfully, this happened to a somewhat simple PR, so it was trivial to re-program it again. It was a nice memory test as well 👍
  3. .. Somehow by starting over, I got a chance to re-think & improve upon my work, and thankfully I'm a bit more knowledgeable about RegEx (used it in Workflow Update PRs), so I used its power to make any Code Formatting choice, which I personally see it as the most fitting, or the "common convention" used in the source code.
  4. Also, my bad for the review comments above.. I didn't mean to delete my own PR 😢 (It was an accident), so it's now referencing to code that doesn't exist anymore (gone forever.. I think).

With that being said, I made the PR read to review. If you've anything you don't like or want to improve upon, @ChrisTitusTech you can do so. image

og-mrk avatar Jul 26 '24 04:07 og-mrk

Could you rename the function and the file Do-preprossing to something following the function naming convention from Microsoft like Start-Preprocessing or Invoke-Preprocessing https://learn.microsoft.com/en-us/powershell/scripting/learn/ps101/09-functions?view=powershell-7.4

Seeing as there are not really any code conventions for winutil in place, and it's quite the wild west, I think it's probably smart to try to adhere to the one from Microsoft at least

Marterich avatar Jul 26 '24 06:07 Marterich

Could you rename the function and the file Do-preprossing to something following the function naming convention from Microsoft like Start-Preprocessing or Invoke-Preprocessing https://learn.microsoft.com/en-us/powershell/scripting/learn/ps101/09-functions?view=powershell-7.4

Yahh I do agree on this weird naming convention I've used 😅, also didn't check the Official Microsoft PowerShell Standards, I'll be sure to refer to it when adding Formatting Rules, thanks @Marterich

og-mrk avatar Jul 26 '24 14:07 og-mrk

This is one big PR @og-mrk still reviewing it. Looks awesome from a cleanup and standardizing some of the files.

ChrisTitusTech avatar Jul 31 '24 01:07 ChrisTitusTech

Thanks @ChrisTitusTech for taking your time to review this.

And although I'm happy with the result of this tiny script I've made (it's quite simple if you checked Invoke-Preprocessing code, just some find & replace code).. there's still room for improvement, and because it's a script that can modify almost every file in the repo.. I'll need to test it more, and see what other formatting rules to add/implement.

Therefore, I'll convert this PR to draft until I see/think it's ready (both "feature" and stability wise).

I know the core concept & idea is finished (tested it with every change along the way).. but when you've RegEx which's untested to every possible case, and said RegEx can modify your entire code base.. yahh, I think I'll do some Unit Testing for this script. And the Tests themselves shouldn't change over time.. as long as the code itself (formatting rule) doesn't change, because the input (possible cases) for each Rule is many, but limited, and expected output is always one (the desired formatted code).

og-mrk avatar Jul 31 '24 03:07 og-mrk

Even though there's more Formatting rules I'd like to add.. the current (and somewhat simple) RegEx formatting is ok.. more complex formatting would require parsing PowerShell and figuring out the AST (Abstract Syntax Tree), which in the long run.. would make it a script that can be used in any project, and would work just as intended (formatting PowerShell code bases).

@ChrisTitusTech Tested this script, and it works as intended. Will make PR ready for review...

og-mrk avatar Aug 06 '24 18:08 og-mrk