From 2e94cdb6abc5d401ee8bb18b8e187e4ac1ee7b4b Mon Sep 17 00:00:00 2001 From: Yosuke Ota Date: Thu, 23 Mar 2023 17:32:42 +0900 Subject: [PATCH] Use `@eslint-community/eslint-utils` package (#2112) --- .eslintrc.js | 4 +- .../require-eslint-community.js | 39 +++++++++++++++++++ lib/rules/custom-event-name-casing.js | 2 +- lib/rules/next-tick-style.js | 2 +- lib/rules/no-async-in-computed-properties.js | 2 +- lib/rules/no-expose-after-await.js | 2 +- lib/rules/no-extra-parens.js | 2 +- lib/rules/no-lifecycle-after-await.js | 4 +- lib/rules/no-multiple-slot-args.js | 2 +- lib/rules/no-mutating-props.js | 2 +- lib/rules/no-restricted-call-after-await.js | 6 +-- lib/rules/no-restricted-custom-event.js | 2 +- lib/rules/no-setup-props-destructure.js | 2 +- .../no-side-effects-in-computed-properties.js | 5 ++- lib/rules/no-unused-properties.js | 2 +- .../no-use-computed-property-like-method.js | 2 +- lib/rules/no-watch-after-await.js | 2 +- .../padding-lines-in-component-definition.js | 2 +- lib/rules/require-explicit-emits.js | 2 +- lib/rules/require-expose.js | 2 +- lib/rules/require-slots-as-functions.js | 2 +- lib/rules/return-in-computed-property.js | 2 +- lib/rules/valid-define-emits.js | 2 +- lib/rules/valid-define-props.js | 2 +- lib/rules/valid-next-tick.js | 2 +- lib/utils/indent-common.js | 2 +- lib/utils/indent-ts.js | 2 +- lib/utils/index.js | 4 +- lib/utils/property-references.js | 2 +- lib/utils/ref-object-references.js | 2 +- lib/utils/ts-ast-utils.js | 2 +- package.json | 2 +- .../eslint-utils/index.d.ts | 6 +-- 33 files changed, 82 insertions(+), 38 deletions(-) create mode 100644 eslint-internal-rules/require-eslint-community.js rename typings/{ => @eslint-community}/eslint-utils/index.d.ts (93%) diff --git a/.eslintrc.js b/.eslintrc.js index b73aa7c94..6792d0296 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -131,7 +131,9 @@ module.exports = { 'unicorn/no-useless-undefined': 'off', 'unicorn/prefer-optional-catch-binding': 'off', // not supported by current ESLint parser version 'unicorn/prefer-module': 'off', - 'unicorn/prevent-abbreviations': 'off' + 'unicorn/prevent-abbreviations': 'off', + + 'require-eslint-community': ['error'] }, overrides: [ { diff --git a/eslint-internal-rules/require-eslint-community.js b/eslint-internal-rules/require-eslint-community.js new file mode 100644 index 000000000..f99afd8f9 --- /dev/null +++ b/eslint-internal-rules/require-eslint-community.js @@ -0,0 +1,39 @@ +'use strict' + +module.exports = { + meta: { + docs: { + description: 'enforce use of the `@eslint-community/*` package', + categories: ['Internal'] + }, + fixable: 'code', + messages: { + useCommunityPackageInstead: + 'Please use `@eslint-community/{{name}}` instead.' + }, + schema: [] + }, + + /** @param {import('eslint').Rule.RuleContext} context */ + create(context) { + return { + /** + * @param {import("../typings/eslint-plugin-vue/util-types/ast").Literal} node + */ + 'CallExpression > Literal.arguments[value=/^(?:eslint-utils|regexpp)$/u]'( + node + ) { + context.report({ + node, + messageId: 'useCommunityPackageInstead', + data: { + name: node.value + }, + fix(fixer) { + return fixer.replaceText(node, `'@eslint-community/${node.value}'`) + } + }) + } + } + } +} diff --git a/lib/rules/custom-event-name-casing.js b/lib/rules/custom-event-name-casing.js index 279aa9896..2361badb1 100644 --- a/lib/rules/custom-event-name-casing.js +++ b/lib/rules/custom-event-name-casing.js @@ -4,7 +4,7 @@ */ 'use strict' -const { findVariable } = require('eslint-utils') +const { findVariable } = require('@eslint-community/eslint-utils') const utils = require('../utils') const casing = require('../utils/casing') const { toRegExp } = require('../utils/regexp') diff --git a/lib/rules/next-tick-style.js b/lib/rules/next-tick-style.js index de9d989a9..ecf447b9b 100644 --- a/lib/rules/next-tick-style.js +++ b/lib/rules/next-tick-style.js @@ -7,7 +7,7 @@ 'use strict' const utils = require('../utils') -const { findVariable } = require('eslint-utils') +const { findVariable } = require('@eslint-community/eslint-utils') /** * @param {Identifier} identifier diff --git a/lib/rules/no-async-in-computed-properties.js b/lib/rules/no-async-in-computed-properties.js index c95b62a59..26255e365 100644 --- a/lib/rules/no-async-in-computed-properties.js +++ b/lib/rules/no-async-in-computed-properties.js @@ -3,7 +3,7 @@ * @author Armano */ 'use strict' -const { ReferenceTracker } = require('eslint-utils') +const { ReferenceTracker } = require('@eslint-community/eslint-utils') const utils = require('../utils') /** diff --git a/lib/rules/no-expose-after-await.js b/lib/rules/no-expose-after-await.js index ff38d1210..64661f1f3 100644 --- a/lib/rules/no-expose-after-await.js +++ b/lib/rules/no-expose-after-await.js @@ -4,7 +4,7 @@ */ 'use strict' -const { findVariable } = require('eslint-utils') +const { findVariable } = require('@eslint-community/eslint-utils') const utils = require('../utils') /** diff --git a/lib/rules/no-extra-parens.js b/lib/rules/no-extra-parens.js index b193a0eed..bf1ff1e46 100644 --- a/lib/rules/no-extra-parens.js +++ b/lib/rules/no-extra-parens.js @@ -3,7 +3,7 @@ */ 'use strict' -const { isParenthesized } = require('eslint-utils') +const { isParenthesized } = require('@eslint-community/eslint-utils') const { wrapCoreRule } = require('../utils') const { getStyleVariablesContext } = require('../utils/style-variables') diff --git a/lib/rules/no-lifecycle-after-await.js b/lib/rules/no-lifecycle-after-await.js index bb097910f..6a54f1c58 100644 --- a/lib/rules/no-lifecycle-after-await.js +++ b/lib/rules/no-lifecycle-after-await.js @@ -3,11 +3,11 @@ * See LICENSE file in root directory for full license. */ 'use strict' -const { ReferenceTracker } = require('eslint-utils') +const { ReferenceTracker } = require('@eslint-community/eslint-utils') const utils = require('../utils') /** - * @typedef {import('eslint-utils').TYPES.TraceMap} TraceMap + * @typedef {import('@eslint-community/eslint-utils').TYPES.TraceMap} TraceMap */ const LIFECYCLE_HOOKS = [ diff --git a/lib/rules/no-multiple-slot-args.js b/lib/rules/no-multiple-slot-args.js index 28b0652be..1b57832af 100644 --- a/lib/rules/no-multiple-slot-args.js +++ b/lib/rules/no-multiple-slot-args.js @@ -5,7 +5,7 @@ 'use strict' const utils = require('../utils') -const { findVariable } = require('eslint-utils') +const { findVariable } = require('@eslint-community/eslint-utils') module.exports = { meta: { diff --git a/lib/rules/no-mutating-props.js b/lib/rules/no-mutating-props.js index f1e2fc623..f79613d9c 100644 --- a/lib/rules/no-mutating-props.js +++ b/lib/rules/no-mutating-props.js @@ -5,7 +5,7 @@ 'use strict' const utils = require('../utils') -const { findVariable } = require('eslint-utils') +const { findVariable } = require('@eslint-community/eslint-utils') // https://github.com/vuejs/vue-next/blob/7c11c58faf8840ab97b6449c98da0296a60dddd8/packages/shared/src/globalsWhitelist.ts const GLOBALS_WHITE_LISTED = new Set([ diff --git a/lib/rules/no-restricted-call-after-await.js b/lib/rules/no-restricted-call-after-await.js index f4f3b6d38..d2b2a1414 100644 --- a/lib/rules/no-restricted-call-after-await.js +++ b/lib/rules/no-restricted-call-after-await.js @@ -5,12 +5,12 @@ 'use strict' const fs = require('fs') const path = require('path') -const { ReferenceTracker } = require('eslint-utils') +const { ReferenceTracker } = require('@eslint-community/eslint-utils') const utils = require('../utils') /** - * @typedef {import('eslint-utils').TYPES.TraceMap} TraceMap - * @typedef {import('eslint-utils').TYPES.TraceKind} TraceKind + * @typedef {import('@eslint-community/eslint-utils').TYPES.TraceMap} TraceMap + * @typedef {import('@eslint-community/eslint-utils').TYPES.TraceKind} TraceKind */ /** diff --git a/lib/rules/no-restricted-custom-event.js b/lib/rules/no-restricted-custom-event.js index 479aa0083..abe104b97 100644 --- a/lib/rules/no-restricted-custom-event.js +++ b/lib/rules/no-restricted-custom-event.js @@ -4,7 +4,7 @@ */ 'use strict' -const { findVariable } = require('eslint-utils') +const { findVariable } = require('@eslint-community/eslint-utils') const utils = require('../utils') const regexp = require('../utils/regexp') diff --git a/lib/rules/no-setup-props-destructure.js b/lib/rules/no-setup-props-destructure.js index 4c8f6109c..f89d9996e 100644 --- a/lib/rules/no-setup-props-destructure.js +++ b/lib/rules/no-setup-props-destructure.js @@ -3,7 +3,7 @@ * See LICENSE file in root directory for full license. */ 'use strict' -const { findVariable } = require('eslint-utils') +const { findVariable } = require('@eslint-community/eslint-utils') const utils = require('../utils') module.exports = { diff --git a/lib/rules/no-side-effects-in-computed-properties.js b/lib/rules/no-side-effects-in-computed-properties.js index 95611c26b..9feb02a89 100644 --- a/lib/rules/no-side-effects-in-computed-properties.js +++ b/lib/rules/no-side-effects-in-computed-properties.js @@ -3,7 +3,10 @@ * @author Michał Sajnóg */ 'use strict' -const { ReferenceTracker, findVariable } = require('eslint-utils') +const { + ReferenceTracker, + findVariable +} = require('@eslint-community/eslint-utils') const utils = require('../utils') /** diff --git a/lib/rules/no-unused-properties.js b/lib/rules/no-unused-properties.js index 040ee414c..99a20a40e 100644 --- a/lib/rules/no-unused-properties.js +++ b/lib/rules/no-unused-properties.js @@ -5,7 +5,7 @@ 'use strict' const utils = require('../utils') -const eslintUtils = require('eslint-utils') +const eslintUtils = require('@eslint-community/eslint-utils') const { isJSDocComment } = require('../utils/comments.js') const { getStyleVariablesContext } = require('../utils/style-variables') const { diff --git a/lib/rules/no-use-computed-property-like-method.js b/lib/rules/no-use-computed-property-like-method.js index f89c804da..242e6f18a 100644 --- a/lib/rules/no-use-computed-property-like-method.js +++ b/lib/rules/no-use-computed-property-like-method.js @@ -4,7 +4,7 @@ */ 'use strict' -const eslintUtils = require('eslint-utils') +const eslintUtils = require('@eslint-community/eslint-utils') const utils = require('../utils') /** diff --git a/lib/rules/no-watch-after-await.js b/lib/rules/no-watch-after-await.js index ae88fd51a..f566fb248 100644 --- a/lib/rules/no-watch-after-await.js +++ b/lib/rules/no-watch-after-await.js @@ -3,7 +3,7 @@ * See LICENSE file in root directory for full license. */ 'use strict' -const { ReferenceTracker } = require('eslint-utils') +const { ReferenceTracker } = require('@eslint-community/eslint-utils') const utils = require('../utils') /** diff --git a/lib/rules/padding-lines-in-component-definition.js b/lib/rules/padding-lines-in-component-definition.js index c15762b34..3f63050b4 100644 --- a/lib/rules/padding-lines-in-component-definition.js +++ b/lib/rules/padding-lines-in-component-definition.js @@ -10,7 +10,7 @@ */ const utils = require('../utils') -const { isCommentToken } = require('eslint-utils') +const { isCommentToken } = require('@eslint-community/eslint-utils') const AvailablePaddingOptions = { Never: 'never', diff --git a/lib/rules/require-explicit-emits.js b/lib/rules/require-explicit-emits.js index 0bcc18241..167613804 100644 --- a/lib/rules/require-explicit-emits.js +++ b/lib/rules/require-explicit-emits.js @@ -15,7 +15,7 @@ const { isOpeningBraceToken, isClosingBraceToken, isOpeningBracketToken -} = require('eslint-utils') +} = require('@eslint-community/eslint-utils') const utils = require('../utils') const { capitalize } = require('../utils/casing') diff --git a/lib/rules/require-expose.js b/lib/rules/require-expose.js index b74f29b93..5dca62ad9 100644 --- a/lib/rules/require-expose.js +++ b/lib/rules/require-expose.js @@ -8,7 +8,7 @@ const { findVariable, isOpeningBraceToken, isClosingBraceToken -} = require('eslint-utils') +} = require('@eslint-community/eslint-utils') const utils = require('../utils') const { getVueComponentDefinitionType } = require('../utils') diff --git a/lib/rules/require-slots-as-functions.js b/lib/rules/require-slots-as-functions.js index f2eaa7f83..671623cb3 100644 --- a/lib/rules/require-slots-as-functions.js +++ b/lib/rules/require-slots-as-functions.js @@ -5,7 +5,7 @@ 'use strict' const utils = require('../utils') -const { findVariable } = require('eslint-utils') +const { findVariable } = require('@eslint-community/eslint-utils') module.exports = { meta: { diff --git a/lib/rules/return-in-computed-property.js b/lib/rules/return-in-computed-property.js index a8f59fb56..87cce8b6f 100644 --- a/lib/rules/return-in-computed-property.js +++ b/lib/rules/return-in-computed-property.js @@ -3,7 +3,7 @@ * @author Armano */ 'use strict' -const { ReferenceTracker } = require('eslint-utils') +const { ReferenceTracker } = require('@eslint-community/eslint-utils') const utils = require('../utils') /** diff --git a/lib/rules/valid-define-emits.js b/lib/rules/valid-define-emits.js index f225c7af6..239da270d 100644 --- a/lib/rules/valid-define-emits.js +++ b/lib/rules/valid-define-emits.js @@ -4,7 +4,7 @@ */ 'use strict' -const { findVariable } = require('eslint-utils') +const { findVariable } = require('@eslint-community/eslint-utils') const utils = require('../utils') module.exports = { diff --git a/lib/rules/valid-define-props.js b/lib/rules/valid-define-props.js index 60101f495..fe471dc15 100644 --- a/lib/rules/valid-define-props.js +++ b/lib/rules/valid-define-props.js @@ -4,7 +4,7 @@ */ 'use strict' -const { findVariable } = require('eslint-utils') +const { findVariable } = require('@eslint-community/eslint-utils') const utils = require('../utils') module.exports = { diff --git a/lib/rules/valid-next-tick.js b/lib/rules/valid-next-tick.js index 2182dad0f..f2743a827 100644 --- a/lib/rules/valid-next-tick.js +++ b/lib/rules/valid-next-tick.js @@ -7,7 +7,7 @@ 'use strict' const utils = require('../utils') -const { findVariable } = require('eslint-utils') +const { findVariable } = require('@eslint-community/eslint-utils') /** * @param {Identifier} identifier diff --git a/lib/utils/indent-common.js b/lib/utils/indent-common.js index 4db6dea7f..4e3edb229 100644 --- a/lib/utils/indent-common.js +++ b/lib/utils/indent-common.js @@ -17,7 +17,7 @@ const { isClosingBracketToken, isSemicolonToken, isNotSemicolonToken -} = require('eslint-utils') +} = require('@eslint-community/eslint-utils') const { isComment, isNotComment, diff --git a/lib/utils/indent-ts.js b/lib/utils/indent-ts.js index 4c046f490..c7ad7ad63 100644 --- a/lib/utils/indent-ts.js +++ b/lib/utils/indent-ts.js @@ -11,7 +11,7 @@ const { isNotClosingParenToken, isClosingBracketToken, isOpeningBracketToken -} = require('eslint-utils') +} = require('@eslint-community/eslint-utils') const { isTypeNode } = require('./ts-ast-utils') /** diff --git a/lib/utils/index.js b/lib/utils/index.js index d76bb5156..8e0f65999 100644 --- a/lib/utils/index.js +++ b/lib/utils/index.js @@ -55,7 +55,7 @@ const VUE3_BUILTIN_COMPONENT_NAMES = new Set( const path = require('path') const vueEslintParser = require('vue-eslint-parser') const { traverseNodes, getFallbackKeys, NS } = vueEslintParser.AST -const { findVariable } = require('eslint-utils') +const { findVariable } = require('@eslint-community/eslint-utils') const { getComponentPropsFromTypeDefine, getComponentEmitsFromTypeDefine, @@ -1859,7 +1859,7 @@ module.exports = { /** * Wraps composition API trace map in both 'vue' and '@vue/composition-api' imports - * @param {import('eslint-utils').TYPES.TraceMap} map + * @param {import('@eslint-community/eslint-utils').TYPES.TraceMap} map */ createCompositionApiTraceMap: (map) => ({ vue: map, diff --git a/lib/utils/property-references.js b/lib/utils/property-references.js index 9e8b6638c..7a881af2f 100644 --- a/lib/utils/property-references.js +++ b/lib/utils/property-references.js @@ -6,7 +6,7 @@ 'use strict' const utils = require('./index') -const eslintUtils = require('eslint-utils') +const eslintUtils = require('@eslint-community/eslint-utils') /** * @typedef {import('./style-variables').StyleVariablesContext} StyleVariablesContext diff --git a/lib/utils/ref-object-references.js b/lib/utils/ref-object-references.js index 7760a49b8..ceecd89e3 100644 --- a/lib/utils/ref-object-references.js +++ b/lib/utils/ref-object-references.js @@ -6,7 +6,7 @@ 'use strict' const utils = require('./index') -const eslintUtils = require('eslint-utils') +const eslintUtils = require('@eslint-community/eslint-utils') const { definePropertyReferenceExtractor } = require('./property-references') const { ReferenceTracker } = eslintUtils diff --git a/lib/utils/ts-ast-utils.js b/lib/utils/ts-ast-utils.js index 181b51a53..e7cc52420 100644 --- a/lib/utils/ts-ast-utils.js +++ b/lib/utils/ts-ast-utils.js @@ -1,4 +1,4 @@ -const { findVariable } = require('eslint-utils') +const { findVariable } = require('@eslint-community/eslint-utils') /** * @typedef {import('@typescript-eslint/types').TSESTree.TypeNode} TypeNode * @typedef {import('@typescript-eslint/types').TSESTree.TSInterfaceBody} TSInterfaceBody diff --git a/package.json b/package.json index 54cef3a87..64c1b28e1 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "eslint": "^6.2.0 || ^7.0.0 || ^8.0.0" }, "dependencies": { - "eslint-utils": "^3.0.0", + "@eslint-community/eslint-utils": "^4.3.0", "natural-compare": "^1.4.0", "nth-check": "^2.0.1", "postcss-selector-parser": "^6.0.9", diff --git a/typings/eslint-utils/index.d.ts b/typings/@eslint-community/eslint-utils/index.d.ts similarity index 93% rename from typings/eslint-utils/index.d.ts rename to typings/@eslint-community/eslint-utils/index.d.ts index 25e9ba8d4..88d2cffbe 100644 --- a/typings/eslint-utils/index.d.ts +++ b/typings/@eslint-community/eslint-utils/index.d.ts @@ -1,6 +1,6 @@ -import * as VAST from '../eslint-plugin-vue/util-types/ast' -import { Token, Comment } from '../eslint-plugin-vue/util-types/node' -import { ParserServices } from '../eslint-plugin-vue/util-types/parser-services' +import * as VAST from '../../eslint-plugin-vue/util-types/ast' +import { Token, Comment } from '../../eslint-plugin-vue/util-types/node' +import { ParserServices } from '../../eslint-plugin-vue/util-types/parser-services' import eslint from 'eslint' export function findVariable(