Skip to content

Commit 497a5b6

Browse files
author
Mateus Felix
committed
refactor(no-container): allow custom render
functions
1 parent d8e555e commit 497a5b6

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

lib/node-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ function isRenderFunction(
118118

119119
export function isRenderVariableDeclarator(
120120
node: TSESTree.VariableDeclarator,
121-
renderFunctions: string[] = []
121+
renderFunctions: string[]
122122
) {
123123
if (node.init) {
124124
if (isAwaitExpression(node.init)) {

lib/rules/no-container.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,30 @@ export default ESLintUtils.RuleCreator(getDocsUrl)({
2525
'Unexpected use of container methods. Prefer the use of "screen.someMethod()".',
2626
},
2727
fixable: null,
28-
schema: [],
28+
schema: [
29+
{
30+
type: 'object',
31+
properties: {
32+
renderFunctions: {
33+
type: 'array',
34+
},
35+
},
36+
},
37+
],
2938
},
30-
defaultOptions: [],
39+
defaultOptions: [
40+
{
41+
renderFunctions: [],
42+
},
43+
],
3144

32-
create(context) {
45+
create(context, [options]) {
46+
const { renderFunctions } = options;
3347
let destructuredContainerName = '';
3448

3549
return {
3650
VariableDeclarator(node) {
37-
if (isRenderVariableDeclarator(node)) {
51+
if (isRenderVariableDeclarator(node, renderFunctions)) {
3852
if (isObjectPattern(node.id)) {
3953
const containerIndex = node.id.properties.findIndex(
4054
property =>
@@ -45,8 +59,7 @@ export default ESLintUtils.RuleCreator(getDocsUrl)({
4559
if (containerIndex !== -1) {
4660
const nodeValue = node.id.properties[containerIndex].value;
4761
destructuredContainerName =
48-
isIdentifier(nodeValue) &&
49-
nodeValue.name;
62+
isIdentifier(nodeValue) && nodeValue.name;
5063
}
5164
}
5265
}

0 commit comments

Comments
 (0)