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

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

Open
mnunezdm opened this issue Apr 21, 2024 · 2 comments

Comments

@mnunezdm
Copy link

mnunezdm commented Apr 21, 2024

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. prettier-plugin-apex@2.0.0]
AP_SALESFORCE@ /Users/miguelnunezdiaz-montes/work/AP_SALESFORCE
└── prettier-plugin-apex@2.1.1
  • Prettier Version (you can check this by running npm ls prettier): [e.g. prettier@3.0.0]
AP_SALESFORCE@ /Users/miguelnunezdiaz-montes/work/AP_SALESFORCE
├─┬ prettier-plugin-apex@2.1.1
│ └── prettier@3.0.3 deduped
└── prettier@3.0.3
  • 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!!!!!!!

@dangmai
Copy link
Owner

dangmai commented Apr 21, 2024

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).

@mnunezdm
Copy link
Author

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 mnunezdm changed the title Differences between standard parser and native parser formatting Differences when running prettier more than one time over the same file content Apr 26, 2024
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

No branches or pull requests

2 participants