Skip to content

Commit

Permalink
Merge pull request #579 from pixiv/chore/eslint-flatconfig
Browse files Browse the repository at this point in the history
Migrate to Flatconfig and Clean Up ESLint Rules
  • Loading branch information
naporin0624 authored Jul 10, 2024
2 parents 5cb313a + a3cc25b commit e542eb0
Show file tree
Hide file tree
Showing 22 changed files with 801 additions and 616 deletions.
12 changes: 0 additions & 12 deletions .eslintignore

This file was deleted.

71 changes: 0 additions & 71 deletions .eslintrc.js

This file was deleted.

166 changes: 166 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
// @ts-nocheck
import eslint from '@eslint/js'
import _import from 'eslint-plugin-import-x'
import globals from 'globals'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import tseslint from 'typescript-eslint'
import eslintPluginReact from 'eslint-plugin-react'
import eslintPluginReactHook from 'eslint-plugin-react-hooks'
import eslintPluginPrettierRecommended from 'eslint-config-prettier'
import { fixupPluginRules } from '@eslint/compat'

const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)

const tseslintConfig = tseslint.config(
...tseslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
{
languageOptions: {
ecmaVersion: 2018,
sourceType: 'module',
parser: tseslint.parser,
parserOptions: {
ecmaFeatures: { jsx: true },
project: ['./tsconfig.json', 'packages/**/tsconfig.json'],
tsconfigRootDir: __dirname,
},
},
rules: {
'@typescript-eslint/no-empty-function': 'error',
'@typescript-eslint/adjacent-overload-signatures': 'error',
'@typescript-eslint/no-empty-interface': 'error',
'@typescript-eslint/no-inferrable-types': 'error',
'@typescript-eslint/ban-ts-comment': 'error',
'@typescript-eslint/prefer-namespace-keyword': 'error',
'@typescript-eslint/no-unsafe-assignment': 'error',
'@typescript-eslint/no-non-null-assertion': 'error',
},
}
)

const typescriptConfig = [
...tseslintConfig,
{
files: ['**/*.ts', '**/*.tsx'],
plugins: {
'@typescript-eslint': tseslint.plugin,
import: _import,
},
rules: {
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-unused-vars': [
'error',
{ argsIgnorePattern: '^_', ignoreRestSiblings: true },
],
'@typescript-eslint/no-unnecessary-condition': 'error',
'@typescript-eslint/strict-boolean-expressions': 'error',
'@typescript-eslint/consistent-type-definitions': 'off',
'@typescript-eslint/no-empty-interface': 'off',
'import/no-extraneous-dependencies': [
'error',
{
devDependencies: [
'*.config.ts',
'**/*.config.ts',
'**/*.test.ts',
'**/*.test.tsx',
'**/*.story.tsx',
'**/_lib/**',
],
},
],
},
},
{
files: ['**/*.tsx', '**/*.ts'],
languageOptions: {
globals: {
...globals.browser,
},
},
plugins: {
react: eslintPluginReact,
'react-hooks': fixupPluginRules(eslintPluginReactHook),
},
rules: {
...eslintPluginReact.configs.recommended.rules,
...eslintPluginReactHook.configs.recommended.rules,
'react/prop-types': 'off',
'react/no-unknown-property': ['error', { ignore: ['css'] }],
'react/jsx-uses-react': 'off',
'react/react-in-jsx-scope': 'off',
},
settings: {
react: {
version: 'detect',
},
},
},
]

const config = [
eslint.configs.recommended,
eslintPluginPrettierRecommended,
...typescriptConfig,
{
ignores: [
'**/dist/',
'**/node_modules/',
'**/__snapshots__/',
'**/.yarn/',
'public/',
'storybook-static/',
'coverage/',
'**/.next/',
'misc/',
'packages/tailwind-diff/bin/tailwind-diff.js',
'packages/icon-files/src/',
'eslint.config.mjs',
'.storybook',
],
},
{
files: ['**/*.ts', '**/*.tsx', '**/*.js', '**/*.jsx'],
rules: {
'no-console': 'warn',
'no-undef': 'off',
'no-constant-condition': 'error',
},
},
{
files: [
'**/*.test.ts',
'**/*.test.tsx',
'**/__tests__/**',
'**/*.config.*',
'*.config.*',
'**/*.story.*',
'.storybook/**',
],
languageOptions: {
globals: {
...globals.node,
...globals.jest,
},
},
plugins: {
import: _import,
},
rules: {
'import/no-extraneous-dependencies': 'off',
},
},
{
files: ['**/docs/**'],
plugins: {
import: _import,
},
rules: {
'import/no-extraneous-dependencies': 'off',
},
},
]

export default config
20 changes: 13 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
"@commitlint/cli": "^16.1.0",
"@commitlint/config-conventional": "^16.0.0",
"@commitlint/config-lerna-scopes": "^16.0.0",
"@eslint/compat": "^1.1.0",
"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.5.0",
"@originjs/vite-plugin-commonjs": "^1.0.3",
"@playwright/test": "^1.40.1",
"@storybook/addon-a11y": "^8.0.5",
Expand All @@ -66,7 +69,8 @@
"@storybook/test-runner": "^0.17.0",
"@storybook/web-components": "^8.0.5",
"@stylelint/postcss-css-in-js": "^0.37.2",
"@types/eslint": "^8.4.1",
"@types/eslint__eslintrc": "^2.1.1",
"@types/eslint__js": "^8.42.3",
"@types/jest": "^27.4.0",
"@types/jest-image-snapshot": "^6.4.0",
"@types/jest-specific-snapshot": "^0.5.9",
Expand All @@ -83,15 +87,16 @@
"css-loader": "^6.10.0",
"esbuild": "^0.14.14",
"esbuild-jest": "^0.5.0",
"eslint": "^8.36.0",
"eslint-config-prettier": "^8.7.0",
"eslint": "^9.6.0",
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jest": "^27.2.1",
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-import-x": "^0.5.3",
"eslint-plugin-jest": "^28.6.0",
"eslint-plugin-react": "^7.34.3",
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-storybook": "^0.8.0",
"glob": "^7.2.0",
"globals": "^15.6.0",
"http-server": "^14.1.1",
"husky": "^9.0.11",
"jest": "^27.4.7",
Expand Down Expand Up @@ -119,6 +124,7 @@
"stylelint-config-styled-components": "^0.1.1",
"ts-jest": "^29.0.5",
"typescript": "^4.9.5",
"typescript-eslint": "^7.15.0",
"vite": "^5.2.7",
"wait-on": "^7.2.0",
"zx": "^7.0.3"
Expand Down
4 changes: 2 additions & 2 deletions packages/icons-cli/src/GitHubClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ export class GithubClient {
const parentCommit = await this.api.git.getCommit({
owner: this.repoOwner,
repo: this.repoName,
// eslint-disable-next-line @typescript-eslint/naming-convention

commit_sha: targetBranch.data.object.sha,
})

const newTree = await this.api.git.createTree({
owner: this.repoOwner,
repo: this.repoName,
// eslint-disable-next-line @typescript-eslint/naming-convention

base_tree: parentCommit.data.tree.sha,
tree,
})
Expand Down
1 change: 0 additions & 1 deletion packages/icons-cli/src/GitlabClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ export class GitlabClient {
this.message,
diff,
{
// eslint-disable-next-line @typescript-eslint/naming-convention
start_branch: this.defaultBranch,
}
)
Expand Down
4 changes: 2 additions & 2 deletions packages/pullrequest-cli/src/GitHubClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,14 @@ export class GithubClient {
const parentCommit = await this.api.git.getCommit({
owner: this.repoOwner,
repo: this.repoName,
// eslint-disable-next-line @typescript-eslint/naming-convention

commit_sha: targetBranch.data.object.sha,
})

const newTree = await this.api.git.createTree({
owner: this.repoOwner,
repo: this.repoName,
// eslint-disable-next-line @typescript-eslint/naming-convention

base_tree: parentCommit.data.tree.sha,
tree,
})
Expand Down
13 changes: 10 additions & 3 deletions packages/react-sandbox/src/components/Carousel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ export default function Carousel({
maxScrollLeft
)
setScrollLeft(scroll, true)
set({ scroll, from: { scroll: scrollLeft }, reset: !animation.current })
void set({
scroll,
from: { scroll: scrollLeft },
reset: !animation.current,
})
animation.current = true
}, [
animation,
Expand All @@ -114,7 +118,11 @@ export default function Carousel({
const { clientWidth } = visibleAreaRef.current
const scroll = Math.max(scrollLeft - clientWidth * scrollAmountCoef, 0)
setScrollLeft(scroll, true)
set({ scroll, from: { scroll: scrollLeft }, reset: !animation.current })
void set({
scroll,
from: { scroll: scrollLeft },
reset: !animation.current,
})
animation.current = true
}, [animation, scrollLeft, set, scrollAmountCoef, setScrollLeft])

Expand Down Expand Up @@ -206,7 +214,6 @@ export default function Carousel({
setScrollLeft(scrollLength, true)
}
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [ref.current])

const handleScrollMove = useCallback(() => {
Expand Down
2 changes: 0 additions & 2 deletions packages/react-sandbox/src/components/Layout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,6 @@ interface StyledCancelLayoutItemBodyPaddingProps {
cancelTop?: boolean
}

/* eslint-disable max-len */
export const StyledCancelLayoutItemBodyPadding = styled.div<StyledCancelLayoutItemBodyPaddingProps>`
margin: 0 -${(p) => (p.wide ? LAYOUT_ITEM_BODY_PADDING.wide.x : LAYOUT_ITEM_BODY_PADDING.default.x)}px;
margin-top: -${({ cancelTop = false, wide }) => (!cancelTop ? 0 : wide ? LAYOUT_ITEM_BODY_PADDING.wide.y : LAYOUT_ITEM_BODY_PADDING.default.y)}px;
Expand All @@ -364,4 +363,3 @@ export const StyledCancelLayoutItemBodyPadding = styled.div<StyledCancelLayoutIt
margin-top: -${({ cancelTop = false }) => (!cancelTop ? 0 : LAYOUT_ITEM_BODY_PADDING.column1.x)}px;
}
`
/* eslint-enable max-len */
1 change: 0 additions & 1 deletion packages/react-sandbox/src/components/icons/Base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ export const IconBasePath = ({
/>
)
} else {
// eslint-disable-next-line react/jsx-no-useless-fragment
return <>{path}</>
}
}
Loading

0 comments on commit e542eb0

Please sign in to comment.