@-k/eslint-plugin-dependencies 中文文档教程
@k/eslint-plugin-dependencies
:warning: 这是一个(临时) fork :warning: 由于 https://github.com/zertosh/eslint-plugin-dependencies/pull/21/files,目标是发布一个与 eslint 6 兼容的版本
Usage
npm install eslint-plugin-dependencies
在你的 .eslintrc
中:
{
"plugins": [
"dependencies"
],
"rules": {
"dependencies/case-sensitive": 1,
"dependencies/no-cycles": 1,
"dependencies/no-unresolved": 1,
"dependencies/require-json-ext": 1
}
}
Rules
一个 eslint 插件...
dependencies/case-sensitive
验证 require("...")
, require.resolve(...)< /code>、
import "..."
和 export … from "..."
id 与目录列表报告的大小写相匹配。
{
"plugins": [
"dependencies"
],
"rules": {
"dependencies/case-sensitive": [1, {"paths": ["custom-path-to-search-for-modules"]}]
}
}
dependencies/no-cycles
防止模块之间的循环引用。 它解析 require("...")
、import "..."
和 export … from "..."
对内部模块的引用(即不是 node_modules
), 判断是否存在环路。 如果您使用的是自定义解析器,规则将使用它来解析依赖项。 该规则采用 skip
字符串数组,它将被视为正则表达式以跳过检查文件。
此外,启用 types
选项后,您还可以检测并防止 import type
循环。 这可能很有用,因为 Flow checker 可能会在此类循环中表现出意外行为。
{
"plugins": [
"dependencies"
],
"rules": {
"dependencies/no-cyles": [1, {"skip": ["/spec/", "/vendor/"], "types": true}]
}
}
dependencies/no-unresolved
检查 require("...")
、require.resolve(...)
、import "..."
和 export … from "... "
存在的引用模块。 采用要忽略的 ignore
模块数组。
{
"plugins": [
"dependencies"
],
"rules": {
"dependencies/no-unresolved": [1, {"ignore": ["atom"], "paths": ["custom-path-to-search-for-modules"]}]
}
}
dependencies/require-json-ext
确保属于 .json
的模块在模块 ID 中包含它们的扩展名。 支持自动修复。
@k/eslint-plugin-dependencies
:warning: This is a (temporary) fork :warning: Aim is to have a release that is comptabible with eslint 6 thanks to https://github.com/zertosh/eslint-plugin-dependencies/pull/21/files
Usage
npm install eslint-plugin-dependencies
In your .eslintrc
:
{
"plugins": [
"dependencies"
],
"rules": {
"dependencies/case-sensitive": 1,
"dependencies/no-cycles": 1,
"dependencies/no-unresolved": 1,
"dependencies/require-json-ext": 1
}
}
Rules
An eslint plugin that …
dependencies/case-sensitive
Verifies that require("…")
, require.resolve(…)
, import "…"
and export … from "…"
ids match the case that is reported by a directory listing.
{
"plugins": [
"dependencies"
],
"rules": {
"dependencies/case-sensitive": [1, {"paths": ["custom-path-to-search-for-modules"]}]
}
}
dependencies/no-cycles
Prevents cyclic references between modules. It resolves require("…")
, import "…"
and export … from "…"
references to internal modules (i.e. not node_modules
), to determine whether there is a cycle. If you're using a custom parser, the rule will use that to parse the dependencies. The rule takes a skip
array of strings, that will be treated as regexps to skip checking files.
Additionally, with the types
option enabled, you can detect and prevent import type
cycles as well. This can be helpful, since the Flow checker can exhibit unexpected behavior with such cycles.
{
"plugins": [
"dependencies"
],
"rules": {
"dependencies/no-cyles": [1, {"skip": ["/spec/", "/vendor/"], "types": true}]
}
}
dependencies/no-unresolved
Checks that require("…")
, require.resolve(…)
, import "…"
and export … from "…"
reference modules that exist. Takes an ignore
array of modules to ignore.
{
"plugins": [
"dependencies"
],
"rules": {
"dependencies/no-unresolved": [1, {"ignore": ["atom"], "paths": ["custom-path-to-search-for-modules"]}]
}
}
dependencies/require-json-ext
Ensures that modules are that are .json
include their extension in the module id. Supports auto fix.