Skip to content

Comments

Add bal scan rule for configurable variables#1175

Merged
TharmiganK merged 22 commits intoballerina-platform:masterfrom
daneshk:master
Mar 5, 2025
Merged

Add bal scan rule for configurable variables#1175
TharmiganK merged 22 commits intoballerina-platform:masterfrom
daneshk:master

Conversation

@daneshk
Copy link
Member

@daneshk daneshk commented Feb 22, 2025

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

  • Linked to an issue
  • Updated the changelog
  • Added tests
  • Updated the spec
  • Checked native-image compatibility

@Override
public void init(CodeAnalysisContext analysisContext) {
analysisContext.addSyntaxNodeAnalysisTask(new LogStatementAnalyzer(reporter),
List.of(CALL_STATEMENT));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created an issue for this ballerina-platform/ballerina-library#7640

document = context.currentPackage().module(context.moduleId()).document(context.documentId());
}

if (context.node() instanceof ExpressionStatementNode expressionStatementNode) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do an early return here

@codecov
Copy link

codecov bot commented Feb 24, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.06%. Comparing base (a28035e) to head (60617b5).
Report is 24 commits behind head on master.

❌ 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.
📢 Have feedback on the report? Share it here.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 5, 2025

@TharmiganK TharmiganK merged commit a4883b4 into ballerina-platform:master Mar 5, 2025
5 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants