@adonisjs/eslint-plugin 2.0.0-beta.4 → 2.0.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/index.d.ts
CHANGED
|
@@ -2,13 +2,9 @@ declare const _default: {
|
|
|
2
2
|
rules: {
|
|
3
3
|
'prefer-lazy-controller-import': import("@typescript-eslint/utils/ts-eslint").RuleModule<"preferLazyControllerImport", [], {
|
|
4
4
|
description: string;
|
|
5
|
-
recommended: string;
|
|
6
|
-
url: string;
|
|
7
5
|
}, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
8
6
|
'prefer-lazy-listener-import': import("@typescript-eslint/utils/ts-eslint").RuleModule<"preferLazyListenerImport", [], {
|
|
9
7
|
description: string;
|
|
10
|
-
recommended: string;
|
|
11
|
-
url: string;
|
|
12
8
|
}, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
13
9
|
};
|
|
14
10
|
};
|
package/build/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { AST_NODE_TYPES } from "@typescript-eslint/utils";
|
|
|
3
3
|
|
|
4
4
|
// src/utils.ts
|
|
5
5
|
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
6
|
-
var createEslintRule = ESLintUtils.RuleCreator((ruleName) => ruleName);
|
|
6
|
+
var createEslintRule = ESLintUtils.RuleCreator((ruleName) => `https://github.com/adonisjs/eslint-plugin-adonisjs#${ruleName}`);
|
|
7
7
|
|
|
8
8
|
// src/rules/prefer_lazy_listener_import.ts
|
|
9
9
|
var prefer_lazy_listener_import_default = createEslintRule({
|
|
@@ -13,9 +13,7 @@ var prefer_lazy_listener_import_default = createEslintRule({
|
|
|
13
13
|
type: "problem",
|
|
14
14
|
fixable: "code",
|
|
15
15
|
docs: {
|
|
16
|
-
description: "(Needed for HMR) Prefer lazy listener import over standard import"
|
|
17
|
-
recommended: "recommended",
|
|
18
|
-
url: "https://github.com/adonisjs/eslint-plugin-adonisjs?tab=readme-ov-file#prefer-lazy-listener-import"
|
|
16
|
+
description: "(Needed for HMR) Prefer lazy listener import over standard import"
|
|
19
17
|
},
|
|
20
18
|
schema: [],
|
|
21
19
|
messages: {
|
|
@@ -87,9 +85,7 @@ var prefer_lazy_controller_import_default = createEslintRule({
|
|
|
87
85
|
type: "problem",
|
|
88
86
|
fixable: "code",
|
|
89
87
|
docs: {
|
|
90
|
-
description: "(Needed for HMR) Prefer lazy controller import over standard import"
|
|
91
|
-
recommended: "recommended",
|
|
92
|
-
url: "https://github.com/adonisjs/eslint-plugin-adonisjs?tab=readme-ov-file#prefer-lazy-controller-import"
|
|
88
|
+
description: "(Needed for HMR) Prefer lazy controller import over standard import"
|
|
93
89
|
},
|
|
94
90
|
schema: [],
|
|
95
91
|
messages: {
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/rules/prefer_lazy_listener_import.ts","../src/utils.ts","../src/rules/prefer_lazy_controller_import.ts","../index.ts"],"sourcesContent":["/*\n * @adonisjs/eslint-plugin\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/utils'\nimport { createEslintRule } from '../utils.js'\n\n/**\n * ESLint rule to force lazy listener imports\n */\nexport default createEslintRule({\n name: 'prefer-lazy-listener-import',\n defaultOptions: [],\n meta: {\n type: 'problem',\n fixable: 'code',\n docs: {\n description: '(Needed for HMR) Prefer lazy listener import over standard import',\n recommended: 'recommended',\n url: 'https://github.com/adonisjs/eslint-plugin-adonisjs?tab=readme-ov-file#prefer-lazy-listener-import',\n },\n schema: [],\n messages: {\n preferLazyListenerImport: 'Replace standard import with lazy listener import',\n },\n },\n\n create: function (context) {\n const importNodes: Record<string, TSESTree.ImportDeclaration> = {}\n const importIdentifiers: string[] = []\n let emitterIdentifier: string = ''\n\n function isEmitterOnCallExpression(node: TSESTree.CallExpression, routerIdentifier: string) {\n return (\n node.callee.type === AST_NODE_TYPES.MemberExpression &&\n node.callee.object.type === AST_NODE_TYPES.Identifier &&\n node.callee.object.name === routerIdentifier &&\n node.callee.property.type === AST_NODE_TYPES.Identifier &&\n node.callee.property.name === 'on'\n )\n }\n\n return {\n /**\n * Track all imported identifiers\n * Also get the local name of the emitter import\n */\n ImportDeclaration(node) {\n for (const specifier of node.specifiers) {\n if (specifier.type === 'ImportDefaultSpecifier' || specifier.type === 'ImportSpecifier') {\n importIdentifiers.push(specifier.local.name)\n importNodes[specifier.local.name] = node\n }\n }\n\n if (node.source.value === '@adonisjs/core/services/emitter') {\n if (node.specifiers[0] && node.specifiers[0].type === 'ImportDefaultSpecifier') {\n emitterIdentifier = node.specifiers[0].local.name\n }\n }\n },\n\n CallExpression(node) {\n /**\n * Check if we are calling emitter.on()\n */\n if (!isEmitterOnCallExpression(node, emitterIdentifier)) {\n return\n }\n\n /**\n * Ensure the second argument is an array\n */\n const secondArgument = node.arguments[1]\n if (secondArgument.type !== AST_NODE_TYPES.ArrayExpression) {\n return\n }\n\n for (const element of secondArgument.elements) {\n if (!element) {\n continue\n }\n\n /**\n * If we are dealing with an Identifier that was imported\n * through a standard import, then report it as an error\n */\n if (element.type !== 'Identifier' || !importIdentifiers.includes(element.name)) {\n continue\n }\n\n context.report({\n node: importNodes[element.name],\n messageId: 'preferLazyListenerImport',\n fix(fixer) {\n const importPath = importNodes[element.name].source.raw\n const newImportDeclaration = `const ${element.name} = () => import(${importPath})`\n return fixer.replaceText(importNodes[element.name], newImportDeclaration)\n },\n })\n }\n },\n }\n },\n})\n","/*\n * @adonisjs/eslint-plugin\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { ESLintUtils } from '@typescript-eslint/utils'\n\nexport const createEslintRule = ESLintUtils.RuleCreator<{\n description: string\n recommended: string\n url: string\n}>((ruleName) => ruleName)\n","/*\n * @adonisjs/eslint-plugin\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/utils'\nimport { createEslintRule } from '../utils.js'\n\nconst HTTP_METHODS = ['get', 'post', 'put', 'delete', 'patch']\n\n/**\n * ESLint rule to force lazy controller import\n */\nexport default createEslintRule({\n name: 'prefer-lazy-controller-import',\n defaultOptions: [],\n meta: {\n type: 'problem',\n fixable: 'code',\n docs: {\n description: '(Needed for HMR) Prefer lazy controller import over standard import',\n recommended: 'recommended',\n url: 'https://github.com/adonisjs/eslint-plugin-adonisjs?tab=readme-ov-file#prefer-lazy-controller-import',\n },\n schema: [],\n messages: {\n preferLazyControllerImport: 'Replace standard import with lazy controller import',\n },\n },\n\n create: function (context) {\n const importNodes: Record<string, TSESTree.ImportDeclaration> = {}\n const importIdentifiers: string[] = []\n let routerIdentifier: string = ''\n\n function isRouteCallExpression(node: TSESTree.CallExpression, identifier: string) {\n return (\n node.callee.type === AST_NODE_TYPES.MemberExpression &&\n node.callee.object.type === AST_NODE_TYPES.Identifier &&\n node.callee.object.name === identifier &&\n node.callee.property.type === AST_NODE_TYPES.Identifier &&\n HTTP_METHODS.includes(node.callee.property.name)\n )\n }\n\n function isRouteResourceCallExpression(node: TSESTree.CallExpression, identifier: string) {\n return (\n node.callee.type === AST_NODE_TYPES.MemberExpression &&\n node.callee.object.type === AST_NODE_TYPES.Identifier &&\n node.callee.object.name === identifier &&\n node.callee.property.type === AST_NODE_TYPES.Identifier &&\n node.callee.property.name === 'resource'\n )\n }\n\n return {\n /**\n * Track all imported identifiers\n * Also get the local name of the router import\n */\n ImportDeclaration(node) {\n for (const specifier of node.specifiers) {\n if (specifier.type === 'ImportDefaultSpecifier' || specifier.type === 'ImportSpecifier') {\n importIdentifiers.push(specifier.local.name)\n importNodes[specifier.local.name] = node\n }\n }\n\n if (node.source.value === '@adonisjs/core/services/router') {\n if (node.specifiers[0] && node.specifiers[0].type === 'ImportDefaultSpecifier') {\n routerIdentifier = node.specifiers[0].local.name\n }\n }\n },\n\n CallExpression(node) {\n /**\n * Check if we are calling router.get() or any other http method\n * OR if we are calling router.resource that also takes a controller\n * as an argument\n *\n *\n * Then let's extract the controller identifier from the call expression\n *\n * In the case of router.get/post/put.. we have to extract\n * the first element from the array\n *\n * router.get(\"/\", [HomeController, 'index'])\n */\n let controller: TSESTree.CallExpressionArgument | null = null\n if (isRouteCallExpression(node, routerIdentifier)) {\n const secondArgument = node.arguments[1]\n if (secondArgument.type === AST_NODE_TYPES.ArrayExpression) {\n controller = secondArgument.elements[0]\n }\n }\n\n /**\n * In the case of router.resource, we just have to extract the first argument\n *\n * router.resource(\"foo\", UserController)\n */\n if (isRouteResourceCallExpression(node, routerIdentifier)) {\n controller = node.arguments[1]\n }\n\n /**\n * Unable to extract controller\n */\n if (!controller) {\n return\n }\n\n /**\n * If we are dealing with an Identifier that was imported\n * through a standard import, then report it as an error\n */\n if (controller.type !== 'Identifier' || !importIdentifiers.includes(controller.name)) {\n return\n }\n\n context.report({\n node: importNodes[controller.name],\n messageId: 'preferLazyControllerImport',\n fix(fixer) {\n const importPath = importNodes[controller.name].source.raw\n const newImportDeclaration = `const ${controller.name} = () => import(${importPath})`\n return fixer.replaceText(importNodes[controller.name], newImportDeclaration)\n },\n })\n },\n }\n },\n})\n","/*\n * @adonisjs/eslint-plugin\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport preferLazyListenerImport from './src/rules/prefer_lazy_listener_import.js'\nimport preferLazyControllerImport from './src/rules/prefer_lazy_controller_import.js'\n\nexport default {\n rules: {\n 'prefer-lazy-controller-import': preferLazyControllerImport,\n 'prefer-lazy-listener-import': preferLazyListenerImport,\n },\n}\n"],"mappings":";AASA,SAAS,sBAAgC;;;ACAzC,SAAS,mBAAmB;AAErB,IAAM,mBAAmB,YAAY,YAIzC,CAAC,aAAa,QAAQ;;;ADAzB,IAAO,sCAAQ,iBAAiB;AAAA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uBAAuB,SAAS,WAAW,IAAI,mBAAmB,UAAU;AAClF,mBAAO,MAAM,YAAY,YAAY,WAAW,IAAI,GAAG,oBAAoB;AAAA,UAC7E;AAAA,QACF,CAAC;AAAA,MACH;AAAA,IACF;AAAA,EACF;AACF,CAAC;;;AC7HD,IAAO,iCAAQ;AAAA,EACb,OAAO;AAAA,IACL,iCAAiC;AAAA,IACjC,+BAA+B;AAAA,EACjC;AACF;","names":["AST_NODE_TYPES","AST_NODE_TYPES"]}
|
|
1
|
+
{"version":3,"sources":["../src/rules/prefer_lazy_listener_import.ts","../src/utils.ts","../src/rules/prefer_lazy_controller_import.ts","../index.ts"],"sourcesContent":["/*\n * @adonisjs/eslint-plugin\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/utils'\nimport { createEslintRule } from '../utils.js'\n\n/**\n * ESLint rule to force lazy listener imports\n */\nexport default createEslintRule({\n name: 'prefer-lazy-listener-import',\n defaultOptions: [],\n meta: {\n type: 'problem',\n fixable: 'code',\n docs: {\n description: '(Needed for HMR) Prefer lazy listener import over standard import',\n },\n schema: [],\n messages: {\n preferLazyListenerImport: 'Replace standard import with lazy listener import',\n },\n },\n\n create: function (context) {\n const importNodes: Record<string, TSESTree.ImportDeclaration> = {}\n const importIdentifiers: string[] = []\n let emitterIdentifier: string = ''\n\n function isEmitterOnCallExpression(node: TSESTree.CallExpression, routerIdentifier: string) {\n return (\n node.callee.type === AST_NODE_TYPES.MemberExpression &&\n node.callee.object.type === AST_NODE_TYPES.Identifier &&\n node.callee.object.name === routerIdentifier &&\n node.callee.property.type === AST_NODE_TYPES.Identifier &&\n node.callee.property.name === 'on'\n )\n }\n\n return {\n /**\n * Track all imported identifiers\n * Also get the local name of the emitter import\n */\n ImportDeclaration(node) {\n for (const specifier of node.specifiers) {\n if (specifier.type === 'ImportDefaultSpecifier' || specifier.type === 'ImportSpecifier') {\n importIdentifiers.push(specifier.local.name)\n importNodes[specifier.local.name] = node\n }\n }\n\n if (node.source.value === '@adonisjs/core/services/emitter') {\n if (node.specifiers[0] && node.specifiers[0].type === 'ImportDefaultSpecifier') {\n emitterIdentifier = node.specifiers[0].local.name\n }\n }\n },\n\n CallExpression(node) {\n /**\n * Check if we are calling emitter.on()\n */\n if (!isEmitterOnCallExpression(node, emitterIdentifier)) {\n return\n }\n\n /**\n * Ensure the second argument is an array\n */\n const secondArgument = node.arguments[1]\n if (secondArgument.type !== AST_NODE_TYPES.ArrayExpression) {\n return\n }\n\n for (const element of secondArgument.elements) {\n if (!element) {\n continue\n }\n\n /**\n * If we are dealing with an Identifier that was imported\n * through a standard import, then report it as an error\n */\n if (element.type !== 'Identifier' || !importIdentifiers.includes(element.name)) {\n continue\n }\n\n context.report({\n node: importNodes[element.name],\n messageId: 'preferLazyListenerImport',\n fix(fixer) {\n const importPath = importNodes[element.name].source.raw\n const newImportDeclaration = `const ${element.name} = () => import(${importPath})`\n return fixer.replaceText(importNodes[element.name], newImportDeclaration)\n },\n })\n }\n },\n }\n },\n})\n","/*\n * @adonisjs/eslint-plugin\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { ESLintUtils } from '@typescript-eslint/utils'\n\nexport const createEslintRule = ESLintUtils.RuleCreator<{\n description: string\n}>((ruleName) => `https://github.com/adonisjs/eslint-plugin-adonisjs#${ruleName}`)\n","/*\n * @adonisjs/eslint-plugin\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/utils'\nimport { createEslintRule } from '../utils.js'\n\nconst HTTP_METHODS = ['get', 'post', 'put', 'delete', 'patch']\n\n/**\n * ESLint rule to force lazy controller import\n */\nexport default createEslintRule({\n name: 'prefer-lazy-controller-import',\n defaultOptions: [],\n meta: {\n type: 'problem',\n fixable: 'code',\n docs: {\n description: '(Needed for HMR) Prefer lazy controller import over standard import',\n },\n schema: [],\n messages: {\n preferLazyControllerImport: 'Replace standard import with lazy controller import',\n },\n },\n\n create: function (context) {\n const importNodes: Record<string, TSESTree.ImportDeclaration> = {}\n const importIdentifiers: string[] = []\n let routerIdentifier: string = ''\n\n function isRouteCallExpression(node: TSESTree.CallExpression, identifier: string) {\n return (\n node.callee.type === AST_NODE_TYPES.MemberExpression &&\n node.callee.object.type === AST_NODE_TYPES.Identifier &&\n node.callee.object.name === identifier &&\n node.callee.property.type === AST_NODE_TYPES.Identifier &&\n HTTP_METHODS.includes(node.callee.property.name)\n )\n }\n\n function isRouteResourceCallExpression(node: TSESTree.CallExpression, identifier: string) {\n return (\n node.callee.type === AST_NODE_TYPES.MemberExpression &&\n node.callee.object.type === AST_NODE_TYPES.Identifier &&\n node.callee.object.name === identifier &&\n node.callee.property.type === AST_NODE_TYPES.Identifier &&\n node.callee.property.name === 'resource'\n )\n }\n\n return {\n /**\n * Track all imported identifiers\n * Also get the local name of the router import\n */\n ImportDeclaration(node) {\n for (const specifier of node.specifiers) {\n if (specifier.type === 'ImportDefaultSpecifier' || specifier.type === 'ImportSpecifier') {\n importIdentifiers.push(specifier.local.name)\n importNodes[specifier.local.name] = node\n }\n }\n\n if (node.source.value === '@adonisjs/core/services/router') {\n if (node.specifiers[0] && node.specifiers[0].type === 'ImportDefaultSpecifier') {\n routerIdentifier = node.specifiers[0].local.name\n }\n }\n },\n\n CallExpression(node) {\n /**\n * Check if we are calling router.get() or any other http method\n * OR if we are calling router.resource that also takes a controller\n * as an argument\n *\n *\n * Then let's extract the controller identifier from the call expression\n *\n * In the case of router.get/post/put.. we have to extract\n * the first element from the array\n *\n * router.get(\"/\", [HomeController, 'index'])\n */\n let controller: TSESTree.CallExpressionArgument | null = null\n if (isRouteCallExpression(node, routerIdentifier)) {\n const secondArgument = node.arguments[1]\n if (secondArgument.type === AST_NODE_TYPES.ArrayExpression) {\n controller = secondArgument.elements[0]\n }\n }\n\n /**\n * In the case of router.resource, we just have to extract the first argument\n *\n * router.resource(\"foo\", UserController)\n */\n if (isRouteResourceCallExpression(node, routerIdentifier)) {\n controller = node.arguments[1]\n }\n\n /**\n * Unable to extract controller\n */\n if (!controller) {\n return\n }\n\n /**\n * If we are dealing with an Identifier that was imported\n * through a standard import, then report it as an error\n */\n if (controller.type !== 'Identifier' || !importIdentifiers.includes(controller.name)) {\n return\n }\n\n context.report({\n node: importNodes[controller.name],\n messageId: 'preferLazyControllerImport',\n fix(fixer) {\n const importPath = importNodes[controller.name].source.raw\n const newImportDeclaration = `const ${controller.name} = () => import(${importPath})`\n return fixer.replaceText(importNodes[controller.name], newImportDeclaration)\n },\n })\n },\n }\n },\n})\n","/*\n * @adonisjs/eslint-plugin\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport preferLazyListenerImport from './src/rules/prefer_lazy_listener_import.js'\nimport preferLazyControllerImport from './src/rules/prefer_lazy_controller_import.js'\n\nexport default {\n rules: {\n 'prefer-lazy-controller-import': preferLazyControllerImport,\n 'prefer-lazy-listener-import': preferLazyListenerImport,\n },\n}\n"],"mappings":";AASA,SAAS,sBAAgC;;;ACAzC,SAAS,mBAAmB;AAErB,IAAM,mBAAmB,YAAY,YAEzC,CAAC,aAAa,sDAAsD,QAAQ,EAAE;;;ADEjF,IAAO,sCAAQ,iBAAiB;AAAA,EAC9B,MAAM;AAAA,EACN,gBAAgB,CAAC;AAAA,EACjB,MAAM;AAAA,IACJ,MAAM;AAAA,IACN,SAAS;AAAA,IACT,MAAM;AAAA,MACJ,aAAa;AAAA,IACf;AAAA,IACA,QAAQ,CAAC;AAAA,IACT,UAAU;AAAA,MACR,0BAA0B;AAAA,IAC5B;AAAA,EACF;AAAA,EAEA,QAAQ,SAAU,SAAS;AACzB,UAAM,cAA0D,CAAC;AACjE,UAAM,oBAA8B,CAAC;AACrC,QAAI,oBAA4B;AAEhC,aAAS,0BAA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AAI,IAAI;AAAA,UACtC;AAAA,QACF;AAEA,YAAI,KAAK,OAAO,UAAU,kCAAkC;AAC1D,cAAI,KAAK,WAAW,CAAC,KAAK,KAAK,WAAW,CAAC,EAAE,SAAS,0BAA0B;AAC9E,+BAAmB,KAAK,WAAW,CAAC,EAAE,MAAM;AAAA,UAC9C;AAAA,QACF;AAAA,MACF;AAAA,MAEA,eAAe,MAAM;AAcnB,YAAI,aAAqD;AACzD,YAAI,sBAAsB,MAAM,gBAAgB,GAAG;AACjD,gBAAM,iBAAiB,KAAK,UAAU,CAAC;AACvC,cAAI,eAAe,SAASA,gBAAe,iBAAiB;AAC1D,yBAAa,eAAe,SAAS,CAAC;AAAA,UACxC;AAAA,QACF;AAOA,YAAI,8BAA8B,MAAM,gBAAgB,GAAG;AACzD,uBAAa,KAAK,UAAU,CAAC;AAAA,QAC/B;AAKA,YAAI,CAAC,YAAY;AACf;AAAA,QACF;AAMA,YAAI,WAAW,SAAS,gBAAgB,CAAC,kBAAkB,SAAS,WAAW,IAAI,GAAG;AACpF;AAAA,QACF;AAEA,gBAAQ,OAAO;AAAA,UACb,MAAM,YAAY,WAAW,IAAI;AAAA,UACjC,WAAW;AAAA,UACX,IAAI,OAAO;AACT,kBAAM,aAAa,YAAY,WAAW,IAAI,EAAE,OAAO;AACvD,kBAAM,uBAAuB,SAAS,WAAW,IAAI,mBAAmB,UAAU;AAClF,mBAAO,MAAM,YAAY,YAAY,WAAW,IAAI,GAAG,oBAAoB;AAAA,UAC7E;AAAA,QACF,CAAC;AAAA,MACH;AAAA,IACF;AAAA,EACF;AACF,CAAC;;;AC3HD,IAAO,iCAAQ;AAAA,EACb,OAAO;AAAA,IACL,iCAAiC;AAAA,IACjC,+BAA+B;AAAA,EACjC;AACF;","names":["AST_NODE_TYPES","AST_NODE_TYPES"]}
|
|
@@ -3,7 +3,5 @@
|
|
|
3
3
|
*/
|
|
4
4
|
declare const _default: import("@typescript-eslint/utils/ts-eslint").RuleModule<"preferLazyControllerImport", [], {
|
|
5
5
|
description: string;
|
|
6
|
-
recommended: string;
|
|
7
|
-
url: string;
|
|
8
6
|
}, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
9
7
|
export default _default;
|
|
@@ -3,7 +3,5 @@
|
|
|
3
3
|
*/
|
|
4
4
|
declare const _default: import("@typescript-eslint/utils/ts-eslint").RuleModule<"preferLazyListenerImport", [], {
|
|
5
5
|
description: string;
|
|
6
|
-
recommended: string;
|
|
7
|
-
url: string;
|
|
8
6
|
}, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
9
7
|
export default _default;
|
package/build/src/utils.d.ts
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import { ESLintUtils } from '@typescript-eslint/utils';
|
|
2
2
|
export declare const createEslintRule: <Options extends readonly unknown[], MessageIds extends string>({ meta, name, ...rule }: Readonly<ESLintUtils.RuleWithMetaAndName<Options, MessageIds, {
|
|
3
3
|
description: string;
|
|
4
|
-
recommended: string;
|
|
5
|
-
url: string;
|
|
6
4
|
}>>) => ESLintUtils.RuleModule<MessageIds, Options, {
|
|
7
5
|
description: string;
|
|
8
|
-
recommended: string;
|
|
9
|
-
url: string;
|
|
10
6
|
}, ESLintUtils.RuleListener>;
|