Skip to content

Commit ccf6c88

Browse files
authored
Merge branch 'Tencent:main' into main
2 parents f92c9de + 488785b commit ccf6c88

23 files changed

Lines changed: 1346 additions & 618 deletions

File tree

.github/workflows/docs.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ jobs:
2424
- name: Checkout Repo
2525
uses: actions/checkout@v3
2626

27-
- name: Setup Node 14
27+
- name: Setup Node 16
2828
uses: actions/setup-node@v3
2929
with:
3030
# 选择要使用的 node 版本
31-
node-version: "14"
31+
node-version: "16"
3232
cache: "yarn"
3333
cache-dependency-path: "doc/yarn.lock"
3434

@@ -39,8 +39,8 @@ jobs:
3939
with:
4040
path: doc/node_modules
4141
key: ${{ runner.os }}-yarn-${{ hashFiles('doc/yarn.lock') }}
42-
restore-keys: |
43-
${{ runner.os }}-yarn-
42+
# restore-keys: |
43+
# ${{ runner.os }}-yarn-
4444

4545
# 如果缓存没有命中,安装依赖
4646
- if: ${{ steps.yarn-cache.outputs.cache-hit == false }}

client/tool/collie.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,11 @@ def __init__(self, params):
2222
self.sensitive_word_maps = {"Collie": "Tool", "collie": "Tool"}
2323

2424
def analyze(self, params):
25-
relpos = len(params.source_dir) + 1
2625
issues = list()
2726
collie = Tool(params=params)
2827
func_output = collie.check()
2928
if func_output and os.path.exists(os.path.join(func_output, "check.csv")):
3029
for issue in collie.get_issue(os.path.join(func_output, "check.csv")):
31-
issue["path"] = issue["path"][relpos:]
3230
issues.append(issue)
3331

3432
return issues

client/tool/util/collie.py

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import os
1010
import csv
11+
import json
1112
import sys
1213
import psutil
1314

@@ -19,6 +20,7 @@
1920
from util.pathfilter import PathMgr, FilterPathUtil
2021
from util.textutil import CommentsManager
2122
from util.logutil import LogPrinter
23+
from util.configlib import ConfigReader
2224
from node.app import settings
2325
from task.authcheck.check_license import __lu__
2426

@@ -125,10 +127,40 @@ def check(self, files=None, want_suffix=None, force_all=False, method_mode=False
125127
]
126128
if method_mode:
127129
options.append("-m")
130+
131+
# 默认开启所有规则
132+
# 支持指定规则,使用配置文件的方式,以下是demo
133+
# {
134+
# "enableCheckers": {
135+
# "GoFuncVisitor": {},
136+
# "JavaScriptFuncVisitor": {
137+
# "ignoreNestingMethods": true
138+
# }
139+
# }
140+
# }
141+
config = dict()
142+
enable_rules = dict()
143+
rule_list = self.params.get("rule_list", list())
144+
for rule in rule_list:
145+
# 因为有这个字段但本身就是None,所以返回None
146+
rule_params = rule.get("params")
147+
if rule_params is None:
148+
rule_params = ""
149+
if f"[{self.tool_name.lower()}]" not in rule_params:
150+
rule_params = f"[{self.tool_name.lower()}]\r\n" + rule_params
151+
rule_params_dict = ConfigReader(cfg_string=rule_params).read(self.tool_name.lower())
152+
enable_rules[rule["name"]] = rule_params_dict
153+
config["enableCheckers"] = enable_rules
154+
config_path = os.path.join(self.work_dir, f"{self.tool_name}_config.json")
155+
with open(config_path, "w") as f:
156+
json.dump(config, f, indent=2)
157+
options.extend(["-c", config_path])
158+
128159
scan_cmd = self.get_cmd(options)
129160

130161
spc = SubProcController(
131162
scan_cmd,
163+
cwd=self.tool_home,
132164
stdout_line_callback=subprocc_log,
133165
stderr_line_callback=subprocc_log,
134166
)
@@ -171,8 +203,9 @@ def get_issue(self, output):
171203
if not output or not os.path.exists(output):
172204
return
173205

206+
relpos = len(self.params.source_dir) + 1
174207
rules = self.params.get("rules", list())
175-
208+
176209
f = open(output, "r", encoding="utf-8")
177210
fieldnames = (
178211
"checker",
@@ -185,19 +218,33 @@ def get_issue(self, output):
185218
reader = csv.DictReader(csv_f, fieldnames)
186219
next(reader)
187220
for row in reader:
188-
path = row["path"]
221+
path = row["path"][relpos:]
189222
line = int(row["line"])
190223
column = int(row["column"])
191224
rule = row["checker"]
192225
if rule not in rules:
193226
continue
194227
msg = row["description"]
228+
229+
row_refs = row[None]
230+
refs = list()
231+
for ref in row_refs:
232+
parts = ref.split(":")
233+
refs.append(
234+
{
235+
"line": parts[2],
236+
"column": parts[3],
237+
"msg": parts[0],
238+
"path": parts[1][relpos:],
239+
}
240+
)
195241
yield {
196242
"rule": rule,
197243
"msg": msg,
198244
"path": path,
199245
"line": line,
200246
"column": column,
247+
"refs": refs,
201248
}
202249

203250
f.close()

doc/.vuepress/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { defineUserConfig } from '@vuepress/cli'
22
import { defaultTheme } from '@vuepress/theme-default'
3+
import { searchPlugin } from '@vuepress/plugin-search'
34
import { navbar, sidebar } from './configs'
4-
const { searchPlugin } = require('@vuepress/plugin-search')
55

66
const isProd = process.env.NODE_ENV === 'production'
77

doc/en/quickStarted/enhanceDeploy.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,13 @@ TCA 增强分析模块,需要用户额外部署 License 鉴权微服务,并
2424
### 准备
2525
- 一台 CLS 微服务专属机器,CLS 微服务需要跟该机器绑定
2626

27+
**注意:不能随意删除CLS目录**
28+
2729
### 步骤
2830
1. 在 TCA 源码中[`server/cls`](https://github.com/Tencent/CodeAnalysis/tree/main/server/cls) 目录下执行以下命令,获取 `Server ID``Client License`
2931

32+
**注意:需要在 CLS 目录下执行命令**
33+
3034
```shell
3135
$ ./cls server
3236
2022-04-13 18:35:29.356510559 +0800 CST [INFO] Version: 20220328.1
@@ -42,8 +46,8 @@ xxx
4246
```ini
4347
[LICENSE_CONFIG]
4448
; [可选]使用独立工具时,需要填写,默认不需要
49+
; License服务的域名和端口
4550
URL=http://<IP或者域名>:<port>
46-
;License服务的域名和端口
4751
BASE_PATH=
4852
LICENSE=<Client License>
4953
```
@@ -88,7 +92,7 @@ tommyzhang@tencent.com
8892
```
8993

9094
6. 启动 TCA 分析任务
91-
在 TCA 平台的分析方案里面勾选独立工具相关的规则包。
95+
在 TCA 平台的分析方案里面勾选独立工具相关的规则包,比如依赖组件分析规则包,然后启动一次分析任务,执行正常则表明设置生效
9296

9397
### CLS 运维
9498
#### 自动重启

doc/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
"tca",
77
"document"
88
],
9+
"type": "module",
910
"license": "MIT",
1011
"scripts": {
1112
"dev": "vuepress dev",
1213
"build:comment": "echo '构建帮助文档,默认base前缀为document,可根据部署需要进行相应调整'",
1314
"build": "BASE=${BASE:-CodeAnalysis} vuepress build -d ./dist"
1415
},
1516
"devDependencies": {
16-
"@vuepress/plugin-search": "^2.0.0-beta.43",
17-
"vuepress": "^2.0.0-beta.42"
17+
"@vuepress/plugin-search": "2.0.0-beta.51",
18+
"vuepress": "2.0.0-beta.51"
1819
}
19-
}
20+
}

0 commit comments

Comments
 (0)