-
Notifications
You must be signed in to change notification settings - Fork 31
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
LC0053 - Issue with internal procedures for testability #529
Comments
Hi, it was a deliberate choice for the moment to always have this diagnostic raised if the internal procedure is not used in the current project. https://github.com/StefanMaron/BusinessCentral.LinterCop/wiki/LC0052#internalsvisibleto If you have other suggestions, feel free to share them though. |
References of procedures are shared across both the normal and test app. Perhaps the linter is able to differentiate between the two apps when checking references? That way at least in VSCode the info wouldn't be raised but we would have a different behaviour when compiling the app. Just sharing my thoughts here. The way it is currently the rule raises more "false positives" than anything else so I will probably disable the rule entirely. |
Yes, that's right. I am not sure if we will be able to have the rule check across multiple projects as I suspect the compiler compiles per project and does not bother with checking your workspace setup. But it could be something to check. I think a first good step could be to let the default behaviour of the rule be "if internalsVisibleTo is not empty, then disable the rule", but add an Second step would be investigating if we could realize what you suggest. What do you think? |
Sounds great. That would be enough for me already. I am not sure about the second step though. I think it's more important to have consistent behaviour for both compiling and VSCode and when compiling the app (like in pipelines) you don't have the testapp yet so there should be no way of knowing cross app references. Sounds like a lot of effort for minimal effect :D I'll look into the code later, maybe I can find a solution to this myself and create a PR. |
I understand the issue on having this rule raised on internal methods that are used for testing only. To answer your question: I believe in theory it would be possible for the code analyzer to verify this in a multi-root workspace, and have this checked cross the App and the Test-App. I'm quite sure this will not work during compiling in a build pipeline and then could break pipelines out there.
I'm not sure if this ia a good idea. In our build for release pipelines we tent to remove the internalsVisibleTo from the app.json in the pipeline, so our shipped artifact doesn't have this property set. Again I believe this could break pipelines out there.
I would suggest to apply a custom ruleset on the workspace when setting the internalsVisibleTo property in the app.json. Personally I would follow the example as Microsoft does and add an comment (and a #pragma in this case) that this event is directly called from the test app. /// <summary>
/// Raises an event to be able to change the return of IsGuiAllowed function. Used for testing.
/// </summary>
[InternalEvent(false)]
procedure OnBeforeGuiAllowed(var Result: Boolean; var Handled: Boolean)
begin
end; |
I can see your concerns with the internalsVisibleTo as this isn't a perfect indicator but I can't see how this might break pipelines The change would only make the rule more restrictive which would result in fewer infos (or warning/errors depending on the ruleset I suppose) and that should never result in a pipeline failure- on a technical level. I can also just set this rule on ignore globally but I think this rule catches a lot of false positives just by the nature of the rule. |
@Arthurvdv why are we always talking about internals visible to for test apps? That's not even the intention of that setting. The intention is to make the internals visible to an API app. That setting would then also need to get shipped. I can also imagine that partners might have multi app architectures depending on that setting, also persisting it in the app.json So I am with @CHovenbitzer, when the internals are visible they should be treated like public's |
Valid point! I've looked again at the documentation of the internalsVisibleTo property of the app.json and you're right; The InternalsVisibleTo setting will expose your internal objects to any extension with the given name, publisher, and ID. Access modifiers are not designed to be used as a security boundary, but for API development. We also, just as @CHovenbitzer mentioned, are using this for our test-apps and I didn't realize that's not the intention of that setting 😳 Seems doable that when there's one (or multiple) Apps defined in the internalsVisibleTo property of the app.json to skip these diagnostics
I'll mark this as enhancement to look into this. @CHovenbitzer if you have the time you're more then welcome to create a PR for this, otherwise I'll try to look into this in the next week. |
I've got some really weird issues now. When booting up a repo without internalsVisibleTo I get errors across multiple rules inlcuding LC0044, LC0052, LC0033. Weirdly enough these issues get resolved when I set the internalsVisibleTo and don't come up again when I remove the property again. Also I'm not sure how this is connected to the change I made. I will look into this more closely.
|
I suspect the build pipeline has some strange issues with resolving methods from the
^ I saw this in both the error messages you shared for rule 033 and 052. |
@ChristianHovenbitzer |
@ChristianHovenbitzer The function is moved to the new ManifestHelper: f55b06a I think I now need to figure out howto add preprocessor directives, cause now the build fails on the current (v12). |
Preprocessor directives are in place and the latest release should now work again. |
The v0.30.13 version of the LinterCop is now released, where I believe this issue is now resolved. If you still encounter issues, feel free to reopen this issue (or create new one). |
Hey, I have an issue with the rule LC0053 "The internal method is only used in the object in which it is declared. ". I frequently use the internal access modifier to allow my test function to direcly call them. This allows me to write tests more granular but the rule does not like that at all.
I'm not sure how to fix this.
The text was updated successfully, but these errors were encountered: