Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.
Python agentagentic-aiagentic-frameworkagentic-workflowaiautomationclaudedeepseekgenaigptllmlow-codemcpnextjsno-codeopenaipythonskillsworkflow
chore: eslint add sonar (#17989)
Joeld80f4c7d3b84
diff --git a/web/app/components/app/configuration/config-prompt/simple-prompt-input.tsx b/web/app/components/app/configuration/config-prompt/simple-prompt-input.tsxindex 90d440aba55..3268c1dc760 100644--- a/web/app/components/app/configuration/config-prompt/simple-prompt-input.tsx+++ b/web/app/components/app/configuration/config-prompt/simple-prompt-input.tsx@@ -241,7 +241,8 @@ const Prompt: FC<ISimplePromptInput> = ({selectable: !hasSetBlockStatus.query,}}onChange={(value) => {- handleChange?.(value, [])+ if (handleChange)+ handleChange(value, [])}}onBlur={() => {handleChange(promptTemplate, getVars(promptTemplate))diff --git a/web/app/components/app/configuration/tools/external-data-tool-modal.tsx b/web/app/components/app/configuration/tools/external-data-tool-modal.tsxindex 9040de1b293..ee4bd573255 100644--- a/web/app/components/app/configuration/tools/external-data-tool-modal.tsx+++ b/web/app/components/app/configuration/tools/external-data-tool-modal.tsx@@ -151,7 +151,7 @@ const ExternalDataToolModal: FC<ExternalDataToolModalProps> = ({return}- if (localeData.variable && !/[a-zA-Z_][a-zA-Z0-9_]{0,29}/g.test(localeData.variable)) {+ if (localeData.variable && !/[a-zA-Z_]\w{0,29}/g.test(localeData.variable)) {notify({ type: 'error', message: t('appDebug.varKeyError.notValid', { key: t('appDebug.feature.tools.modal.variableName.title') }) })return}diff --git a/web/app/components/app/overview/embedded/index.tsx b/web/app/components/app/overview/embedded/index.tsxindex cb00c98355d..c515331961e 100644--- a/web/app/components/app/overview/embedded/index.tsx+++ b/web/app/components/app/overview/embedded/index.tsx@@ -39,12 +39,12 @@ const OPTION_MAP = {`<script>window.difyChatbotConfig = {token: '${token}'${isTestEnv- ? `,+ ? `,isDev: true`- : ''}${IS_CE_EDITION- ? `,+ : ''}${IS_CE_EDITION+ ? `,baseUrl: '${url}'`- : ''},+ : ''},systemVariables: {// user_id: 'YOU CAN DEFINE USER ID HERE',},@@ -110,7 +110,7 @@ const Embedded = ({ siteInfo, isShow, onClose, appBaseUrl, accessToken, classNam}const navigateToChromeUrl = () => {- window.open('https://chrome.google.com/webstore/detail/dify-chatbot/ceehdapohffmjmkdcifjofadiaoeggaf', '_blank')+ window.open('https://chrome.google.com/webstore/detail/dify-chatbot/ceehdapohffmjmkdcifjofadiaoeggaf', '_blank', 'noopener,noreferrer')}useEffect(() => {diff --git a/web/app/components/base/audio-btn/index.tsx b/web/app/components/base/audio-btn/index.tsxindex 1f8c271f9a9..9964d273c05 100644--- a/web/app/components/base/audio-btn/index.tsx+++ b/web/app/components/base/audio-btn/index.tsx@@ -97,7 +97,7 @@ const AudioBtn = ({</div>): (- <div className={`flex h-full w-full items-center justify-center rounded-md ${!isAudition ? 'hover:bg-gray-50' : 'hover:bg-gray-50'}`}>+ <div className={'flex h-full w-full items-center justify-center rounded-md hover:bg-gray-50'}><div className={`h-4 w-4 ${(audioState === 'playing') ? s.pauseIcon : s.playIcon}`}></div></div>)}diff --git a/web/app/components/base/chat/chat/index.tsx b/web/app/components/base/chat/chat/index.tsxindex 23cd471341b..fe38e405a19 100644--- a/web/app/components/base/chat/chat/index.tsx+++ b/web/app/components/base/chat/chat/index.tsx@@ -196,7 +196,8 @@ const Chat: FC<ChatProps> = ({const chatContainer = chatContainerRef.currentif (chatContainer) {const setUserScrolled = () => {- if (chatContainer)+ // eslint-disable-next-line sonarjs/no-gratuitous-expressions+ if (chatContainer) // its in event callback, chatContainer may be nulluserScrolledRef.current = chatContainer.scrollHeight - chatContainer.scrollTop > chatContainer.clientHeight}chatContainer.addEventListener('scroll', setUserScrolled)diff --git a/web/app/components/base/features/new-feature-panel/moderation/moderation-setting-modal.tsx b/web/app/components/base/features/new-feature-panel/moderation/moderation-setting-modal.tsxindex 297e2b3f022..ab5200f38f5 100644--- a/web/app/components/base/features/new-feature-panel/moderation/moderation-setting-modal.tsx+++ b/web/app/components/base/features/new-feature-panel/moderation/moderation-setting-modal.tsx@@ -245,7 +245,7 @@ const ModerationSettingModal: FC<ModerationSettingModalProps> = ({><div className='flex items-center justify-between'><div className='title-2xl-semi-bold text-text-primary'>{t('appDebug.feature.moderation.modal.title')}</div>- <div className='cursor-pointer p-1' onClick={onCancel}><RiCloseLine className='h-4 w-4 text-text-tertiary'/></div>+ <div className='cursor-pointer p-1' onClick={onCancel}><RiCloseLine className='h-4 w-4 text-text-tertiary' /></div></div><div className='py-2'><div className='text-sm font-medium leading-9 text-text-primary'>@@ -348,14 +348,14 @@ const ModerationSettingModal: FC<ModerationSettingModalProps> = ({config={localeData.config?.inputs_config || { enabled: false, preset_response: '' }}onConfigChange={config => handleDataContentChange('inputs_config', config)}info={(localeData.type === 'api' && t('appDebug.feature.moderation.modal.content.fromApi')) || ''}- showPreset={!(localeData.type === 'api')}+ showPreset={localeData.type !== 'api'}/><ModerationContenttitle={t('appDebug.feature.moderation.modal.content.output') || ''}config={localeData.config?.outputs_config || { enabled: false, preset_response: '' }}onConfigChange={config => handleDataContentChange('outputs_config', config)}info={(localeData.type === 'api' && t('appDebug.feature.moderation.modal.content.fromApi')) || ''}- showPreset={!(localeData.type === 'api')}+ showPreset={localeData.type !== 'api'}/><div className='mb-8 mt-1 text-xs font-medium text-text-tertiary'>{t('appDebug.feature.moderation.modal.content.condition')}</div><div className='flex items-center justify-end'>diff --git a/web/app/components/header/account-setting/model-provider-page/hooks.spec.ts b/web/app/components/header/account-setting/model-provider-page/hooks.spec.tsindex 4d6941ddc63..b7a56f7b60d 100644--- a/web/app/components/header/account-setting/model-provider-page/hooks.spec.ts+++ b/web/app/components/header/account-setting/model-provider-page/hooks.spec.ts@@ -50,10 +50,7 @@ jest.mock('@/app/components/plugins/marketplace/utils', () => ({getMarketplacePluginsByCollectionId: jest.fn(),}))-jest.mock('./provider-added-card', () => {- // eslint-disable-next-line no-labels, ts/no-unused-expressions- UPDATE_MODEL_PROVIDER_CUSTOM_MODEL_LIST: []-})+jest.mock('./provider-added-card', () => jest.fn())after(() => {jest.resetModules()diff --git a/web/app/components/header/account-setting/model-provider-page/model-parameter-modal/parameter-item.tsx b/web/app/components/header/account-setting/model-provider-page/model-parameter-modal/parameter-item.tsxindex 6589ab29636..4bb3cbf7d50 100644--- a/web/app/components/header/account-setting/model-provider-page/model-parameter-modal/parameter-item.tsx+++ b/web/app/components/header/account-setting/model-provider-page/model-parameter-modal/parameter-item.tsx@@ -37,7 +37,7 @@ const ParameterItem: FC<ParameterItemProps> = ({if (parameterRule.type === 'int' || parameterRule.type === 'float')defaultValue = isNullOrUndefined(parameterRule.default) ? (parameterRule.min || 0) : parameterRule.defaultelse if (parameterRule.type === 'string' || parameterRule.type === 'text')- defaultValue = parameterRule.options?.length ? (parameterRule.default || '') : (parameterRule.default || '')+ defaultValue = parameterRule.default || ''else if (parameterRule.type === 'boolean')defaultValue = !isNullOrUndefined(parameterRule.default) ? parameterRule.default : falseelse if (parameterRule.type === 'tag')@@ -132,8 +132,6 @@ const ParameterItem: FC<ParameterItemProps> = ({step = 1else if (parameterRule.max < 1000)step = 10- else if (parameterRule.max < 10000)- step = 100}return (diff --git a/web/app/components/plugins/marketplace/list/card-wrapper.tsx b/web/app/components/plugins/marketplace/list/card-wrapper.tsxindex e43b6857369..205f5d850f0 100644--- a/web/app/components/plugins/marketplace/list/card-wrapper.tsx+++ b/web/app/components/plugins/marketplace/list/card-wrapper.tsx@@ -46,25 +46,23 @@ const CardWrapper = ({}/>{- showInstallButton && (- <div className='absolute bottom-0 hidden w-full items-center space-x-2 rounded-b-xl bg-gradient-to-tr from-components-panel-on-panel-item-bg to-background-gradient-mask-transparent px-4 pb-4 pt-8 group-hover:flex'>+ <div className='absolute bottom-0 hidden w-full items-center space-x-2 rounded-b-xl bg-gradient-to-tr from-components-panel-on-panel-item-bg to-background-gradient-mask-transparent px-4 pb-4 pt-8 group-hover:flex'>+ <Button+ variant='primary'+ className='w-[calc(50%-4px)]'+ onClick={showInstallFromMarketplace}+ >+ {t('plugin.detailPanel.operation.install')}+ </Button>+ <a href={`${getPluginLinkInMarketplace(plugin)}?language=${localeFromLocale}`} target='_blank' className='block w-[calc(50%-4px)] flex-1 shrink-0'><Button- variant='primary'- className='w-[calc(50%-4px)]'- onClick={showInstallFromMarketplace}+ className='w-full gap-0.5'>- {t('plugin.detailPanel.operation.install')}+ {t('plugin.detailPanel.operation.detail')}+ <RiArrowRightUpLine className='ml-1 h-4 w-4' /></Button>- <a href={`${getPluginLinkInMarketplace(plugin)}?language=${localeFromLocale}`} target='_blank' className='block w-[calc(50%-4px)] flex-1 shrink-0'>- <Button- className='w-full gap-0.5'- >- {t('plugin.detailPanel.operation.detail')}- <RiArrowRightUpLine className='ml-1 h-4 w-4' />- </Button>- </a>- </div>- )+ </a>+ </div>}{isShowInstallFromMarketplace && (diff --git a/web/app/components/plugins/plugin-page/empty/index.tsx b/web/app/components/plugins/plugin-page/empty/index.tsxindex 372adac29c1..7fee823c02f 100644--- a/web/app/components/plugins/plugin-page/empty/index.tsx+++ b/web/app/components/plugins/plugin-page/empty/index.tsx@@ -72,7 +72,7 @@ const Empty = () => {<div className='flex w-full flex-col gap-y-1'>{[...(- (enable_marketplace && true)+ (enable_marketplace)? [{ icon: MagicBox, text: t('plugin.list.source.marketplace'), action: 'marketplace' }]: []),diff --git a/web/app/components/plugins/plugin-page/install-plugin-dropdown.tsx b/web/app/components/plugins/plugin-page/install-plugin-dropdown.tsxindex 5a61adf8ac2..875cbd0ab26 100644--- a/web/app/components/plugins/plugin-page/install-plugin-dropdown.tsx+++ b/web/app/components/plugins/plugin-page/install-plugin-dropdown.tsx@@ -86,7 +86,7 @@ const InstallPluginDropdown = ({<div className='w-full'>{[...(- (enable_marketplace && true)+ (enable_marketplace)? [{ icon: MagicBox, text: t('plugin.source.marketplace'), action: 'marketplace' }]: []),diff --git a/web/app/components/plugins/update-plugin/from-market-place.tsx b/web/app/components/plugins/update-plugin/from-market-place.tsxindex ded4476e4f5..98994d9b9c6 100644--- a/web/app/components/plugins/update-plugin/from-market-place.tsx+++ b/web/app/components/plugins/update-plugin/from-market-place.tsx@@ -1,7 +1,6 @@'use client'import type { FC } from 'react'import React, { useCallback, useEffect, useMemo, useState } from 'react'-import { RiInformation2Line } from '@remixicon/react'import { useTranslation } from 'react-i18next'import Card from '@/app/components/plugins/card'import Modal from '@/app/components/base/modal'@@ -103,15 +102,7 @@ const UpdatePluginModal: FC<Props> = ({if (uploadStep === UploadStep.installed)onSave()}, [onSave, uploadStep, check, originalPackageInfo.id, handleRefetch, targetPackageInfo.id])- const usedInAppInfo = useMemo(() => {- return (- <div className='flex items-center justify-center gap-0.5 px-0.5'>- <div className='system-xs-medium text-text-warning'>{t(`${i18nPrefix}.usedInApps`, { num: 3 })}</div>- {/* show the used apps */}- <RiInformation2Line className='h-4 w-4 text-text-tertiary' />- </div>- )- }, [t])+return (<ModalisShow={true}@@ -136,7 +127,6 @@ const UpdatePluginModal: FC<Props> = ({<Badge className='mx-1' size="s" state={BadgeState.Warning}>{`${originalPackageInfo.payload.version} -> ${targetPackageInfo.version}`}</Badge>- {false && usedInAppInfo}</>}/>diff --git a/web/app/components/tools/workflow-tool/index.tsx b/web/app/components/tools/workflow-tool/index.tsxindex e7a6852dd70..30afc1aa3e1 100644--- a/web/app/components/tools/workflow-tool/index.tsx+++ b/web/app/components/tools/workflow-tool/index.tsx@@ -66,7 +66,7 @@ const WorkflowToolAsModal: FC<Props> = ({if (name === '')return true- return /^[a-zA-Z0-9_]+$/.test(name)+ return /^\w+$/.test(name)}const onConfirm = () => {diff --git a/web/app/components/workflow/nodes/_base/components/editor/code-editor/editor-support-vars.tsx b/web/app/components/workflow/nodes/_base/components/editor/code-editor/editor-support-vars.tsxindex ba995ebf4ef..7798ed3cb2f 100644--- a/web/app/components/workflow/nodes/_base/components/editor/code-editor/editor-support-vars.tsx+++ b/web/app/components/workflow/nodes/_base/components/editor/code-editor/editor-support-vars.tsx@@ -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}diff --git a/web/app/components/workflow/nodes/_base/components/variable/utils.ts b/web/app/components/workflow/nodes/_base/components/variable/utils.tsindex 335dd1c493c..c27fa43049b 100644--- a/web/app/components/workflow/nodes/_base/components/variable/utils.ts+++ b/web/app/components/workflow/nodes/_base/components/variable/utils.ts@@ -278,6 +278,7 @@ const formatItem = (break}+ // eslint-disable-next-line sonarjs/no-duplicated-branchescase 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] = variableArrif (first === 'sys' || first === 'env' || first === 'conversation')return variableArr@@ -611,6 +612,7 @@ const getLoopItemType = ({}: {valueSelector: ValueSelectorbeforeNodesOutputVars: 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-branchescase BlockEnum.VariableAggregator: {const payload = data as VariableAssignerNodeTypeif (payload.variables) {diff --git a/web/app/components/workflow/nodes/_base/components/variable/var-reference-vars.tsx b/web/app/components/workflow/nodes/_base/components/variable/var-reference-vars.tsxindex 3d347f5a0d4..27117c81b88 100644--- a/web/app/components/workflow/nodes/_base/components/variable/var-reference-vars.tsx+++ b/web/app/components/workflow/nodes/_base/components/variable/var-reference-vars.tsx@@ -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 = objPathconst itemRef = useRef<HTMLDivElement>(null)const [isItemHovering, setIsItemHovering] = useState(false)- const _ = useHover(itemRef, {+ useHover(itemRef, {onChange: (hovering) => {if (hovering) {setIsItemHovering(true)diff --git a/web/app/components/workflow/nodes/agent/default.ts b/web/app/components/workflow/nodes/agent/default.tsindex a0abfb411ef..4e7b447de80 100644--- a/web/app/components/workflow/nodes/agent/default.ts+++ b/web/app/components/workflow/nodes/agent/default.ts@@ -97,7 +97,7 @@ const nodeDefault: NodeDefault<AgentNodeType> = {}// check form of toolselse {- 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) }),}diff --git a/web/app/components/workflow/nodes/agent/node.tsx b/web/app/components/workflow/nodes/agent/node.tsxindex 4fd337eff07..adfba65f35a 100644--- a/web/app/components/workflow/nodes/agent/node.tsx+++ b/web/app/components/workflow/nodes/agent/node.tsx@@ -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>}diff --git a/web/app/components/workflow/nodes/end/default.ts b/web/app/components/workflow/nodes/end/default.tsindex 8ff824a7a07..e8fbb94bd0c 100644--- a/web/app/components/workflow/nodes/end/default.ts+++ b/web/app/components/workflow/nodes/end/default.ts@@ -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: '',}},}diff --git a/web/app/components/workflow/nodes/knowledge-retrieval/components/metadata/condition-list/utils.ts b/web/app/components/workflow/nodes/knowledge-retrieval/components/metadata/condition-list/utils.tsindex 0e7fbeb29c2..6397023991d 100644--- a/web/app/components/workflow/nodes/knowledge-retrieval/components/metadata/condition-list/utils.ts+++ b/web/app/components/workflow/nodes/knowledge-retrieval/components/metadata/condition-list/utils.ts@@ -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}#)\}\}/giexport const COMMON_VARIABLE_REGEX = /\{\{([a-zA-Z0-9_-]{1,50})\}\}/gidiff --git a/web/app/components/workflow/nodes/knowledge-retrieval/utils.ts b/web/app/components/workflow/nodes/knowledge-retrieval/utils.tsindex 68fe3d11e9c..3821a7a0524 100644--- a/web/app/components/workflow/nodes/knowledge-retrieval/utils.ts+++ b/web/app/components/workflow/nodes/knowledge-retrieval/utils.ts@@ -36,7 +36,6 @@ export const getSelectedDatasetsMode = (datasets: DataSet[] = []) => {allHighQualityFullTextSearch = falseallEconomic = falsemixtureHighQualityAndEconomic = false- inconsistentEmbeddingModel = falseallExternal = falseallInternal = falsemixtureInternalAndExternal = falsediff --git a/web/app/components/workflow/note-node/note-editor/utils.ts b/web/app/components/workflow/note-node/note-editor/utils.tsindex b9ce2d33b31..c241e93bf1a 100644--- a/web/app/components/workflow/note-node/note-editor/utils.ts+++ b/web/app/components/workflow/note-node/note-editor/utils.ts@@ -18,4 +18,5 @@ export function getSelectedNode(return $isAtNodeEnd(anchor) ? anchorNode : focusNode}+// eslint-disable-next-line sonarjs/empty-string-repetitionexport const urlRegExp = /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=+$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=+$,\w]+@)[A-Za-z0-9.-]+)((?:\/[+~%/.\w-_]*)?\??(?:[-+=&;%@.\w_]*)#?(?:[\w]*))?)/diff --git a/web/app/components/workflow/panel/chat-variable-panel/components/object-value-item.tsx b/web/app/components/workflow/panel/chat-variable-panel/components/object-value-item.tsxindex ef8a7697787..2649cfb70fe 100644--- a/web/app/components/workflow/panel/chat-variable-panel/components/object-value-item.tsx+++ b/web/app/components/workflow/panel/chat-variable-panel/components/object-value-item.tsx@@ -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})diff --git a/web/app/components/workflow/panel/env-panel/variable-modal.tsx b/web/app/components/workflow/panel/env-panel/variable-modal.tsxindex 41a735e9a99..f7dfbad8928 100644--- a/web/app/components/workflow/panel/env-panel/variable-modal.tsx+++ b/web/app/components/workflow/panel/env-panel/variable-modal.tsx@@ -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(diff --git a/web/app/components/workflow/run/utils/format-log/parallel/index.spec.ts b/web/app/components/workflow/run/utils/format-log/parallel/index.spec.tsdeleted file mode 100644index 0768392c5d3..00000000000--- a/web/app/components/workflow/run/utils/format-log/parallel/index.spec.ts+++ /dev/null@@ -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],- // ],- // },- // },- // ])- })-})diff --git a/web/app/components/workflow/run/utils/format-log/parallel/index.ts b/web/app/components/workflow/run/utils/format-log/parallel/index.tsindex b341dd47a82..f5a1136e3fa 100644--- a/web/app/components/workflow/run/utils/format-log/parallel/index.ts+++ b/web/app/components/workflow/run/utils/format-log/parallel/index.ts@@ -148,6 +148,7 @@ const format = (list: NodeTracing[], t: any, isPrint?: boolean): NodeTracing[] =return falseconst isParallelStartNode = node.parallelDetail?.isParallelStartNode+ // eslint-disable-next-line sonarjs/prefer-single-boolean-returnif (!isParallelStartNode)return falsediff --git a/web/app/components/workflow/utils/variable.ts b/web/app/components/workflow/utils/variable.tsindex cbefe563e5a..f73f92e3715 100644--- a/web/app/components/workflow/utils/variable.ts+++ b/web/app/components/workflow/utils/variable.ts@@ -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)}diff --git a/web/config/index.ts b/web/config/index.tsindex bba893ca54d..2b81adb0956 100644--- a/web/config/index.ts+++ b/web/config/index.ts@@ -265,7 +265,7 @@ Thought: {{agent_scratchpad}}`,}-export const VAR_REGEX = /\{\{(#[a-zA-Z0-9_-]{1,50}(\.[a-zA-Z_][a-zA-Z0-9_]{0,29}){1,10}#)\}\}/gi+export const VAR_REGEX = /\{\{(#[a-zA-Z0-9_-]{1,50}(\.[a-zA-Z_]\w{0,29}){1,10}#)\}\}/giexport const resetReg = () => VAR_REGEX.lastIndex = 0diff --git a/web/eslint.config.mjs b/web/eslint.config.mjsindex 554c34e169a..d40d96356b4 100644--- a/web/eslint.config.mjs+++ b/web/eslint.config.mjs@@ -7,6 +7,8 @@ import storybook from 'eslint-plugin-storybook'// import { fixupConfigRules } from '@eslint/compat'import tailwind from 'eslint-plugin-tailwindcss'import reactHooks from 'eslint-plugin-react-hooks'+import sonar from 'eslint-plugin-sonarjs'+// import reactRefresh from 'eslint-plugin-react-refresh'export default combine(@@ -138,7 +140,48 @@ export default combine('react-hooks': reactHooks,},},- // need futher research+ // sonar+ {+ rules: {+ ...sonar.configs.recommended.rules,+ // code complexity+ 'sonarjs/cognitive-complexity': 'off',+ 'sonarjs/no-nested-functions': 'warn',+ 'sonarjs/no-nested-conditional': 'warn',+ 'sonarjs/nested-control-flow': 'warn', // 3 levels of nesting+ 'sonarjs/no-small-switch': 'off',+ 'sonarjs/no-nested-template-literals': 'warn',+ 'sonarjs/redundant-type-aliases': 'off',+ 'sonarjs/regex-complexity': 'warn',+ // maintainability+ 'sonarjs/no-ignored-exceptions': 'off',+ 'sonarjs/no-commented-code': 'warn',+ 'sonarjs/no-unused-vars': 'warn',+ 'sonarjs/prefer-single-boolean-return': 'warn',+ 'sonarjs/duplicates-in-character-class': 'off',+ 'sonarjs/single-char-in-character-classes': 'off',+ 'sonarjs/anchor-precedence': 'warn',+ 'sonarjs/updated-loop-counter': 'off',+ 'sonarjs/no-dead-store': 'warn',+ 'sonarjs/no-duplicated-branches': 'warn',+ 'sonarjs/max-lines': 'warn', // max 1000 lines+ 'sonarjs/no-variable-usage-before-declaration': 'error',+ // security+ // eslint-disable-next-line sonarjs/no-hardcoded-passwords+ 'sonarjs/no-hardcoded-passwords': 'off', // detect the wrong code that is not password.+ 'sonarjs/no-hardcoded-secrets': 'off',+ 'sonarjs/pseudo-random': 'off',+ // performance+ 'sonarjs/slow-regex': 'warn',+ // others+ 'sonarjs/todo-tag': 'warn',+ 'sonarjs/table-header': 'off',+ },+ plugins: {+ sonarjs: sonar,+ },+ },+ // need further research{rules: {// not exist in old version@@ -150,6 +193,7 @@ export default combine(// useful, but big change'unicorn/prefer-number-properties': 'warn','unicorn/no-new-array': 'warn',+ 'style/indent': 'off',},},// suppress error for `no-undef` rulediff --git a/web/i18n/auto-gen-i18n.js b/web/i18n/auto-gen-i18n.jsindex 540d15503c2..7599a87f3e8 100644--- a/web/i18n/auto-gen-i18n.js+++ b/web/i18n/auto-gen-i18n.js@@ -57,6 +57,7 @@ async function translateMissingKeyDeeply(sourceObj, targetObject, toLanguage) {async function autoGenTrans(fileName, toGenLanguage) {const fullKeyFilePath = path.join(__dirname, targetLanguage, `${fileName}.ts`)const toGenLanguageFilePath = path.join(__dirname, toGenLanguage, `${fileName}.ts`)+ // eslint-disable-next-line sonarjs/code-evalconst fullKeyContent = eval(transpile(fs.readFileSync(fullKeyFilePath, 'utf8')))// To keep object format and format it for magicast to work: const translation = { ... } => export default {...}const readContent = await loadFile(toGenLanguageFilePath)diff --git a/web/i18n/check-i18n.js b/web/i18n/check-i18n.jsindex fbe1bbd2eff..ccd9741a602 100644--- a/web/i18n/check-i18n.js+++ b/web/i18n/check-i18n.js@@ -26,6 +26,7 @@ async function getKeysFromLanuage(language) {) // Convert to camel case// console.log(camelCaseFileName)const content = fs.readFileSync(filePath, 'utf8')+ // eslint-disable-next-line sonarjs/code-evalconst translation = eval(transpile(content))// console.log(translation)const keys = Object.keys(translation)diff --git a/web/models/app.ts b/web/models/app.tsindex 737df6bfae1..545819359f5 100644--- a/web/models/app.ts+++ b/web/models/app.ts@@ -2,63 +2,6 @@ import type { LangFuseConfig, LangSmithConfig, OpikConfig, TracingProvider } froimport type { App, AppMode, AppSSO, AppTemplate, SiteConfig } from '@/types/app'import type { Dependency } from '@/app/components/plugins/types'-/* export type App = {- id: string- name: string- description: string- mode: AppMode- enable_site: boolean- enable_api: boolean- api_rpm: number- api_rph: number- is_demo: boolean- model_config: AppModelConfig- providers: Array<{ provider: string; token_is_set: boolean }>- site: SiteConfig- created_at: string-}--export type AppModelConfig = {- provider: string- model_id: string- configs: {- prompt_template: string- prompt_variables: Array<PromptVariable>- completion_params: CompletionParam- }-}--export type PromptVariable = {- key: string- name: string- description: string- type: string | number- default: string- options: string[]-}--export type CompletionParam = {- max_tokens: number- temperature: number- top_p: number- echo: boolean- stop: string[]- presence_penalty: number- frequency_penalty: number-}--export type SiteConfig = {- access_token: string- title: string- author: string- support_email: string- default_language: string- customize_domain: string- theme: string- customize_token_strategy: 'must' | 'allow' | 'not_allow'- prompt_public: boolean-} */-export enum DSLImportMode {YAML_CONTENT = 'yaml-content',YAML_URL = 'yaml-url',diff --git a/web/package.json b/web/package.jsonindex 0851aba20a0..5edc3880687 100644--- a/web/package.json+++ b/web/package.json@@ -10,6 +10,7 @@"build": "next build","start": "cp -r .next/static .next/standalone/.next/static && cp -r public .next/standalone/public && cross-env PORT=$npm_config_port HOSTNAME=$npm_config_host node .next/standalone/server.js","lint": "pnpm eslint --cache --cache-location node_modules/.cache/eslint/.eslint-cache",+ "lint-only-show-error": "pnpm eslint --cache --cache-location node_modules/.cache/eslint/.eslint-cache --quiet","fix": "next lint --fix","eslint-fix": "eslint --cache --cache-location node_modules/.cache/eslint/.eslint-cache --fix","eslint-fix-only-show-error": "eslint --cache --cache-location node_modules/.cache/eslint/.eslint-cache --fix --quiet",@@ -181,6 +182,7 @@"eslint-config-next": "^15.0.0","eslint-plugin-react-hooks": "^5.1.0","eslint-plugin-react-refresh": "^0.4.19",+ "eslint-plugin-sonarjs": "^3.0.2","eslint-plugin-storybook": "^0.11.2","eslint-plugin-tailwindcss": "^3.18.0","husky": "^9.1.6",diff --git a/web/pnpm-lock.yaml b/web/pnpm-lock.yamlindex 4464e87a2e2..c86fe8baf02 100644--- a/web/pnpm-lock.yaml+++ b/web/pnpm-lock.yaml@@ -473,6 +473,9 @@ importers:eslint-plugin-react-refresh:specifier: ^0.4.19version: 0.4.19([email protected]([email protected]))+ eslint-plugin-sonarjs:+ specifier: ^3.0.2+ version: 3.0.2([email protected]([email protected]))eslint-plugin-storybook:specifier: ^0.11.2@@ -3736,6 +3739,10 @@ packages:resolution: {integrity: sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==}+ resolution: {integrity: sha512-zhaCDicdLuWN5UbN5IMnFqNMhNfo919sH85y2/ea+5Yg9TsTkeZxpL+JLbp6cgYFS4sRLp3YV4S6yDuqVWHYOw==}+ engines: {node: '>=6'}+resolution: {integrity: sha512-bkXY9WsVpY7CvMhKSR6pZilZu9Ln5WDrKVBUXf2S443etkmEO4V58heTecXcUIsNsi4Rx8JUO4NfX1IcQl4deg==}engines: {node: '>=18.20'}@@ -3747,6 +3754,10 @@ packages:resolution: {integrity: sha512-8SFQbg/0hQ9xy3UNTB0YEnsNBbWfhf7RtnzpL7TkBiTBRfrQ9Fxcnz7VJsleJpyp6rVLvXiuORqjlHi5q+PYuA==}engines: {node: '>=10.16.0'}+ resolution: {integrity: sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==}+ engines: {node: '>= 0.8'}+resolution: {integrity: sha512-b6Ilus+c3RrdDk+JhLKUAQfzzgLEPy6wcXqS7f/xe1EETvsDP6GORG7SFuOs6cID5YkqchW/LXZbX5bc8j7ZcQ==}engines: {node: '>=8'}@@ -4864,6 +4875,11 @@ packages:peerDependencies:eslint: '>=8.44.0'+ resolution: {integrity: sha512-LxjbfwI7ypENeTmGyKmDyNux3COSkMi7H/6Cal5StSLQ6edf0naP45SZR43OclaNR7WfhVTZdhOn63q3/Y6puQ==}+ peerDependencies:+ eslint: ^8.0.0 || ^9.0.0+resolution: {integrity: sha512-3WodYD6Bs9ACqnB+TP2TuLh774c/nacAjxSKOP9bHJ2c8rf+nrhocxjjeAWNmO9IPkFIzTKlcl0vNXI2yYpVOw==}engines: {node: '>= 18'}@@ -5181,6 +5197,9 @@ packages:resolution: {integrity: sha512-e5iwyodOHhbMr/yNrc7fDYG4qlbIvI5gajyzPnb5TCwyhjApznQh1BMFou9b30SevY43gCJKXycoCBjMbsuW0Q==}engines: {node: '>= 0.4'}+ resolution: {integrity: sha512-dsKNQNdj6xA3T+QlADDA7mOSlX0qiMINjn0cgr+eGHGsbSHzTabcIogz2+p/iqP1Xs6EP/sS2SbqH+brGTbq0g==}+resolution: {integrity: sha512-xckBUXyTIqT97tq2x2AMb+g163b5JFysYk0x4qxNFwbfQkmNZoiRHb6sPzI9/QV33WeuvVYBUIiD4NzNIyqaRQ==}@@ -8115,6 +8134,11 @@ packages:engines: {node: '>=4.2.0'}hasBin: true+ resolution: {integrity: sha512-p1diW6TqL9L07nNxvRMM7hMMw4c5XOo/1ibL4aAIGmSAt9slTE1Xgw5KWuof2uTOvCg9BY7ZRi+GaF+7sfgPeQ==}+ engines: {node: '>=14.17'}+ hasBin: true+resolution: {integrity: sha512-9a4/uxlTWJ4+a5i0ooc1rU7C7YOw3wT+UGqdeNNHWnOF9qcMBgLRS+4IYUqbczewFx4mLEig6gawh7X6mFlEkA==}@@ -12474,6 +12498,8 @@ snapshots:base64-js: 1.5.1ieee754: 1.2.1+ [email protected]: {}+@@ -12482,6 +12508,8 @@ snapshots:dependencies:streamsearch: 1.1.0+ [email protected]: {}+@@ -13904,6 +13932,19 @@ snapshots:regexp-ast-analysis: 0.7.1scslre: 0.3.0+ dependencies:+ '@eslint-community/regexpp': 4.12.1+ builtin-modules: 3.3.0+ bytes: 3.1.2+ eslint: 9.24.0([email protected])+ functional-red-black-tree: 1.0.1+ jsx-ast-utils: 3.3.5+ minimatch: 9.0.5+ scslre: 0.3.0+ semver: 7.7.1+ typescript: 5.8.3+dependencies:'@storybook/csf': 0.1.13@@ -14310,6 +14351,8 @@ snapshots:hasown: 2.0.2is-callable: 1.2.7+ [email protected]: {}+@@ -18063,6 +18106,8 @@ snapshots:+ [email protected]: {}+diff --git a/web/service/base.ts b/web/service/base.tsindex cb69257c316..247131520eb 100644--- a/web/service/base.ts+++ b/web/service/base.ts@@ -385,11 +385,11 @@ export const ssePost = (options.body = JSON.stringify(body)const accessToken = getAccessToken(isPublicAPI)- ;(options.headers as Headers).set('Authorization', `Bearer ${accessToken}`)+ ; (options.headers as Headers).set('Authorization', `Bearer ${accessToken}`)globalThis.fetch(urlWithPrefix, options as RequestInit).then((res) => {- if (!/^(2|3)\d{2}$/.test(String(res.status))) {+ if (!/^[23]\d{2}$/.test(String(res.status))) {if (res.status === 401) {refreshAccessTokenOrRelogin(TIME_OUT).then(() => {ssePost(url, fetchOptions, otherOptions)diff --git a/web/service/fetch.ts b/web/service/fetch.tsindex bbc1f4fc1ec..75dd775f6cc 100644--- a/web/service/fetch.ts+++ b/web/service/fetch.ts@@ -34,7 +34,7 @@ export type ResponseError = {const afterResponseErrorCode = (otherOptions: IOtherOptions): AfterResponseHook => {return async (_request, _options, response) => {const clonedResponse = response.clone()- if (!/^(2|3)\d{2}$/.test(String(clonedResponse.status))) {+ if (!/^([23])\d{2}$/.test(String(clonedResponse.status))) {const bodyJson = clonedResponse.json() as Promise<ResponseError>switch (clonedResponse.status) {case 403:diff --git a/web/utils/model-config.ts b/web/utils/model-config.tsindex a00bcfbb51b..74d8848a989 100644--- a/web/utils/model-config.ts+++ b/web/utils/model-config.ts@@ -109,10 +109,7 @@ export const userInputsFormToPromptVariables = (useInputs: UserInputFormItem[] |export const promptVariablesToUserInputsForm = (promptVariables: PromptVariable[]) => {const userInputs: UserInputFormItem[] = []promptVariables.filter(({ key, name }) => {- if (key && key.trim() && name && name.trim())- return true-- return false+ return key && key.trim() && name && name.trim()}).forEach((item: any) => {if (item.type === 'string' || item.type === 'paragraph') {userInputs.push({diff --git a/web/utils/var.ts b/web/utils/var.tsindex 70359337585..bb42fc06942 100644--- a/web/utils/var.ts+++ b/web/utils/var.ts@@ -7,7 +7,7 @@ import {} from '@/app/components/base/prompt-editor/constants'import { InputVarType } from '@/app/components/workflow/types'-const otherAllowedRegex = /^[a-zA-Z0-9_]+$/+const otherAllowedRegex = /^\w+$/export const getNewVar = (key: string, type: string) => {const { ...rest } = VAR_ITEM_TEMPLATE@@ -56,7 +56,7 @@ export const checkKey = (key: string, canBeEmpty?: boolean) => {return 'tooLong'if (otherAllowedRegex.test(key)) {- if (/[0-9]/.test(key[0]))+ if (/\d/.test(key[0]))return 'notStartWithNumber'return true@@ -82,7 +82,7 @@ export const checkKeys = (keys: string[], canBeEmpty?: boolean) => {return { isValid, errorKey, errorMessageKey }}-const varRegex = /\{\{([a-zA-Z_][a-zA-Z0-9_]*)\}\}/g+const varRegex = /\{\{([a-zA-Z_]\w*)\}\}/gexport const getVars = (value: string) => {if (!value)return []