Skip to content

Commit

Permalink
feat(eslint): update to eslint@9 and use flat config
Browse files Browse the repository at this point in the history
  • Loading branch information
tomgao365 committed Dec 6, 2024
1 parent fb1355c commit ae23458
Show file tree
Hide file tree
Showing 22 changed files with 1,210 additions and 1,261 deletions.
18 changes: 0 additions & 18 deletions .eslintignore

This file was deleted.

7 changes: 0 additions & 7 deletions .eslintrc.cjs

This file was deleted.

Empty file modified .husky/commit-msg
100644 → 100755
Empty file.
Empty file modified .husky/pre-commit
100644 → 100755
Empty file.
9 changes: 9 additions & 0 deletions eslint.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const eslint = require('@tomjs/eslint');

/**
* @type {import('eslint').Linter.Config[]}
*/
module.exports = [
...eslint,
{ ignores: ['public', 'dist', 'build', 'packages/*/es', 'packages/*/lib'] },
];
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@
"scripts": {
"build": "pnpm -r --stream --filter=@tomjs/* build",
"lint": "run-s lint:eslint lint:prettier",
"lint:eslint": "eslint \"packages/**/*.{js,cjs,ts}\" *.{js,cjs,ts} --fix --cache",
"lint:prettier": "prettier --write \"packages/**/*.{js,cjs,ts,json,md}\" *.{js,cjs,ts,json,md}",
"lint:eslint": "eslint \"packages/**/*.{js,cjs,ts}\" *.cjs --fix --cache",
"lint:prettier": "prettier --write \"packages/**/*.{cjs,ts,json,md}\" *.{cjs,json,md}",
"prepare": "husky",
"postinstall": "pnpm -r --stream --filter=@tomjs/commitlint --filter=@tomjs/eslint --filter=@tomjs/prettier build"
},
"devDependencies": {
"@commitlint/cli": "^19.3.0",
"@commitlint/cli": "^19.6.0",
"@tomjs/commitlint": "workspace:^",
"@tomjs/eslint": "workspace:^",
"@tomjs/prettier": "workspace:^",
"@tomjs/tsconfig": "workspace:^",
"@types/node": "^18.19.33",
"eslint": "^8.57.0",
"husky": "^9.0.11",
"lint-staged": "^15.2.2",
"@types/node": "^18.19.67",
"eslint": "^9.16.0",
"husky": "^9.1.7",
"lint-staged": "^15.2.10",
"npm-run-all": "^4.1.5",
"prettier": "^3.2.5",
"rimraf": "^5.0.7",
"prettier": "^3.4.2",
"rimraf": "^5.0.10",
"typescript": "^5.4.5",
"vite": "^4.5.3",
"vite-plugin-build": "^0.10.0"
Expand Down
30 changes: 15 additions & 15 deletions packages/eslint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,28 +72,28 @@
}
},
"scripts": {
"build": "npm run clean && vite build",
"clean": "rimraf ./es ./lib",
"build": "vite build",
"prepublishOnly": "pnpm build"
},
"dependencies": {
"@typescript-eslint/eslint-plugin": "^7.14.1",
"@typescript-eslint/parser": "^7.14.1",
"@eslint/js": "^9.16.0",
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-n": "^17.9.0",
"eslint-import-resolver-typescript": "^3.7.0",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-n": "^17.14.0",
"eslint-plugin-node-import": "^1.0.4",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-react": "^7.34.3",
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-react-refresh": "^0.4.7",
"eslint-plugin-simple-import-sort": "^12.1.0",
"eslint-plugin-vue": "^9.26.0",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-react": "^7.37.2",
"eslint-plugin-react-hooks": "^5.1.0",
"eslint-plugin-react-refresh": "^0.4.16",
"eslint-plugin-simple-import-sort": "^12.1.1",
"eslint-plugin-vue": "^9.32.0",
"globals": "^15.13.0",
"typescript-eslint": "^8.17.0",
"vue-eslint-parser": "^9.4.3"
},
"peerDependencies": {
"eslint": "^8.56.0",
"eslint": "^9.0.0",
"prettier": "^3.0.0",
"react": ">=17",
"typescript": "*"
Expand All @@ -107,7 +107,7 @@
}
},
"engines": {
"node": "^18.18.0 || >=20.0.0"
"node": "^18.18.0 || ^20.9.0 || >=21.1.0"
},
"devDependencies": {
"eslint-define-config": "^2.1.0"
Expand Down
35 changes: 35 additions & 0 deletions packages/eslint/src/globs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
export const GLOB_EXCLUDE = [
'**/node_modules',
'**/dist',
'**/package-lock.json',
'**/yarn.lock',
'**/pnpm-lock.yaml',
'**/bun.lockb',

'**/output',
'**/coverage',
'**/temp',
'**/.temp',
'**/tmp',
'**/.tmp',
'**/.history',
'**/.vitepress/cache',
'**/.nuxt',
'**/.next',
'**/.svelte-kit',
'**/.vercel',
'**/.changeset',
'**/.idea',
'**/.cache',
'**/.output',
'**/.vite-inspect',
'**/.yarn',
'**/vite.config.*.timestamp-*',

'**/CHANGELOG*.md',
'**/*.min.*',
'**/LICENSE*',
'**/__snapshots__',
'**/auto-import?(s).d.ts',
'**/components.d.ts',
];
33 changes: 33 additions & 0 deletions packages/eslint/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import js from './javascript';
import nodeJs from './node/javascript';
import node from './node/typescript';
import reactJs from './react/javascript';
import react from './react/typescript';
import ts from './typescript';
import vueJs from './vue/javascript';
import vue from './vue/typescript';
import vue2Js from './vue2/javascript';
import vue2 from './vue2/typescript';

export const meta = {
name: '@tomjs/eslint',
version: require('../package.json').version,
};

const configs = {
ts,
js,
node,
'node/js': nodeJs,
vue,
'vue/js': vueJs,
vue2,
'vue2/js': vue2Js,
react,
'react/js': reactJs,
};

export default {
meta,
configs,
};
103 changes: 55 additions & 48 deletions packages/eslint/src/javascript.ts
Original file line number Diff line number Diff line change
@@ -1,53 +1,60 @@
import type { ESLintConfig } from 'eslint-define-config';
import eslint from '@eslint/js';
import type { Linter } from 'eslint';
import importPlugin from 'eslint-plugin-import';
import prettierRecommended from 'eslint-plugin-prettier/recommended';
import simpleImportSort from 'eslint-plugin-simple-import-sort';
import globals from 'globals';
import { GLOB_EXCLUDE } from './globs';

export default {
env: {
es6: true,
},
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
},
plugins: ['import', 'simple-import-sort'],
extends: ['eslint:recommended', 'plugin:prettier/recommended'],
overrides: [
{
env: {
node: true,
},
files: ['.*rc.{js,cjs}'],
parserOptions: {
sourceType: 'script',
},
const config: Linter.Config[] = [
eslint.configs.recommended,
importPlugin.flatConfigs.recommended,
prettierRecommended,
{
plugins: {
'simple-import-sort': simpleImportSort,
},
],
rules: {
/**************************** base ****************************/
'no-unused-vars': [
'error',
{
args: 'after-used',
ignoreRestSiblings: true,
argsIgnorePattern: '^_',
},
],
'no-empty': ['error', { allowEmptyCatch: true }],
rules: {
/**************************** base ****************************/
'no-unused-vars': [
'error',
{
args: 'after-used',
ignoreRestSiblings: true,
argsIgnorePattern: '^_',
},
],
'no-empty': ['error', { allowEmptyCatch: true }],

/************************* import sort *************************/
'simple-import-sort/imports': [
'error',
{
groups: [
['^\\u0000'],
['^node:', '^@?\\w', '^', '^\\.'],
// Style imports.
['^.+\\.(scss|less|css)$'],
],
/************************* import sort *************************/
'simple-import-sort/imports': [
'error',
{
groups: [
['^\\u0000'],
['^node:', '^@?\\w', '^', '^\\.'],
// Style imports.
['^.+\\.(scss|less|css)$'],
],
},
],
'simple-import-sort/exports': 'error',
/************************* import *************************/
'import/first': 'error',
'import/newline-after-import': 'error',
'import/no-duplicates': 'error',
'import/no-unresolved': 'off',
},
ignores: [...GLOB_EXCLUDE],
},
{
files: ['.*rc.{js,cjs,mjs}', '*.config.{js,cjs,mjs}'],
languageOptions: {
globals: {
...globals.node,
},
],
'simple-import-sort/exports': 'error',
'import/first': 'error',
'import/newline-after-import': 'error',
'import/no-duplicates': 'error',
},
},
} as ESLintConfig;
];

export default config;
63 changes: 37 additions & 26 deletions packages/eslint/src/node/javascript.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,39 @@
import type { ESLintConfig } from 'eslint-define-config';
import type { Linter } from 'eslint';
import node from 'eslint-plugin-n';
import nodeImport from 'eslint-plugin-node-import';
import globals from 'globals';
import javascript from '../javascript';

export default {
env: {
node: true,
browser: false,
es6: true,
const config: Linter.Config[] = [
...javascript,
node.configs['flat/recommended'],
{
languageOptions: {
globals: {
...globals.node,
},
},
plugins: {
'node-import': nodeImport,
},
rules: {
// disable rules
'n/shebang': 'off',
'n/hashbang': 'off',
'n/no-process-exit': 'off',
// enable rules
'n/no-path-concat': 'error',
// disallow imports of built-in Node.js modules without the node: prefix
'node-import/prefer-node-protocol': 'error',
// fix bug
'n/no-missing-import': 'off',
'n/no-missing-require': 'off',
'n/no-extraneous-import': 'off',
'n/no-extraneous-require': 'off',
'n/no-unpublished-require': 'off',
'n/no-unpublished-import': 'off',
},
},
extends: ['../javascript', 'plugin:n/recommended'],
plugins: ['node-import'],
rules: {
// disable rules
'n/shebang': 'off',
'n/hashbang': 'off',
'n/no-process-exit': 'off',
// enable rules
'n/no-path-concat': 'error',
// disallow imports of built-in Node.js modules without the node: prefix
'node-import/prefer-node-protocol': 'error',
// fix bug
'n/no-missing-import': 'off',
'n/no-missing-require': 'off',
'n/no-extraneous-import': 'off',
'n/no-extraneous-require': 'off',
'n/no-unpublished-require': 'off',
'n/no-unpublished-import': 'off',
},
} as ESLintConfig;
];

export default config;
15 changes: 6 additions & 9 deletions packages/eslint/src/node/typescript.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import type { ESLintConfig } from 'eslint-define-config';
import type { Linter } from 'eslint';
import typescript from '../typescript';
import javascript from './javascript';

export default {
env: {
node: true,
es6: true,
},
extends: ['./javascript', '../typescript'],
rules: {},
} as ESLintConfig;
const config: Linter.Config[] = [...javascript, ...typescript];

export default config;
Loading

0 comments on commit ae23458

Please sign in to comment.