diff --git a/CHANGELOG.md b/CHANGELOG.md index b68294fb5f..a3fdb5b93d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel ### Added * component detection: add componentWrapperFunctions setting ([#2713][] @@jzabala @LandonSchropp) * [`no-unused-prop-types`]: add ignore option ([#2972][] @grit96) +* version detection: support recursive processor virtual filename ([#2965][] @JounQin) ### Fixed * [`jsx-handler-names`]: properly substitute value into message ([#2975][] @G-Rath) @@ -32,6 +33,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel [#2975]: https://github.com/yannickcr/eslint-plugin-react/pull/2975 [#2974]: https://github.com/yannickcr/eslint-plugin-react/pull/2974 [#2972]: https://github.com/yannickcr/eslint-plugin-react/pull/2972 +[#2965]: https://github.com/yannickcr/eslint-plugin-react/pull/2965 [#2713]: https://github.com/yannickcr/eslint-plugin-react/pull/2713 ## [7.23.2] - 2021.04.08 @@ -3366,4 +3368,4 @@ If you're still not using React 15 you can keep the old behavior by setting the [`function-component-definition`]: docs/rules/function-component-definition.md [`jsx-newline`]: docs/rules/jsx-newline.md [`jsx-no-constructed-context-values`]: docs/rules/jsx-no-constructed-context-values.md -[`no-unstable-nested-components`]: docs/rules/no-unstable-nested-components.md \ No newline at end of file +[`no-unstable-nested-components`]: docs/rules/no-unstable-nested-components.md diff --git a/lib/util/version.js b/lib/util/version.js index 8534f10025..b778c8b940 100644 --- a/lib/util/version.js +++ b/lib/util/version.js @@ -22,25 +22,24 @@ function resetDetectedVersion() { cachedDetectedReactVersion = undefined; } -function resolveBasedir(context) { - let basedir = process.cwd(); - if (context) { - const filename = context.getFilename(); +function resolveBasedir(contextOrFilename) { + if (contextOrFilename) { + const filename = typeof contextOrFilename === 'string' ? contextOrFilename : contextOrFilename.getFilename(); const dirname = path.dirname(filename); try { if (fs.statSync(filename).isFile()) { // dirname must be dir here - basedir = dirname; + return dirname; } } catch (err) { // https://github.com/eslint/eslint/issues/11989 if (err.code === 'ENOTDIR') { - // the error code alreay indicates that dirname is a file - basedir = path.dirname(dirname); + // virtual filename could be recursive + return resolveBasedir(dirname); } } } - return basedir; + return process.cwd(); } // TODO, semver-major: remove context fallback diff --git a/tests/util/version.js b/tests/util/version.js index bd08f2922c..f43c603f53 100644 --- a/tests/util/version.js +++ b/tests/util/version.js @@ -87,6 +87,14 @@ describe('Version', () => { assert.equal(versionUtil.testReactVersion(context, '2.3.5'), false); assert.equal(versionUtil.testFlowVersion(context, '2.92.0'), true); }); + + it('works with recursive virtual filename', () => { + sinon.stub(context, 'getFilename').callsFake(() => path.resolve(base, 'detect-version-sibling', 'test.js/0_fake.md/1_fake.js')); + + assert.equal(versionUtil.testReactVersion(context, '2.3.4'), true); + assert.equal(versionUtil.testReactVersion(context, '2.3.5'), false); + assert.equal(versionUtil.testFlowVersion(context, '2.92.0'), true); + }); }); describe('string version', () => {