Compare commits
2 Commits
3ac5f91988
...
e5546e21ad
Author | SHA1 | Date | |
---|---|---|---|
|
e5546e21ad | ||
|
ba20685f2e |
@ -4,8 +4,8 @@ Personal ESLint config. Guaranteed to have no useless polyfills.
|
||||
|
||||
## flat config support
|
||||
|
||||
- ⏱️ [a11y](https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/pull/993)
|
||||
- ⏱️ [a11y](https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/issues/978)
|
||||
- ✅ [react](https://github.com/jsx-eslint/eslint-plugin-react/pull/3429)
|
||||
- ✅ [unicorn](https://github.com/sindresorhus/eslint-plugin-unicorn/pull/1886)
|
||||
- ❌ [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/eslint-plugin-react/index.d.ts
vendored
9
dist/eslint-plugin-react/index.d.ts
vendored
@ -1,9 +0,0 @@
|
||||
import type { Linter } from 'eslint';
|
||||
|
||||
export const deprecatedRules: Readonly<Linter.RulesRecord>;
|
||||
|
||||
export const configs: {
|
||||
recommended: Linter.BaseConfig;
|
||||
all: Linter.BaseConfig;
|
||||
'jsx-runtime': Linter.BaseConfig;
|
||||
};
|
38
dist/package.json
vendored
38
dist/package.json
vendored
@ -1,24 +1,28 @@
|
||||
{
|
||||
"name": "@aet/eslint-rules",
|
||||
"version": "1.0.1-beta.11",
|
||||
"version": "1.0.1-beta.15",
|
||||
"license": "UNLICENSED",
|
||||
"bin": {
|
||||
"eslint-install": "install.js",
|
||||
"eslint-print": "print-config.sh"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"eslint": "^8.57.0",
|
||||
"typescript": "^5.4.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"@nolyfill/is-core-module": "^1.0.39",
|
||||
"@aet/eslint-define-config": "^0.1.0-beta.15",
|
||||
"@aet/eslint-define-config": "^0.1.0-beta.16",
|
||||
"@eslint-community/eslint-utils": "^4.4.0",
|
||||
"@tanstack/eslint-plugin-query": "^5.51.15",
|
||||
"@types/eslint": "^8.56.11",
|
||||
"@typescript-eslint/eslint-plugin": "^7.17.0",
|
||||
"@typescript-eslint/parser": "^7.17.0",
|
||||
"@typescript-eslint/type-utils": "^7.17.0",
|
||||
"@typescript-eslint/utils": "^7.17.0",
|
||||
"@eslint-react/eslint-plugin": "^1.6.0",
|
||||
"@types/eslint": "^9.6.0",
|
||||
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
||||
"@typescript-eslint/parser": "^8.0.0",
|
||||
"@typescript-eslint/type-utils": "^8.0.0",
|
||||
"@typescript-eslint/utils": "^8.0.0",
|
||||
"@eslint-react/eslint-plugin": "1.7.1",
|
||||
"aria-query": "^5.3.0",
|
||||
"axe-core": "^4.9.1",
|
||||
"axe-core": "^4.10.0",
|
||||
"axobject-query": "4.1.0",
|
||||
"damerau-levenshtein": "1.0.8",
|
||||
"debug": "^4.3.6",
|
||||
@ -30,7 +34,7 @@
|
||||
"eslint-module-utils": "^2.8.1",
|
||||
"eslint-plugin-es-x": "^8.0.0",
|
||||
"eslint-plugin-import-x": "^3.1.0",
|
||||
"eslint-plugin-jsdoc": "^48.8.3",
|
||||
"eslint-plugin-jsdoc": "^48.11.0",
|
||||
"eslint-plugin-react-refresh": "^0.4.9",
|
||||
"eslint-plugin-unicorn": "^55.0.0",
|
||||
"esprima": "^4.0.1",
|
||||
@ -43,9 +47,15 @@
|
||||
"is-glob": "^4.0.3",
|
||||
"language-tags": "^1.0.9",
|
||||
"lodash": "^4.17.21",
|
||||
"resolve": "^2.0.0-next.5",
|
||||
"minimatch": "^10.0.1",
|
||||
"semver": "^7.6.3"
|
||||
},
|
||||
"pnpm": {
|
||||
"overrides": {
|
||||
"is-core-module": "file:./overrides/is-core-module",
|
||||
"supports-preserve-symlinks-flag": "file:./overrides/supports-preserve-symlinks-flag"
|
||||
}
|
||||
},
|
||||
"overrides": {
|
||||
"is-core-module": "file:./overrides/is-core-module",
|
||||
"supports-preserve-symlinks-flag": "file:./overrides/supports-preserve-symlinks-flag"
|
||||
@ -53,11 +63,5 @@
|
||||
"resolutions": {
|
||||
"**/is-core-module": "file:./overrides/is-core-module",
|
||||
"**/supports-preserve-symlinks-flag": "file:./overrides/supports-preserve-symlinks-flag"
|
||||
},
|
||||
"pnpm": {
|
||||
"overrides": {
|
||||
"is-core-module": "file:./overrides/is-core-module",
|
||||
"supports-preserve-symlinks-flag": "file:./overrides/supports-preserve-symlinks-flag"
|
||||
}
|
||||
}
|
||||
}
|
2
dist/print-config.sh
vendored
Normal file
2
dist/print-config.sh
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
#!/bin/bash
|
||||
node -e "console.dir(require('./.eslintrc.js'), { depth: null })"
|
2
dist/types.d.ts
vendored
2
dist/types.d.ts
vendored
@ -6,7 +6,7 @@ import { Rule } from 'eslint';
|
||||
export declare function defineRules(rules: {
|
||||
[ruleName: string]: Rule.RuleModule | ESLintUtils.RuleModule<string, unknown[]>;
|
||||
}): {
|
||||
[ruleName: string]: Rule.RuleModule | ESLintUtils.RuleModule<string, unknown[], ESLintUtils.RuleListener>;
|
||||
[ruleName: string]: Rule.RuleModule | ESLintUtils.RuleModule<string, unknown[], unknown, ESLintUtils.RuleListener>;
|
||||
};
|
||||
export declare function defineRule({ name, create, ...meta }: Rule.RuleMetaData & {
|
||||
name?: string;
|
||||
|
29
package.json
29
package.json
@ -3,14 +3,16 @@
|
||||
"scripts": {
|
||||
"build": "./scripts/build.ts",
|
||||
"check-import": "./scripts/check-imports.ts",
|
||||
"define": "/usr/local/bin/codium ./packages/eslint-define-config"
|
||||
"define": "/usr/local/bin/codium ./packages/eslint-define-config",
|
||||
"do": "yarn build; (cd dist && ver bump && npm publish)"
|
||||
},
|
||||
"private": true,
|
||||
"devDependencies": {
|
||||
"@aet/eslint-define-config": "^0.1.0-beta.15",
|
||||
"@babel/core": "^7.24.9",
|
||||
"@babel/plugin-transform-flow-strip-types": "^7.24.7",
|
||||
"@babel/preset-env": "^7.25.0",
|
||||
"@aet/eslint-define-config": "^0.1.0-beta.16",
|
||||
"@antfu/install-pkg": "^0.3.3",
|
||||
"@babel/core": "^7.25.2",
|
||||
"@babel/plugin-transform-flow-strip-types": "^7.25.2",
|
||||
"@babel/preset-env": "^7.25.3",
|
||||
"@types/babel-plugin-macros": "^3.1.3",
|
||||
"@types/babel__core": "^7.20.5",
|
||||
"@types/eslint": "^9.6.0",
|
||||
@ -19,12 +21,12 @@
|
||||
"@types/estree": "^1.0.5",
|
||||
"@types/estree-jsx": "^1.0.5",
|
||||
"@types/lodash": "^4.17.7",
|
||||
"@types/node": "^20.14.12",
|
||||
"@typescript-eslint/eslint-plugin": "7.17.0",
|
||||
"@typescript-eslint/type-utils": "^7.17.0",
|
||||
"@typescript-eslint/types": "^7.17.0",
|
||||
"@typescript-eslint/typescript-estree": "^7.17.0",
|
||||
"@typescript-eslint/utils": "^7.17.0",
|
||||
"@types/node": "^22.1.0",
|
||||
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
||||
"@typescript-eslint/type-utils": "^8.0.0",
|
||||
"@typescript-eslint/types": "^8.0.0",
|
||||
"@typescript-eslint/typescript-estree": "^8.0.0",
|
||||
"@typescript-eslint/utils": "^8.0.0",
|
||||
"babel-plugin-macros": "^3.1.0",
|
||||
"dts-bundle-generator": "9.4.0",
|
||||
"esbuild": "0.23.0",
|
||||
@ -43,6 +45,7 @@
|
||||
"picocolors": "^1.0.1",
|
||||
"prettier": "^3.3.3",
|
||||
"prop-types": "^15.8.1",
|
||||
"terser": "^5.31.3",
|
||||
"type-fest": "^4.23.0",
|
||||
"typescript": "^5.5.4"
|
||||
},
|
||||
@ -64,9 +67,9 @@
|
||||
"jsonify": "npm:@nolyfill/jsonify@^1",
|
||||
"object-keys": "npm:@nolyfill/object-keys@^1",
|
||||
"set-function-length": "npm:@nolyfill/set-function-length@^1",
|
||||
"@babel/types": "7.24.0",
|
||||
"@babel/types": "7.25.2",
|
||||
"is-core-module": "npm:@nolyfill/is-core-module@^1",
|
||||
"json-stable-stringify": "npm:@nolyfill/json-stable-stringify@^1"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
1650
pnpm-lock.yaml
generated
1650
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -6,6 +6,7 @@ import esbuild from 'esbuild';
|
||||
import type { Plugin } from 'esbuild';
|
||||
import { memoize } from 'lodash';
|
||||
import { gray, green } from 'picocolors';
|
||||
import { minify_sync } from 'terser';
|
||||
import { dependencies } from '../dist/package.json';
|
||||
import { buildLocalRules } from './build-local-rules';
|
||||
import { dts } from './dts';
|
||||
@ -65,14 +66,15 @@ if (process.env.DEBUG) {
|
||||
});
|
||||
}
|
||||
|
||||
function bundle(
|
||||
async function bundle(
|
||||
entry: string,
|
||||
outfile = entry
|
||||
.replace('./packages/', './dist/')
|
||||
.replace('src/', '')
|
||||
.replace('.ts', '.js'),
|
||||
options?: esbuild.BuildOptions & { treeShaking?: boolean },
|
||||
) {
|
||||
return esbuild.build({
|
||||
const output = await esbuild.build({
|
||||
entryPoints: [entry],
|
||||
outfile,
|
||||
bundle: true,
|
||||
@ -87,7 +89,32 @@ function bundle(
|
||||
banner: {
|
||||
js: '/* eslint-disable */',
|
||||
},
|
||||
...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() {
|
||||
@ -132,6 +159,9 @@ async function main() {
|
||||
bundleType('./src/prettier.ts', './dist/prettier.d.ts');
|
||||
bundleType('./src/types.ts', './dist/types.d.ts');
|
||||
|
||||
const unminify = { minify: false };
|
||||
const treeShake = { treeShaking: true, minify: false };
|
||||
|
||||
console.log('Building packages...');
|
||||
await Promise.all([
|
||||
bundle('./packages/eslint-plugin-jsx-a11y/src/index.js'),
|
||||
@ -140,9 +170,10 @@ async function main() {
|
||||
bundle('./packages/eslint-import-resolver-typescript/src/index.ts'),
|
||||
bundle('./src/rules/index.ts', './dist/eslint-plugin-rules/index.js'),
|
||||
bundle('./src/local/index.ts', './dist/eslint-plugin-local/index.js'),
|
||||
bundle('./src/index.ts', './dist/index.js'),
|
||||
bundle('./src/types.ts', './dist/types.js'),
|
||||
bundle('./src/prettier.ts', './dist/prettier.js'),
|
||||
bundle('./src/index.ts', './dist/index.js', unminify),
|
||||
bundle('./src/types.ts', './dist/types.js', unminify),
|
||||
bundle('./src/prettier.ts', './dist/prettier.js', unminify),
|
||||
bundle('./src/install.ts', './dist/install.js', treeShake),
|
||||
editPackageJson(),
|
||||
]);
|
||||
|
||||
|
@ -3,12 +3,10 @@ import glob from 'fast-glob';
|
||||
import fs from 'fs';
|
||||
import { builtinModules } from 'module';
|
||||
import { uniq } from 'lodash';
|
||||
import { dependencies, peerDependencies, overrides } from '../dist/package.json';
|
||||
import { dependencies, peerDependencies } from '../dist/package.json';
|
||||
|
||||
function checkImports() {
|
||||
const deps = Object.keys({ ...dependencies, ...peerDependencies, ...overrides }).concat(
|
||||
'eslint',
|
||||
);
|
||||
const deps = Object.keys({ ...dependencies, ...peerDependencies }).concat('eslint');
|
||||
const builtIn = new Set(builtinModules.flatMap(module => [module, `node:${module}`]));
|
||||
|
||||
function findRequires(text: string) {
|
||||
|
@ -6,10 +6,10 @@
|
||||
"subject": "[meta] add `repository.directory` field"
|
||||
},
|
||||
"eslint-import-resolver-typescript": {
|
||||
"hash": "c9b5626ee69bd529c7e391e40928a4fb28dce179",
|
||||
"date": "2024-07-23T20:40:14+08:00",
|
||||
"hash": "3dfad602a05b4b3812a4d3fc681051932f86e838",
|
||||
"date": "2024-08-01T01:15:59+00:00",
|
||||
"committer": "GitHub",
|
||||
"subject": "chore: release eslint-import-resolver-typescript (#302)"
|
||||
"subject": "chore(deps): update dependency node to v18.20.4 (#309)"
|
||||
},
|
||||
"eslint-plugin-jsx-a11y": {
|
||||
"hash": "cca288b73a39fa0932a57c02a7a88de68fc971fc",
|
||||
|
72
src/env.ts
72
src/env.ts
@ -4,8 +4,54 @@ import { Middleware, storybook } from './index';
|
||||
import { react, reactRefresh } from './presets/react';
|
||||
import { tailwind } from './presets/tailwind';
|
||||
import { reactQuery } from './presets/misc';
|
||||
import { testingLibrary } from './presets/testing-library';
|
||||
|
||||
export function* checkEnv(): Generator<Middleware> {
|
||||
const middlewares = {
|
||||
react,
|
||||
reactRefresh,
|
||||
tailwind,
|
||||
storybook,
|
||||
reactQuery,
|
||||
testingLibrary,
|
||||
};
|
||||
|
||||
export const envs: {
|
||||
dependency: string;
|
||||
eslintPlugin?: string;
|
||||
middleware: keyof typeof middlewares;
|
||||
}[] = [
|
||||
{
|
||||
dependency: 'react',
|
||||
middleware: 'react',
|
||||
},
|
||||
{
|
||||
dependency: '@vitejs/plugin-react',
|
||||
eslintPlugin: 'eslint-plugin-react-refresh',
|
||||
middleware: 'reactRefresh',
|
||||
},
|
||||
{
|
||||
dependency: 'tailwindcss',
|
||||
eslintPlugin: 'eslint-plugin-tailwindcss',
|
||||
middleware: 'tailwind',
|
||||
},
|
||||
{
|
||||
dependency: 'storybook',
|
||||
eslintPlugin: 'eslint-plugin-storybook',
|
||||
middleware: 'storybook',
|
||||
},
|
||||
{
|
||||
dependency: '@tanstack/react-query',
|
||||
eslintPlugin: '@tanstack/eslint-plugin-query',
|
||||
middleware: 'reactQuery',
|
||||
},
|
||||
{
|
||||
dependency: '@testing-library/react',
|
||||
eslintPlugin: 'eslint-plugin-testing-library',
|
||||
middleware: 'testingLibrary',
|
||||
},
|
||||
];
|
||||
|
||||
export function getProjectDependencies() {
|
||||
const rootDir = process.cwd();
|
||||
|
||||
const pkgJsonPath = resolve(rootDir, 'package.json');
|
||||
@ -13,27 +59,21 @@ export function* checkEnv(): Generator<Middleware> {
|
||||
? JSON.parse(fs.readFileSync(pkgJsonPath, 'utf-8'))
|
||||
: {};
|
||||
|
||||
const deps = new Set(
|
||||
return new Set(
|
||||
Object.keys({
|
||||
...pkgJson.dependencies,
|
||||
...pkgJson.devDependencies,
|
||||
...pkgJson.peerDependencies,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
if (deps.has('react')) {
|
||||
yield react;
|
||||
}
|
||||
if (deps.has('@vitejs/plugin-react') && deps.has('eslint-plugin-react-refresh')) {
|
||||
yield reactRefresh;
|
||||
}
|
||||
if (deps.has('tailwindcss') && deps.has('eslint-plugin-tailwindcss')) {
|
||||
yield tailwind;
|
||||
}
|
||||
if (deps.has('storybook') && deps.has('eslint-plugin-storybook')) {
|
||||
yield storybook;
|
||||
}
|
||||
if (deps.has('@tanstack/react-query') && deps.has('@tanstack/eslint-plugin-query')) {
|
||||
yield reactQuery;
|
||||
export function* checkEnv(): Generator<Middleware> {
|
||||
const deps = getProjectDependencies();
|
||||
|
||||
for (const { dependency, eslintPlugin, middleware } of envs) {
|
||||
if (deps.has(dependency) && (!eslintPlugin || deps.has(eslintPlugin))) {
|
||||
yield middlewares[middleware];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -135,7 +135,7 @@ interface MiddlewareFunctions {
|
||||
*/
|
||||
export function extendConfig(
|
||||
of: InputConfig & {
|
||||
middlewares: Middleware[];
|
||||
middlewares?: Middleware[];
|
||||
} = {
|
||||
middlewares: [],
|
||||
},
|
||||
|
16
src/install.ts
Normal file
16
src/install.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import { installPackage } from '@antfu/install-pkg';
|
||||
import { uniq } from 'lodash';
|
||||
import { getProjectDependencies, envs } from './env';
|
||||
|
||||
const deps = getProjectDependencies();
|
||||
const packages = uniq(
|
||||
envs
|
||||
.filter(_ => deps.has(_.dependency) && _.eslintPlugin && !deps.has(_.eslintPlugin))
|
||||
.map(_ => _.eslintPlugin!),
|
||||
);
|
||||
|
||||
console.log('Installing missing ESLint plugins.\n');
|
||||
|
||||
void installPackage(packages, {
|
||||
silent: false,
|
||||
});
|
12
src/presets/testing-library.ts
Normal file
12
src/presets/testing-library.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import type { Middleware } from '../index';
|
||||
import { TestingLibraryRulesObject } from '@aet/eslint-define-config/src/rules/testing-library';
|
||||
|
||||
const testingLibraryRules: Partial<TestingLibraryRulesObject> = {};
|
||||
|
||||
export const testingLibrary: Middleware = (config, { addRules }) => {
|
||||
config.overrides.push({
|
||||
files: ['**/*.(spec|test).{ts,tsx}'],
|
||||
plugins: ['plugin:testing-library/react'],
|
||||
});
|
||||
addRules(testingLibraryRules);
|
||||
};
|
@ -19,7 +19,6 @@ const typescriptRules: Partial<TypeScriptRulesObject> = {
|
||||
'ts-nocheck': 'allow-with-description',
|
||||
},
|
||||
],
|
||||
'@typescript-eslint/ban-types': [error, { extendDefaults: true }],
|
||||
'@typescript-eslint/consistent-type-imports': [
|
||||
error,
|
||||
{ disallowTypeAnnotations: false, fixStyle: 'inline-type-imports' },
|
||||
|
Loading…
x
Reference in New Issue
Block a user