mirror of
https://github.com/pmndrs/zustand.git
synced 2025-12-08 19:45:52 +00:00
chore(eslint): migrate to flat config and simplify (#2912)
* chore(package.json): update related eslint library, update script for eslint.config.js
* chore(pnpm-lock.yaml): reflect changes in package.json
* chore(eslint): migrate eslint configuration .eslintrc.json to eslint.config.js
* chore(examples/demo/package.json): update related eslint library, update script for eslint.config.js
* chore(examples/demo/pnpm-lock.yaml): reflect changes in package.json
* chore(examples/demo/eslint): migrate eslint configuration .eslintrc.cjs to eslint.config.js
* style(examples/demo/utils/copy-to-clipboard.js): add global comment for eslint
* chore(eslint): change file extension 'js' to 'mjs'
* chore(package.json): consise 'lint' scripts
* chore(examples/demo): remove eslint.config.js
* chore(examples/demo/package.json): remove libraries associated wiht eslint, update lint script
* chore(examples/demo/pnpm-lock.yaml): reflect changes in package.json
* chore(examples/demo): reflect 'eslint . --fix' changes based on main 'eslint.config.mjs'
* chore(examples/demo/package.json): add libraries associated wiht eslint, update lint script
* chore(examples/demo/pnpm-lock.yaml): reflect changes in package.json
* chore(examples/demo): add eslint.config.js
* chore(package.json): add mjs in 'eslint', 'test:lint' script
* Update eslint.config.mjs
Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com>
* Update examples/demo/eslint.config.js
Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com>
* chore(eslint): remove eslint configuration related to prettier
* chore(package.json): remove eslint-{config,plugin}-prettier
* chore(package.json): add tslib in devDependencies
* chore(eslint): remove duplicate shared-node-browser from globals
* chore(eslint): change 'eslint-import-resolver-alias' to 'eslint-import-resolver-typescript'
* chore(eslint): add 'import/no-named-as-default-member' off
* chore(eslint): remove duplicate rules, rearrange sequentially within a rule
* chore(eslint): remove the ‘off’ settings in ‘eslint-plugin-import’ to ensure clearer usage.
* chore(eslint): remove 'no-console' in rules
* chore(eslint): simplify settings 'import/resolver'
* chore(eslint): remove 'globals' config
* chore(rollup): add 'eslint-disable no-undef'
* chore(package.json): remove 'globals' library
* chore(pnpm-lock.yaml): reflect changes in package.json
* chore(eslint): add 'importPlugin.flatConfigs.recommended'
* chore(eslint): remove duplicate 'languageOptions'
* chore(eslint): remove 'import/extensions', 'import/parsers' to simplify
* chore(eslint): add 'examples/**' in 'ignores'
* chore(package.json): simplify 'lint' scripts
---------
Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com>
This commit is contained in:
parent
ebf2b7ab16
commit
55a7d0a15b
122
.eslintrc.json
122
.eslintrc.json
@ -1,122 +0,0 @@
|
||||
{
|
||||
"env": {
|
||||
"browser": true,
|
||||
"shared-node-browser": true,
|
||||
"node": true,
|
||||
"es6": true
|
||||
},
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"plugin:@typescript-eslint/recommended",
|
||||
"plugin:react/jsx-runtime",
|
||||
"plugin:react-hooks/recommended",
|
||||
"plugin:import/errors",
|
||||
"plugin:import/warnings",
|
||||
"plugin:prettier/recommended"
|
||||
],
|
||||
"plugins": ["react-compiler"],
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 2018,
|
||||
"sourceType": "module",
|
||||
"ecmaFeatures": {
|
||||
"jsx": true
|
||||
}
|
||||
},
|
||||
"rules": {
|
||||
"react-compiler/react-compiler": "warn",
|
||||
"eqeqeq": "error",
|
||||
"no-var": "error",
|
||||
"prefer-const": "error",
|
||||
"curly": ["warn", "multi-line", "consistent"],
|
||||
"no-console": "off",
|
||||
"import/extensions": ["error", "always"],
|
||||
"import/no-unresolved": ["error", { "commonjs": true, "amd": true }],
|
||||
"import/export": "error",
|
||||
"import/no-duplicates": ["error"],
|
||||
"@typescript-eslint/explicit-module-boundary-types": "off",
|
||||
"@typescript-eslint/no-unused-vars": [
|
||||
"warn",
|
||||
{ "argsIgnorePattern": "^_", "varsIgnorePattern": "^_" }
|
||||
],
|
||||
"@typescript-eslint/no-use-before-define": "off",
|
||||
"@typescript-eslint/no-empty-function": "off",
|
||||
"@typescript-eslint/no-explicit-any": "off",
|
||||
"import/namespace": "off",
|
||||
"import/named": "off",
|
||||
"import/order": [
|
||||
"error",
|
||||
{
|
||||
"alphabetize": { "order": "asc", "caseInsensitive": true },
|
||||
"groups": [
|
||||
"builtin",
|
||||
"external",
|
||||
"internal",
|
||||
"parent",
|
||||
"sibling",
|
||||
"index",
|
||||
"object"
|
||||
],
|
||||
"newlines-between": "never",
|
||||
"pathGroups": [
|
||||
{
|
||||
"pattern": "react",
|
||||
"group": "builtin",
|
||||
"position": "before"
|
||||
}
|
||||
],
|
||||
"pathGroupsExcludedImportTypes": ["builtin"]
|
||||
}
|
||||
],
|
||||
"sort-imports": [
|
||||
"error",
|
||||
{
|
||||
"ignoreDeclarationSort": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"settings": {
|
||||
"react": {
|
||||
"version": "detect"
|
||||
},
|
||||
"import/extensions": [".js", ".jsx", ".ts", ".tsx"],
|
||||
"import/parsers": {
|
||||
"@typescript-eslint/parser": [".js", ".jsx", ".ts", ".tsx"]
|
||||
},
|
||||
"import/resolver": {
|
||||
"alias": {
|
||||
"extensions": [".js", ".jsx", ".ts", ".tsx"],
|
||||
"map": [
|
||||
["^zustand$", "./src/index.ts"],
|
||||
["zustand", "./src"]
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"overrides": [
|
||||
{
|
||||
"extends": [
|
||||
"plugin:jest-dom/recommended",
|
||||
"plugin:testing-library/react",
|
||||
"plugin:@vitest/legacy-recommended"
|
||||
],
|
||||
"files": ["tests/**/*.ts", "tests/**/*.tsx"],
|
||||
"rules": {
|
||||
"testing-library/no-node-access": "off",
|
||||
"import/extensions": ["error", "never"],
|
||||
"@vitest/expect-expect": "off",
|
||||
"@vitest/consistent-test-it": [
|
||||
"error",
|
||||
{ "fn": "it", "withinDescribe": "it" }
|
||||
],
|
||||
"@typescript-eslint/no-unused-vars": "off"
|
||||
}
|
||||
},
|
||||
{
|
||||
"files": ["./*.js"],
|
||||
"rules": {
|
||||
"@typescript-eslint/no-require-imports": "off"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
103
eslint.config.mjs
Normal file
103
eslint.config.mjs
Normal file
@ -0,0 +1,103 @@
|
||||
import eslint from '@eslint/js'
|
||||
import vitest from '@vitest/eslint-plugin'
|
||||
import importPlugin from 'eslint-plugin-import'
|
||||
import jestDom from 'eslint-plugin-jest-dom'
|
||||
import react from 'eslint-plugin-react'
|
||||
import reactCompiler from 'eslint-plugin-react-compiler'
|
||||
import reactHooks from 'eslint-plugin-react-hooks'
|
||||
import testingLibrary from 'eslint-plugin-testing-library'
|
||||
import tseslint from 'typescript-eslint'
|
||||
|
||||
export default tseslint.config(
|
||||
{
|
||||
ignores: ['**/dist/', 'examples/**'],
|
||||
},
|
||||
eslint.configs.recommended,
|
||||
importPlugin.flatConfigs.recommended,
|
||||
tseslint.configs.recommended,
|
||||
react.configs.flat.recommended,
|
||||
react.configs.flat['jsx-runtime'],
|
||||
{
|
||||
plugins: {
|
||||
'react-compiler': reactCompiler,
|
||||
'react-hooks': reactHooks,
|
||||
},
|
||||
settings: {
|
||||
react: {
|
||||
version: 'detect',
|
||||
},
|
||||
'import/resolver': {
|
||||
typescript: true,
|
||||
},
|
||||
},
|
||||
rules: {
|
||||
eqeqeq: 'error',
|
||||
curly: ['warn', 'multi-line', 'consistent'],
|
||||
'sort-imports': [
|
||||
'error',
|
||||
{
|
||||
ignoreDeclarationSort: true,
|
||||
},
|
||||
],
|
||||
'import/no-unresolved': ['error', { commonjs: true, amd: true }],
|
||||
'import/named': 'off',
|
||||
'import/namespace': 'off',
|
||||
'import/no-named-as-default-member': 'off',
|
||||
'import/no-duplicates': 'error',
|
||||
'import/extensions': ['error', 'always'],
|
||||
'import/order': [
|
||||
'error',
|
||||
{
|
||||
alphabetize: { order: 'asc', caseInsensitive: true },
|
||||
groups: [
|
||||
'builtin',
|
||||
'external',
|
||||
'internal',
|
||||
'parent',
|
||||
'sibling',
|
||||
'index',
|
||||
'object',
|
||||
],
|
||||
'newlines-between': 'never',
|
||||
pathGroups: [
|
||||
{
|
||||
pattern: 'react',
|
||||
group: 'builtin',
|
||||
position: 'before',
|
||||
},
|
||||
],
|
||||
pathGroupsExcludedImportTypes: ['builtin'],
|
||||
},
|
||||
],
|
||||
'@typescript-eslint/no-unused-vars': [
|
||||
'warn',
|
||||
{ argsIgnorePattern: '^_', varsIgnorePattern: '^_' },
|
||||
],
|
||||
'@typescript-eslint/no-explicit-any': 'off',
|
||||
...reactHooks.configs.recommended.rules,
|
||||
'react-compiler/react-compiler': 'warn',
|
||||
},
|
||||
},
|
||||
{
|
||||
files: ['tests/**/*.{ts,tsx}'],
|
||||
...testingLibrary.configs['flat/react'],
|
||||
...jestDom.configs['flat/recommended'],
|
||||
...vitest.configs.recommended,
|
||||
rules: {
|
||||
'import/extensions': ['error', 'never'],
|
||||
'testing-library/no-node-access': 'off',
|
||||
'vitest/expect-expect': 'off',
|
||||
'vitest/consistent-test-it': [
|
||||
'error',
|
||||
{ fn: 'it', withinDescribe: 'it' },
|
||||
],
|
||||
'@typescript-eslint/no-unused-vars': 'off',
|
||||
},
|
||||
},
|
||||
{
|
||||
files: ['*.js'],
|
||||
rules: {
|
||||
'@typescript-eslint/no-require-imports': 'off',
|
||||
},
|
||||
},
|
||||
)
|
||||
@ -1,16 +0,0 @@
|
||||
/* eslint-env node */
|
||||
|
||||
module.exports = {
|
||||
root: true,
|
||||
env: { browser: true, es2020: true },
|
||||
extends: ['eslint:recommended', 'plugin:react/recommended', 'plugin:react/jsx-runtime', 'plugin:react-hooks/recommended'],
|
||||
parserOptions: { ecmaVersion: 'latest', sourceType: 'module' },
|
||||
settings: { react: { version: '18.2' } },
|
||||
plugins: ['react-refresh'],
|
||||
rules: {
|
||||
'react-refresh/only-export-components': ['warn', { allowConstantExport: true }],
|
||||
'react/prop-types': 0,
|
||||
'import/extensions': ['off'],
|
||||
'react/no-unknown-property': ['off'],
|
||||
},
|
||||
}
|
||||
44
examples/demo/eslint.config.js
Normal file
44
examples/demo/eslint.config.js
Normal file
@ -0,0 +1,44 @@
|
||||
import eslint from '@eslint/js'
|
||||
import react from 'eslint-plugin-react'
|
||||
import reactHooks from 'eslint-plugin-react-hooks'
|
||||
import reactRefresh from 'eslint-plugin-react-refresh'
|
||||
import globals from 'globals'
|
||||
|
||||
export default [
|
||||
{
|
||||
ignores: ['dist'],
|
||||
},
|
||||
eslint.configs.recommended,
|
||||
react.configs.flat.recommended,
|
||||
react.configs.flat['jsx-runtime'],
|
||||
{
|
||||
languageOptions: {
|
||||
globals: {
|
||||
...globals.browser,
|
||||
...globals.es2020,
|
||||
},
|
||||
parserOptions: {
|
||||
ecmaVersion: 'latest',
|
||||
sourceType: 'module',
|
||||
},
|
||||
},
|
||||
plugins: {
|
||||
'react-hooks': reactHooks,
|
||||
'react-refresh': reactRefresh,
|
||||
},
|
||||
settings: {
|
||||
react: {
|
||||
version: 'detect',
|
||||
},
|
||||
},
|
||||
rules: {
|
||||
...reactHooks.configs.recommended.rules,
|
||||
'react-refresh/only-export-components': [
|
||||
'warn',
|
||||
{ allowConstantExport: true },
|
||||
],
|
||||
'react/prop-types': 'off',
|
||||
'react/no-unknown-property': ['off'],
|
||||
},
|
||||
},
|
||||
]
|
||||
@ -6,7 +6,7 @@
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build",
|
||||
"lint": "eslint src --ext js,jsx --report-unused-disable-directives --max-warnings 0",
|
||||
"lint": "eslint .",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"prettier": {
|
||||
@ -29,13 +29,15 @@
|
||||
"zustand": "^4.3.9"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/js": "^9.17.0",
|
||||
"@types/react": "^18.2.14",
|
||||
"@types/react-dom": "^18.2.6",
|
||||
"@vitejs/plugin-react-swc": "^3.3.2",
|
||||
"eslint": "^8.44.0",
|
||||
"eslint-plugin-react": "^7.32.2",
|
||||
"eslint-plugin-react-hooks": "^4.6.0",
|
||||
"eslint-plugin-react-refresh": "^0.4.1",
|
||||
"eslint": "^9.17.0",
|
||||
"eslint-plugin-react": "^7.37.2",
|
||||
"eslint-plugin-react-hooks": "^5.1.0",
|
||||
"eslint-plugin-react-refresh": "^0.4.16",
|
||||
"globals": "^15.14.0",
|
||||
"vite": "^4.4.0"
|
||||
}
|
||||
}
|
||||
|
||||
1161
examples/demo/pnpm-lock.yaml
generated
1161
examples/demo/pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,5 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import react from '@vitejs/plugin-react-swc'
|
||||
import { defineConfig } from 'vite'
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
|
||||
17
package.json
17
package.json
@ -65,11 +65,11 @@
|
||||
"build:traditional": "rollup -c --config-traditional",
|
||||
"postbuild": "pnpm patch-d-ts && pnpm copy && pnpm patch-old-ts && pnpm patch-esm-ts",
|
||||
"prettier": "prettier \"*.{js,json,md}\" \"{examples,src,tests,docs}/**/*.{js,jsx,ts,tsx,md,mdx}\" --write",
|
||||
"eslint": "eslint --no-eslintrc --c .eslintrc.json --fix '*.{js,ts}' '{src,tests}/**/*.{ts,tsx}'",
|
||||
"eslint": "eslint . --fix",
|
||||
"test": "pnpm run '/^test:.*/'",
|
||||
"test:format": "prettier '*.{js,json,md}' '{examples,src,tests,docs}/**/*.{js,jsx,ts,tsx,md,mdx}' --list-different",
|
||||
"test:types": "tsc --noEmit",
|
||||
"test:lint": "eslint --no-eslintrc --c .eslintrc.json '*.{js,ts}' '{src,tests}/**/*.{ts,tsx}'",
|
||||
"test:lint": "eslint .",
|
||||
"test:spec": "vitest run",
|
||||
"patch-d-ts": "node -e \"var {entries}=require('./rollup.config.js');require('shelljs').find('dist/**/*.d.ts').forEach(f=>{entries.forEach(({find,replacement})=>require('shelljs').sed('-i',new RegExp(' from \\''+find.source.slice(0,-1)+'\\';$'),' from \\''+replacement+'\\';',f));require('shelljs').sed('-i',/ from '(\\.[^']+)\\.ts';$/,' from \\'\\$1\\';',f)})\"",
|
||||
"copy": "shx cp -r dist/src/* dist/esm && shx cp -r dist/src/* dist && shx rm -rf dist/src && shx rm -rf dist/{src,tests} && shx cp package.json readme.md LICENSE dist && json -I -f dist/package.json -e \"this.private=false; this.devDependencies=undefined; this.optionalDependencies=undefined; this.scripts=undefined; this.prettier=undefined;\"",
|
||||
@ -107,6 +107,7 @@
|
||||
"homepage": "https://github.com/pmndrs/zustand",
|
||||
"packageManager": "pnpm@8.15.0",
|
||||
"devDependencies": {
|
||||
"@eslint/js": "^9.17.0",
|
||||
"@redux-devtools/extension": "^3.3.0",
|
||||
"@rollup/plugin-alias": "^5.1.1",
|
||||
"@rollup/plugin-node-resolve": "^15.3.0",
|
||||
@ -118,21 +119,17 @@
|
||||
"@types/react": "^18.3.12",
|
||||
"@types/react-dom": "^18.3.1",
|
||||
"@types/use-sync-external-store": "^0.0.6",
|
||||
"@typescript-eslint/eslint-plugin": "^8.17.0",
|
||||
"@typescript-eslint/parser": "^8.17.0",
|
||||
"@vitest/coverage-v8": "^2.1.8",
|
||||
"@vitest/eslint-plugin": "^1.1.14",
|
||||
"@vitest/ui": "^2.1.8",
|
||||
"esbuild": "^0.24.0",
|
||||
"eslint": "8.57.0",
|
||||
"eslint-config-prettier": "^9.1.0",
|
||||
"eslint-import-resolver-alias": "^1.1.2",
|
||||
"eslint": "9.17.0",
|
||||
"eslint-import-resolver-typescript": "^3.7.0",
|
||||
"eslint-plugin-import": "^2.31.0",
|
||||
"eslint-plugin-jest-dom": "^5.5.0",
|
||||
"eslint-plugin-prettier": "^5.2.1",
|
||||
"eslint-plugin-react": "^7.37.2",
|
||||
"eslint-plugin-react-compiler": "19.0.0-beta-df7b47d-20241124",
|
||||
"eslint-plugin-react-hooks": "^5.0.0",
|
||||
"eslint-plugin-react-hooks": "^5.1.0",
|
||||
"eslint-plugin-testing-library": "^7.0.0",
|
||||
"immer": "^10.1.1",
|
||||
"jsdom": "^25.0.1",
|
||||
@ -145,7 +142,9 @@
|
||||
"rollup-plugin-esbuild": "^6.1.1",
|
||||
"shelljs": "^0.8.5",
|
||||
"shx": "^0.3.4",
|
||||
"tslib": "^2.8.1",
|
||||
"typescript": "^5.7.2",
|
||||
"typescript-eslint": "^8.18.0",
|
||||
"use-sync-external-store": "^1.2.2",
|
||||
"vitest": "^2.1.8"
|
||||
},
|
||||
|
||||
726
pnpm-lock.yaml
generated
726
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -1,3 +1,4 @@
|
||||
/* eslint-disable no-undef */
|
||||
const path = require('path')
|
||||
const alias = require('@rollup/plugin-alias')
|
||||
const resolve = require('@rollup/plugin-node-resolve')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user