From e19f960e5933792d25a72fe9cb0d8ddbc8142115 Mon Sep 17 00:00:00 2001 From: JounQin Date: Mon, 18 Mar 2024 18:45:24 +0800 Subject: [PATCH] refactor: migrate imports-first rule --- src/docs-url.ts | 2 +- src/index.ts | 3 ++- src/rules/imports-first.js | 15 --------------- src/rules/imports-first.ts | 22 ++++++++++++++++++++++ 4 files changed, 25 insertions(+), 17 deletions(-) delete mode 100644 src/rules/imports-first.js create mode 100644 src/rules/imports-first.ts diff --git a/src/docs-url.ts b/src/docs-url.ts index 61e029c0a8..dd97f7f845 100644 --- a/src/docs-url.ts +++ b/src/docs-url.ts @@ -1,5 +1,5 @@ // eslint-disable-next-line @typescript-eslint/ban-ts-comment -// @ts-ignore - We're using commonjs +// @ts-ignore - The structures of `lib` and `src` are same import pkg from '../package.json' const repoUrl = 'https://github.com/un-es/eslint-plugin-import-x' diff --git a/src/index.ts b/src/index.ts index 1bbcb16808..f735dcbc4b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -47,6 +47,7 @@ import noImportModuleExports from './rules/no-import-module-exports' import noEmptyNamedBlocks from './rules/no-empty-named-blocks' import exportsLast from './rules/exports-last' import noDeprecated from './rules/no-deprecated' +import importsFirst from './rules/imports-first' // configs import recommended from './config/recommended' @@ -111,7 +112,7 @@ export const rules = { 'no-deprecated': noDeprecated, // deprecated aliases to rules - 'imports-first': require('./rules/imports-first'), + 'imports-first': importsFirst, } satisfies Record> export const configs = { diff --git a/src/rules/imports-first.js b/src/rules/imports-first.js deleted file mode 100644 index 620d5f7e3e..0000000000 --- a/src/rules/imports-first.js +++ /dev/null @@ -1,15 +0,0 @@ -import { docsUrl } from '../docs-url' - -const first = require('./first') - -const newMeta = { - ...first.meta, - deprecated: true, - docs: { - category: 'Style guide', - description: 'Replaced by `import-x/first`.', - url: docsUrl('imports-first', '7b25c1cb95ee18acc1531002fd343e1e6031f9ed'), - }, -} - -module.exports = { ...first, meta: newMeta } diff --git a/src/rules/imports-first.ts b/src/rules/imports-first.ts new file mode 100644 index 0000000000..63b4642eb0 --- /dev/null +++ b/src/rules/imports-first.ts @@ -0,0 +1,22 @@ +import { ESLintUtils } from '@typescript-eslint/utils' + +import { docsUrl } from '../docs-url' + +import first from './first' + +const createRule = ESLintUtils.RuleCreator(ruleName => + docsUrl(ruleName, '7b25c1cb95ee18acc1531002fd343e1e6031f9ed'), +) + +export = createRule({ + ...first, + name: 'imports-first', + meta: { + ...first.meta, + deprecated: true, + docs: { + category: 'Style guide', + description: 'Replaced by `import-x/first`.', + }, + }, +})