dangmai / prettier-plugin-apex

Code formatter for the Apex Programming Language
https://apex.dangmai.net
MIT License
256 stars 44 forks source link

Running with new native parser makes all classes interfaces! #1335

Closed mnunezdm closed 7 months ago

mnunezdm commented 7 months ago

Self-Troubleshooting Checklist

Describe your Issue

# Prettier options (if any):
        {
            "files": "**/*.{cls,trigger,apex}",
            "options": {
                "tabWidth": 4,
                "apexStandaloneParser": "native"
            }
        },

I have tried the experimental feature and try to format thid code

/**
 * @description       : clase para emitir eventos de cliente 360
 * @last modified on  : 19-04-2024
 **/
public with sharing class ClientEventHelper {
    private static final String CLASS_NAME = 'ClientEventHelper';
    private static final String ERROR_MESSAGE = 'Errors while inserting client 360 events';

    /**
     * @description Different types of ids
     */
    public enum IdType {
        gigya,
        contactId
    }

    /**
     * @description publica un listado de eventos
     * @param List<Event__c> events
     **/
    public void publish(List<Event__c> events) {
        ClientEventHelper.publishEvents(events);
    }

    /**
     * @description publica un listado de eventos
     * @param List<Event__c> events
     **/
    public static void publishEvents(List<Event__c> events) {
        String method = 'publishEvents';
        System.debug(
            LoggingLevel.INFO,
            CLASS_NAME + ' - ' + method + ' INICIO'
        );
        new PlatformEventHelper('aaa', CLASS_NAME)
            .publishEvents(events);
        System.debug(LoggingLevel.INFO, CLASS_NAME + ' - ' + method + ' FIN');
    }

    /**
     * @description contruye un evento desde un cgr
     * @param contactRequest__c cgr
     * @return Event__c
     **/
    public static Event__c buildByCgr(
        contactRequest__c cgr
    ) {
        return new Event__c(
            id__c = cgr.Contact__c,
            idType__c = IdType.contactId.name()
        );
    }

    /**
     * @description contruye un evento desde la tenencia
     * @param tenencia__c tenencia
     * @return Event__c
     **/
    public static Event__c buildByTenencia(
        tenencia__c tenencia
    ) {
        return new Event__c(
            id__c = tenencia.Contact__c,
            idType__c = IdType.contactId.name()
        );
    }
}

After running it, this was the result

/**
 * @description       : clase para emitir eventos de cliente 360
 * @last modified on  : 19-04-2024
 **/
public with sharing class ClientEventHelper {
    private static final String CLASS_NAME;
    private static final String ERROR_MESSAGE;

    /**
     * @description Different types of ids
     */
    public enum IdType {
        gigya,
        contactId
    }

    /**
     * @description publica un listado de eventos
     * @param List<Event__c> events
     **/
    public publish(List<Event__c> events);
    /**
     * @description publica un listado de eventos
     * @param List<Event__c> events
     **/
    public static publishEvents(List<Event__c> events);
    /**
     * @description contruye un evento desde un cgr
     * @param contactRequest cgr
     * @return Event__c
     **/
    public static buildByCgr(contactRequest cgr);
    /**
     * @description contruye un evento desde la tenencia
     * @param tenencia__c tenencia
     * @return Event__c
     **/
    public static buildByTenencia(tenencia__c tenencia);
}

Additional information (please fill this out):

AP_SALESFORCE@ /Users/miguelnunezdiaz-montes/work/AP_SALESFORCE
└── prettier-plugin-apex@2.1.0
AP_SALESFORCE@ /Users/miguelnunezdiaz-montes/work/AP_SALESFORCE
├─┬ prettier-plugin-apex@2.1.0
│ └── prettier@3.0.3 deduped
└── prettier@3.0.3
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)
dangmai commented 7 months ago

Thank you for trying out the experimental parser! Finally I have some real world folks who use it, so now I can debug it more easily 😅 I'll take a look at this soon and see what I can do to fix it.

dangmai commented 7 months ago

I've fixed this in master, the next version will contain it. Thanks again for trying this out!

Updated: v2.1.1 has been released with this fix, please try it out and let me know if you run into any more issues in the future 😇

dangmai commented 1 month ago

Just fyi the native parser is now the default parser in v2.2.0. I'd appreciate if you could upgrade and let me know if you run into any issues ⚡