This commit is contained in:
Alex 2024-08-02 23:04:37 -04:00
parent ba20685f2e
commit e5546e21ad
9 changed files with 110 additions and 26 deletions

View File

@ -8,4 +8,4 @@ Personal ESLint config. Guaranteed to have no useless polyfills.
- ✅ [react](https://github.com/jsx-eslint/eslint-plugin-react/pull/3429) - ✅ [react](https://github.com/jsx-eslint/eslint-plugin-react/pull/3429)
- ✅ [unicorn](https://github.com/sindresorhus/eslint-plugin-unicorn/pull/1886) - ✅ [unicorn](https://github.com/sindresorhus/eslint-plugin-unicorn/pull/1886)
- ❌ [import](https://github.com/un-ts/eslint-plugin-import-x/issues/29) - ❌ [import](https://github.com/un-ts/eslint-plugin-import-x/issues/29)
- ❌ [jsx-a11y](https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/issues/978) - ❌ [jsx-a11y](https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/issues/978, supports flat config)

9
dist/package.json vendored
View File

@ -1,9 +1,10 @@
{ {
"name": "@aet/eslint-rules", "name": "@aet/eslint-rules",
"version": "1.0.1-beta.13", "version": "1.0.1-beta.15",
"license": "UNLICENSED", "license": "UNLICENSED",
"bin": { "bin": {
"eslint-install": "./install.js" "eslint-install": "install.js",
"eslint-print": "print-config.sh"
}, },
"peerDependencies": { "peerDependencies": {
"eslint": "^8.57.0", "eslint": "^8.57.0",
@ -19,7 +20,7 @@
"@typescript-eslint/parser": "^8.0.0", "@typescript-eslint/parser": "^8.0.0",
"@typescript-eslint/type-utils": "^8.0.0", "@typescript-eslint/type-utils": "^8.0.0",
"@typescript-eslint/utils": "^8.0.0", "@typescript-eslint/utils": "^8.0.0",
"@eslint-react/eslint-plugin": "^1.8.0", "@eslint-react/eslint-plugin": "1.7.1",
"aria-query": "^5.3.0", "aria-query": "^5.3.0",
"axe-core": "^4.10.0", "axe-core": "^4.10.0",
"axobject-query": "4.1.0", "axobject-query": "4.1.0",
@ -63,4 +64,4 @@
"**/is-core-module": "file:./overrides/is-core-module", "**/is-core-module": "file:./overrides/is-core-module",
"**/supports-preserve-symlinks-flag": "file:./overrides/supports-preserve-symlinks-flag" "**/supports-preserve-symlinks-flag": "file:./overrides/supports-preserve-symlinks-flag"
} }
} }

2
dist/print-config.sh vendored Normal file
View File

@ -0,0 +1,2 @@
#!/bin/bash
node -e "console.dir(require('./.eslintrc.js'), { depth: null })"

View File

@ -45,6 +45,7 @@
"picocolors": "^1.0.1", "picocolors": "^1.0.1",
"prettier": "^3.3.3", "prettier": "^3.3.3",
"prop-types": "^15.8.1", "prop-types": "^15.8.1",
"terser": "^5.31.3",
"type-fest": "^4.23.0", "type-fest": "^4.23.0",
"typescript": "^5.5.4" "typescript": "^5.5.4"
}, },

47
pnpm-lock.yaml generated
View File

@ -132,6 +132,9 @@ importers:
prop-types: prop-types:
specifier: ^15.8.1 specifier: ^15.8.1
version: 15.8.1 version: 15.8.1
terser:
specifier: ^5.31.3
version: 5.31.3
type-fest: type-fest:
specifier: ^4.23.0 specifier: ^4.23.0
version: 4.23.0 version: 4.23.0
@ -923,6 +926,9 @@ packages:
resolution: {integrity: sha512-R8gLRTZeyp03ymzP/6Lil/28tGeGEzhx1q2k703KGWRAI1VdvPIXdG70VJc2pAMw3NA6JKL5hhFu1sJX0Mnn/A==} resolution: {integrity: sha512-R8gLRTZeyp03ymzP/6Lil/28tGeGEzhx1q2k703KGWRAI1VdvPIXdG70VJc2pAMw3NA6JKL5hhFu1sJX0Mnn/A==}
engines: {node: '>=6.0.0'} engines: {node: '>=6.0.0'}
'@jridgewell/source-map@0.3.6':
resolution: {integrity: sha512-1ZJTZebgqllO79ue2bm3rIGud/bOe0pP5BjSRCRxxYkEZS8STV7zN84UBbiYu7jy+eCKSnVIUgoWWE/tt+shMQ==}
'@jridgewell/sourcemap-codec@1.5.0': '@jridgewell/sourcemap-codec@1.5.0':
resolution: {integrity: sha512-gv3ZRaISU3fjPAgNsriBRqGWQL6quFx04YMPW/zD8XMLsU32mhCCbfbO6KZFLjvYpCZ8zyDEgqsgf+PwPaM7GQ==} resolution: {integrity: sha512-gv3ZRaISU3fjPAgNsriBRqGWQL6quFx04YMPW/zD8XMLsU32mhCCbfbO6KZFLjvYpCZ8zyDEgqsgf+PwPaM7GQ==}
@ -1158,6 +1164,9 @@ packages:
engines: {node: ^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7} engines: {node: ^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7}
hasBin: true hasBin: true
buffer-from@1.1.2:
resolution: {integrity: sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==}
call-me-maybe@1.0.2: call-me-maybe@1.0.2:
resolution: {integrity: sha512-HpX65o1Hnr9HH25ojC1YGs7HCQLq0GCOibSaWER0eNpgJ/Z1MZv2mTc7+xh6WOPxbRVcmgbv4hGU+uSQ/2xFZQ==} resolution: {integrity: sha512-HpX65o1Hnr9HH25ojC1YGs7HCQLq0GCOibSaWER0eNpgJ/Z1MZv2mTc7+xh6WOPxbRVcmgbv4hGU+uSQ/2xFZQ==}
@ -1197,6 +1206,9 @@ packages:
color-name@1.1.4: color-name@1.1.4:
resolution: {integrity: sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==} resolution: {integrity: sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==}
commander@2.20.3:
resolution: {integrity: sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==}
common-path-prefix@3.0.0: common-path-prefix@3.0.0:
resolution: {integrity: sha512-QE33hToZseCH3jS0qN96O/bSh3kaw/h+Tq7ngyY9eWDUnTlTNUyqfqvCXioLe5Na5jFsL78ra/wuBU4iuEgd4w==} resolution: {integrity: sha512-QE33hToZseCH3jS0qN96O/bSh3kaw/h+Tq7ngyY9eWDUnTlTNUyqfqvCXioLe5Na5jFsL78ra/wuBU4iuEgd4w==}
@ -1782,6 +1794,13 @@ packages:
resolution: {integrity: sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==} resolution: {integrity: sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==}
engines: {node: '>=8'} engines: {node: '>=8'}
source-map-support@0.5.21:
resolution: {integrity: sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==}
source-map@0.6.1:
resolution: {integrity: sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==}
engines: {node: '>=0.10.0'}
stable-hash@0.0.4: stable-hash@0.0.4:
resolution: {integrity: sha512-LjdcbuBeLcdETCrPn9i8AYAZ1eCtu4ECAWtP7UleOiZ9LzVxRzzUZEoZ8zB24nhkQnDWyET0I+3sWokSDS3E7g==} resolution: {integrity: sha512-LjdcbuBeLcdETCrPn9i8AYAZ1eCtu4ECAWtP7UleOiZ9LzVxRzzUZEoZ8zB24nhkQnDWyET0I+3sWokSDS3E7g==}
@ -1813,6 +1832,11 @@ packages:
resolution: {integrity: sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==} resolution: {integrity: sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==}
engines: {node: '>= 0.4'} engines: {node: '>= 0.4'}
terser@5.31.3:
resolution: {integrity: sha512-pAfYn3NIZLyZpa83ZKigvj6Rn9c/vd5KfYGX7cN1mnzqgDcxWvrU5ZtAfIKhEXz9nRecw4z3LXkjaq96/qZqAA==}
engines: {node: '>=10'}
hasBin: true
text-table@0.2.0: text-table@0.2.0:
resolution: {integrity: sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==} resolution: {integrity: sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==}
@ -2843,6 +2867,11 @@ snapshots:
'@jridgewell/set-array@1.2.1': {} '@jridgewell/set-array@1.2.1': {}
'@jridgewell/source-map@0.3.6':
dependencies:
'@jridgewell/gen-mapping': 0.3.5
'@jridgewell/trace-mapping': 0.3.25
'@jridgewell/sourcemap-codec@1.5.0': {} '@jridgewell/sourcemap-codec@1.5.0': {}
'@jridgewell/trace-mapping@0.3.25': '@jridgewell/trace-mapping@0.3.25':
@ -3131,6 +3160,8 @@ snapshots:
node-releases: 2.0.18 node-releases: 2.0.18
update-browserslist-db: 1.1.0(browserslist@4.23.3) update-browserslist-db: 1.1.0(browserslist@4.23.3)
buffer-from@1.1.2: {}
call-me-maybe@1.0.2: {} call-me-maybe@1.0.2: {}
callsites@3.1.0: {} callsites@3.1.0: {}
@ -3168,6 +3199,8 @@ snapshots:
color-name@1.1.4: {} color-name@1.1.4: {}
commander@2.20.3: {}
common-path-prefix@3.0.0: {} common-path-prefix@3.0.0: {}
concat-map@0.0.1: {} concat-map@0.0.1: {}
@ -3768,6 +3801,13 @@ snapshots:
slash@3.0.0: {} slash@3.0.0: {}
source-map-support@0.5.21:
dependencies:
buffer-from: 1.1.2
source-map: 0.6.1
source-map@0.6.1: {}
stable-hash@0.0.4: {} stable-hash@0.0.4: {}
string-argv@0.3.2: {} string-argv@0.3.2: {}
@ -3794,6 +3834,13 @@ snapshots:
supports-preserve-symlinks-flag@1.0.0: {} supports-preserve-symlinks-flag@1.0.0: {}
terser@5.31.3:
dependencies:
'@jridgewell/source-map': 0.3.6
acorn: 8.12.1
commander: 2.20.3
source-map-support: 0.5.21
text-table@0.2.0: {} text-table@0.2.0: {}
tmp@0.0.33: tmp@0.0.33:

View File

@ -6,6 +6,7 @@ import esbuild from 'esbuild';
import type { Plugin } from 'esbuild'; import type { Plugin } from 'esbuild';
import { memoize } from 'lodash'; import { memoize } from 'lodash';
import { gray, green } from 'picocolors'; import { gray, green } from 'picocolors';
import { minify_sync } from 'terser';
import { dependencies } from '../dist/package.json'; import { dependencies } from '../dist/package.json';
import { buildLocalRules } from './build-local-rules'; import { buildLocalRules } from './build-local-rules';
import { dts } from './dts'; import { dts } from './dts';
@ -65,15 +66,15 @@ if (process.env.DEBUG) {
}); });
} }
function bundle( async function bundle(
entry: string, entry: string,
outfile = entry outfile = entry
.replace('./packages/', './dist/') .replace('./packages/', './dist/')
.replace('src/', '') .replace('src/', '')
.replace('.ts', '.js'), .replace('.ts', '.js'),
options?: esbuild.BuildOptions, options?: esbuild.BuildOptions & { treeShaking?: boolean },
) { ) {
return esbuild.build({ const output = await esbuild.build({
entryPoints: [entry], entryPoints: [entry],
outfile, outfile,
bundle: true, bundle: true,
@ -90,6 +91,30 @@ function bundle(
}, },
...options, ...options,
}); });
if (options?.treeShaking) {
const [text, setText] = await useText(outfile);
const minified = minify_sync(text, {
module: true,
compress: {
conditionals: true,
dead_code: true,
defaults: false,
evaluate: true,
passes: 3,
pure_new: true,
side_effects: true,
unused: true,
},
mangle: false,
format: {
comments: true,
},
});
setText(minified.code!);
}
return output;
} }
async function editPackageJson() { async function editPackageJson() {
@ -134,6 +159,9 @@ async function main() {
bundleType('./src/prettier.ts', './dist/prettier.d.ts'); bundleType('./src/prettier.ts', './dist/prettier.d.ts');
bundleType('./src/types.ts', './dist/types.d.ts'); bundleType('./src/types.ts', './dist/types.d.ts');
const unminify = { minify: false };
const treeShake = { treeShaking: true, minify: false };
console.log('Building packages...'); console.log('Building packages...');
await Promise.all([ await Promise.all([
bundle('./packages/eslint-plugin-jsx-a11y/src/index.js'), bundle('./packages/eslint-plugin-jsx-a11y/src/index.js'),
@ -142,10 +170,10 @@ async function main() {
bundle('./packages/eslint-import-resolver-typescript/src/index.ts'), bundle('./packages/eslint-import-resolver-typescript/src/index.ts'),
bundle('./src/rules/index.ts', './dist/eslint-plugin-rules/index.js'), bundle('./src/rules/index.ts', './dist/eslint-plugin-rules/index.js'),
bundle('./src/local/index.ts', './dist/eslint-plugin-local/index.js'), bundle('./src/local/index.ts', './dist/eslint-plugin-local/index.js'),
bundle('./src/index.ts', './dist/index.js'), bundle('./src/index.ts', './dist/index.js', unminify),
bundle('./src/types.ts', './dist/types.js'), bundle('./src/types.ts', './dist/types.js', unminify),
bundle('./src/prettier.ts', './dist/prettier.js'), bundle('./src/prettier.ts', './dist/prettier.js', unminify),
bundle('./src/install.ts', './dist/install.js', { minify: false }), bundle('./src/install.ts', './dist/install.js', treeShake),
editPackageJson(), editPackageJson(),
]); ]);

View File

@ -6,39 +6,48 @@ import { tailwind } from './presets/tailwind';
import { reactQuery } from './presets/misc'; import { reactQuery } from './presets/misc';
import { testingLibrary } from './presets/testing-library'; import { testingLibrary } from './presets/testing-library';
const middlewares = {
react,
reactRefresh,
tailwind,
storybook,
reactQuery,
testingLibrary,
};
export const envs: { export const envs: {
dependency: string; dependency: string;
eslintPlugin?: string; eslintPlugin?: string;
middleware: Middleware; middleware: keyof typeof middlewares;
}[] = [ }[] = [
{ {
dependency: 'react', dependency: 'react',
middleware: react, middleware: 'react',
}, },
{ {
dependency: '@vitejs/plugin-react', dependency: '@vitejs/plugin-react',
eslintPlugin: 'eslint-plugin-react-refresh', eslintPlugin: 'eslint-plugin-react-refresh',
middleware: reactRefresh, middleware: 'reactRefresh',
}, },
{ {
dependency: 'tailwindcss', dependency: 'tailwindcss',
eslintPlugin: 'eslint-plugin-tailwindcss', eslintPlugin: 'eslint-plugin-tailwindcss',
middleware: tailwind, middleware: 'tailwind',
}, },
{ {
dependency: 'storybook', dependency: 'storybook',
eslintPlugin: 'eslint-plugin-storybook', eslintPlugin: 'eslint-plugin-storybook',
middleware: storybook, middleware: 'storybook',
}, },
{ {
dependency: '@tanstack/react-query', dependency: '@tanstack/react-query',
eslintPlugin: '@tanstack/eslint-plugin-query', eslintPlugin: '@tanstack/eslint-plugin-query',
middleware: reactQuery, middleware: 'reactQuery',
}, },
{ {
dependency: '@testing-library/react', dependency: '@testing-library/react',
eslintPlugin: 'eslint-plugin-testing-library', eslintPlugin: 'eslint-plugin-testing-library',
middleware: testingLibrary, middleware: 'testingLibrary',
}, },
]; ];
@ -64,7 +73,7 @@ export function* checkEnv(): Generator<Middleware> {
for (const { dependency, eslintPlugin, middleware } of envs) { for (const { dependency, eslintPlugin, middleware } of envs) {
if (deps.has(dependency) && (!eslintPlugin || deps.has(eslintPlugin))) { if (deps.has(dependency) && (!eslintPlugin || deps.has(eslintPlugin))) {
yield middleware; yield middlewares[middleware];
} }
} }
} }

View File

@ -135,7 +135,7 @@ interface MiddlewareFunctions {
*/ */
export function extendConfig( export function extendConfig(
of: InputConfig & { of: InputConfig & {
middlewares: Middleware[]; middlewares?: Middleware[];
} = { } = {
middlewares: [], middlewares: [],
}, },

View File

@ -9,11 +9,7 @@ const packages = uniq(
.map(_ => _.eslintPlugin!), .map(_ => _.eslintPlugin!),
); );
console.log('Installing missing ESLint plugins:'); console.log('Installing missing ESLint plugins.\n');
for (const pkg of packages) {
console.log(`- ${pkg}`);
}
console.log();
void installPackage(packages, { void installPackage(packages, {
silent: false, silent: false,