Function aiChatStream
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
export async function aiChatStream(
messages: ChatMessage[],
aiProvider: AIProvider,
callback?: (response: string) => void
): Promise<string> {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function aiChatNonStream
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
export async function aiChatNonStream(
messages: ChatMessage[],
aiProvider: AIProvider
): Promise<string> {
const provider = providers[aiProvider.name];
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
A space is required before "]" Open
'parts': [{ 'text': message.content }],
- Read upRead up
- Exclude checks
Rule: array-bracket-spacing
enforce consistent spacing inside array brackets
Rationale
A number of style guides require or disallow spaces between array brackets and other tokens. This rule applies to both array literals and destructuring assignments (ECMAScript 6).
Config
The rule takes one or two options. The first is a string, which can be:
-
"never"
(default) disallows spaces inside array brackets -
"always"
requires one or more spaces or newlines inside array brackets
The second option is an object for exceptions to the "never"
option:
-
"singleValue": true
requires one or more spaces or newlines inside brackets of array literals that contain a single element -
"objectsInArrays": true
requires one or more spaces or newlines between brackets of array literals and braces of their object literal elements[ {
or} ]
-
"arraysInArrays": true
requires one or more spaces or newlines between brackets of array literals and brackets of their array literal elements[ [
or] ]
When using the "always"
option the second option takes on these exceptions:
-
"singleValue": false
disallows spaces inside brackets of array literals that contain a single element -
"objectsInArrays": false
disallows spaces between brackets of array literals and braces of their object literal elements[ {
or} ]
-
"arraysInArrays": false
disallows spaces between brackets of array literals and brackets of their array literal elements[ [
or] ]
This rule has build-in exceptions:
-
"never"
(and also the exceptions to the"always"
option) allows newlines inside array brackets, because this is a common pattern -
"always"
does not require spaces or newlines in empty array literals[]
Examples
"array-bracket-spacing":
"array-bracket-spacing": [true, "always"]
"array-bracket-spacing":
"array-bracket-spacing": [true, "never"]
"array-bracket-spacing":
"array-bracket-spacing": [true, "never", {
"arraysInArrays": true
}]
Schema
{
"anyOf": [
{
"type": "array",
"items": [
{
"enum": [
"always",
"never"
]
}
],
"minItems": 0,
"maxItems": 1
},
{
"type": "object",
"properties": {
"singleValue": {
"type": "boolean"
},
"objectsInArrays": {
"type": "boolean"
},
"arraysInArrays": {
"type": "boolean"
}
},
"additionalProperties": false
}
]
}
For more information see this page.
misplaced opening brace Open
{
- Read upRead up
- Exclude checks
Rule: one-line
Requires the specified tokens to be on the same line as the expression preceding them.
Notes
- Has Fix
Config
Five arguments may be optionally provided:
-
"check-catch"
checks thatcatch
is on the same line as the closing brace fortry
. -
"check-finally"
checks thatfinally
is on the same line as the closing brace forcatch
. -
"check-else"
checks thatelse
is on the same line as the closing brace forif
. -
"check-open-brace"
checks that an open brace falls on the same line as its preceding expression. -
"check-whitespace"
checks preceding whitespace for the specified tokens.
Examples
"one-line": true,check-catch,check-finally,check-else
Schema
{
"type": "array",
"items": {
"type": "string",
"enum": [
"check-catch",
"check-finally",
"check-else",
"check-open-brace",
"check-whitespace"
]
},
"minLength": 0,
"maxLength": 5
}
For more information see this page.
A space is required after "[" Open
'parts': [{ 'text': message.content }],
- Read upRead up
- Exclude checks
Rule: array-bracket-spacing
enforce consistent spacing inside array brackets
Rationale
A number of style guides require or disallow spaces between array brackets and other tokens. This rule applies to both array literals and destructuring assignments (ECMAScript 6).
Config
The rule takes one or two options. The first is a string, which can be:
-
"never"
(default) disallows spaces inside array brackets -
"always"
requires one or more spaces or newlines inside array brackets
The second option is an object for exceptions to the "never"
option:
-
"singleValue": true
requires one or more spaces or newlines inside brackets of array literals that contain a single element -
"objectsInArrays": true
requires one or more spaces or newlines between brackets of array literals and braces of their object literal elements[ {
or} ]
-
"arraysInArrays": true
requires one or more spaces or newlines between brackets of array literals and brackets of their array literal elements[ [
or] ]
When using the "always"
option the second option takes on these exceptions:
-
"singleValue": false
disallows spaces inside brackets of array literals that contain a single element -
"objectsInArrays": false
disallows spaces between brackets of array literals and braces of their object literal elements[ {
or} ]
-
"arraysInArrays": false
disallows spaces between brackets of array literals and brackets of their array literal elements[ [
or] ]
This rule has build-in exceptions:
-
"never"
(and also the exceptions to the"always"
option) allows newlines inside array brackets, because this is a common pattern -
"always"
does not require spaces or newlines in empty array literals[]
Examples
"array-bracket-spacing":
"array-bracket-spacing": [true, "always"]
"array-bracket-spacing":
"array-bracket-spacing": [true, "never"]
"array-bracket-spacing":
"array-bracket-spacing": [true, "never", {
"arraysInArrays": true
}]
Schema
{
"anyOf": [
{
"type": "array",
"items": [
{
"enum": [
"always",
"never"
]
}
],
"minItems": 0,
"maxItems": 1
},
{
"type": "object",
"properties": {
"singleValue": {
"type": "boolean"
},
"objectsInArrays": {
"type": "boolean"
},
"arraysInArrays": {
"type": "boolean"
}
},
"additionalProperties": false
}
]
}
For more information see this page.