Skip to content

Commit

Permalink
Use @eslint-community/eslint-utils package (#2112)
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi authored Mar 23, 2023
1 parent cfbfa12 commit 2e94cdb
Show file tree
Hide file tree
Showing 33 changed files with 82 additions and 38 deletions.
4 changes: 3 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand Down
39 changes: 39 additions & 0 deletions eslint-internal-rules/require-eslint-community.js
Original file line number Diff line number Diff line change
@@ -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}'`)
}
})
}
}
}
}
2 changes: 1 addition & 1 deletion lib/rules/custom-event-name-casing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/next-tick-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-async-in-computed-properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @author Armano
*/
'use strict'
const { ReferenceTracker } = require('eslint-utils')
const { ReferenceTracker } = require('@eslint-community/eslint-utils')
const utils = require('../utils')

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-expose-after-await.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
'use strict'

const { findVariable } = require('eslint-utils')
const { findVariable } = require('@eslint-community/eslint-utils')
const utils = require('../utils')

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-extra-parens.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
4 changes: 2 additions & 2 deletions lib/rules/no-lifecycle-after-await.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-multiple-slot-args.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-mutating-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
6 changes: 3 additions & 3 deletions lib/rules/no-restricted-call-after-await.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-restricted-custom-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-setup-props-destructure.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
5 changes: 4 additions & 1 deletion lib/rules/no-side-effects-in-computed-properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-unused-properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-use-computed-property-like-method.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
'use strict'

const eslintUtils = require('eslint-utils')
const eslintUtils = require('@eslint-community/eslint-utils')
const utils = require('../utils')

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-watch-after-await.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/padding-lines-in-component-definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/

const utils = require('../utils')
const { isCommentToken } = require('eslint-utils')
const { isCommentToken } = require('@eslint-community/eslint-utils')

const AvailablePaddingOptions = {
Never: 'never',
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/require-explicit-emits.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/require-expose.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const {
findVariable,
isOpeningBraceToken,
isClosingBraceToken
} = require('eslint-utils')
} = require('@eslint-community/eslint-utils')
const utils = require('../utils')
const { getVueComponentDefinitionType } = require('../utils')

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/require-slots-as-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/return-in-computed-property.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @author Armano
*/
'use strict'
const { ReferenceTracker } = require('eslint-utils')
const { ReferenceTracker } = require('@eslint-community/eslint-utils')
const utils = require('../utils')

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/valid-define-emits.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
'use strict'

const { findVariable } = require('eslint-utils')
const { findVariable } = require('@eslint-community/eslint-utils')
const utils = require('../utils')

module.exports = {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/valid-define-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
'use strict'

const { findVariable } = require('eslint-utils')
const { findVariable } = require('@eslint-community/eslint-utils')
const utils = require('../utils')

module.exports = {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/valid-next-tick.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/indent-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const {
isClosingBracketToken,
isSemicolonToken,
isNotSemicolonToken
} = require('eslint-utils')
} = require('@eslint-community/eslint-utils')
const {
isComment,
isNotComment,
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/indent-ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const {
isNotClosingParenToken,
isClosingBracketToken,
isOpeningBracketToken
} = require('eslint-utils')
} = require('@eslint-community/eslint-utils')
const { isTypeNode } = require('./ts-ast-utils')

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/property-references.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/ref-object-references.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/utils/ts-ast-utils.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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(
Expand Down

0 comments on commit 2e94cdb

Please sign in to comment.