Skip to content

Commit 437c2c0

Browse files
authored
[babel] Remove @elastic/eslint-config-kibana and babel-eslint-plugin (#6808)
* Remove deprecated babel eslint packages - `eslint-plugin-babel` is not used by anything in our repo except for: - `@elastic/eslint-config-kibana` is no longer supported/maintained, and exists in Kibana now. It doesn't make sense for us to import from Kibana, so we should likely just maintain our own eslint config settings * Replace rules from in `eslint-config-kibana` @see https://github.com/elastic/eslint-config-kibana/blob/master/.eslintrc.js - excluding rules that overlap w/ Prettier (spacing, quotes, indentation, etc) - excluded `no-undef`, `no-redeclare` - `@typescript/eslint` already handles these without throwing errors on globals and type exports (see https://stackoverflow.com/a/64197516/4294462) - also allows removing `env` config + update eqeqeq rule and no-empty rule to allow empty catches [opinionated] - removed `no-nested-ternary`, as we use those plenty and Prettier styles them to be very readable - also removed several rules which just don't come up for us often, e.g. `__proto__` and `__iterator__` checks * Restore `mocha` rules set by Kibana eslint config + upgrade `mocha` eslint plugin to latest * Restore `import` rules set by Kibana eslint config + remove unused import disable rules + remove `import/named` - it doesn't know how to handle types and `@typescript/eslint` already does it better * Restore `react` rules set by Kibana eslint config + upgrade react eslint packages to latest + remove unused disable rules * Remove `react` rule causing unused fragments to not be linted + remove unnecessary `jsx` import in Jest test
1 parent accaf64 commit 437c2c0

35 files changed

+413
-277
lines changed

.eslintrc.js

+49-10
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,48 @@ module.exports = {
3030
},
3131
},
3232
extends: [
33-
'@elastic/eslint-config-kibana',
3433
'plugin:@typescript-eslint/recommended',
3534
// Prettier options need to come last, in order to override other style
3635
// rules.
3736
'prettier/react',
3837
'prettier/standard',
3938
'plugin:prettier/recommended',
4039
],
41-
plugins: ['jsx-a11y', 'prettier', 'local', 'react-hooks', '@emotion'],
40+
plugins: [
41+
'mocha',
42+
'jsx-a11y',
43+
'prettier',
44+
'local',
45+
'import',
46+
'react',
47+
'react-hooks',
48+
'@emotion',
49+
],
4250
rules: {
51+
'block-scoped-var': 'error',
52+
camelcase: 'off',
53+
'dot-notation': ['error', { allowKeywords: true }],
54+
eqeqeq: ['error', 'always', { null: 'ignore' }],
55+
'guard-for-in': 'error',
56+
'new-cap': ['error', { capIsNewExceptions: ['Private'] }],
57+
'no-caller': 'error',
58+
'no-const-assign': 'error',
59+
'no-debugger': 'error',
60+
'no-empty': ['error', { allowEmptyCatch: true }],
61+
'no-eval': 'error',
62+
'no-extend-native': 'error',
63+
'no-global-assign': 'error',
64+
'no-loop-func': 'error',
65+
'no-restricted-globals': ['error', 'context'],
66+
'no-script-url': 'error',
67+
'no-sequences': 'error',
68+
'no-var': 'error',
69+
'no-with': 'error',
70+
'prefer-const': 'error',
4371
'prefer-template': 'error',
72+
strict: ['error', 'never'],
73+
'valid-typeof': 'error',
74+
4475
'local/i18n': 'error',
4576
'local/href-with-rel': 'error',
4677
'local/forward-ref': 'error',
@@ -53,9 +84,18 @@ module.exports = {
5384
license: SSPL_ELASTIC_2_0_LICENSE_HEADER,
5485
},
5586
],
56-
'no-use-before-define': 'off',
57-
quotes: ['warn', 'single', 'avoid-escape'],
58-
camelcase: 'off',
87+
88+
'import/no-unresolved': ['error', { amd: true, commonjs: true }],
89+
'import/namespace': 'error',
90+
'import/default': 'error',
91+
'import/export': 'error',
92+
'import/no-named-as-default': 'error',
93+
'import/no-named-as-default-member': 'error',
94+
'import/no-duplicates': 'error',
95+
96+
'mocha/handle-done-callback': 'error',
97+
'mocha/no-exclusive-tests': 'error',
98+
5999
'jsx-a11y/accessible-emoji': 'error',
60100
'jsx-a11y/alt-text': 'error',
61101
'jsx-a11y/anchor-has-content': 'error',
@@ -82,6 +122,10 @@ module.exports = {
82122
'jsx-a11y/tabindex-no-positive': 'error',
83123
'jsx-a11y/label-has-associated-control': 'error',
84124

125+
'react/jsx-uses-vars': 'error',
126+
'react/jsx-no-undef': 'error',
127+
'react/jsx-pascal-case': 'error',
128+
85129
'react-hooks/rules-of-hooks': 'error',
86130
'react-hooks/exhaustive-deps': 'warn',
87131

@@ -119,16 +163,11 @@ module.exports = {
119163
{ fixMixedExportsWithInlineTypeSpecifier: false },
120164
],
121165
},
122-
env: {
123-
jest: true,
124-
},
125166
overrides: [
126167
{
127168
files: ['*.d.ts'],
128169
rules: {
129-
'react/no-multi-comp': 'off',
130170
'react/prefer-es6-class': 'off',
131-
'react/prefer-stateless-function': 'off',
132171
},
133172
},
134173
],

package.json

+3-5
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@
115115
"@cypress/webpack-dev-server": "^1.7.0",
116116
"@elastic/charts": "^53.1.1",
117117
"@elastic/datemath": "^5.0.3",
118-
"@elastic/eslint-config-kibana": "^0.15.0",
119118
"@emotion/babel-preset-css-prop": "^11.10.0",
120119
"@emotion/cache": "^11.10.3",
121120
"@emotion/css": "^11.10.0",
@@ -178,16 +177,15 @@
178177
"eslint": "^7.10.0",
179178
"eslint-config-prettier": "^6.12.0",
180179
"eslint-import-resolver-webpack": "^0.13.0",
181-
"eslint-plugin-babel": "^5.3.1",
182180
"eslint-plugin-import": "^2.22.1",
183181
"eslint-plugin-jest": "^24.1.0",
184182
"eslint-plugin-jsx-a11y": "^6.5.1",
185183
"eslint-plugin-local": "^1.0.0",
186-
"eslint-plugin-mocha": "^8.0.0",
184+
"eslint-plugin-mocha": "^10.1.0",
187185
"eslint-plugin-prefer-object-spread": "^1.2.1",
188186
"eslint-plugin-prettier": "^3.1.4",
189-
"eslint-plugin-react": "^7.21.3",
190-
"eslint-plugin-react-hooks": "^4.1.2",
187+
"eslint-plugin-react": "^7.32.2",
188+
"eslint-plugin-react-hooks": "^4.6.0",
191189
"expose-gc": "^1.0.0",
192190
"file-loader": "^6.1.0",
193191
"findup": "^0.1.5",

scripts/babel/react-docgen-typescript.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ module.exports = function ({ types }) {
8888
savePropValueAsString: true,
8989
})
9090
.parseWithProgramProvider(filename, () => program);
91-
// eslint-disable-next-line no-empty
9291
} catch (e) {}
9392

9493
/**
@@ -349,4 +348,5 @@ const intrinsicValuesRaw = [
349348
const reactElementTypeExpanded =
350349
'ReactElement<any, string | JSXElementConstructor<any>>';
351350

352-
const reactNodeTypeExpanded = /(string \| number \| boolean \| {} \| ReactElement \| ReactNodeArray \| ReactPortal)( \| \({} & string\).+\(ReactPortal & string\))?/g;
351+
const reactNodeTypeExpanded =
352+
/(string \| number \| boolean \| {} \| ReactElement \| ReactNodeArray \| ReactPortal)( \| \({} & string\).+\(ReactPortal & string\))?/g;

src-docs/src/components/guide_section/guide_section.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,6 @@ export const GuideSection: FunctionComponent<GuideSectionProps> = ({
230230
<GuideSectionExample
231231
example={
232232
<EuiErrorBoundary>
233-
{/* eslint-disable-next-line no-nested-ternary */}
234233
{fullScreen == null ? (
235234
<div>{demo}</div>
236235
) : demo == null ? (

src-docs/src/views/date_picker/custom_input.js

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ ExampleCustomInput.propTypes = {
2121
value: PropTypes.string,
2222
};
2323

24-
// eslint-disable-next-line react/no-multi-comp
2524
export default () => {
2625
const [startDate, setStartDate] = useState(moment());
2726

src-docs/src/views/elastic_charts/pie_alts.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable no-nested-ternary */
21
import React, { useState } from 'react';
32
import groupBy from 'lodash/groupBy';
43
import mapValues from 'lodash/mapValues';

src-docs/src/views/elastic_charts/pie_slices.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable no-nested-ternary */
21
import React, { useState } from 'react';
32
import { Chart, Partition, Settings, PartitionLayout } from '@elastic/charts';
43

src-docs/src/views/elastic_charts/theming_categorical.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable no-nested-ternary */
21
import React, { useState, useEffect } from 'react';
32
import { Chart, Settings, Axis, DataGenerator } from '@elastic/charts';
43

src-docs/src/views/empty_prompt/empty_prompt_multiple_types.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable import/no-unresolved */
21
import React, { ReactNode, useState } from 'react';
32

43
import { EuiSpacer, EuiSelect } from '../../../../src/components';

src-docs/src/views/empty_prompt/empty_prompt_panel_options.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable import/no-unresolved */
21
import React, { useState } from 'react';
32

43
import {

src-docs/src/views/form_layouts/form_layouts_example.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { Fragment } from 'react';
1+
import React from 'react';
22
import { Link } from 'react-router-dom';
33

44
import { GuideSectionTypes } from '../../components';

src-docs/src/views/form_validation/guidelines.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, Fragment } from 'react';
1+
import React, { useState } from 'react';
22
import { GuideRule, GuideRuleExample } from '../../components';
33
import {
44
EuiTitle,

src-docs/src/views/page_template/_page_demo.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable no-nested-ternary */
21
import React, { useState, FunctionComponent } from 'react';
32
import { useRouteMatch } from 'react-router';
43
import {

src-docs/src/views/popover/popover_htmlelement_anchor.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable react/no-multi-comp */
21
import React, { useState, useEffect } from 'react';
32

43
import { render, unmountComponentAtNode } from 'react-dom';

src-docs/src/views/suggest/suggest_item_example.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable import/no-unresolved */
21
import React, { useState } from 'react';
32

43
import { EuiSwitch, EuiSuggestItem } from '../../../../src/components';

src-docs/src/views/tabs/tabs_example.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable import/no-unresolved */
21
import React from 'react';
32
import { Link } from 'react-router-dom';
43

src-docs/src/views/theme/consuming_hoc.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { withEuiTheme, WithEuiThemeProps } from '../../../../src/services';
44
import { EuiIcon } from '../../../../src/components/icon';
55
import { EuiText } from '../../../../src/components/text';
66

7-
// eslint-disable-next-line react/prefer-stateless-function
87
class Block extends React.Component<WithEuiThemeProps> {
98
render() {
109
const { theme } = this.props;

src/components/button/button.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ export const EuiButton: FunctionComponent<Props> = (props) => {
101101
isLoading: rest.isLoading,
102102
});
103103

104-
// eslint-disable-next-line no-nested-ternary
105104
const color = buttonIsDisabled ? 'disabled' : _color;
106105

107106
const buttonColorStyles = useEuiButtonColorCSS({

src/components/button/button_empty/button_empty.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ export const EuiButtonEmpty: FunctionComponent<EuiButtonEmptyProps> = (
130130
isLoading,
131131
});
132132

133-
// eslint-disable-next-line no-nested-ternary
134133
const color = isDisabled ? 'disabled' : _color === 'ghost' ? 'text' : _color;
135134
const buttonColorStyles = useEuiButtonColorCSS({
136135
display: 'empty',

src/components/button/button_group/button_group_button.tsx

-2
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,7 @@ export const EuiButtonGroupButton: FunctionComponent<Props> = ({
100100
};
101101
}
102102

103-
// eslint-disable-next-line no-nested-ternary
104103
const color = isDisabled ? 'disabled' : _color;
105-
// eslint-disable-next-line no-nested-ternary
106104
const display = isSelected
107105
? 'fill'
108106
: size === 'compressed'

src/components/button/button_icon/button_icon.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ export const EuiButtonIcon: FunctionComponent<Props> = (props) => {
156156
);
157157
}
158158

159-
// eslint-disable-next-line no-nested-ternary
160159
const color = isDisabled ? 'disabled' : _color === 'ghost' ? 'text' : _color;
161160

162161
const styles = {

src/components/context_menu/context_menu.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,6 @@ export class EuiContextMenu extends Component<EuiContextMenuProps, State> {
207207

208208
componentDidUpdate(prevProps: EuiContextMenuProps) {
209209
if (prevProps.panels !== this.props.panels) {
210-
// eslint-disable-next-line react/no-did-update-set-state
211210
this.setState({
212211
idToRenderedItemsMap: this.mapIdsToRenderedItems(this.props.panels),
213212
});

src/components/datagrid/body/data_grid_cell_popover.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ export const JsonPopoverContent = ({ cellText }: { cellText: string }) => {
147147
let formattedText = cellText;
148148
try {
149149
formattedText = JSON.stringify(JSON.parse(formattedText), null, 2);
150-
} catch (e) {} // eslint-disable-line no-empty
150+
} catch (e) {}
151151

152152
return (
153153
<EuiCodeBlock

src/components/datagrid/body/header/data_grid_header_cell.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,6 @@ export const useSortingUtils = ({
223223
* @see https://github.com/w3c/aria/issues/283 for potential future multi-column usage
224224
*/
225225
const ariaSort: AriaAttributes['aria-sort'] =
226-
// eslint-disable-next-line no-nested-ternary
227226
isColumnSorted && hasOnlyOneSort
228227
? sorting.columns[0].direction === 'asc'
229228
? 'ascending'

src/components/focus_trap/focus_trap.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ export class EuiFocusTrap extends Component<EuiFocusTrapProps, State> {
7272

7373
componentDidUpdate(prevProps: EuiFocusTrapProps) {
7474
if (prevProps.disabled === true && this.props.disabled === false) {
75-
// eslint-disable-next-line react/no-did-update-set-state
7675
this.setState({ hasBeenDisabledByClick: false });
7776
}
7877
}

src/components/form/file_picker/file_picker.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ export class EuiFilePicker extends Component<EuiFilePickerProps> {
245245
<EuiIcon
246246
className="euiFilePicker__icon"
247247
color={
248-
isInvalid ? 'danger' : disabled ? 'subdued' : 'primary' // eslint-disable-line no-nested-ternary
248+
isInvalid ? 'danger' : disabled ? 'subdued' : 'primary'
249249
}
250250
type={isInvalid ? 'alert' : 'importAction'}
251251
size={normalFormControl ? 'm' : 'l'}

src/components/form/range/dual_range.tsx

-6
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,12 @@ export class EuiDualRangeClass extends Component<
9595

9696
componentDidMount() {
9797
if (this.rangeSliderRef && this.rangeSliderRef.clientWidth === 0) {
98-
// Safe to call `setState` inside conditional
99-
// https://reactjs.org/docs/react-component.html#componentdidmount
100-
// eslint-disable-next-line react/no-did-mount-set-state
10198
this.setState({ isVisible: false });
10299
}
103100
}
104101

105102
componentDidUpdate() {
106103
if (this.rangeSliderRef?.clientWidth && !this.state.isVisible) {
107-
// Safe to call `setState` inside conditional
108-
// https://reactjs.org/docs/react-component.html#componentdidupdate
109-
// eslint-disable-next-line react/no-did-update-set-state
110104
this.setState({ isVisible: true });
111105
}
112106
}

src/components/icon/icon.tsx

-3
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ export class EuiIconClass extends PureComponent<
153153
const { type } = this.props;
154154

155155
if (isEuiIconType(type) && this.state.icon == null) {
156-
//eslint-disable-next-line react/no-did-mount-set-state
157156
this.setState({
158157
neededLoading: true,
159158
isLoading: true,
@@ -169,14 +168,12 @@ export class EuiIconClass extends PureComponent<
169168
const { type } = this.props;
170169
if (type !== prevProps.type) {
171170
if (isEuiIconType(type)) {
172-
// eslint-disable-next-line react/no-did-update-set-state
173171
this.setState({
174172
neededLoading: iconComponentCache.hasOwnProperty(type),
175173
isLoading: true,
176174
});
177175
this.loadIconComponent(type);
178176
} else {
179-
// eslint-disable-next-line react/no-did-update-set-state
180177
this.setState({
181178
icon: type,
182179
neededLoading: true,

src/components/markdown_editor/unified-plugins.d.ts

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ declare module 'remark-emoji' {
1414
}
1515

1616
declare module 'mdast-util-to-hast/lib/all' {
17-
// eslint-disable-next-line import/no-unresolved
1817
import { Node } from 'unist';
1918
import { H } from 'mdast-util-to-hast';
2019

src/components/popover/popover.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,6 @@ export class EuiPopover extends Component<Props, State> {
439439
if (this.state.suppressingPopover) {
440440
// component was created with isOpen=true; now that it's mounted
441441
// stop suppressing and start opening
442-
// eslint-disable-next-line react/no-did-mount-set-state
443442
this.setState({ suppressingPopover: false, isOpening: true }, () => {
444443
this.onOpenPopover();
445444
});

src/components/search_bar/search_bar.test.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* Side Public License, v 1.
77
*/
88

9-
/* eslint-disable react/no-multi-comp */
109
import React, { useState } from 'react';
1110
import { act } from 'react-dom/test-utils';
1211

src/components/selectable/selectable_list/selectable_list_item.tsx

-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ export type EuiSelectableListItemProps = LiHTMLAttributes<HTMLLIElement> &
8686
textWrap?: 'truncate' | 'wrap';
8787
};
8888

89-
// eslint-disable-next-line react/prefer-stateless-function
9089
export class EuiSelectableListItem extends Component<
9190
EuiSelectableListItemProps
9291
> {
@@ -243,7 +242,6 @@ export class EuiSelectableListItem extends Component<
243242
switch (checked) {
244243
case 'on':
245244
state = screenReaderStrings.checked.state;
246-
// eslint-disable-next-line no-nested-ternary
247245
instructions = allowExclusions
248246
? screenReaderStrings.excluded.instructions
249247
: searchable

src/components/tree_view/tree_view.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ export class EuiTreeView extends Component<EuiTreeViewProps, EuiTreeViewState> {
131131

132132
componentDidUpdate(prevProps: EuiTreeViewProps) {
133133
if (this.props.id !== prevProps.id) {
134-
// eslint-disable-next-line react/no-did-update-set-state
135134
this.setState({
136135
treeID: getTreeId(this.props.id, this.context, this.treeIdGenerator),
137136
});

0 commit comments

Comments
 (0)