Skip to content

Commit

Permalink
Fix(ESLint): Cannot read properties of null (reading 'type')
Browse files Browse the repository at this point in the history
  • Loading branch information
0Miles committed Mar 1, 2024
1 parent 0a67984 commit 1669ac0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/eslint-plugin/src/utils/define-visitors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ export default function defineVisitors({ context, settings, options }: { context
VAttribute: function (node: any) {
if (node.value && node.value.type === 'VLiteral') {
visitNode(node)
} else if (node.value && node.value.type === 'VExpressionContainer' && node.value.expression.type === 'ArrayExpression') {
} else if (node.value && node.value.type === 'VExpressionContainer' && node.value.expression?.type === 'ArrayExpression') {
node.value.expression.elements.forEach((arg) => {
visitNode(node, arg)
})
} else if (node.value && node.value.type === 'VExpressionContainer' && node.value.expression.type === 'ObjectExpression') {
} else if (node.value && node.value.type === 'VExpressionContainer' && node.value.expression?.type === 'ObjectExpression') {
node.value.expression.properties.forEach((prop) => {
visitNode(node, prop)
})
Expand Down
23 changes: 22 additions & 1 deletion packages/eslint-plugin/tests/class-matching/vue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ const ruleTester = new RuleTester({
})

ruleTester.run('vue class order', rule, {
valid: [{ code: `<div class="bg:black f:24 fg:white m:8 p:8">Simple, basic</div>` }],
valid: [
{ code: `<div class="bg:black f:24 fg:white m:8 p:8">Simple, basic</div>` }
],
invalid: [
{
code: `<template><div class="m:8 bg:black p:8 f:24 fg:white">Enhancing readability</div></template>`,
Expand Down Expand Up @@ -102,6 +104,25 @@ ruleTester.run('vue class order', rule, {
],
filename: 'test.vue',
parser: require.resolve('vue-eslint-parser'),
},
{
code: `<template>
<input type="password"
placeholder="如果我在Vue元件內不小心寫了沒有function的事件VSCODE的ESLINT套件會無法格式化,輸出會有錯誤"
class="bg:black p:8 f:24 fg:white m:8"
@blur.prevent="" />
</template>`,
output: `<template>
<input type="password"
placeholder="如果我在Vue元件內不小心寫了沒有function的事件VSCODE的ESLINT套件會無法格式化,輸出會有錯誤"
class="bg:black f:24 fg:white m:8 p:8"
@blur.prevent="" />
</template>`,
errors: [
{ messageId: 'invalidClassOrder' }
],
filename: 'test.vue',
parser: require.resolve('vue-eslint-parser'),
}
],
})

0 comments on commit 1669ac0

Please sign in to comment.