Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: ESLint v9 #5197

Merged
merged 12 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 0 additions & 31 deletions .eslintrc.js

This file was deleted.

50 changes: 50 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import smarthr from 'eslint-config-smarthr'
import storybook from 'eslint-plugin-storybook'

/**
* @type {import('eslint').Linter.Config[]}
*/
export default [
...smarthr,
...storybook.configs['flat/recommended'],
{
rules: {
'jsx-a11y/anchor-is-valid': 'warn',
'jsx-a11y/click-events-have-key-events': 'warn',
'jsx-a11y/no-static-element-interactions': 'warn',
'jsx-a11y/label-has-associated-control': [
'error',
{
controlComponents: ['Input', 'InputWithTooltip'],
},
],
'@typescript-eslint/consistent-type-definitions': [
'error',
'type',
],
'smarthr/require-barrel-import': 'off',
'smarthr/a11y-anchor-has-href-attribute': [
'error',
{
checkType: 'allow-spread-attributes',
}
],
'smarthr/a11y-input-has-name-attribute': [
'error',
{
checkType: 'allow-spread-attributes',
}
],
},
},
{
ignores: [
'**/*.{mjs,js}',
'sandbox/',
'storybook-static/',
'packages/smarthr-ui/esm/',
'packages/smarthr-ui/lib/',
'packages/smarthr-ui/.storybook',
]
},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FlatConfig では、 ignores のみを持つオブジェクトを定義することで、全体の ignore リストが設定できるらしいです。

]
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"devDependencies": {
"@commitlint/cli": "^19.6.1",
"@commitlint/config-conventional": "^19.6.0",
"eslint": "^8.57.0",
"eslint-config-smarthr": "^7.3.0",
"eslint": "^9.17.0",
"eslint-config-smarthr": "^8.0.0",
"eslint-plugin-storybook": "^0.11.1",
"husky": "^9.1.7",
"lint-staged": "^15.2.11",
Expand Down
4 changes: 0 additions & 4 deletions packages/smarthr-ui/.eslintignore

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export function ButtonWrapper({
if (props.isAnchor) {
const { anchorRef, elementAs, isAnchor: _, ...others } = props
const Component = elementAs || 'a'
// eslint-disable-next-line jsx-a11y/anchor-has-content

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ESLint v9 では、このように無効な無効化コメントを検知できるようになりました。

return <Component {...others} className={anchorStyle} ref={anchorRef} />
} else {
const { buttonRef, disabled, onClick, ...others } = props
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ const ListBoxItemButton = <T,>({
)

return isNew ? (
// eslint-disable-next-line smarthr/a11y-clickable-element-has-text
<button
type="button"
key={option.id}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { Stack } from '../../../Layout'
import { Text } from '../../../Text'
import { SingleComboBox } from '../SingleComboBox'

// eslint-disable-next-line storybook/prefer-pascal-case
export const defaultItems = {
'option 1': {
label: 'option 1',
Expand Down Expand Up @@ -68,7 +67,6 @@ export const defaultItems = {
},
}

// eslint-disable-next-line storybook/prefer-pascal-case
export const prefixes = { なし: '', あり: <FaCirclePlusIcon /> }

export default {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export const MessageDialogContentInner: FC<MessageDialogContentInnerProps> = ({
<DialogBody contentPadding={contentPadding} contentBgColor={contentBgColor}>
{description}
</DialogBody>
{/* eslint-disable-next-line smarthr/best-practice-for-layouts */}
<Cluster as="footer" justify="flex-end" className={actionArea()}>
<Button onClick={onClickClose} className="smarthr-ui-Dialog-closeButton">
{decorators?.closeButtonLabel?.(CLOSE_BUTTON_LABEL) || CLOSE_BUTTON_LABEL}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default {
},
args: {
title: 'フォームコントロール',
// eslint-disable-next-line smarthr/a11y-input-has-name-attribute, smarthr/a11y-input-in-form-control

children: <Input />,
},
parameters: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type { Meta, StoryObj } from '@storybook/react'
export default {
title: 'Forms(フォーム)/SearchInput',
component: SearchInput,
// eslint-disable-next-line smarthr/a11y-input-in-form-control

render: (args) => <SearchInput {...args} />,
args: {
tooltipMessage: '氏名、ヨミガナ、社員番号で検索できます。スペース区切りでAND検索ができます。',
Expand Down Expand Up @@ -55,7 +55,6 @@ export const Width: StoryObj<typeof SearchInput> = {
render: (args) => (
<Stack align="flex-start">
{['15em', '50%', 200].map((width) => (
// eslint-disable-next-line smarthr/a11y-input-in-form-control
<SearchInput {...args} width={width} key={width} />
))}
</Stack>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ type Props<T extends React.ElementType> = PropsWithChildren<
> &
ComponentPropsWithoutRef<T>

const _Cluster = <T extends React.ElementType = 'div'>(
const ActualCluster = <T extends React.ElementType = 'div'>(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここリネームしてます。

ESLint のバージョンアップによって、「Hooks を使えるのは React コンポーネントだけだぞ」ってルールに引っかかりました。

これはちゃんと React コンポーネントなんですが、どうやらコンポーネントならキャメルメースの命名のはずだと疑われてしまったので、ちゃんとキャメルメースを満たす名前に変えました。

{ as, gap = 0.5, inline = false, align, justify, className, ...rest }: Props<T>,
ref: ForwardedRef<HTMLDivElement>,
) => {
Expand All @@ -119,4 +119,4 @@ const _Cluster = <T extends React.ElementType = 'div'>(
)
}

export const Cluster = genericsForwardRef(_Cluster)
export const Cluster = genericsForwardRef(ActualCluster)
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@ export const All: StoryFn = () => {
return (
<Stack as="article" gap="M" style={{ padding: '20px' }}>
<header>
{/* eslint-disable-next-line smarthr/a11y-heading-in-sectioning-content */}
<Heading>Reel</Heading>
</header>
<Stack as="section">
{/* eslint-disable-next-line smarthr/a11y-heading-in-sectioning-content */}
<Heading type="sectionTitle">
with <code>gap</code>, <code>padding</code>
</Heading>
Expand All @@ -46,7 +44,6 @@ export const All: StoryFn = () => {
</Reel>
</Stack>
<Stack as="section">
{/* eslint-disable-next-line smarthr/a11y-heading-in-sectioning-content */}
<Heading type="sectionTitle">
<code>TabBar</code>
</Heading>
Expand All @@ -66,7 +63,6 @@ export const All: StoryFn = () => {
</Reel>
</Stack>
<Stack as="section">
{/* eslint-disable-next-line smarthr/a11y-heading-in-sectioning-content */}
<Heading type="sectionTitle">
<code>Table</code>
</Heading>
Expand Down
2 changes: 1 addition & 1 deletion packages/smarthr-ui/src/components/Picker/TimePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const TimePicker = forwardRef<HTMLInputElement, PickerProps<Props>>(

return (
<span className={wrapperStyle}>
{/* eslint-disable-next-line smarthr/a11y-input-in-form-control */}
{}
s-sasaki-0529 marked this conversation as resolved.
Show resolved Hide resolved
<input
{...rest}
data-smarthr-ui-input="true"
Expand Down
1 change: 0 additions & 1 deletion packages/smarthr-ui/src/hooks/usePortal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export function usePortal() {
document.body.removeChild(portalRoot)
}
// spread parentSeqs array for deps
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [portalRoot, ...parentSeqs])

const isChildPortal = useCallback(
Expand Down
Loading
Loading