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

[migrate] upgrade to ESLint 9, Node.js 20 & other latest Upstream packages/actions #16

Merged
merged 12 commits into from
Sep 14, 2024
72 changes: 72 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import globals from 'globals';
import js from '@eslint/js';
import json from '@eslint/json';
import markdown from '@eslint/markdown';
import tseslint from 'typescript-eslint';

import react from 'eslint-plugin-react';
import eslintConfigPrettier from 'eslint-config-prettier';
import simpleImportSort from 'eslint-plugin-simple-import-sort';

export default [
// import sort
{
plugins: {
'simple-import-sort': simpleImportSort
},
rules: {
'simple-import-sort/exports': 'error',
'simple-import-sort/imports': 'error'
}
},
// typescript
Soecka marked this conversation as resolved.
Show resolved Hide resolved
{
files: ['**/*.{ts,tsx}'],
plugins: {
'@typescript-eslint': tseslint.plugin
}
},
// js
Soecka marked this conversation as resolved.
Show resolved Hide resolved
{
name: 'eslint/js',
files: ['**/*.{js,ts,jsx,tsx}'],
languageOptions: { globals: globals.browser },
plugins: { js },
rules: {
'consistent-return': 'error'
}
},
// react
Soecka marked this conversation as resolved.
Show resolved Hide resolved
{
name: 'react-jsx',
files: ['**/*.{js,ts,jsx,tsx}'],
plugins: { react },
rules: {
'react/jsx-no-target-blank': 'warn',
'react/jsx-sort-props': [
'error',
{
reservedFirst: true,
shorthandLast: true,
callbacksLast: true,
noSortAlphabetically: true
}
]
}
},
// JSON files
{
name: 'eslint/json',
files: ['**/*.json', '.c8rc'],
ignores: ['**/package-lock.json'],
language: 'json/json',
plugins: { json }
},
// markdown
Soecka marked this conversation as resolved.
Show resolved Hide resolved
{
files: ['**/*.md'],
language: 'markdown/gfm',
plugins: { markdown }
},
eslintConfigPrettier
];
54 changes: 33 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,52 +5,61 @@
"author": "[email protected]",
"dependencies": {
"@editorjs/code": "^2.9.0",
"@editorjs/editorjs": "^2.29.1",
"@editorjs/header": "^2.8.1",
"@editorjs/image": "^2.9.0",
"@editorjs/editorjs": "^2.30.5",
"@editorjs/header": "^2.8.7",
"@editorjs/image": "^2.9.3",
"@editorjs/link": "^2.6.2",
"@editorjs/list": "^1.9.0",
"@editorjs/paragraph": "^2.11.5",
"@editorjs/quote": "^2.6.0",
"@editorjs/list": "^1.10.0",
"@editorjs/paragraph": "^2.11.6",
"@editorjs/quote": "^2.7.2",
"browser-fs-access": "^0.35.0",
"browser-unhandled-rejection": "^1.0.2",
"echarts-jsx": "^1.2.0",
"echarts-jsx": "^1.2.1",
"editorjs-html": "^3.4.3",
"idea-react": "^2.0.0-rc.2",
"koajax": "^1.1.2",
"koajax": "^3.0.2",
"lodash": "^4.17.21",
"mobx": "^6.12.4",
"mobx": "^6.13.1",
"mobx-github": "^0.3.2",
"mobx-i18n": "^0.5.0",
"mobx-react": "^9.1.1",
"mobx-restful": "^1.0.0",
"mobx-restful-table": "^2.0.0-rc.1",
Soecka marked this conversation as resolved.
Show resolved Hide resolved
"preact": "^10.22.0",
"react-bootstrap": "^2.10.3",
"preact": "^10.23.2",
"react-bootstrap": "^2.10.4",
"react-bootstrap-editor": "^2.0.4",
"react-editor-js": "^2.1.0",
"react-router-class-tools": "^0.1.3",
"react-router-dom": "^6.24.0",
"react-router-dom": "^6.26.1",
"web-utility": "^4.4.0"
},
"devDependencies": {
"@babel/runtime": "^7.24.7",
"@babel/runtime": "^7.25.6",
"@eslint/js": "^9.9.1",
"@eslint/json": "^0.4.0",
"@eslint/markdown": "^6.0.0",
"@parcel/config-default": "~2.12.0",
"@parcel/packager-raw-url": "~2.12.0",
"@parcel/transformer-less": "~2.12.0",
"@parcel/transformer-typescript-tsc": "~2.12.0",
"@parcel/transformer-webmanifest": "~2.12.0",
"@types/lodash": "^4.17.5",
"@types/node": "^18.19.39",
"@types/lodash": "^4.17.7",
"@types/node": "^20.16.2",
Soecka marked this conversation as resolved.
Show resolved Hide resolved
"buffer": "^6.0.3",
"husky": "^9.0.11",
"lint-staged": "^15.2.7",
"eslint": "9.9.1",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-react": "^7.35.0",
"eslint-plugin-simple-import-sort": "^12.1.1",
"globals": "^15.9.0",
"husky": "^9.1.5",
"lint-staged": "^15.2.9",
"parcel": "~2.12.0",
"parcel-transformer-mdx": "^0.3.3",
"prettier": "^3.3.2",
"parcel-transformer-mdx": "^0.4.2",
"prettier": "^3.3.3",
"prismjs": "^1.29.0",
"process": "^0.11.10",
"typescript": "~5.5.2",
"typescript": "~5.5.4",
"typescript-eslint": "^8.4.0",
"workbox-cli": "^7.1.0"
},
"alias": {
Expand All @@ -66,7 +75,10 @@
"tabWidth": 4
},
"lint-staged": {
"*.{html,md,less,json,yml,js,ts,tsx}": "prettier --write"
"*.{html,md,less,json,yml,js,ts,tsx}": [
Soecka marked this conversation as resolved.
Show resolved Hide resolved
"eslint --fix",
"prettier --write"
]
Copy link
Member

Choose a reason for hiding this comment

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

先格式化再检查代码规范会比较好

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 规则通过?

Copy link
Member

Choose a reason for hiding this comment

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

格式不对会影响 eslint 规则通过?

有少数规则会,因为代码越格式规范出问题的概率越小。

Copy link
Contributor Author

@Soecka Soecka Sep 10, 2024

Choose a reason for hiding this comment

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

官方文档推荐写的,一个是代码质量规则,一个是格式化规则,它们的交集也用插件 disable 了,很难想象格式会影响代码质量检查
https://github.com/lint-staged/lint-staged#task-concurrency

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 --fix 出问题都会再过一遍,用 prettier 收尾是正常流程?

},
"browserslist": "> 0.5%, last 2 versions, not dead, IE 11",
"scripts": {
Expand Down
Loading