Skip to content

Commit

Permalink
doc: refresh documentation for latest statement support (#183)
Browse files Browse the repository at this point in the history
* added block stmt doc

* fixed lint issue

* Added Return statement

* added assert stmt

* added assert stmt

* 🐛 fix lint
  • Loading branch information
shivasurya authored Dec 1, 2024
1 parent fa305a8 commit 3899d5c
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 10 deletions.
37 changes: 37 additions & 0 deletions docs/src/content/docs/api/Entities/assertstmt.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
title: AssertStmt - Code-Pathfinder Reference | CodeQL Alternative
description: "AssertStmt Statement Entity - Code PathFinder API Index"
---
import PostHogLayout from '../../../../layouts/PostHogLayout.astro';
import { Badge } from '@astrojs/starlight/components';

<PostHogLayout>
</PostHogLayout>

### AssertStmt <Badge text="Entity" variant="tip" size="small" />

AssertStmt is a statement that asserts a condition.

#### Example
```java
class MyClass {
...
public void myMethod()
{
assert myLocalVariable == 1; // AssertStmt
}
....
}
```

### Attributes

| Entity | Description |
| ------------------------------ | ----------------------------------------------------------------------------------|
| GetAPrimaryQlClass() string | Returns the primary QL class name for the assert statement |
| GetHalsteadID() int | Returns the Halstead ID metric for complexity measurement of the assert statement |
| GetPP() string | Returns the pretty-printed representation of the assert statement |
| ToString() string | Returns a string representation of the assert statement |
| GetMessage() *Expr | Returns the message expression associated with the assert statement if present |
| GetExpr() *Expr | Returns the condition expression being asserted in the statement |
| ------------------------------ | ----------------------------------------------------------------------------------|
40 changes: 40 additions & 0 deletions docs/src/content/docs/api/Entities/blockstmt.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
title: BlockStmt - Code-Pathfinder Reference | CodeQL Alternative
description: "Block Statement Entity - Code PathFinder API Index"
---
import PostHogLayout from '../../../../layouts/PostHogLayout.astro';
import { Badge } from '@astrojs/starlight/components';

<PostHogLayout>
</PostHogLayout>

### BlockStmt <Badge text="Entity" variant="tip" size="small" />

BlockStmt is a statement that contains a list of statements. It is used to declare variables, methods, and classes.

#### Example
```java
class MyClass {
...
public void myMethod()
{ // BlockStmt
int myLocalVariable; // BlockStmt
Double myLocalVariable2; // BlockStmt
System.out.Println("Hello World"); // BlockStmt
} // BlockStmt
....
}
```

### Attributes

| Entity | Description |
| ------------------------------ | ----------------------------------------------------------|
| `GetAPrimaryQlClass()` | Returns the primary QL class name as a string |
| `GetHalsteadID()` | Returns the Halstead complexity metric ID |
| `GetPP()` | Returns the pretty-printed representation of the block |
| `ToString()` | Returns string representation of the block statement |
| `GetStmt(index int)` | Returns the statement at the specified index |
| `GetAStmt()` | Returns a statement from the block |
| `GetNumStmt()` | Returns the total number of statements in the block |
| `GetLastStmt()` | Returns the last statement in the block |
5 changes: 4 additions & 1 deletion docs/src/content/docs/api/Entities/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,7 @@ Learn more about the entity methods below in the API Index.
- [JavaDoc Declaration](./javadoc/)
- [Method Declaration](./method/)
- [Method Invocation](./method_call/)
- [Variable Declaration](./variable/)
- [Variable Declaration](./variable/)
- [Assert Statement](./assertstmt/)
- [Block Statement](./blockstmt/)
- [Return Statement](./returnstmt/)
36 changes: 36 additions & 0 deletions docs/src/content/docs/api/Entities/returnstmt.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
title: ReturnStmt - Code-Pathfinder Reference | CodeQL Alternative
description: Return Statement Entity - Code PathFinder API Index"
---
import PostHogLayout from '../../../../layouts/PostHogLayout.astro';
import { Badge } from '@astrojs/starlight/components';

<PostHogLayout>
</PostHogLayout>

### ReturnStmt <Badge text="Entity" variant="tip" size="small" />

ReturnStmt is a statement that returns a value from a method.

#### Example
```java
class MyClass {
...
public int myMethod()
{
return 1; // ReturnStmt
}
....
}
```

### Attributes

| Method | Description |
| ------------------------------ | -----------------------------------------------------------|
| GetAPrimaryQlClass() string | Returns the primary CodeQL class name for this entity |
| GetHalsteadID() int | Returns the Halstead complexity metric identifier |
| GetPP() string | Returns the pretty-printed representation of the statement |
| ToString() string | Returns a string representation of the return statement |
| GetResult() *Expr | Returns the expression being returned by this statement |
| ------------------------------ | -----------------------------------------------------------|
8 changes: 1 addition & 7 deletions sourcecode-parser/.golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ linters:
- errorlint

# Checks for pointers to enclosing loop variables.
- exportloopref
- copyloopvar

# As you already know I'm a co-author. It would be strange to not use
# one of my warmly loved projects.
Expand Down Expand Up @@ -208,9 +208,6 @@ linters:
# I'm fine to check the error from json.Marshal ¯\_(ツ)_/¯
- errchkjson

# All SQL queries MUST BE covered with tests.
- execinquery

# Forces to handle more cases. Cool but noisy.
- exhaustive
- exhaustruct
Expand Down Expand Up @@ -251,9 +248,6 @@ linters:
# I don't use file headers.
- goheader

# Reports magic consts. Might be noisy but still good.
- gomnd

# Allowed/blocked packages to import. I prefer to do it manually.
- gomodguard

Expand Down
2 changes: 1 addition & 1 deletion sourcecode-parser/cmd/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func processQuery(input string, codeGraph *graph.CodeGraph, output string) (stri
result["line"] = entityObject.LineNumber
result["code"] = entityObject.CodeSnippet

results["result_set"] = append(results["result_set"].([]map[string]interface{}), result)
results["result_set"] = append(results["result_set"].([]map[string]interface{}), result) //nolint:all
}
}
queryResults, err := json.Marshal(results)
Expand Down
2 changes: 1 addition & 1 deletion sourcecode-parser/graph/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ func FilterEntities(node []*Node, query parser.Query) bool {
fmt.Println("Error evaluating expression: ", err)
return false
}
if output.(bool) {
if output.(bool) { //nolint:all
return true
}
return false
Expand Down

0 comments on commit 3899d5c

Please sign in to comment.