chore: eslint add sonar (#17989)

This commit is contained in:
Joel 2025-04-14 15:28:20 +08:00 • committed by GitHub
commit d80f4c7d3b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
38 changed files with 157 additions and 180 deletions

View file

@ -84,7 +84,7 @@ const CodeEditor: FC<Props> = ({
const getUniqVarName = (varName: string) => {
if (varList.find(v => v.variable === varName)) {
const match = varName.match(/_([0-9]+)$/)
const match = varName.match(/_(\d+)$/)
const index = (() => {
if (match)
@ -92,7 +92,7 @@ const CodeEditor: FC<Props> = ({
return 1
})()
return getUniqVarName(`${varName.replace(/_([0-9]+)$/, '')}_${index}`)
return getUniqVarName(`${varName.replace(/_(\d+)$/, '')}_${index}`)
}
return varName
}

View file

@ -278,6 +278,7 @@ const formatItem = (
break
}
// eslint-disable-next-line sonarjs/no-duplicated-branches
case BlockEnum.VariableAggregator: {
const {
output_type,
@ -466,7 +467,7 @@ const formatItem = (
res.vars = res.vars.filter((v) => {
const isCurrentMatched = filterVar(v, (() => {
const variableArr = v.variable.split('.')
const [first, ..._other] = variableArr
const [first] = variableArr
if (first === 'sys' || first === 'env' || first === 'conversation')
return variableArr
@ -611,6 +612,7 @@ const getLoopItemType = ({
}: {
valueSelector: ValueSelector
beforeNodesOutputVars: NodeOutPutVar[]
// eslint-disable-next-line sonarjs/no-identical-functions
}): VarType => {
const outputVarNodeId = valueSelector[0]
const isSystem = isSystemVar(valueSelector)
@ -1243,6 +1245,7 @@ export const updateNodeVars = (oldNode: Node, oldVarSelector: ValueSelector, new
}
break
}
// eslint-disable-next-line sonarjs/no-duplicated-branches
case BlockEnum.VariableAggregator: {
const payload = data as VariableAssignerNodeType
if (payload.variables) {

View file

@ -64,7 +64,7 @@ const Item: FC<ItemProps> = ({
const isChatVar = itemData.variable.startsWith('conversation.')
const itemRef = useRef<HTMLDivElement>(null)
const [isItemHovering, setIsItemHovering] = useState(false)
const _ = useHover(itemRef, {
useHover(itemRef, {
onChange: (hovering) => {
if (hovering) {
setIsItemHovering(true)
@ -185,7 +185,7 @@ const ObjectChildren: FC<ObjectChildrenProps> = ({
const currObjPath = objPath
const itemRef = useRef<HTMLDivElement>(null)
const [isItemHovering, setIsItemHovering] = useState(false)
const _ = useHover(itemRef, {
useHover(itemRef, {
onChange: (hovering) => {
if (hovering) {
setIsItemHovering(true)

View file

@ -97,7 +97,7 @@ const nodeDefault: NodeDefault<AgentNodeType> = {
}
// check form of tools
else {
let validState = {
const validState = {
isValid: true,
errorMessage: '',
}
@ -108,13 +108,13 @@ const nodeDefault: NodeDefault<AgentNodeType> = {
schemas.forEach((schema: any) => {
if (schema?.required) {
if (schema.form === 'form' && !userSettings[schema.name]?.value) {
return validState = {
return {
isValid: false,
errorMessage: t('workflow.errorMsg.toolParameterRequired', { field: renderI18nObject(param.label, language), param: renderI18nObject(schema.label, language) }),
}
}
if (schema.form === 'llm' && reasoningConfig[schema.name]?.auto === 0 && !reasoningConfig[schema.name]?.value) {
return validState = {
return {
isValid: false,
errorMessage: t('workflow.errorMsg.toolParameterRequired', { field: renderI18nObject(param.label, language), param: renderI18nObject(schema.label, language) }),
}

View file

@ -102,6 +102,7 @@ const AgentNode: FC<NodeProps<AgentNodeType>> = (props) => {
{t('workflow.nodes.agent.toolbox')}
</GroupLabel>}>
<div className='grid grid-cols-10 gap-0.5'>
{/* eslint-disable-next-line sonarjs/no-uniq-key */}
{tools.map(tool => <ToolIcon {...tool} key={Math.random()} />)}
</div>
</Group>}

View file

@ -16,16 +16,10 @@ const nodeDefault: NodeDefault<EndNodeType> = {
getAvailableNextNodes() {
return []
},
checkValid(payload: EndNodeType) {
let isValid = true
let errorMessages = ''
if (payload.type) {
isValid = true
errorMessages = ''
}
checkValid() {
return {
isValid,
errorMessage: errorMessages,
isValid: true,
errorMessage: '',
}
},
}

View file

@ -62,5 +62,5 @@ export const comparisonOperatorNotRequireValue = (operator?: ComparisonOperator)
return [ComparisonOperator.empty, ComparisonOperator.notEmpty, ComparisonOperator.isNull, ComparisonOperator.isNotNull, ComparisonOperator.exists, ComparisonOperator.notExists].includes(operator)
}
export const VARIABLE_REGEX = /\{\{(#[a-zA-Z0-9_-]{1,50}(\.[a-zA-Z_][a-zA-Z0-9_]{0,29}){1,10}#)\}\}/gi
export const VARIABLE_REGEX = /\{\{(#[a-zA-Z0-9_-]{1,50}(\.[a-zA-Z_]\w{0,29}){1,10}#)\}\}/gi
export const COMMON_VARIABLE_REGEX = /\{\{([a-zA-Z0-9_-]{1,50})\}\}/gi

View file

@ -36,7 +36,6 @@ export const getSelectedDatasetsMode = (datasets: DataSet[] = []) => {
allHighQualityFullTextSearch = false
allEconomic = false
mixtureHighQualityAndEconomic = false
inconsistentEmbeddingModel = false
allExternal = false
allInternal = false
mixtureInternalAndExternal = false

View file

@ -18,4 +18,5 @@ export function getSelectedNode(
return $isAtNodeEnd(anchor) ? anchorNode : focusNode
}
// eslint-disable-next-line sonarjs/empty-string-repetition
export const urlRegExp = /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=+$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=+$,\w]+@)[A-Za-z0-9.-]+)((?:\/[+~%/.\w-_]*)?\??(?:[-+=&;%@.\w_]*)#?(?:[\w]*))?)/

View file

@ -38,7 +38,7 @@ const ObjectValueItem: FC<Props> = ({
const handleKeyChange = useCallback((index: number) => {
return (e: React.ChangeEvent<HTMLInputElement>) => {
const newList = produce(list, (draft: any[]) => {
if (!/^[a-zA-Z0-9_]+$/.test(e.target.value))
if (!/^\w+$/.test(e.target.value))
return notify({ type: 'error', message: 'key is can only contain letters, numbers and underscores' })
draft[index].key = e.target.value
})

View file

@ -95,7 +95,7 @@ const VariableModal = ({
type === 'number' && 'border-[1.5px] border-components-option-card-option-selected-border bg-components-option-card-option-selected-bg font-medium text-text-primary shadow-xs hover:border-components-option-card-option-selected-border',
)} onClick={() => {
setType('number')
if (!(/^[0-9]$/).test(value))
if (!(/^\d$/).test(value))
setValue('')
}}>Number</div>
<div className={cn(

View file

@ -1,37 +0,0 @@
import graphToLogStruct from '../graph-to-log-struct'
describe('parallel', () => {
const list = graphToLogStruct('(parallel, parallelNode, nodeA, nodeB -> nodeC)')
const [parallelNode, ...parallelDetail] = list
const parallelI18n = 'PARALLEL'
// format will change the list...
// const result = format(cloneDeep(list) as any, () => parallelI18n)
test('parallel should put nodes in details', () => {
// expect(result as any).toEqual([
// {
// ...parallelNode,
// parallelDetail: {
// isParallelStartNode: true,
// parallelTitle: `${parallelI18n}-1`,
// children: [
// parallelNode,
// {
// ...parallelDetail[0],
// parallelDetail: {
// branchTitle: `${parallelI18n}-1-A`,
// },
// },
// {
// ...parallelDetail[1],
// parallelDetail: {
// branchTitle: `${parallelI18n}-1-B`,
// },
// },
// parallelDetail[2],
// ],
// },
// },
// ])
})
})

View file

@ -148,6 +148,7 @@ const format = (list: NodeTracing[], t: any, isPrint?: boolean): NodeTracing[] =
return false
const isParallelStartNode = node.parallelDetail?.isParallelStartNode
// eslint-disable-next-line sonarjs/prefer-single-boolean-return
if (!isParallelStartNode)
return false

View file

@ -14,8 +14,5 @@ export const variableTransformer = (v: ValueSelector | string) => {
}
export const isExceptionVariable = (variable: string, nodeType?: BlockEnum) => {
if ((variable === 'error_message' || variable === 'error_type') && hasErrorHandleNode(nodeType))
return true
return false
return (variable === 'error_message' || variable === 'error_type') && hasErrorHandleNode(nodeType)
}