Add bal scan rule for configurable variables#1175
Add bal scan rule for configurable variables#1175TharmiganK merged 22 commits intoballerina-platform:masterfrom
Conversation
...er-plugin-tests/src/test/resources/static_code_analyzer/ballerina_packages/rule1/Config.toml
Outdated
Show resolved
Hide resolved
.../src/main/java/io/ballerina/stdlib/log/compiler/staticcodeanalyzer/LogStatementAnalyzer.java
Outdated
Show resolved
Hide resolved
...er-plugin/src/main/java/io/ballerina/stdlib/log/compiler/staticcodeanalyzer/RuleFactory.java
Show resolved
Hide resolved
| @Override | ||
| public void init(CodeAnalysisContext analysisContext) { | ||
| analysisContext.addSyntaxNodeAnalysisTask(new LogStatementAnalyzer(reporter), | ||
| List.of(CALL_STATEMENT)); |
There was a problem hiding this comment.
While it's not the common (or ideal) usage, since logs are just another function returning nil, they can be used as expressions too.
import ballerina/log;
public function fn() {
housekeeping(1, log:printInfo("fn called"));
}
function housekeeping(int val, () logCall) {
// ...
}We can handle that later maybe.
There was a problem hiding this comment.
Created an issue for this ballerina-platform/ballerina-library#7640
compiler-plugin/src/main/java/io/ballerina/stdlib/log/compiler/staticcodeanalyzer/LogRule.java
Outdated
Show resolved
Hide resolved
.../src/main/java/io/ballerina/stdlib/log/compiler/staticcodeanalyzer/LogStatementAnalyzer.java
Outdated
Show resolved
Hide resolved
.../src/main/java/io/ballerina/stdlib/log/compiler/staticcodeanalyzer/LogStatementAnalyzer.java
Outdated
Show resolved
Hide resolved
compiler-plugin-tests/src/test/resources/static_code_analyzer/ballerina_packages/rule1/main.bal
Outdated
Show resolved
Hide resolved
compiler-plugin-tests/src/test/resources/static_code_analyzer/ballerina_packages/rule1/main.bal
Outdated
Show resolved
Hide resolved
...rc/test/java/io/ballerina/stdlib/log/compiler/staticcodeanalyzer/StaticCodeAnalyzerTest.java
Outdated
Show resolved
Hide resolved
compiler-plugin-tests/src/test/resources/static_code_analyzer/ballerina_packages/rule1/main.bal
Show resolved
Hide resolved
| document = context.currentPackage().module(context.moduleId()).document(context.documentId()); | ||
| } | ||
|
|
||
| if (context.node() instanceof ExpressionStatementNode expressionStatementNode) { |
There was a problem hiding this comment.
We can do an early return here
compiler-plugin/src/main/java/io/ballerina/stdlib/log/compiler/LogCompilerPlugin.java
Outdated
Show resolved
Hide resolved
compiler-plugin/src/main/java/io/ballerina/stdlib/log/compiler/staticcodeanalyzer/LogRule.java
Outdated
Show resolved
Hide resolved
.../src/main/java/io/ballerina/stdlib/log/compiler/staticcodeanalyzer/LogStatementAnalyzer.java
Outdated
Show resolved
Hide resolved
compiler-plugin-tests/src/test/resources/static_code_analyzer/ballerina_packages/rule1/main.bal
Show resolved
Hide resolved
Codecov ReportAll modified and coverable lines are covered by tests ✅
❌ Your project status has failed because the head coverage (79.06%) is below the target coverage (80.00%). You can increase the head coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## master #1175 +/- ##
=========================================
Coverage 79.06% 79.06%
Complexity 3 3
=========================================
Files 4 4
Lines 172 172
Branches 48 48
=========================================
Hits 136 136
Misses 35 35
Partials 1 1 ☔ View full report in Codecov by Sentry. |
|



Purpose
Related issue: ballerina-platform/ballerina-library#7283
This will add a rule to the log module to check any configurable variables is logged in the application.
Examples
Checklist