Skip to content

Commit 322d8f8

Browse files
committed
Upgrade eslint, flow and related code style dependencies. Fix eslint errors
1 parent 748cab3 commit 322d8f8

35 files changed

+560
-3275
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
; ignore the submodules
22
gutenberg
3+
symlinked-packages
34
symlinked-packages-in-parent
45
react-native-aztec
56
bundle

.eslintrc

-31
This file was deleted.

.eslintrc.js

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/**
2+
* External dependencies
3+
*/
4+
const { map } = require( 'lodash' );
5+
6+
module.exports = {
7+
parser: "babel-eslint",
8+
env: {
9+
browser: true,
10+
"jest/globals": true
11+
},
12+
globals: {
13+
__DEV__: true
14+
},
15+
plugins: [
16+
"react",
17+
"react-native",
18+
"jest",
19+
"flowtype"
20+
],
21+
extends: [
22+
"plugin:@wordpress/eslint-plugin/recommended",
23+
"plugin:flowtype/recommended",
24+
],
25+
settings: {
26+
flowtype: {
27+
onlyFilesWithFlowAnnotation: true,
28+
},
29+
react: {
30+
pragma: "React",
31+
version: "16.8.3",
32+
flowVersion: "0.92.0",
33+
},
34+
},
35+
rules: {
36+
'no-restricted-syntax': [
37+
'error',
38+
// NOTE: We can't include the forward slash in our regex or
39+
// we'll get a `SyntaxError` (Invalid regular expression: \ at end of pattern)
40+
// here. That's why we use \\u002F in the regexes below.
41+
{
42+
selector: 'ImportDeclaration[source.value=/^@wordpress\\u002F.+\\u002F/]',
43+
message: 'Path access on WordPress dependencies is not allowed.',
44+
},
45+
{
46+
selector: 'CallExpression[callee.name=/^(__|_x|_n|_nx)$/] Literal[value=/\\.{3}/]',
47+
message: 'Use ellipsis character (…) in place of three dots',
48+
},
49+
{
50+
selector: 'ImportDeclaration[source.value="lodash"] Identifier.imported[name="memoize"]',
51+
message: 'Use memize instead of Lodash’s memoize',
52+
},
53+
{
54+
selector: 'CallExpression[callee.object.name="page"][callee.property.name="waitFor"]',
55+
message: 'Prefer page.waitForSelector instead.',
56+
},
57+
{
58+
selector: 'JSXAttribute[name.name="id"][value.type="Literal"]',
59+
message: 'Do not use string literals for IDs; use withInstanceId instead.',
60+
},
61+
{
62+
// Discourage the usage of `Math.random()` as it's a code smell
63+
// for UUID generation, for which we already have a higher-order
64+
// component: `withInstanceId`.
65+
selector: 'CallExpression[callee.object.name="Math"][callee.property.name="random"]',
66+
message: 'Do not use Math.random() to generate unique IDs; use withInstanceId instead. (If you’re not generating unique IDs: ignore this message.)',
67+
},
68+
{
69+
selector: 'CallExpression[callee.name="withDispatch"] > :function > BlockStatement > :not(VariableDeclaration,ReturnStatement)',
70+
message: 'withDispatch must return an object with consistent keys. Avoid performing logic in `mapDispatchToProps`.',
71+
},
72+
],
73+
},
74+
}

__mocks__/styleMock.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ module.exports = {
1919
blockCode: {
2020
fontFamily: 'serif',
2121
},
22-
'editor-rich-text': {
22+
'block-editor-rich-text': {
2323
fontFamily: 'serif',
24+
minHeight: 30,
2425
},
25-
'editor-plain-text': {
26+
'block-editor-plain-text': {
2627
fontFamily: 'serif',
2728
},
2829
blockHolderFocused: {

bundle/android/App.js

-1,374
This file was deleted.

bundle/android/App.js.map

-1
This file was deleted.

bundle/ios/App.js

-1,379
This file was deleted.

bundle/ios/App.js.map

-1
This file was deleted.

i18n-cache/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,15 @@ const fetchTranslations = () => {
9090
const translationFilePromises = fetchedTranslations.map( ( languageResult ) => {
9191
return new Promise( ( resolve, reject ) => {
9292
const translationRelativePath = getTranslationFilePath( languageResult.locale );
93-
const translationAbsolutePath = path.resolve( __dirname, translationRelativePath );
9493

9594
if ( languageResult.inCache ) {
9695
languageResult.path = translationRelativePath;
9796
resolve( translationRelativePath );
9897
return;
9998
}
10099

100+
const translationAbsolutePath = path.resolve( __dirname, translationRelativePath );
101+
101102
fs.writeFile( translationAbsolutePath, JSON.stringify( languageResult.response ), 'utf8', ( err ) => {
102103
if ( err ) {
103104
reject( err );

index.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
/** @flow
22
* @format */
33

4+
/**
5+
* Internal dependencies
6+
*/
47
import { registerApp } from './src';
58

69
registerApp();

jest/setup.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jest.mock( 'react-native-safe-area', () => {
2020
accept( { safeAreaInsets: { bottom: 34 } } );
2121
} );
2222
},
23-
addEventListener: addEventListener,
23+
addEventListener,
2424
removeEventListener: jest.fn(),
2525
};
2626
} );

package.json

+7-10
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@
1212
},
1313
"devDependencies": {
1414
"@babel/core": "^7.3.3",
15-
"@wordpress/babel-plugin-import-jsx-pragma": "^1.1.2",
16-
"@wordpress/babel-preset-default": "^3.0.1",
17-
"@wordpress/eslint-plugin": "^1.0.0",
18-
"@wordpress/jest-preset-default": "^3.0.2",
15+
"@wordpress/babel-preset-default": "^4.0.0",
16+
"@wordpress/eslint-plugin": "^2.0.0",
17+
"@wordpress/jest-preset-default": "^4.0.0",
1918
"babel-core": "^7.0.0-bridge.0",
2019
"babel-eslint": "^8.2.2",
2120
"babel-jest": "^24.1.0",
@@ -24,13 +23,11 @@
2423
"cross-env": "^5.1.4",
2524
"empty": "^0.10.1",
2625
"equivalent-key-map": "^0.2.0",
27-
"eslint": "^4.19.1",
28-
"eslint-plugin-flowtype": "^2.46.1",
26+
"eslint": "^5.12.1",
27+
"eslint-plugin-flowtype": "^3.4.2",
2928
"eslint-plugin-jest": "^21.15.0",
30-
"eslint-plugin-jsx-a11y": "^6.0.3",
31-
"eslint-plugin-react": "^7.7.0",
32-
"eslint-plugin-react-native": "^3.2.1",
33-
"eslint-plugin-wordpress": "git+https://github.com/WordPress-Coding-Standards/eslint-plugin-wordpress.git#1774343f6226052a46b081e01db3fca8793cc9f1",
29+
"eslint-plugin-react-native": "^3.6.0",
30+
"eslint-plugin-wordpress": "git://github.com/WordPress-Coding-Standards/eslint-plugin-wordpress.git#552af1454d175e15f6d25aadc2ccde30a1922d4f",
3431
"flow-bin": "0.92.0",
3532
"identity-obj-proxy": "^3.0.0",
3633
"jest": "^24.1.0",

react-native-gutenberg-bridge/index.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
/** @format */
22

3+
/**
4+
* External dependencies
5+
*/
36
import { NativeModules, NativeEventEmitter, Platform } from 'react-native';
47

58
const { RNReactNativeGutenbergBridge } = NativeModules;

sass-transformer-inside-gb.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ function transform( src, filename, options ) {
113113
const result = sass.renderSync( {
114114
data: src,
115115
includePaths: [ path.dirname( filename ), ...autoImportIncludePaths ],
116-
importer: function( url /*, prev, done */ ) {
116+
importer( url /*, prev, done */ ) {
117117
// url is the path in import as is, which LibSass encountered.
118118
// prev is the previously resolved path.
119119
// done is an optional callback, either consume it or return value synchronously.

sass-transformer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ function transform( src, filename, options ) {
116116
const result = sass.renderSync( {
117117
data: src,
118118
includePaths: [ path.dirname( filename ), ...autoImportIncludePaths ],
119-
importer: function( url /*, prev, done */ ) {
119+
importer( url /*, prev, done */ ) {
120120
// url is the path in import as is, which LibSass encountered.
121121
// prev is the previously resolved path.
122122
// done is an optional callback, either consume it or return value synchronously.

src/app/App.js

+6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
/** @flow
22
* @format */
33

4+
/**
5+
* External dependencies
6+
*/
47
import React from 'react';
58

9+
/**
10+
* Internal dependencies
11+
*/
612
import AppContainer from './AppContainer';
713
import initialHtml from './initial-html';
814

src/app/App.test.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
/** @format */
22

3+
/**
4+
* External dependencies
5+
*/
36
import renderer from 'react-test-renderer';
47

8+
/**
9+
* WordPress dependencies
10+
*/
11+
import { dispatch, select } from '@wordpress/data';
12+
13+
/**
14+
* Internal dependencies
15+
*/
516
import { bootstrapEditor } from '..';
617
import App from './App';
718
import BlockHolder from '../block-management/block-holder';
8-
import { dispatch, select } from '@wordpress/data';
919

1020
describe( 'App', () => {
1121
beforeAll( bootstrapEditor );

src/app/AppContainer.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
/** @flow
22
* @format */
33

4+
/**
5+
* External dependencies
6+
*/
47
import React from 'react';
58
import type { EmitterSubscription } from 'react-native';
69
import RNReactNativeGutenbergBridge, {
@@ -11,14 +14,19 @@ import RNReactNativeGutenbergBridge, {
1114
} from 'react-native-gutenberg-bridge';
1215
import { isEmpty } from 'lodash';
1316

17+
/**
18+
* WordPress dependencies
19+
*/
1420
import { parse, serialize } from '@wordpress/blocks';
1521
import { withDispatch, withSelect } from '@wordpress/data';
1622
import { compose } from '@wordpress/compose';
1723
import { BlockEditorProvider } from '@wordpress/block-editor';
1824
import { UnsupportedBlock } from '@wordpress/editor';
1925

26+
/**
27+
* Internal dependencies
28+
*/
2029
import type { BlockType } from '../store/types';
21-
2230
import BlockManager from '../block-management/block-manager';
2331

2432
type PropsType = {

src/block-management/block-holder.js

+13-8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
* @flow
44
*/
55

6+
/**
7+
* External dependencies
8+
*/
69
import React from 'react';
710
import {
811
View,
@@ -11,20 +14,22 @@ import {
1114
NativeSyntheticEvent,
1215
NativeTouchEvent,
1316
} from 'react-native';
14-
import InlineToolbar, { InlineToolbarActions } from './inline-toolbar';
17+
import TextInputState from 'react-native/lib/TextInputState';
1518

19+
/**
20+
* WordPress dependencies
21+
*/
1622
import { withDispatch, withSelect } from '@wordpress/data';
1723
import { compose } from '@wordpress/compose';
18-
19-
import type { BlockType } from '../store/types';
20-
21-
import styles from './block-holder.scss';
22-
23-
// Gutenberg imports
2424
import { getBlockType } from '@wordpress/blocks';
2525
import { BlockEdit } from '@wordpress/block-editor';
2626

27-
import TextInputState from 'react-native/lib/TextInputState';
27+
/**
28+
* Internal dependencies
29+
*/
30+
import type { BlockType } from '../store/types';
31+
import styles from './block-holder.scss';
32+
import InlineToolbar, { InlineToolbarActions } from './inline-toolbar';
2833

2934
type PropsType = BlockType & {
3035
clientId: string,

src/block-management/block-manager.js

+16-12
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,26 @@
44
*/
55

66
/**
7-
* WordPress dependencies
7+
* External dependencies
88
*/
9-
import { __ } from '@wordpress/i18n';
10-
119
import React from 'react';
1210
import { identity } from 'lodash';
13-
1411
import { Text, View, Keyboard, LayoutChangeEvent, SafeAreaView, Dimensions, Platform } from 'react-native';
12+
13+
/**
14+
* WordPress dependencies
15+
*/
16+
import { __ } from '@wordpress/i18n';
17+
import { withDispatch, withSelect } from '@wordpress/data';
18+
import { compose } from '@wordpress/compose';
19+
import { createBlock, isUnmodifiedDefaultBlock } from '@wordpress/blocks';
20+
import { PostTitle } from '@wordpress/editor';
21+
import { DefaultBlockAppender } from '@wordpress/block-editor';
22+
import { sendNativeEditorDidLayout, subscribeSetFocusOnTitle } from 'react-native-gutenberg-bridge';
23+
24+
/**
25+
* Internal dependencies
26+
*/
1527
import BlockHolder from './block-holder';
1628
import type { BlockType } from '../store/types';
1729
import styles from './block-manager.scss';
@@ -25,14 +37,6 @@ import KeyboardAvoidingView from '../components/keyboard-avoiding-view';
2537
import { KeyboardAwareFlatList, handleCaretVerticalPositionChange } from '../components/keyboard-aware-flat-list';
2638
import SafeArea from 'react-native-safe-area';
2739

28-
// Gutenberg imports
29-
import { withDispatch, withSelect } from '@wordpress/data';
30-
import { compose } from '@wordpress/compose';
31-
import { createBlock, isUnmodifiedDefaultBlock } from '@wordpress/blocks';
32-
import { PostTitle } from '@wordpress/editor';
33-
import { DefaultBlockAppender } from '@wordpress/block-editor';
34-
import { sendNativeEditorDidLayout, subscribeSetFocusOnTitle } from 'react-native-gutenberg-bridge';
35-
3640
type PropsType = {
3741
rootClientId: ?string,
3842
blockClientIds: Array<string>,

0 commit comments

Comments
 (0)