From 74748cbebb76f43d78da3b8180075d9ab79a77f3 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Sat, 11 Nov 2023 02:59:06 +0100 Subject: [PATCH] feat: expose sub entries for each rule --- packages/eslint-plugin-js/package.json | 69 ++++++++++++++++++++++++- packages/eslint-plugin-jsx/package.json | 20 ++++++- packages/eslint-plugin-ts/package.json | 23 ++++++++- scripts/prepare.ts | 26 ++++++++++ 4 files changed, 135 insertions(+), 3 deletions(-) diff --git a/packages/eslint-plugin-js/package.json b/packages/eslint-plugin-js/package.json index be5463fda..5d0c4231d 100644 --- a/packages/eslint-plugin-js/package.json +++ b/packages/eslint-plugin-js/package.json @@ -23,7 +23,74 @@ }, "./rule-options": { "types": "./dts/rule-options.d.ts" - } + }, + "./rules/array-bracket-newline": "./dist/array-bracket-newline.js", + "./rules/array-bracket-spacing": "./dist/array-bracket-spacing.js", + "./rules/array-element-newline": "./dist/array-element-newline.js", + "./rules/arrow-parens": "./dist/arrow-parens.js", + "./rules/arrow-spacing": "./dist/arrow-spacing.js", + "./rules/block-spacing": "./dist/block-spacing.js", + "./rules/brace-style": "./dist/brace-style.js", + "./rules/comma-dangle": "./dist/comma-dangle.js", + "./rules/comma-spacing": "./dist/comma-spacing.js", + "./rules/comma-style": "./dist/comma-style.js", + "./rules/computed-property-spacing": "./dist/computed-property-spacing.js", + "./rules/dot-location": "./dist/dot-location.js", + "./rules/eol-last": "./dist/eol-last.js", + "./rules/func-call-spacing": "./dist/func-call-spacing.js", + "./rules/function-call-argument-newline": "./dist/function-call-argument-newline.js", + "./rules/function-paren-newline": "./dist/function-paren-newline.js", + "./rules/generator-star-spacing": "./dist/generator-star-spacing.js", + "./rules/implicit-arrow-linebreak": "./dist/implicit-arrow-linebreak.js", + "./rules/indent": "./dist/indent.js", + "./rules/jsx-quotes": "./dist/jsx-quotes.js", + "./rules/key-spacing": "./dist/key-spacing.js", + "./rules/keyword-spacing": "./dist/keyword-spacing.js", + "./rules/linebreak-style": "./dist/linebreak-style.js", + "./rules/lines-around-comment": "./dist/lines-around-comment.js", + "./rules/lines-between-class-members": "./dist/lines-between-class-members.js", + "./rules/max-len": "./dist/max-len.js", + "./rules/max-statements-per-line": "./dist/max-statements-per-line.js", + "./rules/multiline-ternary": "./dist/multiline-ternary.js", + "./rules/new-parens": "./dist/new-parens.js", + "./rules/newline-per-chained-call": "./dist/newline-per-chained-call.js", + "./rules/no-confusing-arrow": "./dist/no-confusing-arrow.js", + "./rules/no-extra-parens": "./dist/no-extra-parens.js", + "./rules/no-extra-semi": "./dist/no-extra-semi.js", + "./rules/no-floating-decimal": "./dist/no-floating-decimal.js", + "./rules/no-mixed-operators": "./dist/no-mixed-operators.js", + "./rules/no-mixed-spaces-and-tabs": "./dist/no-mixed-spaces-and-tabs.js", + "./rules/no-multi-spaces": "./dist/no-multi-spaces.js", + "./rules/no-multiple-empty-lines": "./dist/no-multiple-empty-lines.js", + "./rules/no-tabs": "./dist/no-tabs.js", + "./rules/no-trailing-spaces": "./dist/no-trailing-spaces.js", + "./rules/no-whitespace-before-property": "./dist/no-whitespace-before-property.js", + "./rules/nonblock-statement-body-position": "./dist/nonblock-statement-body-position.js", + "./rules/object-curly-newline": "./dist/object-curly-newline.js", + "./rules/object-curly-spacing": "./dist/object-curly-spacing.js", + "./rules/object-property-newline": "./dist/object-property-newline.js", + "./rules/one-var-declaration-per-line": "./dist/one-var-declaration-per-line.js", + "./rules/operator-linebreak": "./dist/operator-linebreak.js", + "./rules/padded-blocks": "./dist/padded-blocks.js", + "./rules/padding-line-between-statements": "./dist/padding-line-between-statements.js", + "./rules/quote-props": "./dist/quote-props.js", + "./rules/quotes": "./dist/quotes.js", + "./rules/rest-spread-spacing": "./dist/rest-spread-spacing.js", + "./rules/semi": "./dist/semi.js", + "./rules/semi-spacing": "./dist/semi-spacing.js", + "./rules/semi-style": "./dist/semi-style.js", + "./rules/space-before-blocks": "./dist/space-before-blocks.js", + "./rules/space-before-function-paren": "./dist/space-before-function-paren.js", + "./rules/space-in-parens": "./dist/space-in-parens.js", + "./rules/space-infix-ops": "./dist/space-infix-ops.js", + "./rules/space-unary-ops": "./dist/space-unary-ops.js", + "./rules/spaced-comment": "./dist/spaced-comment.js", + "./rules/switch-colon-spacing": "./dist/switch-colon-spacing.js", + "./rules/template-curly-spacing": "./dist/template-curly-spacing.js", + "./rules/template-tag-spacing": "./dist/template-tag-spacing.js", + "./rules/wrap-iife": "./dist/wrap-iife.js", + "./rules/wrap-regex": "./dist/wrap-regex.js", + "./rules/yield-star-spacing": "./dist/yield-star-spacing.js" }, "main": "./dist/index.js", "types": "./dts/index.d.ts", diff --git a/packages/eslint-plugin-jsx/package.json b/packages/eslint-plugin-jsx/package.json index 6ba371d30..0975b3344 100644 --- a/packages/eslint-plugin-jsx/package.json +++ b/packages/eslint-plugin-jsx/package.json @@ -23,7 +23,25 @@ }, "./rule-options": { "types": "./dts/rule-options.d.ts" - } + }, + "./rules/jsx-child-element-spacing": "./dist/jsx-child-element-spacing.js", + "./rules/jsx-closing-bracket-location": "./dist/jsx-closing-bracket-location.js", + "./rules/jsx-closing-tag-location": "./dist/jsx-closing-tag-location.js", + "./rules/jsx-curly-brace-presence": "./dist/jsx-curly-brace-presence.js", + "./rules/jsx-curly-newline": "./dist/jsx-curly-newline.js", + "./rules/jsx-curly-spacing": "./dist/jsx-curly-spacing.js", + "./rules/jsx-equals-spacing": "./dist/jsx-equals-spacing.js", + "./rules/jsx-first-prop-new-line": "./dist/jsx-first-prop-new-line.js", + "./rules/jsx-indent": "./dist/jsx-indent.js", + "./rules/jsx-indent-props": "./dist/jsx-indent-props.js", + "./rules/jsx-max-props-per-line": "./dist/jsx-max-props-per-line.js", + "./rules/jsx-newline": "./dist/jsx-newline.js", + "./rules/jsx-one-expression-per-line": "./dist/jsx-one-expression-per-line.js", + "./rules/jsx-props-no-multi-spaces": "./dist/jsx-props-no-multi-spaces.js", + "./rules/jsx-self-closing-comp": "./dist/jsx-self-closing-comp.js", + "./rules/jsx-sort-props": "./dist/jsx-sort-props.js", + "./rules/jsx-tag-spacing": "./dist/jsx-tag-spacing.js", + "./rules/jsx-wrap-multilines": "./dist/jsx-wrap-multilines.js" }, "main": "./dist/index.js", "types": "./dts/index.d.ts", diff --git a/packages/eslint-plugin-ts/package.json b/packages/eslint-plugin-ts/package.json index e27202291..dfd519249 100644 --- a/packages/eslint-plugin-ts/package.json +++ b/packages/eslint-plugin-ts/package.json @@ -23,7 +23,28 @@ }, "./rule-options": { "types": "./dts/rule-options.d.ts" - } + }, + "./rules/block-spacing": "./dist/block-spacing.js", + "./rules/brace-style": "./dist/brace-style.js", + "./rules/comma-dangle": "./dist/comma-dangle.js", + "./rules/comma-spacing": "./dist/comma-spacing.js", + "./rules/func-call-spacing": "./dist/func-call-spacing.js", + "./rules/indent": "./dist/indent.js", + "./rules/key-spacing": "./dist/key-spacing.js", + "./rules/keyword-spacing": "./dist/keyword-spacing.js", + "./rules/lines-around-comment": "./dist/lines-around-comment.js", + "./rules/lines-between-class-members": "./dist/lines-between-class-members.js", + "./rules/member-delimiter-style": "./dist/member-delimiter-style.js", + "./rules/no-extra-parens": "./dist/no-extra-parens.js", + "./rules/no-extra-semi": "./dist/no-extra-semi.js", + "./rules/object-curly-spacing": "./dist/object-curly-spacing.js", + "./rules/padding-line-between-statements": "./dist/padding-line-between-statements.js", + "./rules/quotes": "./dist/quotes.js", + "./rules/semi": "./dist/semi.js", + "./rules/space-before-blocks": "./dist/space-before-blocks.js", + "./rules/space-before-function-paren": "./dist/space-before-function-paren.js", + "./rules/space-infix-ops": "./dist/space-infix-ops.js", + "./rules/type-annotation-spacing": "./dist/type-annotation-spacing.js" }, "main": "./dist/index.js", "types": "./dts/index.d.ts", diff --git a/scripts/prepare.ts b/scripts/prepare.ts index c18d82c7d..85622e103 100644 --- a/scripts/prepare.ts +++ b/scripts/prepare.ts @@ -25,6 +25,7 @@ async function run() { await writeRulesIndex(pkg) await writeREADME(pkg) await writePackageDTS(pkg) + await updateExports(pkg) packages.push(pkg) } @@ -175,6 +176,7 @@ async function writePackageDTS(pkg: PackageInfo) { ] }), '}', + '', ] await fs.writeFile( @@ -197,6 +199,30 @@ export {} ) } +async function updateExports(pkg: PackageInfo) { + if (!pkg.rules.length) + return + + const pkgJson = JSON.parse(await fs.readFile(join(pkg.path, 'package.json'), 'utf-8')) + pkgJson.exports = { + '.': { + types: './dts/index.d.ts', + require: './dist/index.js', + default: './dist/index.js', + }, + './define-config-support': { + types: './dts/define-config-support.d.ts', + }, + './rule-options': { + types: './dts/rule-options.d.ts', + }, + ...Object.fromEntries( + pkg.rules.map(i => [`./rules/${i.name}`, `./dist/${i.name}.js`]), + ), + } + await fs.writeFile(join(pkg.path, 'package.json'), `${JSON.stringify(pkgJson, null, 2)}\n`, 'utf-8') +} + async function writeREADME(pkg: PackageInfo) { if (!pkg.rules.length) return