Skip to content

Commit 880ab8c

Browse files
JounQinljharb
authored andcommitted
[Fix] version detection: support recursive processor virtual filename
1 parent f0e6700 commit 880ab8c

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
88
### Added
99
* component detection: add componentWrapperFunctions setting ([#2713][] @@jzabala @LandonSchropp)
1010
* [`no-unused-prop-types`]: add ignore option ([#2972][] @grit96)
11+
* version detection: support recursive processor virtual filename ([#2965][] @JounQin)
1112

1213
### Fixed
1314
* [`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
3233
[#2975]: https://github.com/yannickcr/eslint-plugin-react/pull/2975
3334
[#2974]: https://github.com/yannickcr/eslint-plugin-react/pull/2974
3435
[#2972]: https://github.com/yannickcr/eslint-plugin-react/pull/2972
36+
[#2965]: https://github.com/yannickcr/eslint-plugin-react/pull/2965
3537
[#2713]: https://github.com/yannickcr/eslint-plugin-react/pull/2713
3638

3739
## [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
33663368
[`function-component-definition`]: docs/rules/function-component-definition.md
33673369
[`jsx-newline`]: docs/rules/jsx-newline.md
33683370
[`jsx-no-constructed-context-values`]: docs/rules/jsx-no-constructed-context-values.md
3369-
[`no-unstable-nested-components`]: docs/rules/no-unstable-nested-components.md
3371+
[`no-unstable-nested-components`]: docs/rules/no-unstable-nested-components.md

lib/util/version.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,24 @@ function resetDetectedVersion() {
2222
cachedDetectedReactVersion = undefined;
2323
}
2424

25-
function resolveBasedir(context) {
26-
let basedir = process.cwd();
27-
if (context) {
28-
const filename = context.getFilename();
25+
function resolveBasedir(contextOrFilename) {
26+
if (contextOrFilename) {
27+
const filename = typeof contextOrFilename === 'string' ? contextOrFilename : contextOrFilename.getFilename();
2928
const dirname = path.dirname(filename);
3029
try {
3130
if (fs.statSync(filename).isFile()) {
3231
// dirname must be dir here
33-
basedir = dirname;
32+
return dirname;
3433
}
3534
} catch (err) {
3635
// https://github.com/eslint/eslint/issues/11989
3736
if (err.code === 'ENOTDIR') {
38-
// the error code alreay indicates that dirname is a file
39-
basedir = path.dirname(dirname);
37+
// virtual filename could be recursive
38+
return resolveBasedir(dirname);
4039
}
4140
}
4241
}
43-
return basedir;
42+
return process.cwd();
4443
}
4544

4645
// TODO, semver-major: remove context fallback

tests/util/version.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@ describe('Version', () => {
8787
assert.equal(versionUtil.testReactVersion(context, '2.3.5'), false);
8888
assert.equal(versionUtil.testFlowVersion(context, '2.92.0'), true);
8989
});
90+
91+
it('works with recursive virtual filename', () => {
92+
sinon.stub(context, 'getFilename').callsFake(() => path.resolve(base, 'detect-version-sibling', 'test.js/0_fake.md/1_fake.js'));
93+
94+
assert.equal(versionUtil.testReactVersion(context, '2.3.4'), true);
95+
assert.equal(versionUtil.testReactVersion(context, '2.3.5'), false);
96+
assert.equal(versionUtil.testFlowVersion(context, '2.92.0'), true);
97+
});
9098
});
9199

92100
describe('string version', () => {

0 commit comments

Comments
 (0)