Skip to content

Commit a3dd99a

Browse files
committed
Make sure we point out to the not defined but used props correctly
1 parent af8a524 commit a3dd99a

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

lib/util/getUsedVariablesInPug.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,17 @@ const getUsedVariablesInPug = (template = '') => {
154154
variablesInScope = getUsedVariablesInPug(body)
155155
.filter(item => item.allNames.length > 1 || item.extra.isSpreadElement === true)
156156
.map(item => ({
157-
// @TODO: Make the `loc` value relative to the main template
158157
...item,
158+
loc: {
159+
start: {
160+
line: variable.loc.start.line + item.loc.start.line - 1,
161+
column: item.loc.start.column,
162+
},
163+
end: {
164+
line: variable.loc.start.line + item.loc.end.line - 1,
165+
column: item.loc.end.column,
166+
},
167+
},
159168
allNames: item.allNames[0] === token.val
160169
? ['__COMPUTED_PROP__', ...item.allNames.slice(1)]
161170
: item.allNames,

tests/lib/rules/prop-types.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,31 @@ const cases = [
641641
buildError([9, 23], [9, 37], buildUnusedMessage('a.unused')),
642642
],
643643
},
644+
{
645+
only: true,
646+
code: `
647+
function Component(props) {
648+
const id = true
649+
650+
return pug\`
651+
each item in props.list
652+
div
653+
div(key=item.id)
654+
= item.test
655+
div Hello
656+
657+
= item.test
658+
\`
659+
}
660+
Component.propTypes = {
661+
list: PropTypes.arrayOf(PropTypes.shape({})),
662+
}
663+
`,
664+
errors: [
665+
buildError([8, 32], [8, 34], buildMissingMessage('list[].id')),
666+
buildError([9, 28], [9, 32], buildMissingMessage('list[].test')),
667+
],
668+
},
644669
],
645670
},
646671
]

0 commit comments

Comments
 (0)