diff --git a/CHANGELOG.md b/CHANGELOG.md index 9256cd7f9..97473c44e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel ## [Unreleased] ### Added - [`no-unused-modules`]: consider exported TypeScript interfaces, types and enums ([#1819], thanks [@nicolashenry]) +- [`no-cycle`]: allow `maxDepth` option to be `"∞"` (thanks [@ljharb]) ### Fixed - [`order`]/TypeScript: properly support `import = object` expressions ([#1823], thanks [@manuth]) diff --git a/docs/rules/no-cycle.md b/docs/rules/no-cycle.md index 6329bb272..7d54e81ff 100644 --- a/docs/rules/no-cycle.md +++ b/docs/rules/no-cycle.md @@ -2,7 +2,7 @@ Ensures that there is no resolvable path back to this module via its dependencies. -This includes cycles of depth 1 (imported module imports me) to `Infinity`, if the +This includes cycles of depth 1 (imported module imports me) to `"∞"` (or `Infinity`), if the [`maxDepth`](#maxdepth) option is not set. ```js diff --git a/src/rules/no-cycle.js b/src/rules/no-cycle.js index 8f39246b5..2ad381e91a 100644 --- a/src/rules/no-cycle.js +++ b/src/rules/no-cycle.js @@ -14,10 +14,18 @@ module.exports = { type: 'suggestion', docs: { url: docsUrl('no-cycle') }, schema: [makeOptionsSchema({ - maxDepth:{ - description: 'maximum dependency depth to traverse', - type: 'integer', - minimum: 1, + maxDepth: { + oneOf: [ + { + description: 'maximum dependency depth to traverse', + type: 'integer', + minimum: 1, + }, + { + enum: ['∞'], + type: 'string', + }, + ], }, ignoreExternal: { description: 'ignore external modules', @@ -32,7 +40,7 @@ module.exports = { if (myPath === '') return {} // can't cycle-check a non-file const options = context.options[0] || {} - const maxDepth = options.maxDepth || Infinity + const maxDepth = typeof options.maxDepth === 'number' ? options.maxDepth : Infinity const ignoreModule = (name) => options.ignoreExternal ? isExternalModule(name) : false function checkSourceValue(sourceNode, importer) { diff --git a/tests/src/rules/no-cycle.js b/tests/src/rules/no-cycle.js index b0f4153e8..2539ba594 100644 --- a/tests/src/rules/no-cycle.js +++ b/tests/src/rules/no-cycle.js @@ -161,6 +161,16 @@ ruleTester.run('no-cycle', rule, { parser: require.resolve('babel-eslint'), errors: [error(`Dependency cycle via ./flow-types-depth-two:4=>./depth-one:1`)], }), + test({ + code: 'import { foo } from "./depth-two"', + options: [{ maxDepth: Infinity }], + errors: [error(`Dependency cycle via ./depth-one:1`)], + }), + test({ + code: 'import { foo } from "./depth-two"', + options: [{ maxDepth: '∞' }], + errors: [error(`Dependency cycle via ./depth-one:1`)], + }), ], }) // })