-
Notifications
You must be signed in to change notification settings - Fork 6
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
Implement Ballerina Scan Tool for Static Code Analysis #1
Conversation
@@ -0,0 +1,2 @@ | |||
# Ensure all Java files use LF. | |||
*.java eol=lf |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*.java eol=lf | |
*.java eol=lf | |
packageUser: ${{ github.actor }} | ||
packagePAT: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
./gradlew build |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
./gradlew build | |
./gradlew build | |
.vscode/ | ||
|
||
### Mac OS ### | ||
.DS_Store |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.DS_Store | |
.DS_Store | |
4. Run analysis and generate an analysis report. | ||
```bash | ||
bal scan --scan-report | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can remove this extra line
} | ||
|
||
public int getStartLine() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
message, | ||
issueType, | ||
type, | ||
moduleName + "/" + documentName, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
File separator is depend on the OS. So it is better to not hardcode it.
throw new RuntimeException(e); | ||
} | ||
|
||
return target; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove the target
variable and return in each scenario separately.
@@ -0,0 +1,13 @@ | |||
# Scan tool properties | |||
scanToolVersion=1.0.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix these ^M
return allIssues; | ||
} | ||
|
||
public void analyzeDocument(Project currentProject, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure whether this is the expected formatting for parameters in the Java function definitions. Can you check
@@ -0,0 +1,2 @@ | |||
rootProject.name = 'static-code-analysis-tool' | |||
include 'ScanCommand' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
include 'ScanCommand' | |
include 'ScanCommand' | |
import ballerina/io; | ||
public function main() { | ||
io:println("Ballerina Scan tool"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} | |
} | |
Since this PR is too large, will be breaking it down to smaller parts and send them |
Purpose
The purpose of this PR is to develop a Ballerina tool that performs static code analysis for Ballerina projects for identifying potential bugs, security vulnerabilities, and style violations and report analysis issues to static code analysis platforms like SonarQube.
Fixes #42256
Goals
Approach
The initial release introduces the
bal scan
command. Current implementation uses the project API to retrieve syntax trees of all Ballerina files in a project for performing core analysis and generating an analysis report. However the generated report will have no issues as core rules are not implemented yet. As core analysis rules are reviewed and implemented, the scan tool will progressively gain the ability to identify and report potential issues and further features will be added iteratively as outlined in task #42260Check List