Skip to main content

sv check

sv check 在你的项目中发现错误和警告,例如:

¥sv check finds errors and warnings in your project, such as:

  • 未使用的 CSS

    ¥unused CSS

  • 可访问性提示

    ¥accessibility hints

  • JavaScript/TypeScript 编译器错误

    ¥JavaScript/TypeScript compiler errors

需要 Node 16 或更高版本。

¥Requires Node 16 or later.

安装(Installation)

¥Installation

你需要在项目中安装 svelte-check 软件包:

¥You will need to have the svelte-check package installed in your project:

npm i -D svelte-check

用法(Usage)

¥Usage

npx sv check

选项(Options)

¥Options

--workspace <path>

工作区路径。除 node_modules--ignore 中列出的子目录外的所有子目录都经过检查。

¥Path to your workspace. All subdirectories except node_modules and those listed in --ignore are checked.

--output <format>

如何显示错误和警告。参见 机器可读输出

¥How to display errors and warnings. See machine-readable output.

  • human

  • human-verbose

  • machine

  • machine-verbose

--watch

保持进程活跃并监视更改。

¥Keeps the process alive and watches for changes.

--preserveWatchOutput

防止在监视模式下清除屏幕。

¥Prevents the screen from being cleared in watch mode.

--tsconfig <path>

传递 tsconfigjsconfig 文件的路径。路径可以是相对于工作区路径的相对路径,也可以是绝对路径。这样做意味着只有与配置文件的 files / include/exclude 模式匹配的文件才会被诊断。它还意味着报告来自 TypeScript 和 JavaScript 文件的错误。如果没有给出,将从项目目录向上遍历寻找下一个 jsconfig/tsconfig.json 文件。

¥Pass a path to a tsconfig or jsconfig file. The path can be relative to the workspace path or absolute. Doing this means that only files matched by the files / include/exclude pattern of the config file are diagnosed. It also means that errors from TypeScript and JavaScript files are reported. If not given, will traverse upwards from the project directory looking for the next jsconfig/tsconfig.json file.

--no-tsconfig

如果你只想检查当前目录及以下目录中的 Svelte 文件并忽略任何 .js / .ts 文件(它们不会被类型检查),请使用此功能

¥Use this if you only want to check the Svelte files found in the current directory and below and ignore any .js / .ts files (they will not be type-checked)

--ignore <paths>

要忽略的文件/文件夹,相对于工作区根目录。路径应该用逗号分隔并加引号。示例:

¥Files/folders to ignore, relative to workspace root. Paths should be comma-separated and quoted. Example:

npx sv check --ignore "dist,build"

仅与 --no-tsconfig 结合使用时才有效。当与 --tsconfig 结合使用时,这只会对监视的文件产生影响,而不会对诊断的文件产生影响,然后由 tsconfig.json 确定。

¥Only has an effect when used in conjunction with --no-tsconfig. When used in conjunction with --tsconfig, this will only have effect on the files watched, not on the files that are diagnosed, which is then determined by the tsconfig.json.

--fail-on-warnings

如果提供,警告将导致 sv check 退出并显示错误代码。

¥If provided, warnings will cause sv check to exit with an error code.

--compiler-warnings <warnings>

用引号括起来的逗号分隔的 code:behaviour 对列表,其中 code编译器警告代码,而 behaviourignoreerror

¥A quoted, comma-separated list of code:behaviour pairs where code is a compiler warning code and behaviour is either ignore or error:

npx sv check --compiler-warnings "css_unused_selector:ignore,a11y_missing_attribute:error"

--diagnostic-sources <sources>

用引号括起来的逗号分隔的源列表,这些源应该在你的代码上运行诊断。默认情况下,所有都是活动的:

¥A quoted, comma-separated list of sources that should run diagnostics on your code. By default, all are active:

  • js(包括 TypeScript)

    ¥js (includes TypeScript)

  • svelte

  • css

示例:

¥Example:

npx sv check --diagnostic-sources "js,svelte"

--threshold <level>

过滤诊断:

¥Filters the diagnostics:

  • warning(默认) - 显示错误和警告

    ¥warning (default) — both errors and warnings are shown

  • error — 仅显示错误

    ¥error — only errors are shown

故障排除(Troubleshooting)

¥Troubleshooting

查看 language-tools 文档 有关预处理器设置和其他故障排除的更多信息。

¥See the language-tools documentation for more information on preprocessor setup and other troubleshooting.

机器可读输出(Machine-readable output)

¥Machine-readable output

--output 设置为 machinemachine-verbose 将以更易于机器读取的方式格式化输出,例如在 CI 管道内部,用于代码质量检查等。

¥Setting the --output to machine or machine-verbose will format output in a way that is easier to read by machines, e.g. inside CI pipelines, for code quality checks, etc.

每行对应一条新记录。行由由单个空格字符分隔的列组成。每行的第一列包含一个以毫秒为单位的时间戳,可用于监控目的。第二列为我们提供了 “运行脚本”,后续列的数量和类型可能基于此而有所不同。

¥Each row corresponds to a new record. Rows are made up of columns that are separated by a single space character. The first column of every row contains a timestamp in milliseconds which can be used for monitoring purposes. The second column gives us the “row type”, based on which the number and types of subsequent columns may differ.

第一行是 START 类型,包含工作区文件夹(用引号括起来)。示例:

¥The first row is of type START and contains the workspace folder (wrapped in quotes). Example:

1590680325583 START "/home/user/language-tools/packages/language-server/test/plugins/typescript/testfiles"

可能随后有任意数量的 ERRORWARNING 记录。它们的结构相同,取决​​于输出参数。

¥Any number of ERROR or WARNING records may follow. Their structure is identical and depends on the output argument.

如果参数是 machine,它将告诉我们文件名、起始行号和列号以及错误消息。文件名相对于工作区目录。文件名和消息都用引号括起来。示例:

¥If the argument is machine it will tell us the filename, the starting line and column numbers, and the error message. The filename is relative to the workspace directory. The filename and the message are both wrapped in quotes. Example:

1590680326283 ERROR "codeactions.svelte" 1:16 "Cannot find module 'blubb' or its corresponding type declarations."
1590680326778 WARNING "imported-file.svelte" 0:37 "Component has unused export property 'prop'. If it is for external reference only, please consider using `export const prop`"

如果参数是 machine-verbose,它将告诉我们文件名、起始行号和列号、结束行号和列号、错误消息、诊断代码、代码的人性化描述以及诊断的人性化来源(例如 svelte/typescript)。文件名相对于工作区目录。每个诊断都表示为以日志时间戳为前缀的 ndjson 行。示例:

¥If the argument is machine-verbose it will tell us the filename, the starting line and column numbers, the ending line and column numbers, the error message, the code of diagnostic, the human-friendly description of the code and the human-friendly source of the diagnostic (eg. svelte/typescript). The filename is relative to the workspace directory. Each diagnostic is represented as an ndjson line prefixed by the timestamp of the log. Example:

1590680326283 {"type":"ERROR","fn":"codeaction.svelte","start":{"line":1,"character":16},"end":{"line":1,"character":23},"message":"Cannot find module 'blubb' or its corresponding type declarations.","code":2307,"source":"js"}
1590680326778 {"type":"WARNING","filename":"imported-file.svelte","start":{"line":0,"character":37},"end":{"line":0,"character":51},"message":"Component has unused export property 'prop'. If it is for external reference only, please consider using `export
const prop`","code":"unused-export-let","source":"svelte"}

输出以 COMPLETED 消息结束,该消息总结了检查期间遇到的文件总数、错误和警告。示例:

¥The output concludes with a COMPLETED message that summarizes total numbers of files, errors and warnings that were encountered during the check. Example:

1590680326807 COMPLETED 20 FILES 21 ERRORS 1 WARNINGS 3 FILES_WITH_PROBLEMS

如果应用遇到运行时错误,此错误将显示为 FAILURE 记录。示例:

¥If the application experiences a runtime error, this error will appear as a FAILURE record. Example:

1590680328921 FAILURE "Connection closed"

致谢(Credits)

¥Credits

  • svelte-check 奠定基础的 Vue 的 VTI

    ¥Vue’s VTI which laid the foundation for svelte-check

常见问题(FAQ)

¥FAQ

为什么没有仅检查特定文件的选项(例如仅暂存文件)?(Why is there no option to only check specific files (for example only staged files)?)

¥Why is there no option to only check specific files (for example only staged files)?

svelte-check 需要对整个项目进行 ‘see’ 检查才能有效。假设你重命名了组件 prop,但没有更新使用该 prop 的任何地方 - 使用站点现在都是错误,但如果检查仅在更改的文件上运行,你会遗漏它们。

¥svelte-check needs to ‘see’ the whole project for checks to be valid. Suppose you renamed a component prop but didn’t update any of the places where the prop is used — the usage sites are all errors now, but you would miss them if checks only ran on changed files.

上一页 下一页