diff --git a/docs/src/content/docs/api/Entities/assertstmt.mdx b/docs/src/content/docs/api/Entities/assertstmt.mdx new file mode 100644 index 00000000..a02d32e7 --- /dev/null +++ b/docs/src/content/docs/api/Entities/assertstmt.mdx @@ -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'; + + + + +### AssertStmt + +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 | +| ------------------------------ | ----------------------------------------------------------------------------------| \ No newline at end of file diff --git a/docs/src/content/docs/api/Entities/blockstmt.mdx b/docs/src/content/docs/api/Entities/blockstmt.mdx new file mode 100644 index 00000000..9e3d28a0 --- /dev/null +++ b/docs/src/content/docs/api/Entities/blockstmt.mdx @@ -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'; + + + + +### BlockStmt + +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 | \ No newline at end of file diff --git a/docs/src/content/docs/api/Entities/index.mdx b/docs/src/content/docs/api/Entities/index.mdx index bd8a0946..b2b93e78 100644 --- a/docs/src/content/docs/api/Entities/index.mdx +++ b/docs/src/content/docs/api/Entities/index.mdx @@ -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/) \ No newline at end of file +- [Variable Declaration](./variable/) +- [Assert Statement](./assertstmt/) +- [Block Statement](./blockstmt/) +- [Return Statement](./returnstmt/) \ No newline at end of file diff --git a/docs/src/content/docs/api/Entities/returnstmt.mdx b/docs/src/content/docs/api/Entities/returnstmt.mdx new file mode 100644 index 00000000..0eb7fa28 --- /dev/null +++ b/docs/src/content/docs/api/Entities/returnstmt.mdx @@ -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'; + + + + +### ReturnStmt + +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 | +| ------------------------------ | -----------------------------------------------------------| diff --git a/sourcecode-parser/.golangci.yml b/sourcecode-parser/.golangci.yml index 5ec33e70..e0ec8802 100644 --- a/sourcecode-parser/.golangci.yml +++ b/sourcecode-parser/.golangci.yml @@ -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. @@ -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 @@ -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 diff --git a/sourcecode-parser/cmd/query.go b/sourcecode-parser/cmd/query.go index c179fb4d..6f91895c 100644 --- a/sourcecode-parser/cmd/query.go +++ b/sourcecode-parser/cmd/query.go @@ -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) diff --git a/sourcecode-parser/graph/query.go b/sourcecode-parser/graph/query.go index f287fdf9..cb21c8e4 100644 --- a/sourcecode-parser/graph/query.go +++ b/sourcecode-parser/graph/query.go @@ -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