-
Notifications
You must be signed in to change notification settings - Fork 10
Add rule for non isolated public constructs #35
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
Merged
keizer619
merged 14 commits into
ballerina-platform:main
from
SasinduDilshara:lang_static_rules_non_isolated_functions
Mar 15, 2025
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
665d674
Add rule for non isolated public construct
SasinduDilshara a9e43f6
Merge branch 'static-code-analysis-tool' of https://github.com/baller…
SasinduDilshara a2e5611
Update scan command tests for public constructs
SasinduDilshara ad37667
Merge branch 'static-code-analysis-tool' of https://github.com/baller…
SasinduDilshara 8f89ef7
Add static rule warning for public isolated constructs
SasinduDilshara 22fd8a2
Fix windows build issue with non isolated public construct static rule
SasinduDilshara 3741490
Refactor utill methods
SasinduDilshara 4341403
Merge branch 'main' of https://github.com/ballerina-platform/static-c…
SasinduDilshara f6b5ee2
Add tests for service classes and object types
SasinduDilshara e32d98e
Merge branch 'main' of https://github.com/ballerina-platform/static-c…
SasinduDilshara bf0081b
Update windows tests in reports
SasinduDilshara cbb6486
Update public isolated construct rules
SasinduDilshara c877b5f
Divide public construct warnings into four
SasinduDilshara 0ac1e50
Merge branch 'main' of https://github.com/ballerina-platform/static-c…
SasinduDilshara File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
scan-command/src/test/java/io/ballerina/scan/internal/Rule003And004Test.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| /* | ||
| * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). | ||
| * | ||
| * WSO2 LLC. licenses this file to you under the Apache License, | ||
| * Version 2.0 (the "License"); you may not use this file except | ||
| * in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package io.ballerina.scan.internal; | ||
|
|
||
| import io.ballerina.projects.Document; | ||
| import io.ballerina.scan.Issue; | ||
| import io.ballerina.scan.RuleKind; | ||
| import org.testng.Assert; | ||
| import org.testng.annotations.Test; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Non isolated public constructs usage tests. | ||
| * | ||
| * @since 0.1.0 | ||
| */ | ||
| public class Rule003And004Test extends StaticCodeAnalyzerTest { | ||
| public static final String PUBLIC_NON_ISOLATED_FUNCTION_CONSTRUCT = | ||
| "Non isolated public function"; | ||
| public static final String PUBLIC_NON_ISOLATED_METHOD_CONSTRUCT = | ||
| "Non isolated public method"; | ||
| public static final String PUBLIC_NON_ISOLATED_CLASS_CONSTRUCT = | ||
| "Non isolated public class"; | ||
|
|
||
| @Test(description = "test non isolated public functions analyzer") | ||
| void testNonIsolatedPublicFunctionOrMethodConstructsUsage() { | ||
| String documentName = "rule003_and_004_rules_non_isolated_public_functions_or_methods.bal"; | ||
| Document document = loadDocument(documentName); | ||
| ScannerContextImpl scannerContext = new ScannerContextImpl(List.of( | ||
| CoreRule.PUBLIC_NON_ISOLATED_FUNCTION_CONSTRUCT.rule(), | ||
| CoreRule.PUBLIC_NON_ISOLATED_METHOD_CONSTRUCT.rule(), | ||
| CoreRule.PUBLIC_NON_ISOLATED_CLASS_CONSTRUCT.rule())); | ||
| StaticCodeAnalyzer staticCodeAnalyzer = new StaticCodeAnalyzer(document, scannerContext, | ||
| document.module().getCompilation().getSemanticModel()); | ||
| staticCodeAnalyzer.analyze(); | ||
|
|
||
| List<Issue> issues = scannerContext.getReporter().getIssues(); | ||
| Assert.assertEquals(issues.size(), 12); | ||
| assertIssue(issues.get(0), documentName, 16, 0, 18, 1, "ballerina:3", 3, | ||
| PUBLIC_NON_ISOLATED_FUNCTION_CONSTRUCT, RuleKind.CODE_SMELL); | ||
| assertIssue(issues.get(1), documentName, 63, 4, 65, 5, "ballerina:4", 4, | ||
| PUBLIC_NON_ISOLATED_METHOD_CONSTRUCT, RuleKind.CODE_SMELL); | ||
| assertIssue(issues.get(2), documentName, 67, 4, 69, 5, "ballerina:4", 4, | ||
| PUBLIC_NON_ISOLATED_METHOD_CONSTRUCT, RuleKind.CODE_SMELL); | ||
| assertIssue(issues.get(3), documentName, 75, 4, 77, 5, "ballerina:4", 4, | ||
| PUBLIC_NON_ISOLATED_METHOD_CONSTRUCT, RuleKind.CODE_SMELL); | ||
| assertIssue(issues.get(4), documentName, 89, 4, 91, 5, "ballerina:4", 4, | ||
| PUBLIC_NON_ISOLATED_METHOD_CONSTRUCT, RuleKind.CODE_SMELL); | ||
| assertIssue(issues.get(5), documentName, 97, 4, 99, 5, "ballerina:4", 4, | ||
| PUBLIC_NON_ISOLATED_METHOD_CONSTRUCT, RuleKind.CODE_SMELL); | ||
| assertIssue(issues.get(6), documentName, 102, 0, 122, 1, "ballerina:5", 5, | ||
| PUBLIC_NON_ISOLATED_CLASS_CONSTRUCT, RuleKind.CODE_SMELL); | ||
| assertIssue(issues.get(7), documentName, 111, 4, 113, 5, "ballerina:4", 4, | ||
| PUBLIC_NON_ISOLATED_METHOD_CONSTRUCT, RuleKind.CODE_SMELL); | ||
| assertIssue(issues.get(8), documentName, 133, 4, 135, 5, "ballerina:4", 4, | ||
| PUBLIC_NON_ISOLATED_METHOD_CONSTRUCT, RuleKind.CODE_SMELL); | ||
| assertIssue(issues.get(9), documentName, 146, 0, 166, 1, "ballerina:5", 5, | ||
| PUBLIC_NON_ISOLATED_CLASS_CONSTRUCT, RuleKind.CODE_SMELL); | ||
| assertIssue(issues.get(10), documentName, 155, 4, 157, 5, "ballerina:4", 4, | ||
| PUBLIC_NON_ISOLATED_METHOD_CONSTRUCT, RuleKind.CODE_SMELL); | ||
| assertIssue(issues.get(11), documentName, 180, 0, 184, 1, "ballerina:5", 5, | ||
| PUBLIC_NON_ISOLATED_CLASS_CONSTRUCT, RuleKind.CODE_SMELL); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.