prettier-plugin-apex icon indicating copy to clipboard operation
prettier-plugin-apex copied to clipboard

Differences when running prettier more than one time over the same file content

Open mnunezdm opened this issue 1 year ago • 2 comments

Hello!!

First of all congrats on the native parser solution, just ran it through my entire company code base (7500 files) and went from 1 hour and 10 minutes on the First run to 10 minutes on the native

After running it I found 4 mismatches between the first run (over an 'ugly' file) and the second run (over a 'prettied' file)

Describe your Issue

		{
			"files": "**/*.{cls,trigger,apex}",
			"options": {
				"tabWidth": 4,
				"apexStandaloneParser": "native"
			}
		},

1.1. First run

			REP_obj_casosProductos__c nuevoCasoProducto = new REP_obj_casosProductos__c /*Name = ESDIM_cls_metodosComunes.TEST,*/(
				REP_fld_product__c = equiposMaestro[i].Id,
				REP_fld_caso__c = lstCase[i].Id
			);
			insert nuevoCasoProducto;

1.2. Second run

			REP_obj_casosProductos__c nuevoCasoProducto = new REP_obj_casosProductos__c(
				/*Name = ESDIM_cls_metodosComunes.TEST,*/ REP_fld_product__c = equiposMaestro[
						i
					]
					.Id,
				REP_fld_caso__c = lstCase[i].Id
			);
			insert nuevoCasoProducto;

2.1. First run

						if (
							mapOrderItem.containsKey(
								porder.OrderId
							) /* && mapOrderTank.containsKey(porder.OrderId)*/
						) {
							System.debug('Lo contiene el map de OI');
							mapOrderItem.get(porder.OrderId).add(porder);
							//mapOrderTank.get(porder.OrderId).add(porder.ESESO_fld_nombreTanqueL__c);
						} else {
							System.debug('No lo contiene el mapa de OI');
							mapOrderItem.put(
								porder.OrderId,
								new List<OrderItem>{ porder }
							);
							//mapOrderTank.put(porder.OrderId, new List<Id>{porder.ESESO_fld_nombreTanqueL__c});
						}

2.2. Second run

						if (mapOrderItem.containsKey(porder.OrderId)) {
							/* && mapOrderTank.containsKey(porder.OrderId)*/
							System.debug('Lo contiene el map de OI');
							mapOrderItem.get(porder.OrderId).add(porder);
							//mapOrderTank.get(porder.OrderId).add(porder.ESESO_fld_nombreTanqueL__c);
						} else {
							System.debug('No lo contiene el mapa de OI');
							mapOrderItem.put(
								porder.OrderId,
								new List<OrderItem>{ porder }
							);
							//mapOrderTank.put(porder.OrderId, new List<Id>{porder.ESESO_fld_nombreTanqueL__c});
						}

3.1. First run

	@TestVisible
	private static Map<String, Map<String, Map<String, QueryExecuted>>> executeQueryObjetosLabel(
		Map<String, Map<String, Map<String, PicklistToExecute>>> mapParams,
		List<QueryExecuted> listQueryExec /*,SObject valoresObjeto*/
	) {

3.2. Second run

	@TestVisible
	private static Map<String, Map<String, Map<String, QueryExecuted>>> executeQueryObjetosLabel(
		Map<String, Map<String, Map<String, PicklistToExecute>>> mapParams,
		List<QueryExecuted> listQueryExec
	) {
		/*,SObject valoresObjeto*/

4.1. First run

	public static REP_obj_organizacionVenta__c createOrganizacionVtas(
		boolean bolInsert,
		String strCOdigoOrganizacion /*, REP_obj_sociedad__c objSociedad*/
	) {

4.2. Second run

	public static REP_obj_organizacionVenta__c createOrganizacionVtas(
		boolean bolInsert,
		String strCOdigoOrganizacion
	) {
		/*, REP_obj_sociedad__c objSociedad*/

Additional information (please fill this out):

  • OS: macos
  • Version (you can check this by running npm ls prettier-plugin-apex): [e.g. [email protected]]
AP_SALESFORCE@ /Users/miguelnunezdiaz-montes/work/AP_SALESFORCE
└── [email protected]
  • Prettier Version (you can check this by running npm ls prettier): [e.g. [email protected]]
AP_SALESFORCE@ /Users/miguelnunezdiaz-montes/work/AP_SALESFORCE
├─┬ [email protected]
│ └── [email protected] deduped
└── [email protected]
  • Java Version (you can check this by running java -version): [e.g. openjdk version "11"]
$ java -version
openjdk version "21.0.2" 2024-01-16 LTS
OpenJDK Runtime Environment Temurin-21.0.2+13 (build 21.0.2+13-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.2+13 (build 21.0.2+13-LTS, mixed mode)

Huge congrats again on the performance boost!!!!!!!

mnunezdm avatar Apr 21 '24 21:04 mnunezdm

Thanks (again) for testing the native parser out, I appreciate the help in checking out the edge cases for it.

May I ask how you did the tests? (i.e. how did you find out the diffs between the standard parser vs the native parser)

I'm curious to know if it's actually the problem with the native parser, or if you found a bug with some unstable formatting in the library itself (unstable here means that multiple subsequent formats change the formatted code, usually it's a bug that needs fixing).

dangmai avatar Apr 21 '24 21:04 dangmai

Hello!

Thanks to you for making this awesome product!!!

My test was:

  1. Run prettier to all my codebase using the standard parser
  2. Commit changes
  3. Run prettier to all my codebase using the native parser
  4. Compare differences in git

Following your request, in one of the classes I tried this:

  1. Run prettier
  2. Stage changes
  3. Run prettier again
  4. Compare changes, the comment has moved...

This happens with both native and standard parser, so this is not longer related only to the native parser, I'm updating the title of the issue

mnunezdm avatar Apr 26 '24 11:04 mnunezdm