From d9cba64400e5e2c26185567bc2f19e96c85ca303 Mon Sep 17 00:00:00 2001 From: Ruslan Baigunussov Date: Sun, 12 Mar 2023 02:45:41 +0300 Subject: [PATCH] feat: use @eslint-community dependencies --- docs/architecture/Utils.mdx | 2 +- packages/eslint-plugin/package.json | 2 +- .../eslint-plugin/src/rules/prefer-includes.ts | 4 ++-- .../src/rules/prefer-string-starts-ends-with.ts | 4 ++-- packages/utils/package.json | 2 +- .../src/ast-utils/eslint-utils/PatternMatcher.ts | 10 +++++----- .../ast-utils/eslint-utils/ReferenceTracker.ts | 10 +++++----- .../src/ast-utils/eslint-utils/astUtilities.ts | 16 ++++++++-------- .../src/ast-utils/eslint-utils/predicates.ts | 2 +- .../src/ast-utils/eslint-utils/scopeAnalysis.ts | 6 +++--- ...s.d.ts => eslint-community-eslint-utils.d.ts} | 2 +- yarn.lock | 12 ++++++++++++ 12 files changed, 42 insertions(+), 30 deletions(-) rename packages/utils/typings/{eslint-utils.d.ts => eslint-community-eslint-utils.d.ts} (96%) diff --git a/docs/architecture/Utils.mdx b/docs/architecture/Utils.mdx index 9270f2ed8e5..7c4fd674d70 100644 --- a/docs/architecture/Utils.mdx +++ b/docs/architecture/Utils.mdx @@ -19,7 +19,7 @@ Any custom rules you write generally will be as well. | ----------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `AST_NODE_TYPES` | An enum with the names of every single _node_ found in `TSESTree`. | | `AST_TOKEN_TYPES` | An enum with the names of every single _token_ found in `TSESTree`. | -| `ASTUtils` | Tools for operating on the ESTree AST. Also includes the [`eslint-utils`](https://www.npmjs.com/package/eslint-utils) package, correctly typed to work with the types found in `TSESTree` | +| `ASTUtils` | Tools for operating on the ESTree AST. Also includes the [`@eslint-community/eslint-utils`](https://www.npmjs.com/package/@eslint-community/eslint-utils) package, correctly typed to work with the types found in `TSESTree` | | `ESLintUtils` | Tools for creating ESLint rules with TypeScript. | | `JSONSchema` | Types from the [`@types/json-schema`](https://www.npmjs.com/package/@types/json-schema) package, re-exported to save you having to manually import them. Also ensures you're using the same version of the types as this package. | | `ParserServices` | Typing for the parser services provided when parsing a file using `@typescript-eslint/typescript-estree`. | diff --git a/packages/eslint-plugin/package.json b/packages/eslint-plugin/package.json index 5aaf65c6f07..cd383f9c6fb 100644 --- a/packages/eslint-plugin/package.json +++ b/packages/eslint-plugin/package.json @@ -44,6 +44,7 @@ "typecheck": "tsc -p tsconfig.json --noEmit" }, "dependencies": { + "@eslint-community/regexpp": "^4.4.0", "@typescript-eslint/scope-manager": "5.54.1", "@typescript-eslint/type-utils": "5.54.1", "@typescript-eslint/utils": "5.54.1", @@ -51,7 +52,6 @@ "grapheme-splitter": "^1.0.4", "ignore": "^5.2.0", "natural-compare-lite": "^1.4.0", - "regexpp": "^3.2.0", "semver": "^7.3.7", "tsutils": "^3.21.0" }, diff --git a/packages/eslint-plugin/src/rules/prefer-includes.ts b/packages/eslint-plugin/src/rules/prefer-includes.ts index 720d5fbe809..e0b5719a510 100644 --- a/packages/eslint-plugin/src/rules/prefer-includes.ts +++ b/packages/eslint-plugin/src/rules/prefer-includes.ts @@ -1,7 +1,7 @@ +import type { AST as RegExpAST } from '@eslint-community/regexpp'; +import { parseRegExpLiteral } from '@eslint-community/regexpp'; import type { TSESLint, TSESTree } from '@typescript-eslint/utils'; import { AST_NODE_TYPES } from '@typescript-eslint/utils'; -import type { AST as RegExpAST } from 'regexpp'; -import { parseRegExpLiteral } from 'regexpp'; import * as ts from 'typescript'; import { diff --git a/packages/eslint-plugin/src/rules/prefer-string-starts-ends-with.ts b/packages/eslint-plugin/src/rules/prefer-string-starts-ends-with.ts index 104637062bb..6548468430c 100644 --- a/packages/eslint-plugin/src/rules/prefer-string-starts-ends-with.ts +++ b/packages/eslint-plugin/src/rules/prefer-string-starts-ends-with.ts @@ -1,7 +1,7 @@ +import type { AST as RegExpAST } from '@eslint-community/regexpp'; +import { RegExpParser } from '@eslint-community/regexpp'; import type { TSESLint, TSESTree } from '@typescript-eslint/utils'; import { AST_NODE_TYPES } from '@typescript-eslint/utils'; -import type { AST as RegExpAST } from 'regexpp'; -import { RegExpParser } from 'regexpp'; import { createRule, diff --git a/packages/utils/package.json b/packages/utils/package.json index 266f24b0c52..585d8150a81 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -39,13 +39,13 @@ "typecheck": "tsc -p tsconfig.json --noEmit" }, "dependencies": { + "@eslint-community/eslint-utils": "^4.2.0", "@types/json-schema": "^7.0.9", "@types/semver": "^7.3.12", "@typescript-eslint/scope-manager": "5.54.1", "@typescript-eslint/types": "5.54.1", "@typescript-eslint/typescript-estree": "5.54.1", "eslint-scope": "^5.1.1", - "eslint-utils": "^3.0.0", "semver": "^7.3.7" }, "peerDependencies": { diff --git a/packages/utils/src/ast-utils/eslint-utils/PatternMatcher.ts b/packages/utils/src/ast-utils/eslint-utils/PatternMatcher.ts index 3f45db7db46..0cf5708f82e 100644 --- a/packages/utils/src/ast-utils/eslint-utils/PatternMatcher.ts +++ b/packages/utils/src/ast-utils/eslint-utils/PatternMatcher.ts @@ -1,24 +1,24 @@ -import * as eslintUtils from 'eslint-utils'; +import * as eslintUtils from '@eslint-community/eslint-utils'; interface PatternMatcher { /** * Iterate all matched parts in a given string. * - * @see {@link https://eslint-utils.mysticatea.dev/api/ast-utils.html#matcher-execall} + * @see {@link https://eslint-community.github.io/eslint-utils/api/ast-utils.html#matcher-execall} */ execAll(str: string): IterableIterator; /** * Check whether this pattern matches a given string or not. * - * @see {@link https://eslint-utils.mysticatea.dev/api/ast-utils.html#matcher-test} + * @see {@link https://eslint-community.github.io/eslint-utils/api/ast-utils.html#matcher-test} */ test(str: string): boolean; /** * Replace all matched parts by a given replacer. * - * @see {@link https://eslint-utils.mysticatea.dev/api/ast-utils.html#matcher-symbol-replace} + * @see {@link https://eslint-community.github.io/eslint-utils/api/ast-utils.html#matcher-symbol-replace} * @example * const { PatternMatcher } = require("eslint-utils") * const matcher = new PatternMatcher(/\\p{Script=Greek}/g) @@ -47,7 +47,7 @@ interface PatternMatcher { * The class to find a pattern in strings as handling escape sequences. * It ignores the found pattern if it's escaped with `\`. * - * @see {@link https://eslint-utils.mysticatea.dev/api/ast-utils.html#patternmatcher-class} + * @see {@link https://eslint-community.github.io/eslint-utils/api/ast-utils.html#patternmatcher-class} */ const PatternMatcher = eslintUtils.PatternMatcher as { new (pattern: RegExp, options?: { escaped?: boolean }): PatternMatcher; diff --git a/packages/utils/src/ast-utils/eslint-utils/ReferenceTracker.ts b/packages/utils/src/ast-utils/eslint-utils/ReferenceTracker.ts index 893c16ffc0c..9e0841fb4de 100644 --- a/packages/utils/src/ast-utils/eslint-utils/ReferenceTracker.ts +++ b/packages/utils/src/ast-utils/eslint-utils/ReferenceTracker.ts @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/no-namespace */ -import * as eslintUtils from 'eslint-utils'; +import * as eslintUtils from '@eslint-community/eslint-utils'; import type * as TSESLint from '../../ts-eslint'; import type { TSESTree } from '../../ts-estree'; @@ -15,7 +15,7 @@ interface ReferenceTracker { * Iterate the references that the given `traceMap` determined. * This method starts to search from global variables. * - * @see {@link https://eslint-utils.mysticatea.dev/api/scope-utils.html#tracker-iterateglobalreferences} + * @see {@link https://eslint-community.github.io/eslint-utils/api/scope-utils.html#tracker-iterateglobalreferences} */ iterateGlobalReferences( traceMap: ReferenceTracker.TraceMap, @@ -25,7 +25,7 @@ interface ReferenceTracker { * Iterate the references that the given `traceMap` determined. * This method starts to search from `require()` expression. * - * @see {@link https://eslint-utils.mysticatea.dev/api/scope-utils.html#tracker-iteratecjsreferences} + * @see {@link https://eslint-community.github.io/eslint-utils/api/scope-utils.html#tracker-iteratecjsreferences} */ iterateCjsReferences( traceMap: ReferenceTracker.TraceMap, @@ -35,7 +35,7 @@ interface ReferenceTracker { * Iterate the references that the given `traceMap` determined. * This method starts to search from `import`/`export` declarations. * - * @see {@link https://eslint-utils.mysticatea.dev/api/scope-utils.html#tracker-iterateesmreferences} + * @see {@link https://eslint-community.github.io/eslint-utils/api/scope-utils.html#tracker-iterateesmreferences} */ iterateEsmReferences( traceMap: ReferenceTracker.TraceMap, @@ -91,7 +91,7 @@ namespace ReferenceTracker { /** * The tracker for references. This provides reference tracking for global variables, CommonJS modules, and ES modules. * - * @see {@link https://eslint-utils.mysticatea.dev/api/scope-utils.html#referencetracker-class} + * @see {@link https://eslint-community.github.io/eslint-utils/api/scope-utils.html#referencetracker-class} */ const ReferenceTracker = eslintUtils.ReferenceTracker as ReferenceTrackerStatic; diff --git a/packages/utils/src/ast-utils/eslint-utils/astUtilities.ts b/packages/utils/src/ast-utils/eslint-utils/astUtilities.ts index 6410d0b49de..e57046ca12d 100644 --- a/packages/utils/src/ast-utils/eslint-utils/astUtilities.ts +++ b/packages/utils/src/ast-utils/eslint-utils/astUtilities.ts @@ -1,4 +1,4 @@ -import * as eslintUtils from 'eslint-utils'; +import * as eslintUtils from '@eslint-community/eslint-utils'; import type * as TSESLint from '../../ts-eslint'; import type { TSESTree } from '../../ts-estree'; @@ -6,7 +6,7 @@ import type { TSESTree } from '../../ts-estree'; /** * Get the proper location of a given function node to report. * - * @see {@link https://eslint-utils.mysticatea.dev/api/ast-utils.html#getfunctionheadlocation} + * @see {@link https://eslint-community.github.io/eslint-utils/api/ast-utils.html#getfunctionheadlocation} */ const getFunctionHeadLocation = eslintUtils.getFunctionHeadLocation as ( node: @@ -19,7 +19,7 @@ const getFunctionHeadLocation = eslintUtils.getFunctionHeadLocation as ( /** * Get the name and kind of a given function node. * - * @see {@link https://eslint-utils.mysticatea.dev/api/ast-utils.html#getfunctionnamewithkind} + * @see {@link https://eslint-community.github.io/eslint-utils/api/ast-utils.html#getfunctionnamewithkind} */ const getFunctionNameWithKind = eslintUtils.getFunctionNameWithKind as ( node: @@ -33,7 +33,7 @@ const getFunctionNameWithKind = eslintUtils.getFunctionNameWithKind as ( * Get the property name of a given property node. * If the node is a computed property, this tries to compute the property name by the getStringIfConstant function. * - * @see {@link https://eslint-utils.mysticatea.dev/api/ast-utils.html#getpropertyname} + * @see {@link https://eslint-community.github.io/eslint-utils/api/ast-utils.html#getpropertyname} * @returns The property name of the node. If the property name is not constant then it returns `null`. */ const getPropertyName = eslintUtils.getPropertyName as ( @@ -52,7 +52,7 @@ const getPropertyName = eslintUtils.getPropertyName as ( * not been modified. * For example, it considers `Symbol.iterator`, ` String.raw``hello`` `, and `Object.freeze({a: 1}).a` as static. * - * @see {@link https://eslint-utils.mysticatea.dev/api/ast-utils.html#getstaticvalue} + * @see {@link https://eslint-community.github.io/eslint-utils/api/ast-utils.html#getstaticvalue} * @returns The `{ value: any }` shaped object. The `value` property is the static value. If it couldn't compute the * static value of the node, it returns `null`. */ @@ -65,7 +65,7 @@ const getStaticValue = eslintUtils.getStaticValue as ( * Get the string value of a given node. * This function is a tiny wrapper of the getStaticValue function. * - * @see {@link https://eslint-utils.mysticatea.dev/api/ast-utils.html#getstringifconstant} + * @see {@link https://eslint-community.github.io/eslint-utils/api/ast-utils.html#getstringifconstant} */ const getStringIfConstant = eslintUtils.getStringIfConstant as ( node: TSESTree.Node, @@ -93,7 +93,7 @@ const getStringIfConstant = eslintUtils.getStringIfConstant as ( * - `Property([computed = true])` * - `UnaryExpression([operator = "-" | "+" | "!" | "~"])` * - * @see {@link https://eslint-utils.mysticatea.dev/api/ast-utils.html#hassideeffect} + * @see {@link https://eslint-community.github.io/eslint-utils/api/ast-utils.html#hassideeffect} */ const hasSideEffect = eslintUtils.hasSideEffect as ( node: TSESTree.Node, @@ -109,7 +109,7 @@ const isParenthesized = eslintUtils.isParenthesized as { * Check whether a given node is parenthesized or not. * This function detects it correctly even if it's parenthesized by specific syntax. * - * @see {@link https://eslint-utils.mysticatea.dev/api/ast-utils.html#isparenthesized} + * @see {@link https://eslint-community.github.io/eslint-utils/api/ast-utils.html#isparenthesized} * @returns `true` if the node is parenthesized. * If `times` was given, it returns `true` only if the node is parenthesized the `times` times. * For example, `isParenthesized(2, node, sourceCode)` returns true for `((foo))`, but not for `(foo)`. diff --git a/packages/utils/src/ast-utils/eslint-utils/predicates.ts b/packages/utils/src/ast-utils/eslint-utils/predicates.ts index 9d1534882d1..2a3d6d678d4 100644 --- a/packages/utils/src/ast-utils/eslint-utils/predicates.ts +++ b/packages/utils/src/ast-utils/eslint-utils/predicates.ts @@ -1,4 +1,4 @@ -import * as eslintUtils from 'eslint-utils'; +import * as eslintUtils from '@eslint-community/eslint-utils'; import type { TSESTree } from '../../ts-estree'; diff --git a/packages/utils/src/ast-utils/eslint-utils/scopeAnalysis.ts b/packages/utils/src/ast-utils/eslint-utils/scopeAnalysis.ts index 61ab8e33a41..563c51c7782 100644 --- a/packages/utils/src/ast-utils/eslint-utils/scopeAnalysis.ts +++ b/packages/utils/src/ast-utils/eslint-utils/scopeAnalysis.ts @@ -1,4 +1,4 @@ -import * as eslintUtils from 'eslint-utils'; +import * as eslintUtils from '@eslint-community/eslint-utils'; import type * as TSESLint from '../../ts-eslint'; import type { TSESTree } from '../../ts-estree'; @@ -6,7 +6,7 @@ import type { TSESTree } from '../../ts-estree'; /** * Get the variable of a given name. * - * @see {@link https://eslint-utils.mysticatea.dev/api/scope-utils.html#findvariable} + * @see {@link https://eslint-community.github.io/eslint-utils/api/scope-utils.html#findvariable} */ const findVariable = eslintUtils.findVariable as ( initialScope: TSESLint.Scope.Scope, @@ -16,7 +16,7 @@ const findVariable = eslintUtils.findVariable as ( /** * Get the innermost scope which contains a given node. * - * @see {@link https://eslint-utils.mysticatea.dev/api/scope-utils.html#getinnermostscope} + * @see {@link https://eslint-community.github.io/eslint-utils/api/scope-utils.html#getinnermostscope} * @returns The innermost scope which contains the given node. * If such scope doesn't exist then it returns the 1st argument `initialScope`. */ diff --git a/packages/utils/typings/eslint-utils.d.ts b/packages/utils/typings/eslint-community-eslint-utils.d.ts similarity index 96% rename from packages/utils/typings/eslint-utils.d.ts rename to packages/utils/typings/eslint-community-eslint-utils.d.ts index 5843e99466f..7c5fea7d256 100644 --- a/packages/utils/typings/eslint-utils.d.ts +++ b/packages/utils/typings/eslint-community-eslint-utils.d.ts @@ -1,4 +1,4 @@ -declare module 'eslint-utils' { +declare module '@eslint-community/eslint-utils' { export const findVariable: unknown; export const getFunctionHeadLocation: unknown; export const getFunctionNameWithKind: unknown; diff --git a/yarn.lock b/yarn.lock index 1b3a9987d30..cbe3e536a70 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2007,6 +2007,18 @@ dependencies: eslint-visitor-keys "^3.3.0" +"@eslint-community/eslint-utils@^4.2.0": + version "4.2.0" + resolved "https://registry.yarnpkg.com/@eslint-community/eslint-utils/-/eslint-utils-4.2.0.tgz#a831e6e468b4b2b5ae42bf658bea015bf10bc518" + integrity sha512-gB8T4H4DEfX2IV9zGDJPOBgP1e/DbfCPDTtEqUMckpvzS1OYtva8JdFYBqMwYk7xAQ429WGF/UPqn8uQ//h2vQ== + dependencies: + eslint-visitor-keys "^3.3.0" + +"@eslint-community/regexpp@^4.4.0": + version "4.4.0" + resolved "https://registry.yarnpkg.com/@eslint-community/regexpp/-/regexpp-4.4.0.tgz#3e61c564fcd6b921cb789838631c5ee44df09403" + integrity sha512-A9983Q0LnDGdLPjxyXQ00sbV+K+O+ko2Dr+CZigbHWtX9pNfxlaBkMR8X1CztI73zuEyEBXTVjx7CE+/VSwDiQ== + "@eslint/eslintrc@^1.2.3": version "1.2.3" resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-1.2.3.tgz#fcaa2bcef39e13d6e9e7f6271f4cc7cae1174886"