Skip to content

Commit

Permalink
Improve compatibility with ESLint v9 (#2331)
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi authored Nov 29, 2023
1 parent 022afb5 commit 7b7b4ce
Show file tree
Hide file tree
Showing 62 changed files with 290 additions and 165 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
/* empty */
}
4 changes: 4 additions & 0 deletions docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ export default async () => {
plugins: [vitePluginRequireResolve(), viteCommonjs()],
resolve: {
alias: {
'eslint/use-at-your-own-risk': path.join(
dirname,
'./build-system/shim/eslint/use-at-your-own-risk.mjs'
),
eslint: path.join(dirname, './build-system/shim/eslint.mjs'),
assert: path.join(dirname, './build-system/shim/assert.mjs'),
path: path.join(dirname, './build-system/shim/path.mjs'),
Expand Down
14 changes: 14 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,20 @@ module.exports = [
'dot-notation': 'error',
'arrow-body-style': 'error',

'no-restricted-properties': [
'error',
{
object: 'context',
property: 'parserServices',
message: 'Use sourceCode.parserServices'
},
{
object: 'context',
property: 'getScope',
message: 'Use utils.getScope'
}
],

'unicorn/consistent-function-scoping': [
'error',
{ checkArrowFunctions: false }
Expand Down
5 changes: 3 additions & 2 deletions lib/rules/block-order.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,10 @@ module.exports = {
function getOrderElement(element) {
return orders.find((o) => o.selector.test(element))
}
const sourceCode = context.getSourceCode()
const documentFragment =
context.parserServices.getDocumentFragment &&
context.parserServices.getDocumentFragment()
sourceCode.parserServices.getDocumentFragment &&
sourceCode.parserServices.getDocumentFragment()

function getTopLevelHTMLElements() {
if (documentFragment) {
Expand Down
7 changes: 3 additions & 4 deletions lib/rules/block-tag-newline.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,14 @@ module.exports = {
},
/** @param {RuleContext} context */
create(context) {
const sourceCode = context.getSourceCode()
const df =
context.parserServices.getDocumentFragment &&
context.parserServices.getDocumentFragment()
sourceCode.parserServices.getDocumentFragment &&
sourceCode.parserServices.getDocumentFragment()
if (!df) {
return {}
}

const sourceCode = context.getSourceCode()

/**
* @param {VStartTag} startTag
* @param {string} beforeText
Expand Down
5 changes: 3 additions & 2 deletions lib/rules/comment-directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,10 @@ module.exports = {
const options = context.options[0] || {}
/** @type {boolean} */
const reportUnusedDisableDirectives = options.reportUnusedDisableDirectives
const sourceCode = context.getSourceCode()
const documentFragment =
context.parserServices.getDocumentFragment &&
context.parserServices.getDocumentFragment()
sourceCode.parserServices.getDocumentFragment &&
sourceCode.parserServices.getDocumentFragment()

return {
Program(node) {
Expand Down
5 changes: 3 additions & 2 deletions lib/rules/component-name-in-template-casing.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,10 @@ module.exports = {
/** @type {string[]} */
const globals = (options.globals || []).map(casing.pascalCase)
const registeredComponentsOnly = options.registeredComponentsOnly !== false
const sourceCode = context.getSourceCode()
const tokens =
context.parserServices.getTemplateBodyTokenStore &&
context.parserServices.getTemplateBodyTokenStore()
sourceCode.parserServices.getTemplateBodyTokenStore &&
sourceCode.parserServices.getTemplateBodyTokenStore()

/** @type { Set<string> } */
const registeredComponents = new Set(globals)
Expand Down
15 changes: 12 additions & 3 deletions lib/rules/custom-event-name-casing.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,10 @@ module.exports = {
return
}
// const emit = defineEmits()
const variable = findVariable(context.getScope(), emitParam)
const variable = findVariable(
utils.getScope(context, emitParam),
emitParam
)
if (!variable) {
return
}
Expand Down Expand Up @@ -251,7 +254,10 @@ module.exports = {
}
const emitParam = emitProperty.value
// `setup(props, {emit})`
const variable = findVariable(context.getScope(), emitParam)
const variable = findVariable(
utils.getScope(context, emitParam),
emitParam
)
if (!variable) {
return
}
Expand All @@ -260,7 +266,10 @@ module.exports = {
}
} else {
// `setup(props, context)`
const variable = findVariable(context.getScope(), contextParam)
const variable = findVariable(
utils.getScope(context, contextParam),
contextParam
)
if (!variable) {
return
}
Expand Down
5 changes: 3 additions & 2 deletions lib/rules/first-attribute-linebreak.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ module.exports = {
const multiline =
(context.options[0] && context.options[0].multiline) || 'below'

const sourceCode = context.getSourceCode()
const template =
context.parserServices.getTemplateBodyTokenStore &&
context.parserServices.getTemplateBodyTokenStore()
sourceCode.parserServices.getTemplateBodyTokenStore &&
sourceCode.parserServices.getTemplateBodyTokenStore()

/**
* Report attribute
Expand Down
5 changes: 3 additions & 2 deletions lib/rules/html-closing-bracket-newline.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ module.exports = {
},
context.options[0] || {}
)
const sourceCode = context.getSourceCode()
const template =
context.parserServices.getTemplateBodyTokenStore &&
context.parserServices.getTemplateBodyTokenStore()
sourceCode.parserServices.getTemplateBodyTokenStore &&
sourceCode.parserServices.getTemplateBodyTokenStore()

return utils.defineDocumentVisitor(context, {
/** @param {VStartTag | VEndTag} node */
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/html-closing-bracket-spacing.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ module.exports = {
create(context) {
const sourceCode = context.getSourceCode()
const tokens =
context.parserServices.getTemplateBodyTokenStore &&
context.parserServices.getTemplateBodyTokenStore()
sourceCode.parserServices.getTemplateBodyTokenStore &&
sourceCode.parserServices.getTemplateBodyTokenStore()
const options = parseOptions(context.options[0], tokens)

return utils.defineDocumentVisitor(context, {
Expand Down
5 changes: 3 additions & 2 deletions lib/rules/html-indent.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ const utils = require('../utils')
module.exports = {
/** @param {RuleContext} context */
create(context) {
const sourceCode = context.getSourceCode()
const tokenStore =
context.parserServices.getTemplateBodyTokenStore &&
context.parserServices.getTemplateBodyTokenStore()
sourceCode.parserServices.getTemplateBodyTokenStore &&
sourceCode.parserServices.getTemplateBodyTokenStore()
const visitor = indentCommon.defineVisitor(context, tokenStore, {
baseIndent: 1
})
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/html-self-closing.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ module.exports = {
},
fix(fixer) {
const tokens =
context.parserServices.getTemplateBodyTokenStore()
sourceCode.parserServices.getTemplateBodyTokenStore()
const close = tokens.getLastToken(node.startTag)
if (close.type !== 'HTMLTagClose') {
return null
Expand All @@ -183,7 +183,7 @@ module.exports = {
},
fix(fixer) {
const tokens =
context.parserServices.getTemplateBodyTokenStore()
sourceCode.parserServices.getTemplateBodyTokenStore()
const close = tokens.getLastToken(node.startTag)
if (close.type !== 'HTMLSelfClosingTagClose') {
return null
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/max-attributes-per-line.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ module.exports = {
const multilineMaximum = configuration.multiline
const singlelinemMaximum = configuration.singleline
const template =
context.parserServices.getTemplateBodyTokenStore &&
context.parserServices.getTemplateBodyTokenStore()
sourceCode.parserServices.getTemplateBodyTokenStore &&
sourceCode.parserServices.getTemplateBodyTokenStore()

return utils.defineTemplateBodyVisitor(context, {
VStartTag(node) {
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/max-len.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,8 @@ module.exports = {
const scriptTokens = sourceCode.ast.tokens
const scriptComments = sourceCode.getAllComments()

if (context.parserServices.getTemplateBodyTokenStore && templateBody) {
const tokenStore = context.parserServices.getTemplateBodyTokenStore()
if (sourceCode.parserServices.getTemplateBodyTokenStore && templateBody) {
const tokenStore = sourceCode.parserServices.getTemplateBodyTokenStore()

const templateTokens = tokenStore.getTokens(templateBody, {
includeComments: true
Expand Down
5 changes: 3 additions & 2 deletions lib/rules/max-lines-per-block.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ module.exports = {
}

const code = context.getSourceCode()
const sourceCode = context.getSourceCode()
const documentFragment =
context.parserServices.getDocumentFragment &&
context.parserServices.getDocumentFragment()
sourceCode.parserServices.getDocumentFragment &&
sourceCode.parserServices.getDocumentFragment()

function getTopLevelHTMLElements() {
if (documentFragment) {
Expand Down
6 changes: 3 additions & 3 deletions lib/rules/multiline-html-element-content-newline.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ module.exports = {
const ignores = options.ignores
const ignoreWhenEmpty = options.ignoreWhenEmpty
const allowEmptyLines = options.allowEmptyLines
const template =
context.parserServices.getTemplateBodyTokenStore &&
context.parserServices.getTemplateBodyTokenStore()
const sourceCode = context.getSourceCode()
const template =
sourceCode.parserServices.getTemplateBodyTokenStore &&
sourceCode.parserServices.getTemplateBodyTokenStore()

/** @type {VElement | null} */
let inIgnoreElement = null
Expand Down
5 changes: 3 additions & 2 deletions lib/rules/mustache-interpolation-spacing.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ module.exports = {
/** @param {RuleContext} context */
create(context) {
const options = context.options[0] || 'always'
const sourceCode = context.getSourceCode()
const template =
context.parserServices.getTemplateBodyTokenStore &&
context.parserServices.getTemplateBodyTokenStore()
sourceCode.parserServices.getTemplateBodyTokenStore &&
sourceCode.parserServices.getTemplateBodyTokenStore()

return utils.defineTemplateBodyVisitor(context, {
/** @param {VExpressionContainer} node */
Expand Down
5 changes: 4 additions & 1 deletion lib/rules/next-tick-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ function getVueNextTickCallExpression(identifier, context) {
identifier.parent.type === 'CallExpression' &&
identifier.parent.callee === identifier
) {
const variable = findVariable(context.getScope(), identifier)
const variable = findVariable(
utils.getScope(context, identifier),
identifier
)

if (variable != null && variable.defs.length === 1) {
const def = variable.defs[0]
Expand Down
5 changes: 3 additions & 2 deletions lib/rules/no-async-in-computed-properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,9 @@ module.exports = {

return utils.compositingVisitors(
{
Program() {
const tracker = new ReferenceTracker(context.getScope())
/** @param {Program} program */
Program(program) {
const tracker = new ReferenceTracker(utils.getScope(context, program))
const traceMap = utils.createCompositionApiTraceMap({
[ReferenceTracker.ESM]: true,
computed: {
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/no-child-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ module.exports = {
if (elementNode.endTag === null) {
return
}

const tokenStore = context.parserServices.getTemplateBodyTokenStore()
const sourceCode = context.getSourceCode()
const tokenStore = sourceCode.parserServices.getTemplateBodyTokenStore()
const elementComments = tokenStore.getTokensBetween(
elementNode.startTag,
elementNode.endTag,
Expand Down
7 changes: 5 additions & 2 deletions lib/rules/no-dupe-keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ module.exports = {
for (const prop of props) {
if (!prop.propName) continue

const variable = findVariable(context.getScope(), prop.propName)
const variable = findVariable(
utils.getScope(context, node),
prop.propName
)
if (!variable || variable.defs.length === 0) continue

if (
Expand Down Expand Up @@ -149,7 +152,7 @@ module.exports = {
*/
function extractReferences(node) {
if (node.type === 'Identifier') {
const variable = findVariable(context.getScope(), node)
const variable = findVariable(utils.getScope(context, node), node)
if (!variable) {
return []
}
Expand Down
5 changes: 3 additions & 2 deletions lib/rules/no-dupe-v-else-if.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,10 @@ module.exports = {
},
/** @param {RuleContext} context */
create(context) {
const sourceCode = context.getSourceCode()
const tokenStore =
context.parserServices.getTemplateBodyTokenStore &&
context.parserServices.getTemplateBodyTokenStore()
sourceCode.parserServices.getTemplateBodyTokenStore &&
sourceCode.parserServices.getTemplateBodyTokenStore()
/**
* Determines whether the two given nodes are considered to be equal. In particular, given that the nodes
* represent expressions in a boolean context, `||` and `&&` can be considered as commutative operators.
Expand Down
5 changes: 3 additions & 2 deletions lib/rules/no-empty-component-block.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,11 @@ module.exports = {
* @returns {RuleListener} AST event handlers.
*/
create(context) {
if (!context.parserServices.getDocumentFragment) {
const sourceCode = context.getSourceCode()
if (!sourceCode.parserServices.getDocumentFragment) {
return {}
}
const documentFragment = context.parserServices.getDocumentFragment()
const documentFragment = sourceCode.parserServices.getDocumentFragment()
if (!documentFragment) {
return {}
}
Expand Down
10 changes: 8 additions & 2 deletions lib/rules/no-expose-after-await.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,10 @@ module.exports = {
// `setup(props, {emit})`
const variable =
exposeParam.type === 'Identifier'
? findVariable(context.getScope(), exposeParam)
? findVariable(
utils.getScope(context, exposeParam),
exposeParam
)
: null
if (!variable) {
return
Expand All @@ -205,7 +208,10 @@ module.exports = {
}
} else if (contextParam.type === 'Identifier') {
// `setup(props, context)`
const variable = findVariable(context.getScope(), contextParam)
const variable = findVariable(
utils.getScope(context, contextParam),
contextParam
)
if (!variable) {
return
}
Expand Down
5 changes: 3 additions & 2 deletions lib/rules/no-extra-parens.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,11 @@ function isIIFE(node) {
* @returns {TemplateListener} AST event handlers.
*/
function createForVueSyntax(context) {
if (!context.parserServices.getTemplateBodyTokenStore) {
const sourceCode = context.getSourceCode()
if (!sourceCode.parserServices.getTemplateBodyTokenStore) {
return {}
}
const tokenStore = context.parserServices.getTemplateBodyTokenStore()
const tokenStore = sourceCode.parserServices.getTemplateBodyTokenStore()

/**
* Checks if the given node turns into a filter when unwraped.
Expand Down
5 changes: 3 additions & 2 deletions lib/rules/no-lifecycle-after-await.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ module.exports = {

return utils.compositingVisitors(
{
Program() {
const tracker = new ReferenceTracker(context.getScope())
/** @param {Program} program */
Program(program) {
const tracker = new ReferenceTracker(utils.getScope(context, program))
const traceMap = {
/** @type {TraceMap} */
vue: {
Expand Down
Loading

0 comments on commit 7b7b4ce

Please sign in to comment.