-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from yamada-ui/refactor/eslint
Add ESLint configurations and rules
- Loading branch information
Showing
74 changed files
with
2,900 additions
and
4,725 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import type { Linter } from "eslint" | ||
import { sharedFiles } from "./shared" | ||
|
||
export const baseConfig: Linter.Config = { | ||
name: "eslint/base", | ||
files: sharedFiles, | ||
rules: { | ||
"constructor-super": "error", | ||
"for-direction": "error", | ||
"getter-return": "error", | ||
"no-async-promise-executor": "error", | ||
"no-case-declarations": "error", | ||
"no-class-assign": "error", | ||
"no-compare-neg-zero": "error", | ||
"no-cond-assign": "error", | ||
"no-const-assign": "error", | ||
"no-constant-binary-expression": "error", | ||
"no-constant-condition": "error", | ||
"no-control-regex": "error", | ||
"no-debugger": "error", | ||
"no-delete-var": "error", | ||
"no-dupe-args": "error", | ||
"no-dupe-class-members": "error", | ||
"no-dupe-else-if": "error", | ||
"no-dupe-keys": "error", | ||
"no-duplicate-case": "error", | ||
"no-empty-character-class": "error", | ||
"no-empty-pattern": "error", | ||
"no-empty-static-block": "error", | ||
"no-ex-assign": "error", | ||
"no-fallthrough": "error", | ||
"no-func-assign": "error", | ||
"no-global-assign": "error", | ||
"no-import-assign": "error", | ||
"no-invalid-regexp": "error", | ||
"no-loss-of-precision": "error", | ||
"no-misleading-character-class": "error", | ||
"no-new-native-nonconstructor": "error", | ||
"no-nonoctal-decimal-escape": "error", | ||
"no-obj-calls": "error", | ||
"no-octal": "error", | ||
"no-redeclare": "error", | ||
"no-regex-spaces": "error", | ||
"no-self-assign": "error", | ||
"no-setter-return": "error", | ||
"no-this-before-super": "error", | ||
"no-undef": "error", | ||
"no-unexpected-multiline": "error", | ||
"no-unreachable": "error", | ||
"no-unsafe-finally": "error", | ||
"no-unsafe-negation": "error", | ||
"no-unsafe-optional-chaining": "error", | ||
"no-unused-labels": "error", | ||
"no-unused-private-class-members": "error", | ||
"no-useless-backreference": "error", | ||
"no-useless-catch": "error", | ||
"no-var": "error", | ||
"no-with": "error", | ||
"require-yield": "error", | ||
"use-isnan": "error", | ||
"valid-typeof": "error", | ||
|
||
"no-console": ["warn", { allow: ["warn", "error"] }], | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import type { Linter } from "eslint" | ||
import cspellPlugin from "@cspell/eslint-plugin" | ||
import { sharedFiles } from "./shared" | ||
|
||
export const cspellConfig: Linter.Config = { | ||
name: "eslint/cspell", | ||
files: sharedFiles, | ||
plugins: { "@cspell": cspellPlugin }, | ||
rules: { | ||
"@cspell/spellchecker": [ | ||
"warn", | ||
{ | ||
configFile: new URL("../cspell.json", import.meta.url).toString(), | ||
cspell: {}, | ||
}, | ||
], | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import type { Linter } from "eslint" | ||
import { fixupPluginRules } from "@eslint/compat" | ||
import { flatConfigs } from "eslint-plugin-import" | ||
import unusedImportsPlugin from "eslint-plugin-unused-imports" | ||
import { sharedFiles } from "./shared" | ||
|
||
export const importConfigArray: Linter.Config[] = [ | ||
{ | ||
name: "eslint/import/order", | ||
files: sharedFiles, | ||
plugins: { | ||
import: fixupPluginRules(flatConfigs.recommended.plugins.import), | ||
}, | ||
rules: { | ||
"import/consistent-type-specifier-style": ["error", "prefer-top-level"], | ||
}, | ||
settings: { | ||
"import/parsers": { | ||
"@typescript-eslint/parser": [ | ||
".js", | ||
".cjs", | ||
".mjs", | ||
".jsx", | ||
".ts", | ||
".cts", | ||
".mts", | ||
".tsx", | ||
".d.ts", | ||
], | ||
}, | ||
"import/resolver": { | ||
node: true, | ||
typescript: true, | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "eslint/import/unused", | ||
files: sharedFiles, | ||
plugins: { | ||
"unused-imports": unusedImportsPlugin, | ||
}, | ||
rules: { | ||
"unused-imports/no-unused-imports": "error", | ||
}, | ||
}, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export * from "./base" | ||
export * from "./cspell" | ||
export * from "./import" | ||
export * from "./jsx-a11y" | ||
export * from "./next" | ||
export * from "./perfectionist" | ||
export * from "./react" | ||
export * from "./react-hooks" | ||
export * from "./shared" | ||
export * from "./typescript" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import type { Linter } from "eslint" | ||
import jsxA11yPlugin from "eslint-plugin-jsx-a11y" | ||
import { sharedFiles } from "./shared" | ||
|
||
export const jsxA11yConfig: Linter.Config = { | ||
name: "eslint/jsx-a11y", | ||
files: sharedFiles, | ||
plugins: { | ||
"jsx-a11y": jsxA11yPlugin, | ||
}, | ||
rules: { | ||
...jsxA11yPlugin.configs.recommended.rules, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import type { Linter } from "eslint" | ||
import { fixupPluginRules } from "@eslint/compat" | ||
import nextPlugin from "@next/eslint-plugin-next" | ||
import { sharedFiles } from "./shared" | ||
|
||
export const nextConfig: Linter.Config = { | ||
name: "eslint/next", | ||
files: sharedFiles, | ||
plugins: { | ||
"@next/next": fixupPluginRules(nextPlugin), | ||
}, | ||
rules: { | ||
...nextPlugin.configs.recommended.rules, | ||
...nextPlugin.configs["core-web-vitals"].rules, | ||
"@next/next/no-assign-module-variable": "off", | ||
"@next/next/no-title-in-document-head": "off", | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
import type { TSESLint } from "@typescript-eslint/utils" | ||
import perfectionistPlugin from "eslint-plugin-perfectionist" | ||
import { sharedFiles } from "./shared" | ||
|
||
const type = "natural" | ||
|
||
const semanticSizes = { | ||
base: "base", | ||
"9xs": "9xs", | ||
"8xs": "8xs", | ||
"7xs": "7xs", | ||
"6xs": "6xs", | ||
"5xs": "5xs", | ||
"4xs": "4xs", | ||
"3xs": "3xs", | ||
"2xs": ["2xs", "hairline", "ultra-fast"], | ||
xs: ["xs", "thin", "tighter", "faster", "shorter"], | ||
sm: ["sm", "light", "tight", "fast", "short"], | ||
md: ["md", "normal"], | ||
lg: ["lg", "medium", "wide", "slow", "tall"], | ||
xl: ["xl", "semibold", "wider", "slower", "taller"], | ||
"2xl": ["2xl", "bold", "widest", "ultra-slow"], | ||
"3xl": ["3xl", "extrabold"], | ||
"4xl": ["4xl", "black"], | ||
"5xl": "5xl", | ||
"6xl": "6xl", | ||
"7xl": "7xl", | ||
"8xl": "8xl", | ||
"9xl": "9xl", | ||
} | ||
|
||
const sortObjectGroups = { | ||
customGroups: { | ||
aria: "aria-*", | ||
callback: "on*", | ||
data: "data-*", | ||
internal: "__*", | ||
primary: ["key", "ref", "id", "lang"], | ||
props: "*Props", | ||
pseudos: "_*", | ||
quaternary: ["className", "alt"], | ||
quinary: ["css", "sx", "style"], | ||
secondary: ["as", "form", "type", "htmlFor"], | ||
senary: ["layerStyle", "textStyle", "baseStyle", "apply"], | ||
septenary: ["variant", "size", "colorScheme"], | ||
tertiary: ["name", "src", "srcSet", "href", "target"], | ||
...semanticSizes, | ||
}, | ||
groups: [ | ||
"primary", | ||
"secondary", | ||
"tertiary", | ||
"quaternary", | ||
"quinary", | ||
"senary", | ||
"septenary", | ||
...Object.keys(semanticSizes), | ||
["aria", "data"], | ||
"unknown", | ||
"pseudos", | ||
"props", | ||
"callback", | ||
"internal", | ||
], | ||
} | ||
|
||
export const perfectionistConfig: TSESLint.FlatConfig.Config = { | ||
name: "eslint/perfectionist", | ||
files: sharedFiles, | ||
plugins: { perfectionist: perfectionistPlugin }, | ||
rules: { | ||
"perfectionist/sort-exports": ["error", { type }], | ||
"perfectionist/sort-imports": [ | ||
"error", | ||
{ | ||
type, | ||
groups: [ | ||
"type", | ||
["external-type", "builtin-type", "internal-type"], | ||
["parent-type", "sibling-type", "index-type"], | ||
["builtin", "external"], | ||
"internal", | ||
["parent", "sibling", "index"], | ||
"object", | ||
"unknown", | ||
["side-effect", "side-effect-style"], | ||
], | ||
newlinesBetween: "never", | ||
}, | ||
], | ||
|
||
"perfectionist/sort-array-includes": ["warn", { type }], | ||
"perfectionist/sort-interfaces": [ | ||
"warn", | ||
{ | ||
type, | ||
groupKind: "required-first", | ||
partitionByNewLine: true, | ||
...sortObjectGroups, | ||
}, | ||
], | ||
"perfectionist/sort-intersection-types": ["warn", { type }], | ||
"perfectionist/sort-jsx-props": [ | ||
"warn", | ||
{ | ||
type, | ||
...sortObjectGroups, | ||
}, | ||
], | ||
"perfectionist/sort-maps": ["warn", { type }], | ||
"perfectionist/sort-named-exports": ["warn", { type }], | ||
"perfectionist/sort-named-imports": ["warn", { type }], | ||
"perfectionist/sort-object-types": [ | ||
"warn", | ||
{ | ||
type, | ||
groupKind: "required-first", | ||
partitionByNewLine: true, | ||
...sortObjectGroups, | ||
}, | ||
], | ||
"perfectionist/sort-objects": [ | ||
"warn", | ||
{ | ||
type, | ||
partitionByNewLine: true, | ||
...sortObjectGroups, | ||
}, | ||
], | ||
"perfectionist/sort-sets": ["warn", { type }], | ||
"perfectionist/sort-union-types": ["warn", { type }], | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import type { Linter } from "eslint" | ||
import { fixupPluginRules } from "@eslint/compat" | ||
import reactHooksPlugin from "eslint-plugin-react-hooks" | ||
import { sharedFiles } from "./shared" | ||
|
||
export const reactHooksConfig: Linter.Config = { | ||
name: "eslint/react-hooks", | ||
files: sharedFiles, | ||
plugins: { "react-hooks": fixupPluginRules(reactHooksPlugin) }, | ||
rules: { | ||
...reactHooksPlugin.configs.recommended.rules, | ||
|
||
"react-hooks/exhaustive-deps": "error", | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import type { Linter } from "eslint" | ||
import reactPlugin from "eslint-plugin-react" | ||
import { sharedFiles } from "./shared" | ||
|
||
export const reactConfig: Linter.Config = { | ||
name: "eslint/react", | ||
files: sharedFiles, | ||
plugins: { react: reactPlugin }, | ||
rules: { | ||
...reactPlugin.configs.recommended.rules, | ||
|
||
"react/no-unescaped-entities": "off", | ||
"react/prop-types": "off", | ||
|
||
"react/forward-ref-uses-ref": "error", | ||
"react/jsx-boolean-value": "error", | ||
"react/jsx-curly-brace-presence": "error", | ||
"react/jsx-fragments": "error", | ||
"react/jsx-no-leaked-render": "error", | ||
"react/jsx-no-useless-fragment": "error", | ||
"react/jsx-pascal-case": "error", | ||
"react/react-in-jsx-scope": "off", | ||
"react/self-closing-comp": "error", | ||
}, | ||
settings: { react: { version: "detect" } }, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export const sharedFiles = [ | ||
"**/*.js", | ||
"**/*.cjs", | ||
"**/*.mjs", | ||
"**/*.jsx", | ||
"**/*.ts", | ||
"**/*.cts", | ||
"**/*.mts", | ||
"**/*.tsx", | ||
"**/*.d.ts", | ||
] |
Oops, something went wrong.