apex-enterprise-patterns / fflib-apex-mocks

An Apex mocking framework for true unit testing in Salesforce, with Stub API support
BSD 3-Clause "New" or "Revised" License
423 stars 214 forks source link

Implement Prettier and EditorConfig #114

Closed ClayChipps closed 3 years ago

ClayChipps commented 3 years ago

In an attempt to end the religious code formatting wars, there had been some prior discussion about using tools such as Prettier coupled with EditorConfig in order to enforce a baseline standard of formatting for new additions to the codebase, and to minimize the erroneous whitespace changes that many PRs across all of the AEP repos introduce.

In that spirit, this PR introduces the following changes:

  1. Adds an EditorConfig file, with a baseline configuration
  2. Adds a Prettier config file, which defers to EditorConfig for its spacing determinations
  3. Adds a Prettier ignore file, to ignore files commonly not desired to be formatted
  4. Reformats the entire codebase with the aforementioned configuration

This should provide a solid foundation for the standardization of formatting for the repo, given the following considerations.

  1. EditorConfig is supported by most all modern IDEs, and has a rich plugin support community
  2. EditorConfig allows potential contributors to immediately begin working off of the same "sheet of music" that we setup
  3. Prettier provides us with opinionated code formatting, saving us from religious debates over silly things
  4. Prettier defers its basic configuration to EditorConfig, which enhances the ability for contributors to follow a standard formatting guideline for the project

Given the above, I think that the EditorConfig configuration is up for debate and consideration. I used a configuration that has worked well for our teams in the past, but as always, we should decide on what configuration makes the most sense for the AEP projects. I am open and happy to hear some feedback regarding this, and happy to make a couple of iterations to see what pans out.

The repo has been in a relatively stable place for a while now, and I think this is a good time for us to figure this out for the mocks repo, as it is one of the most stable AEP projects.


This change is Reviewable

ImJohnMDaniel commented 3 years ago

G'day @ctchipps Thanks for the submission. As you say, this is "religious war" territory. 😂

Let @daveespo, @stohn777, and I take some time and see what we want to include and we will get you feedback.

Cheers!

daveespo commented 3 years ago

Hi @ctchipps ,

Thanks for this PR -- we discussed it at our monthly review meeting and here's the summary, in no particular order :-)

You may be asking: what about fflib-apex-common and force-di and at4dx?

I'll admit that I've never used Prettier in an Apex project so if there are any traps that the above decisions walk us into, please chime up before revising this PR :-)

ClayChipps commented 3 years ago
  1. Updated .cls and .trigger files to indent using tabs instead of spaces (I know we said .cls only, but wasn't sure if we wanted to mix space and tabs between the two since I feel most people think of .trigger the same as *.cls)
  2. Removed .sfdx-project.json overrides, no complaints on that
  3. Added a CONTRIBUTING.md and added a reference to it in the README.md

Yes, I did use Dang Mai's apex plugin for the formatting. Did you install the latest version of prettier, and if so, are you on JDK 11? Typical errors from the prettier apex plugin are from path length being too long (if you are on windows), or recently prettier 1.9.0 requires JDK 11, as opposed to JDK 8. I was able to recreate the formatting on a different machine today.

In my experience I don't see any of the above decisions leading us into any traps. We've reliably used the apex prettier plugin on a number of projects and thus far the AST has never lead us astray. Dang Mai has done a really good job ensuring that the AST of the original code and formatted code is always the same, and I've never ran into a scenario where the post-formatted code behaves any differently then pre-formatted code.