13 Commits

2 changed files with 32 additions and 22 deletions

View File

@@ -59,7 +59,7 @@ python app.py
### 1. 构建镜像 ### 1. 构建镜像
```bash ```bash
docker build -t dcr-by1jwyxk44.71826370.xyz/whlaoding/code-scan:latest . docker buildx build --load --push -t dcr-by1jwyxk44.71826370.xyz/whlaoding/code-scan:latest .
``` ```
### 2. 登录仓库 ### 2. 登录仓库
@@ -71,7 +71,7 @@ docker login dcr-by1jwyxk44.71826370.xyz
### 3. Push 到仓库 ### 3. Push 到仓库
```bash ```bash
docker push dcr-by1jwyxk44.71826370.xyz/whlaoding/code-scan:latest docker run -d --name code-scan -p 5000:5000 dcr-by1jwyxk44.71826370.xyz/whlaoding/code-scan:latest
``` ```
### 4. 使用 docker compose 启动 ### 4. 使用 docker compose 启动

View File

@@ -19,10 +19,36 @@ import collections as col # 使用了 col 但 flake8 可能检测
# 缺陷2: 未使用的变量 # 缺陷2: 未使用的变量
def unused_variable_demo(): # def unused_variable_demo():
"""演示未使用的变量""" # """演示未使用的变量"""
result = calculate() # result 未被使用 # result = calculate() # result 未被使用
print("Function executed") # print("Function executed")
# 缺陷8: 行太长(风格问题)
def long_line():
"""这是一行非常非常非常非常非常非常非常非常非常非常非常非常长的代码超过了 120 个字符的限制"""
# 缺陷9: 缺少空格
def missing_spaces():
"""缺少必要空格"""
x=1+2
y=3*99
if x==1:
print(x)
# 缺陷1: 未使用的导入
import unused_module # 未使用
import collections as col # 使用了 col 但 flake8 可能检测
# 缺陷2: 未使用的变量
# def unused_variable_demo():
# """演示未使用的变量"""
# result = calculate() # result 未被使用
# print("Function executed")
def calculate(): def calculate():
@@ -41,19 +67,3 @@ def use_before_define():
"""在定义前使用变量""" """在定义前使用变量"""
print(before_var) # before_var 在下面才定义 print(before_var) # before_var 在下面才定义
before_var = 100 before_var = 100
# 缺陷5: 硬编码密码(安全问题)
def connect_database():
"""连接数据库"""
password = "admin123" # 硬编码密码
username = "root"
return f"Connecting with {username}:{password}"
# 缺陷6: 使用 eval安全问题
def unsafe_eval():
"""危险使用 eval"""
user_input = "os.system('ls')"
result = eval(user_input) # 危险!
return result