【问题标题】:ESLint rule: maximum nesting path for fileESLint 规则:文件的最大嵌套路径
【发布时间】:2025-12-29 19:30:06
【问题描述】:

是否有这样的规则来检查文件路径嵌套级别?例如:

此规则的错误代码示例:

import { notifyDevelopers } from '../../../../../utils/ajax'

此规则的正确代码示例:

import { notifyDevelopers } from './../utils/ajax'
import { notifyDevelopers } from 'utils/ajax'

我只找到了这个包: https://github.com/benmosher/eslint-plugin-import

但是这个包好像没有这个规则

【问题讨论】:

    标签: javascript eslint


    【解决方案1】:

    .eslintrc

    {
      "rules": {
        "no-restricted-imports": [
          "error",
          {
            "patterns": ["../../../*"]
          }
        ]
      }
    }
    
    

    no-restricted-modules规则,也支持这个

    【讨论】: