@samitouri / QOS-React-2 / commits / eee874ce6e

Cross-fork lint: Support named export declaration (#20784)

Noticed this didn't work when I ran `replace-fork` and a named export declaration in ReactFiberReconciler was not properly fixed.

Andrew Clark committed Feb 10, 2021 at 13:01 UTC eee874ce6efed53a02f875385b23a53e10dc2c4e
3 files changed +72 -37
packages/react-reconciler/src/ReactFiberReconciler.old.js
+1 -1
@@ -104,7 +104,7 @@ export {
104 IdleLanePriority as IdleEventPriority,
105 } from './ReactFiberLane.old';
106
107 -export {registerMutableSourceForHydration} from './ReactMutableSource.new';
107 +export {registerMutableSourceForHydration} from './ReactMutableSource.old';
108 export {createPortal} from './ReactPortal';
109 export {
110 createComponentSelector,
scripts/eslint-rules/__tests__/no-cross-fork-imports-test.internal.js
+24
@@ -94,5 +94,29 @@ ruleTester.run('eslint-rules/no-cross-fork-imports', rule, {
94 ],
95 output: "import {scheduleUpdateOnFiber} from './ReactFiberWorkLoop.new';",
96 },
97 + {
98 + code: "export {DiscreteEventPriority} from './ReactFiberLane.old.js';",
99 + filename: 'ReactFiberReconciler.new.js',
100 + errors: [
101 + {
102 + message:
103 + 'A module that belongs to the new fork cannot import a module ' +
104 + 'from the old fork.',
105 + },
106 + ],
107 + output: "export {DiscreteEventPriority} from './ReactFiberLane.new';",
108 + },
109 + {
110 + code: "export {DiscreteEventPriority} from './ReactFiberLane.new.js';",
111 + filename: 'ReactFiberReconciler.old.js',
112 + errors: [
113 + {
114 + message:
115 + 'A module that belongs to the old fork cannot import a module ' +
116 + 'from the new fork.',
117 + },
118 + ],
119 + output: "export {DiscreteEventPriority} from './ReactFiberLane.old';",
120 + },
121 ],
122 });
scripts/eslint-rules/no-cross-fork-imports.js
+47 -36
@@ -26,48 +26,59 @@ module.exports = {
26 const sourceFilename = context.getFilename();
27
28 if (isOldFork(sourceFilename)) {
29 + const visitor = node => {
30 + const sourceNode = node.source;
31 + if (sourceNode === null) {
32 + return;
33 + }
34 + const filename = sourceNode.value;
35 + if (isNewFork(filename)) {
36 + context.report({
37 + node: sourceNode,
38 + message:
39 + 'A module that belongs to the old fork cannot import a module ' +
40 + 'from the new fork.',
41 + fix(fixer) {
42 + return fixer.replaceText(
43 + sourceNode,
44 + `'${filename.replace(/\.new(\.js)?$/, '.old')}'`
45 + );
46 + },
47 + });
48 + }
49 + };
50 return {
30 - ImportDeclaration(node) {
31 - const importSourceNode = node.source;
32 - const filename = importSourceNode.value;
33 - if (isNewFork(filename)) {
34 - context.report({
35 - node: importSourceNode,
36 - message:
37 - 'A module that belongs to the old fork cannot import a module ' +
38 - 'from the new fork.',
39 - fix(fixer) {
40 - return fixer.replaceText(
41 - importSourceNode,
42 - `'${filename.replace(/\.new(\.js)?$/, '.old')}'`
43 - );
44 - },
45 - });
46 - }
47 - },
51 + ImportDeclaration: visitor,
52 + ExportNamedDeclaration: visitor,
53 };
54 }
55
56 if (isNewFork(sourceFilename)) {
57 + const visitor = node => {
58 + const sourceNode = node.source;
59 + if (sourceNode === null) {
60 + return;
61 + }
62 + const filename = sourceNode.value;
63 + if (isOldFork(filename)) {
64 + context.report({
65 + node: sourceNode,
66 + message:
67 + 'A module that belongs to the new fork cannot import a module ' +
68 + 'from the old fork.',
69 + fix(fixer) {
70 + return fixer.replaceText(
71 + sourceNode,
72 + `'${filename.replace(/\.old(\.js)?$/, '.new')}'`
73 + );
74 + },
75 + });
76 + }
77 + };
78 +
79 return {
53 - ImportDeclaration(node) {
54 - const importSourceNode = node.source;
55 - const filename = importSourceNode.value;
56 - if (isOldFork(filename)) {
57 - context.report({
58 - node: importSourceNode,
59 - message:
60 - 'A module that belongs to the new fork cannot import a module ' +
61 - 'from the old fork.',
62 - fix(fixer) {
63 - return fixer.replaceText(
64 - importSourceNode,
65 - `'${filename.replace(/\.old(\.js)?$/, '.new')}'`
66 - );
67 - },
68 - });
69 - }
70 - },
80 + ImportDeclaration: visitor,
81 + ExportNamedDeclaration: visitor,
82 };
83 }
84