Skip to content

Commit ed3707c

Browse files
committed
Reconfigure ESLint
1 parent d574245 commit ed3707c

20 files changed

+581
-2114
lines changed

.eslintrc.js

+7-11
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
module.exports = {
2-
extends: ['airbnb-typescript', 'prettier'],
2+
extends: ['airbnb', 'airbnb-typescript', 'prettier'],
33

44
parserOptions: {
55
project: './tsconfig.eslint.json',
66
},
77

8-
// ecmaFeatures: {
9-
// jsx: true,
10-
// },
11-
128
env: {
139
es6: true,
1410
},
@@ -19,12 +15,12 @@ module.exports = {
1915
},
2016
},
2117

22-
// rules: {
23-
// 'max-params': ['error', 10],
24-
// 'no-warning-comments': 'error',
25-
26-
// 'import/no-commonjs': 'off',
27-
// },
18+
rules: {
19+
'import/no-cycle': 'off', // TODO: We have to fix our cycle issue before being able to activate it again
20+
'no-underscore-dangle': 'off',
21+
'prefer-destructuring': 'off',
22+
'react/jsx-fragments': 'off',
23+
},
2824

2925
overrides: [
3026
{

package.json

+12-11
Original file line numberDiff line numberDiff line change
@@ -30,33 +30,34 @@
3030
"@babel/preset-env": "7.15.6",
3131
"@babel/preset-react": "7.14.5",
3232
"@babel/preset-typescript": "^7.15.0",
33-
"@commitlint/cli": "8.3.5",
34-
"@commitlint/config-angular": "8.3.4",
3533
"@types/enzyme": "^3.10.9",
3634
"@types/enzyme-adapter-react-16": "^1.0.6",
3735
"@types/jest": "^27.0.2",
3836
"@types/react": "^17.0.26",
3937
"@types/react-is": "^17.0.2",
38+
"@typescript-eslint/eslint-plugin": "^4.29.3",
39+
"@typescript-eslint/parser": "^4.29.3",
4040
"babel-eslint": "10.1.0",
41-
"babel-jest": "24.9.0",
41+
"babel-jest": "27.2.4",
4242
"babel-register": "6.26.0",
4343
"conventional-changelog-cli": "2.1.1",
4444
"doctoc": "1.4.0",
4545
"enzyme": "3.11.0",
4646
"enzyme-adapter-react-16": "1.15.6",
47-
"eslint": "7.25.0",
48-
"eslint-config-airbnb-typescript": "12.3.1",
49-
"eslint-config-algolia": "14.0.1",
47+
"eslint": "7.32.0",
48+
"eslint-config-airbnb": "^18.2.1",
49+
"eslint-config-airbnb-typescript": "^14.0.0",
50+
"eslint-config-algolia": "19.0.2",
5051
"eslint-config-prettier": "8.3.0",
51-
"eslint-plugin-import": "2.22.1",
52-
"eslint-plugin-jest": "22.21.0",
52+
"eslint-plugin-import": "2.24.2",
53+
"eslint-plugin-jest": "24.5.0",
5354
"eslint-plugin-jsx-a11y": "6.4.1",
54-
"eslint-plugin-react": "7.23.2",
55+
"eslint-plugin-react": "7.26.1",
5556
"eslint-plugin-react-hooks": "4.2.0",
5657
"esm": "3.2.25",
57-
"expect": "27.2.3",
58+
"expect": "27.2.4",
5859
"husky": "3.1.0",
59-
"jest": "27.2.3",
60+
"jest": "27.2.4",
6061
"json": "10.0.0",
6162
"lint-staged": "10.5.4",
6263
"mversion": "2.0.1",

src/AnonymousStatelessComponent.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import React from 'react'; // eslint-disable-next-line react/display-name
1+
import React from 'react';
22

3+
// eslint-disable-next-line func-names
34
export default function (props: { children: React.ReactNode }) {
45
const { children } = props; // eslint-disable-line react/prop-types
56

src/formatter/createPropFilter.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ export default function createPropFilter(
44
) {
55
if (Array.isArray(filter)) {
66
return (key: string) => filter.indexOf(key) === -1;
7-
} else {
8-
// @ts-expect-error: flow to TS
9-
return (key: string) => filter(props[key], key);
107
}
8+
9+
// @ts-expect-error: flow to TS
10+
return (key: string) => filter(props[key], key);
1111
}

src/formatter/formatComplexDataStructure.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { isValidElement } from 'react';
22
import { prettyPrint } from '@base2/pretty-print-object';
33
import sortObject from './sortObject';
4-
import parseReactElement from './../parser/parseReactElement';
4+
import parseReactElement from '../parser/parseReactElement';
55
import formatTreeNode from './formatTreeNode';
66
import formatFunction from './formatFunction';
77
import spacer from './spacer';
8-
import type { Options } from './../options';
8+
import type { Options } from '../options';
99

1010
export default (
1111
value: Record<string, any> | Array<any>,

src/formatter/formatFunction.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Options } from './../options';
1+
import type { Options } from '../options';
22

33
function noRefCheck() {}
44

src/formatter/formatProp.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import spacer from './spacer';
22
import formatPropValue from './formatPropValue';
3-
import type { Options } from './../options';
3+
import type { Options } from '../options';
44

55
export default (
66
name: string,

src/formatter/formatPropValue.spec.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import formatPropValue from './formatPropValue';
3-
import parseReactElement from './../parser/parseReactElement';
3+
import parseReactElement from '../parser/parseReactElement';
44
import formatTreeNode from './formatTreeNode';
55
import formatComplexDataStructure from './formatComplexDataStructure';
66

src/formatter/formatPropValue.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { isValidElement } from 'react';
33
import formatComplexDataStructure from './formatComplexDataStructure';
44
import formatFunction from './formatFunction';
55
import formatTreeNode from './formatTreeNode';
6-
import type { Options } from './../options';
7-
import parseReactElement from './../parser/parseReactElement';
6+
import type { Options } from '../options';
7+
import parseReactElement from '../parser/parseReactElement';
88

99
const escape = (s: string): string => s.replace(/"/g, '&quot;');
1010

@@ -49,7 +49,7 @@ const formatPropValue = (
4949
}
5050

5151
if (propValue instanceof Date) {
52-
if (isNaN(propValue.valueOf())) {
52+
if (Number.isNaN(propValue.valueOf())) {
5353
return `{new Date(NaN)}`;
5454
}
5555

src/formatter/formatReactElementNode.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import formatProp from './formatProp';
44
import mergeSiblingPlainStringChildrenReducer from './mergeSiblingPlainStringChildrenReducer';
55
import sortPropsByNames from './sortPropsByNames';
66
import createPropFilter from './createPropFilter';
7-
import type { Options } from './../options';
8-
import type { ReactElementTreeNode } from './../tree';
7+
import type { Options } from '../options';
8+
import type { ReactElementTreeNode } from '../tree';
99

1010
const compensateMultilineStringElementIndentation = (
1111
element: any,

src/formatter/formatReactFragmentNode.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import type { Key } from 'react';
22
import formatReactElementNode from './formatReactElementNode';
3-
import type { Options } from './../options';
3+
import type { Options } from '../options';
44
import type {
55
ReactElementTreeNode,
66
ReactFragmentTreeNode,
77
TreeNode,
8-
} from './../tree';
8+
} from '../tree';
9+
910
const REACT_FRAGMENT_TAG_NAME_SHORT_SYNTAX = '';
1011
const REACT_FRAGMENT_TAG_NAME_EXPLICIT_SYNTAX = 'React.Fragment';
1112

src/formatter/formatTree.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import formatTreeNode from './formatTreeNode';
2-
import type { Options } from './../options';
3-
import type { TreeNode } from './../tree';
2+
import type { Options } from '../options';
3+
import type { TreeNode } from '../tree';
44

55
export default (node: TreeNode, options: Options): string =>
66
formatTreeNode(node, false, 0, options);

src/formatter/formatTreeNode.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import formatReactElementNode from './formatReactElementNode';
22
import formatReactFragmentNode from './formatReactFragmentNode';
3-
import type { Options } from './../options';
4-
import type { TreeNode } from './../tree';
3+
import type { Options } from '../options';
4+
import type { TreeNode } from '../tree';
55

66
const jsxStopChars = ['<', '>', '{', '}'];
77
const shouldBeEscaped = (s: string) =>

src/formatter/mergeSiblingPlainStringChildrenReducer.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import {
33
createNumberTreeNode,
44
createStringTreeNode,
55
createReactElementTreeNode,
6-
} from './../tree';
7-
import type { TreeNode } from './../tree';
6+
} from '../tree';
7+
import type { TreeNode } from '../tree';
88

99
test('mergeSiblingPlainStringChildrenReducer should merge sibling string tree nodes', () => {
1010
const childrens: TreeNode[] = [

src/formatter/mergeSiblingPlainStringChildrenReducer.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { createStringTreeNode } from './../tree';
2-
import type { TreeNode } from './../tree';
1+
import { createStringTreeNode } from '../tree';
2+
import type { TreeNode } from '../tree';
33

44
export default (
55
previousNodes: TreeNode[],

src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import type { ReactElement } from 'react';
12
import formatTree from './formatter/formatTree';
23
import parseReactElement from './parser/parseReactElement';
3-
import type { ReactElement } from 'react';
44
import type { Options } from './options';
55

66
const reactElementToJsxString = (

src/options.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import type { ReactElement } from 'react';
22

33
export type Options = {
44
filterProps: string[];
@@ -11,5 +11,5 @@ export type Options = {
1111
sortProps: boolean;
1212

1313
maxInlineAttributesLineLength?: number;
14-
displayName?: (element: React.ReactElement) => string;
14+
displayName?: (element: ReactElement) => string;
1515
};

src/parser/parseReactElement.spec.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable react/jsx-curly-brace-presence */
2+
13
import React, { Fragment } from 'react';
24
import parseReactElement from './parseReactElement';
35

src/parser/parseReactElement.ts

+12-6
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ import {
1212
isSuspense,
1313
Memo,
1414
} from 'react-is';
15-
import type { Options } from './../options';
15+
import type { Options } from '../options';
1616
import {
1717
createStringTreeNode,
1818
createNumberTreeNode,
1919
createReactElementTreeNode,
2020
createReactFragmentTreeNode,
21-
} from './../tree';
22-
import type { TreeNode } from './../tree';
21+
} from '../tree';
22+
import type { TreeNode } from '../tree';
2323

2424
const supportFragment = Boolean(Fragment);
2525

@@ -112,7 +112,9 @@ const filterProps = (
112112
const filteredProps: Record<string, any> = {};
113113
Object.keys(originalProps)
114114
.filter((key) => cb(originalProps[key], key))
115-
.forEach((key) => (filteredProps[key] = originalProps[key]));
115+
.forEach((key) => {
116+
filteredProps[key] = originalProps[key];
117+
});
116118
return filteredProps;
117119
};
118120

@@ -124,9 +126,13 @@ const parseReactElement = (
124126

125127
if (typeof element === 'string') {
126128
return createStringTreeNode(element);
127-
} else if (typeof element === 'number') {
129+
}
130+
131+
if (typeof element === 'number') {
128132
return createNumberTreeNode(element);
129-
} else if (!React.isValidElement(element)) {
133+
}
134+
135+
if (!React.isValidElement(element)) {
130136
throw new Error(
131137
`react-element-to-jsx-string: Expected a React.Element, got \`${typeof element}\``
132138
);

0 commit comments

Comments
 (0)