Skip to content

Commit 6dc59f9

Browse files
proxihenningmu
andauthored
refactor: Adopt @doist/eslint-config (#377)
* Install @doist/eslint-config. * Adopt @doist/eslint-config. * Disable func-style. * Ignore prefer-string-starts-ends-with. * Fix no-named-as-default. * Fix react/no-unescaped-entities. * Ignore react/display-name. * Ignore no-default-export. * Allow unescaped entities in test. * fix: address linting error in MenuStory * fix: address linting error in button component * fix: ignore linting error in time-utils * .eslintignore jest.config.js Co-authored-by: Henning Muszynski <henningmu@users.noreply.github.com>
1 parent f82aeae commit 6dc59f9

File tree

11 files changed

+49
-24
lines changed

11 files changed

+49
-24
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
lint-staged.config.js
2+
jest.config.js

.eslintrc

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
{
22
"plugins": ["jest"],
33
"extends": [
4+
"@doist/eslint-config/recommended-requiring-type-checking",
5+
"@doist/eslint-config/react",
46
"react-app",
5-
"prettier/@typescript-eslint",
6-
"plugin:prettier/recommended",
7-
"plugin:jest/recommended",
8-
"prettier",
9-
"plugin:@typescript-eslint/eslint-recommended",
10-
"plugin:@typescript-eslint/recommended",
11-
"plugin:@typescript-eslint/recommended-requiring-type-checking",
12-
"prettier/@typescript-eslint"
7+
"plugin:jest/recommended"
138
],
149
"parser": "@typescript-eslint/parser",
1510
"parserOptions": {
@@ -30,9 +25,8 @@
3025
"webpack.config.*"
3126
],
3227
"rules": {
33-
"prettier/prettier": "error",
34-
"react/no-did-mount-set-state": "error",
35-
"react/no-did-update-set-state": "error",
28+
"func-style": "off",
29+
"import/no-default-export": "off", // Legacy API.
3630
"react/no-find-dom-node": "off",
3731
"@typescript-eslint/explicit-module-boundary-types": "off",
3832
"@typescript-eslint/ban-ts-comment": "off"
@@ -43,6 +37,7 @@
4337
// jest mocks are hard to type, allow incomplete types in tests.
4438
"files": ["stories/**/*", "*.test.*"],
4539
"rules": {
40+
"react/no-unescaped-entities": "off",
4641
"@typescript-eslint/no-unsafe-member-access": "off",
4742
"@typescript-eslint/no-unsafe-call": "off",
4843
"@typescript-eslint/no-unsafe-assignment": "off",

package-lock.json

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"@babel/preset-react": "^7.0.0",
5858
"@babel/preset-typescript": "^7.10.1",
5959
"@babel/register": "^7.0.0",
60+
"@doist/eslint-config": "^3.0.0",
6061
"@doist/prettier-config": "^3.0.5",
6162
"@storybook/addon-actions": "^5.3.18",
6263
"@storybook/addon-docs": "^5.3.18",

src/components/avatar/utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ function getInitials(name?: string) {
88
const lastInitial = seed[seed.length - 1]
99

1010
let initials = firstInitial[0]
11+
// Better readable this way.
12+
// eslint-disable-next-line @typescript-eslint/prefer-string-starts-ends-with
1113
if (firstInitial[0] !== lastInitial[0]) {
1214
initials += lastInitial[0]
1315
}

src/components/button/button.tsx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React from 'react'
2-
import PropTypes from 'prop-types'
32
import classNames from 'classnames'
43

54
import { Tooltip } from '../tooltip'
@@ -77,13 +76,6 @@ const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(function Button(
7776

7877
Button.displayName = 'Button'
7978

80-
Button.propTypes = {
81-
loading: PropTypes.bool,
82-
variant: PropTypes.oneOf(['primary', 'secondary', 'danger', 'link']),
83-
size: PropTypes.oneOf(['default', 'small', 'large']),
84-
tooltip: PropTypes.node,
85-
}
86-
8779
Button.defaultProps = {
8880
size: 'default',
8981
loading: false,

src/components/modal/modal.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import ReactDOM from 'react-dom'
33
import { shallow, mount } from 'enzyme'
44
import toJson from 'enzyme-to-json'
55

6-
import * as Modal from './modal'
6+
import { default as Modal } from '../modal'
77
import type { Modal as ModalType } from '../modal'
88
import Button from '../button' // for more descriptive snapshots
99

src/components/time/time-utils.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
import dayjs from 'dayjs'
2+
/**
3+
* There's a problem with our setup where the default export from
4+
* localizedFormat (and likely every other dayjs plugin) isn't properly
5+
* recognized. The proposed workarounds (importing with `.js` ending, or adding
6+
* `allowSyntheticDefaultImports` to the tsconfig) either broke linting or type
7+
* checking. After spending some time on this it was decided that further
8+
* investigations are not worth it, the code works and the eslint ignore is fine.
9+
* ref: https://github.com/iamkun/dayjs/issues/593
10+
* ref: https://day.js.org/docs/en/installation/typescript
11+
*/
12+
// eslint-disable-next-line import/default
213
import LocalizedFormat from 'dayjs/plugin/localizedFormat'
314

415
dayjs.extend(LocalizedFormat)

stories/components/ButtonStory.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function StandardButtonsStory() {
2626
<Button>Plain Button</Button>
2727
<p>
2828
You can <Button variant="link">add link buttons inline</Button> and it works as
29-
you'd expect.
29+
you&apos;d expect.
3030
</p>
3131
</section>
3232
)

stories/components/MenuStory.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ function SimpleMenuExample() {
109109

110110
const SimpleMenuChapter = {
111111
subtitle: 'Some menu examples',
112+
// eslint-disable-next-line react/display-name
112113
sections: [{ sectionFn: () => <SimpleMenuExample />, options: optionsSourceOnly }],
113114
}
114115

@@ -154,8 +155,8 @@ function OverflowMenuExample() {
154155
be used as a context menu).
155156
</p>
156157
<ul>
157-
{items.map((item) => (
158-
<Item {...item} />
158+
{items.map((item, index) => (
159+
<Item key={index} {...item} />
159160
))}
160161
</ul>
161162
</section>
@@ -164,6 +165,7 @@ function OverflowMenuExample() {
164165

165166
const OverflowMenuChapter = {
166167
subtitle: 'A list of items with an overflow options menu',
168+
// eslint-disable-next-line react/display-name
167169
sections: [{ sectionFn: () => <OverflowMenuExample />, options: optionsSourceOnly }],
168170
}
169171

0 commit comments

Comments
 (0)