Files
gsfdc/demo-dify/dify/scripts/ast_grep_rules/no_new_mock.yml
T
wuzilongandCursor 6519682885 chore: 纳入本地 Dify 1.19.0 源码及品牌与免登改动
演示目录只保留可重建的源码。运行密钥、数据卷、依赖和带口令的本地配置不进入仓库。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-18 13:59:25 +08:00

62 lines
2.0 KiB
YAML

id: no-new-mock
language: python
severity: error
message: Use a real instance instead of adding a Mock, MagicMock, or SimpleNamespace constructor.
rule:
all:
- pattern: $CALLEE($$$ARGS)
- any:
- has:
field: function
stopBy: end
regex: '(^|\.)(Mock|MagicMock|SimpleNamespace)$'
- inside:
kind: module
stopBy: end
has:
stopBy: end
all:
- pattern:
context: from package import $ORIGINAL as $CALLEE
selector: aliased_import
- any:
- all:
- has:
field: name
stopBy: end
regex: '^(Mock|MagicMock)$'
- inside:
kind: import_from_statement
stopBy: end
has:
field: module_name
stopBy: end
regex: '^unittest\.mock$'
- all:
- has:
field: name
stopBy: end
regex: '^SimpleNamespace$'
- inside:
kind: import_from_statement
stopBy: end
has:
field: module_name
stopBy: end
regex: '^types$'
- all:
- has:
field: function
kind: identifier
- inside:
kind: module
stopBy: end
has:
stopBy: end
all:
- pattern: $CALLEE = $ORIGINAL
- has:
field: right
stopBy: end
regex: '(^|\.)(Mock|MagicMock|SimpleNamespace)$'