MCPcopy Index your code
hub / github.com/Tencent/CodeAnalysis / scan

Method scan

client/tool/eslint.py:334–430  ·  view source on GitHub ↗

:param params: :param config_path: :param error_output: :return:

(self, params, config_path, error_output, eslint_ext)

Source from the content-addressed store, hash-verified

332 return tsconfigFile
333
334 def scan(self, params, config_path, error_output, eslint_ext):
335 """
336
337 :param params:
338 :param config_path:
339 :param error_output:
340 :return:
341 """
342 source_dir = params.source_dir
343 path_exclude = params.path_filters.get("wildcard_exclusion", [])
344 path_include = params.path_filters.get("wildcard_inclusion", [])
345 incr_scan = params["incr_scan"]
346 envs = os.environ
347
348 if "ESLINT_MAX_OLD_SPACE_SIZE" in envs:
349 # 或者设置NODE_OPTIONS="--max-old-space-size=4096"
350 scan_cmd = ["node", "--max-old-space-size=" + envs["ESLINT_MAX_OLD_SPACE_SIZE"]]
351 if sys.platform == "win32":
352 scan_cmd.append(os.path.join(envs.get("NODE_HOME"), "node_modules", "eslint", "bin", "eslint.js"))
353 else:
354 scan_cmd.append(
355 os.path.join(envs.get("NODE_HOME"), "lib", "node_modules", "eslint", "bin", "eslint.js")
356 )
357 else:
358 scan_cmd = ["eslint"]
359
360 if config_path:
361 scan_cmd.extend(["--config", config_path, "--no-eslintrc"])
362
363 scan_cmd.extend(["-f", "checkstyle", "-o", error_output, "--debug"])
364
365 if "ESLINT_OPTION_PARAMS" in envs:
366 scan_cmd.extend(shlex.split(envs["ESLINT_OPTION_PARAMS"]))
367
368 scan_cmd.extend(["--ext", eslint_ext])
369
370 # 设置扫描路径过滤 exclusion and inclusion
371 scan_cmd.extend(self._get_path_filte(path_exclude, path_include))
372 # 默认不使用代码库下eslintignore文件中的过滤路径, 除非设置环境变量ESLINT_IGNORE指定
373 eslint_ignore = envs.get("ESLINT_IGNORE", None)
374 ignore_file = eslint_ignore if eslint_ignore else self.get_ignore_file(params)
375 scan_cmd.extend(["--ignore-path", ignore_file])
376
377 # 指定扫描目录或者文件,支持增量
378 relpos = len(source_dir) + 1
379 if incr_scan:
380 diffs = SCMMgr(params).get_scm_diff()
381 toscans = [
382 os.path.join(source_dir, diff.path)
383 for diff in diffs
384 if diff.path.endswith(tuple(eslint_ext.split(","))) and diff.state != "del"
385 ]
386 toscans = FilterPathUtil(params).get_include_files(toscans, relpos)
387 toscans = [path[relpos:].replace(os.sep, "/") for path in toscans]
388
389 # windows下增量文件路径总长度超长,改为扫描整个soucedir,否则会执行异常
390 # 因为 windows 下执行subprocess.Popen方法且shell=False的情况下,命令长度限制为32768字节
391 # 这里文件路径长度限制为32500,因为前面还要预留cppcheck命令的长度

Callers 3

analyzeMethod · 0.95
analyzeMethod · 0.95
analyzeMethod · 0.95

Calls 8

_get_path_filteMethod · 0.95
get_ignore_fileMethod · 0.95
print_logMethod · 0.95
__get_stderr_logMethod · 0.95
ConfigErrorClass · 0.90
debugMethod · 0.80
errorMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected