Skip to content

Commit 8217b37

Browse files
committed
ESLint warnings.
1 parent a4e8023 commit 8217b37

13 files changed

+719
-707
lines changed

.eslintrc.json

Lines changed: 61 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,46 +6,90 @@
66
"es2020": true
77
},
88
"extends": [
9+
"airbnb",
10+
"airbnb-typescript",
11+
"airbnb/hooks",
12+
// "plugin:@typescript-eslint/recommended",
13+
// "plugin:@typescript-eslint/recommended-requiring-type-checking",
914
"prettier",
10-
"plugin:prettier/recommended",
11-
"plugin:import/errors",
12-
"plugin:import/warnings",
13-
"plugin:array-func/all",
1415
"plugin:sonarjs/recommended",
16+
"plugin:prettier/recommended",
1517
"plugin:react/recommended",
1618
"plugin:react/jsx-runtime",
19+
"plugin:import/recommended",
20+
"plugin:import/typescript",
1721
"plugin:react-hooks/recommended",
18-
"plugin:promise/recommended"
22+
"plugin:promise/recommended",
23+
"plugin:unicorn/recommended"
1924
],
2025
"plugins": [
2126
"@typescript-eslint",
2227
"react",
2328
"prettier",
2429
"import",
2530
"sonarjs",
26-
"array-func",
27-
"promise"
31+
"promise",
32+
"unicorn"
2833
],
2934
"parser": "@typescript-eslint/parser",
3035
"parserOptions": {
3136
"ecmaVersion": 2020,
3237
"sourceType": "module",
38+
"project": "./tsconfig.json",
3339
"ecmaFeatures": {
3440
"jsx": true
3541
}
3642
},
3743
"rules": {
44+
"no-continue": "off",
45+
"no-plusplus": "off",
46+
"no-case-declarations": "off",
47+
// Too restrictive, writing ugly code to defend against a very unlikely scenario: https://eslint.org/docs/rules/no-prototype-builtins
48+
"no-prototype-builtins": "off",
49+
// https://basarat.gitbooks.io/typescript/docs/tips/defaultIsBad.html
50+
"import/prefer-default-export": "off",
51+
"import/no-default-export": "off",
52+
// Too restrictive: https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/destructuring-assignment.md
53+
"react/destructuring-assignment": "off",
54+
"react/require-default-props": "off",
55+
"react/jsx-props-no-spreading": "off",
56+
"react/no-unstable-nested-components": ["warn", { "allowAsProps": true }],
57+
// No jsx extension: https://github.com/facebook/create-react-app/issues/87#issuecomment-234627904
58+
"react/jsx-filename-extension": "off",
59+
// Use function hoisting to improve code readability
60+
"no-use-before-define": [
61+
"error",
62+
{ "functions": false, "classes": true, "variables": true }
63+
],
64+
"@typescript-eslint/no-unused-vars": "off",
65+
// Allow most functions to rely on type inference. If the function is exported, then `@typescript-eslint/explicit-module-boundary-types` will ensure it's typed.
66+
"@typescript-eslint/explicit-function-return-type": "off",
67+
"@typescript-eslint/no-use-before-define": [
68+
"error",
69+
{ "functions": false, "classes": true, "variables": true, "typedefs": true }
70+
],
71+
// Common abbreviations are known and readable
72+
"unicorn/prevent-abbreviations": "off",
73+
"unicorn/filename-case": "off",
74+
// Disable for simplify type checking for TS
75+
"unicorn/no-useless-undefined": "off",
76+
"unicorn/prefer-node-protocol": "off",
77+
// Temporary turn it off.
78+
"no-restricted-syntax": "off",
79+
"@typescript-eslint/no-unsafe-member-access": "off",
80+
"@typescript-eslint/no-unsafe-call": "off",
81+
"import/no-extraneous-dependencies": "off",
82+
"require-atomic-updates": "warn",
3883
"curly": ["warn", "multi-line", "consistent"],
3984
"no-console": "off",
85+
"import/named": "off",
86+
"import/no-named-as-default": "off",
4087
"import/no-unresolved": ["error", { "commonjs": true, "amd": true }],
4188
"import/export": "error",
89+
"react-hooks/rules-of-hooks": "error",
90+
"react-hooks/exhaustive-deps": "warn",
4291
"@typescript-eslint/no-duplicate-imports": ["error"],
4392
"@typescript-eslint/explicit-module-boundary-types": "off",
44-
"@typescript-eslint/no-unused-vars": [
45-
"warn",
46-
{ "argsIgnorePattern": "^_", "varsIgnorePattern": "^_" }
47-
],
48-
"@typescript-eslint/no-use-before-define": "off",
4993
"@typescript-eslint/no-empty-function": "off",
5094
"@typescript-eslint/no-empty-interface": "off",
5195
"@typescript-eslint/no-explicit-any": "off",
@@ -75,6 +119,7 @@
75119
],
76120
"react/jsx-uses-react": "off",
77121
"react/react-in-jsx-scope": "off",
122+
"react/no-arrow-function-lifecycle": "warn",
78123
"sort-imports": [
79124
"error",
80125
{
@@ -94,6 +139,10 @@
94139
"node": {
95140
"extensions": [".js", ".jsx", ".ts", ".tsx", ".json"],
96141
"paths": ["src"]
142+
},
143+
"typescript": {
144+
"alwaysTryTypes": true,
145+
"project": "./tsconfig.json"
97146
}
98147
}
99148
},

package.json

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nosferatu500/react-sortable-tree",
3-
"version": "4.0.0-beta.12",
3+
"version": "4.0.0",
44
"description": "Drag-and-drop sortable component for nested data and hierarchies",
55
"main": "./index.js",
66
"types": "./index.d.ts",
@@ -23,7 +23,7 @@
2323
"build:storybook": "build-storybook -o build",
2424
"clean": "rimraf dist",
2525
"clean:storybook": "rimraf build",
26-
"lint": "eslint --fix '*.{js,json}' '{src,tests}/**/*.{ts,tsx}'",
26+
"lint": "eslint '*.{js,json}' '{src,tests}/**/*.{ts,tsx}'",
2727
"prepublishOnly": "yarn build",
2828
"release": "standard-version",
2929
"storybook": "start-storybook -p ${PORT:-3001} -h 0.0.0.0",
@@ -68,11 +68,11 @@
6868
"lodash.isequal": "^4.5.0",
6969
"react-dnd": "^14.0.4",
7070
"react-dnd-html5-backend": "^14.0.2",
71-
"react-virtuoso": "^2.2.6"
71+
"react-virtuoso": "^2.2.7"
7272
},
7373
"devDependencies": {
7474
"@babel/core": "^7.16.0",
75-
"@babel/eslint-parser": "^7.16.0",
75+
"@babel/eslint-parser": "^7.16.3",
7676
"@babel/helper-module-imports": "^7.16.0",
7777
"@babel/plugin-transform-react-jsx": "^7.16.0",
7878
"@babel/preset-env": "^7.16.0",
@@ -88,20 +88,24 @@
8888
"@types/lodash.isequal": "^4.5.5",
8989
"@types/react": "^17.0.34",
9090
"@types/react-dom": "^17.0.11",
91-
"@typescript-eslint/eslint-plugin": "^5.3.0",
92-
"@typescript-eslint/parser": "^5.3.0",
91+
"@typescript-eslint/eslint-plugin": "^5.3.1",
92+
"@typescript-eslint/parser": "^5.3.1",
9393
"acorn-jsx": "^5.3.2",
9494
"babel-plugin-macros": "^3.1.0",
95-
"esbuild": "^0.13.12",
95+
"esbuild": "^0.13.13",
9696
"eslint": "^8.2.0",
97+
"eslint-config-airbnb": "^19.0.0",
98+
"eslint-config-airbnb-typescript": "^15.0.0",
9799
"eslint-config-prettier": "^8.3.0",
98-
"eslint-plugin-array-func": "^3.1.7",
99-
"eslint-plugin-import": "^2.25.2",
100+
"eslint-import-resolver-typescript": "^2.5.0",
101+
"eslint-plugin-import": "^2.25.3",
102+
"eslint-plugin-jsx-a11y": "^6.5.1",
100103
"eslint-plugin-prettier": "^4.0.0",
101104
"eslint-plugin-promise": "^5.1.1",
102-
"eslint-plugin-react": "^7.26.1",
103-
"eslint-plugin-react-hooks": "^4.2.0",
105+
"eslint-plugin-react": "^7.27.0",
106+
"eslint-plugin-react-hooks": "^4.3.0",
104107
"eslint-plugin-sonarjs": "^0.10.0",
108+
"eslint-plugin-unicorn": "^38.0.1",
105109
"json": "^11.0.0",
106110
"postcss": "^8.3.11",
107111
"prettier": "^2.4.1",
@@ -110,7 +114,7 @@
110114
"react-dnd-touch-backend": "^14.1.1",
111115
"react-dom": "^17.0.2",
112116
"rimraf": "^3.0.2",
113-
"rollup": "^2.59.0",
117+
"rollup": "^2.60.0",
114118
"rollup-plugin-esbuild": "^4.6.0",
115119
"rollup-plugin-postcss": "^4.0.1",
116120
"shx": "^0.3.3",
@@ -126,7 +130,7 @@
126130
"production": [
127131
">0.2%",
128132
"not dead",
129-
"not ie",
133+
"not ie <= 11",
130134
"not op_mini all"
131135
],
132136
"development": [

src/index.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
import SortableTree, {
2-
SortableTreeWithoutDndContext,
3-
} from './react-sortable-tree'
4-
51
export * from './utils/default-handlers'
62
export * from './utils/tree-data-utils'
7-
export default SortableTree
83

94
// Export the tree component without the react-dnd DragDropContext,
105
// for when component is used with other components using react-dnd.
116
// see: https://github.com/gaearon/react-dnd/issues/186
12-
export { SortableTreeWithoutDndContext }
7+
8+
export { default, SortableTreeWithoutDndContext } from './react-sortable-tree'

src/node-renderer-default.tsx

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export interface NodeRendererProps {
3030
isSearchFocus: boolean
3131
canDrag: boolean
3232
scaffoldBlockPxWidth: number
33-
toggleChildrenVisibility?(data: NodeData): void | undefined | null
33+
toggleChildrenVisibility?(data: NodeData): void | undefined
3434
buttons?: JSX.Element[] | undefined
3535
className?: string | undefined
3636
style?: React.CSSProperties | undefined
@@ -57,7 +57,7 @@ export interface NodeRendererProps {
5757
canDrop?: boolean | undefined
5858
}
5959

60-
const NodeRendererDefault: React.FC<NodeRendererProps> = (props) => {
60+
const NodeRendererDefault: React.FC<NodeRendererProps> = function (props) {
6161
props = { ...defaultProps, ...props }
6262

6363
const {
@@ -88,17 +88,15 @@ const NodeRendererDefault: React.FC<NodeRendererProps> = (props) => {
8888
} = props
8989
const nodeTitle = title || node.title
9090
const nodeSubtitle = subtitle || node.subtitle
91-
const rowDirectionClass = rowDirection === 'rtl' ? 'rst__rtl' : null
91+
const rowDirectionClass = rowDirection === 'rtl' ? 'rst__rtl' : undefined
9292

9393
let handle
9494
if (canDrag) {
95-
if (typeof node.children === 'function' && node.expanded) {
96-
// Show a loading symbol on the handle when the children are expanded
97-
// and yet still defined by a function (a callback to fetch the children)
98-
handle = (
95+
handle =
96+
typeof node.children === 'function' && node.expanded ? (
9997
<div className="rst__loadingHandle">
10098
<div className="rst__loadingCircle">
101-
{Array.from(new Array(12), (_, index) => (
99+
{[...Array.from({ length: 12 })].map((_, index) => (
102100
<div
103101
// eslint-disable-next-line react/no-array-index-key
104102
key={index}
@@ -110,13 +108,11 @@ const NodeRendererDefault: React.FC<NodeRendererProps> = (props) => {
110108
))}
111109
</div>
112110
</div>
111+
) : (
112+
connectDragSource(<div className="rst__moveHandle" />, {
113+
dropEffect: 'copy',
114+
})
113115
)
114-
} else {
115-
// Show the handle used to initiate a drag-and-drop
116-
handle = connectDragSource(<div className="rst__moveHandle" />, {
117-
dropEffect: 'copy',
118-
})
119-
}
120116
}
121117

122118
const isDraggedDescendant = draggedNode && isDescendant(draggedNode, node)

src/placeholder-renderer-default.tsx

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,20 @@ const defaultProps = {
1414
canDrop: false,
1515
}
1616

17-
const PlaceholderRendererDefault: React.FC<PlaceholderRendererProps> = (
18-
props
19-
) => {
20-
props = { ...defaultProps, ...props }
21-
const { canDrop, isOver } = props
17+
const PlaceholderRendererDefault: React.FC<PlaceholderRendererProps> =
18+
function (props) {
19+
props = { ...defaultProps, ...props }
20+
const { canDrop, isOver } = props
2221

23-
return (
24-
<div
25-
className={classnames(
26-
'rst__placeholder',
27-
canDrop ? 'rst__placeholderLandingPad' : '',
28-
canDrop && !isOver ? 'rst__placeholderCancelPad' : ''
29-
)}
30-
/>
31-
)
32-
}
22+
return (
23+
<div
24+
className={classnames(
25+
'rst__placeholder',
26+
canDrop ? 'rst__placeholderLandingPad' : '',
27+
canDrop && !isOver ? 'rst__placeholderCancelPad' : ''
28+
)}
29+
/>
30+
)
31+
}
3332

3433
export default PlaceholderRendererDefault

0 commit comments

Comments
 (0)