react/scripts/eslint-rules/no-cross-fork-imports.js
Andrew Clark 8f05f2bd6d
Land Lanes implementation in old fork (#19108)
* Add autofix to cross-fork lint rule

* replace-fork: Replaces old fork contents with new

For each file in the new fork, copies the contents into the
corresponding file of the old fork, replacing what was already there.

In contrast to merge-fork, which performs a three-way merge.

* Replace old fork contents with new fork

First I ran  `yarn replace-fork`.

Then I ran `yarn lint` with autofix enabled. There's currently no way to
do that from the command line (we should fix that), so I had to edit the
lint script file.

* Manual fix-ups

Removes dead branches, removes prefixes from internal fields.  Stuff
like that.

* Fix DevTools tests

DevTools tests only run against the old fork, which is why I didn't
catch these earlier.

There is one test that is still failing. I'm fairly certain it's related
to the layout of the Suspense fiber: we no longer conditionally wrap the
primary children. They are always wrapped in an extra fiber.

Since this has been running in www for weeks without major issues, I'll
defer fixing the remaining test to a follow up.
2020-06-11 20:05:15 -07:00

77 lines
1.9 KiB
JavaScript

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @emails react-core
*/
'use strict';
function isOldFork(filename) {
return filename.endsWith('.old.js') || filename.endsWith('.old');
}
function isNewFork(filename) {
return filename.endsWith('.new.js') || filename.endsWith('.new');
}
module.exports = {
meta: {
type: 'problem',
fixable: 'code',
},
create(context) {
const sourceFilename = context.getFilename();
if (isOldFork(sourceFilename)) {
return {
ImportDeclaration(node) {
const importSourceNode = node.source;
const filename = importSourceNode.value;
if (isNewFork(filename)) {
context.report({
node: importSourceNode,
message:
'A module that belongs to the old fork cannot import a module ' +
'from the new fork.',
fix(fixer) {
return fixer.replaceText(
importSourceNode,
`'${filename.replace(/\.new(\.js)?$/, '.old')}'`
);
},
});
}
},
};
}
if (isNewFork(sourceFilename)) {
return {
ImportDeclaration(node) {
const importSourceNode = node.source;
const filename = importSourceNode.value;
if (isOldFork(filename)) {
context.report({
node: importSourceNode,
message:
'A module that belongs to the new fork cannot import a module ' +
'from the old fork.',
fix(fixer) {
return fixer.replaceText(
importSourceNode,
`'${filename.replace(/\.old(\.js)?$/, '.new')}'`
);
},
});
}
},
};
}
return {};
},
};