Skip to content

Commit

Permalink
Upgrade ESLint so we can use JSX Fragment syntax (#16328)
Browse files Browse the repository at this point in the history
Now that we're using Babel 7, this is the last blocker.
  • Loading branch information
acdlite authored Aug 9, 2019
1 parent 07d062d commit 0bd0c52
Show file tree
Hide file tree
Showing 40 changed files with 831 additions and 682 deletions.
39 changes: 22 additions & 17 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,13 @@ module.exports = {
extends: 'fbjs',

// Stop ESLint from looking for a configuration file in parent folders
'root': true,
root: true,

plugins: [
'jest',
'no-for-of-loops',
'react',
'react-internal',
],
plugins: ['jest', 'no-for-of-loops', 'react', 'react-internal'],

parser: 'espree',
parser: 'babel-eslint',
parserOptions: {
ecmaVersion: 2017,
ecmaVersion: 8,
sourceType: 'script',
ecmaFeatures: {
experimentalObjectRestSpread: true,
Expand All @@ -40,8 +35,8 @@ module.exports = {
'dot-location': [ERROR, 'property'],
'dot-notation': ERROR,
'eol-last': ERROR,
'eqeqeq': [ERROR, 'allow-null'],
'indent': OFF,
eqeqeq: [ERROR, 'allow-null'],
indent: OFF,
'jsx-quotes': [ERROR, 'prefer-double'],
'keyword-spacing': [ERROR, {after: true, before: true}],
'no-bitwise': OFF,
Expand All @@ -51,9 +46,9 @@ module.exports = {
'no-shadow': ERROR,
'no-unused-expressions': ERROR,
'no-unused-vars': [ERROR, {args: 'none'}],
'no-use-before-define': [ERROR, {functions: false, variables: false}],
'no-use-before-define': OFF,
'no-useless-concat': OFF,
'quotes': [ERROR, 'single', {avoidEscape: true, allowTemplateLiterals: true }],
quotes: [ERROR, 'single', {avoidEscape: true, allowTemplateLiterals: true}],
'space-before-blocks': ERROR,
'space-before-function-paren': OFF,
'valid-typeof': [ERROR, {requireStringLiterals: true}],
Expand All @@ -65,6 +60,12 @@ module.exports = {
'no-var': ERROR,
strict: ERROR,

// Enforced by Prettier
// TODO: Prettier doesn't handle long strings or long comments. Not a big
// deal. But I turned it off because loading the plugin causes some obscure
// syntax error and it didn't seem worth investigating.
'max-len': OFF,

// React & JSX
// Our transforms set this automatically
'react/jsx-boolean-value': [ERROR, 'always'],
Expand All @@ -78,7 +79,10 @@ module.exports = {
'react/react-in-jsx-scope': ERROR,
'react/self-closing-comp': ERROR,
// We don't care to do this
'react/jsx-wrap-multilines': [ERROR, {declaration: false, assignment: false}],
'react/jsx-wrap-multilines': [
ERROR,
{declaration: false, assignment: false},
],

// Prevent for...of loops because they require a Symbol polyfill.
// You can disable this rule for code that isn't shipped (e.g. build scripts and tests).
Expand Down Expand Up @@ -112,6 +116,7 @@ module.exports = {
files: esNextPaths,
parser: 'babel-eslint',
parserOptions: {
ecmaVersion: 8,
sourceType: 'module',
},
rules: {
Expand All @@ -124,14 +129,14 @@ module.exports = {
rules: {
// https://github.com/jest-community/eslint-plugin-jest
'jest/no-focused-tests': ERROR,
}
},
},
{
files: ['packages/react-native-renderer/**/*.js'],
globals: {
nativeFabricUIManager: true,
}
}
},
},
],

globals: {
Expand Down
12 changes: 6 additions & 6 deletions fixtures/dom/src/components/fixtures/suspense/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ class SuspendyTreeChild extends React.Component {

render() {
return (
<React.Fragment>
<>
<Suspense fallback={<div>(display: none)</div>}>
<div>
<AsyncStep text={`${this.state.step} + ${this.id}`} ms={500} />
{this.props.children}
</div>
</Suspense>
<button onClick={this.increment}>Hide</button>
</React.Fragment>
</>
);
}
}
Expand Down Expand Up @@ -86,22 +86,22 @@ class SuspendyTree extends React.Component {
};
render() {
return (
<React.Fragment>
<>
<div ref={this.parentContainer}>
<div ref={this.container} />
</div>
<div>
{this.container.current !== null
? ReactDOM.createPortal(
<React.Fragment>
<>
<SuspendyTreeChild>{this.props.children}</SuspendyTreeChild>
<button onClick={this.removeAndRestore}>Remove</button>
</React.Fragment>,
</>,
this.container.current
)
: null}
</div>
</React.Fragment>
</>
);
}
}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@
"cross-env": "^5.1.1",
"danger": "^3.0.4",
"error-stack-parser": "^2.0.2",
"eslint": "^4.1.0",
"eslint": "^6.1.0",
"eslint-config-fbjs": "^1.1.1",
"eslint-plugin-babel": "^3.3.0",
"eslint-plugin-flowtype": "^2.25.0",
"eslint-plugin-jest": "^21.6.1",
"eslint-plugin-no-for-of-loops": "^1.0.0",
"eslint-plugin-babel": "^5.3.0",
"eslint-plugin-react": "^6.7.1",
"eslint-plugin-react-internal": "link:./scripts/eslint-rules",
"fbjs-scripts": "^0.8.3",
Expand Down
10 changes: 5 additions & 5 deletions packages/react-dom/src/__tests__/ReactDOMFiber-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,11 @@ describe('ReactDOMFiber', () => {

it('renders an empty fragment', () => {
const Div = () => <div />;
const EmptyFragment = () => <React.Fragment />;
const EmptyFragment = () => <></>;
const NonEmptyFragment = () => (
<React.Fragment>
<>
<Div />
</React.Fragment>
</>
);

ReactDOM.render(<EmptyFragment />, container);
Expand Down Expand Up @@ -475,10 +475,10 @@ describe('ReactDOMFiber', () => {
return (
<div>
{this.state.show && (
<React.Fragment>
<>
{ReactDOM.createPortal(null, portalContainer)}
<div>child</div>
</React.Fragment>
</>
)}
<div>parent</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -581,11 +581,11 @@ describe('ReactDOMFiberAsync', () => {
}

root.render(
<React.Fragment>
<>
<Text text="A" />
<Text text="B" />
<Text text="C" />
</React.Fragment>,
</>,
);

// Nothing should have rendered yet
Expand Down
8 changes: 4 additions & 4 deletions packages/react-dom/src/__tests__/ReactDOMHooks-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ describe('ReactDOMHooks', () => {
});

return (
<React.Fragment>
<>
<input ref={inputRef} onInput={handleInput} />
<label ref={labelRef}>{text}</label>
</React.Fragment>
</>
);
};

Expand Down Expand Up @@ -115,10 +115,10 @@ describe('ReactDOMHooks', () => {
});

return (
<React.Fragment>
<>
<input ref={inputRef} onInput={handleInput} />
<label ref={labelRef}>{text}</label>
</React.Fragment>
</>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,12 @@ describe('ReactDOMServerIntegration', () => {
</Theme.Provider>
<LanguageConsumer>
{language => (
<React.Fragment>
<>
<ThemeConsumer>
{theme => <div id="theme3">{theme}</div>}
</ThemeConsumer>
<div id="language2">{language}</div>
</React.Fragment>
</>
)}
</LanguageConsumer>
</Theme.Provider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ describe('ReactDOMServerIntegration', () => {
describe('React.Fragment', () => {
itRenders('a fragment with one child', async render => {
let e = await render(
<React.Fragment>
<>
<div>text1</div>
</React.Fragment>,
</>,
);
let parent = e.parentNode;
expect(parent.childNodes[0].tagName).toBe('DIV');
Expand All @@ -56,19 +56,19 @@ describe('ReactDOMServerIntegration', () => {
};
let Footer = props => {
return (
<React.Fragment>
<>
<h2>footer</h2>
<h3>about</h3>
</React.Fragment>
</>
);
};
let e = await render(
<React.Fragment>
<>
<div>text1</div>
<span>text2</span>
<Header />
<Footer />
</React.Fragment>,
</>,
);
let parent = e.parentNode;
expect(parent.childNodes[0].tagName).toBe('DIV');
Expand All @@ -80,21 +80,21 @@ describe('ReactDOMServerIntegration', () => {

itRenders('a nested fragment', async render => {
let e = await render(
<React.Fragment>
<React.Fragment>
<>
<>
<div>text1</div>
</React.Fragment>
</>
<span>text2</span>
<React.Fragment>
<React.Fragment>
<React.Fragment>
<>
<>
<>
{null}
<p />
</React.Fragment>
</>
{false}
</React.Fragment>
</React.Fragment>
</React.Fragment>,
</>
</>
</>,
);
let parent = e.parentNode;
expect(parent.childNodes[0].tagName).toBe('DIV');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,12 @@ describe('ReactDOMServerIntegration', () => {
</Theme.Provider>
<Language.Consumer>
{language => (
<React.Fragment>
<>
<Theme.Consumer>
{theme => <div id="theme3">{theme}</div>}
</Theme.Consumer>
<div id="language2">{language}</div>
</React.Fragment>
</>
)}
</Language.Consumer>
</Theme.Provider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,10 @@ describe('ReactDOMServerPartialHydration', () => {
throw promise;
} else {
return (
<React.Fragment>
<>
<div>Middle</div>
Some text
</React.Fragment>
</>
);
}
}
Expand Down Expand Up @@ -1022,12 +1022,12 @@ describe('ReactDOMServerPartialHydration', () => {
<div>
<Suspense
fallback={
<React.Fragment>
<>
<Suspense fallback="Loading...">
<Child />
</Suspense>
<span>Inner Sibling</span>
</React.Fragment>
</>
}>
<Child />
</Suspense>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ describe('ReactBatchedMode', () => {
const root = ReactNoop.createSyncRoot();

root.render(
<React.Fragment>
<>
<Text text="A" />
<Text text="B" />
<Text text="C" />
</React.Fragment>,
</>,
);

// Nothing should have rendered yet
Expand Down Expand Up @@ -112,11 +112,11 @@ describe('ReactBatchedMode', () => {
expect(Scheduler).toHaveYielded(['Promise resolved [B]']);
expect(Scheduler).toFlushExpired(['A', 'B', 'C']);
expect(root).toMatchRenderedOutput(
<React.Fragment>
<>
<span>A</span>
<span>B</span>
<span>C</span>
</React.Fragment>,
</>,
);
});

Expand All @@ -133,10 +133,10 @@ describe('ReactBatchedMode', () => {
const foo1 = React.createRef(null);
const foo2 = React.createRef(null);
root.render(
<React.Fragment>
<>
<Foo label="A" ref={foo1} />
<Foo label="B" ref={foo2} />
</React.Fragment>,
</>,
);

// Mount
Expand Down
Loading

0 comments on commit 0bd0c52

Please sign in to comment.