Einstein-GPT-for-Developers icon indicating copy to clipboard operation
Einstein-GPT-for-Developers copied to clipboard

Custom rule not followed

Open eclarke-cfg opened this issue 11 months ago • 9 comments

Summary

Custom rule related to Apex class naming is not followed.

Steps To Reproduce:

  1. Define a custom rule for apex naming called apex-naming.md and place in the .sfdx/a4d/rules directory
  2. Ask the assistant to generate an Apex class
  3. Observe that the naming convention was not fully followed
  4. Upon review, the assistant still claims rules were followed

Expected result

The generated Apex class should follow naming rules.

Actual result

Not all rules were followed.

Additional information

Image

Custom rule contents:

# Rule: Apex Naming Conventions

**Description:** Enforce naming and formatting standards for Apex code.

**Applies to:** `**/*.cls` and `**/*.trigger`.

**Guidelines:**
- Class names must be PascalCase (ie. `AccountService`)
- Class names must be prefixed by cfg_
- Method names must be camelCase
- Constants must be UPPER_SNAKE_CASE
- Use `@isTest` and `seeAllData=false` for all test classes

Salesforce Extension Version in VS Code: 63.16.3

Salesforce Einstein For Developers Version in VS Code: 2.9.0

OS and version: Windows 11

VS Code version: 1.100.3

eclarke-cfg avatar Jun 05 '25 22:06 eclarke-cfg

I encountered this and the responses are much better if you close your rule file.

By default whatever is active in the editor goes as context instead of code file causing the model to confuse itself..

msrivastav13 avatar Jun 05 '25 22:06 msrivastav13

Thanks for the reply @msrivastav13 but even with no files open in the editor I get the same results.

It's possible that refining the rule further may give better results, but it's pretty unfortunate that's it's failing to do this (in my mind) simple thing.

eclarke-cfg avatar Jun 05 '25 22:06 eclarke-cfg

Definitely this needs an investigation..

But I am curious to see what you get if you have a .cls file open in the editor already and try it out..

msrivastav13 avatar Jun 05 '25 23:06 msrivastav13

Thanks @msrivastav13 @eclarke-cfg Can you please retry with a cls file open - think the rules are applied based on open file context.

mohanraj-r avatar Jun 06 '25 00:06 mohanraj-r

@mohanraj-r I tried again with a Trigger file named AccountTrigger. It did not correctly rename the trigger class name.

I then created a new empty Apex class file named cfg_AccountHandler and it correctly kept the cfg_ prefix.

Image

It feels a bit reductive if I have to setup the files in advance to make it follow those guidelines? The whole point in my mind is to accelerate development and assist devs who may not intimately know the guidelines by applying them consistently. Maybe I'm being overly critical here, but I will close this issue with the following workaround:

  • ensure a file with the correct naming standard is open in the editor when asking assistant to generate code

eclarke-cfg avatar Jun 06 '25 15:06 eclarke-cfg

Thanks @eclarke-cfg we will look into updating the docs and discuss about potentially changing how this works to make it more intuitive/easier.

mohanraj-r avatar Jun 06 '25 17:06 mohanraj-r

@mohanraj-r Can we open this back please! We need to address this. Thank you

msrivastav13 avatar Jun 07 '25 15:06 msrivastav13

@eclarke-cfg I definitely agree.. It should be a smooth experience and one should not have to do workarounds..

Note if you ground the files now with User Specified Context it is much better. I use both together. May be you want to look at that together

Triggers are something the rules do not play well with @mohanraj-r!

Can we open an engineering investigation here for this?

msrivastav13 avatar Jun 07 '25 15:06 msrivastav13

@msrivastav13 @eclarke-cfg thanks for the feedback. we will investigate this further and work with our AI research partner team. cc: @smarvez

diyer avatar Jun 10 '25 05:06 diyer