|
4 | 4 | */ |
5 | 5 | 'use strict'; |
6 | 6 |
|
7 | | -// const variableUtil = require('../util/variable'); |
| 7 | +const variableUtil = require('../util/variable'); |
8 | 8 |
|
9 | 9 | // ------------------------------------------------------------------------------ |
10 | 10 | // Rule Definition |
@@ -33,7 +33,7 @@ module.exports = { |
33 | 33 | const sourceCode = context.getSourceCode(); |
34 | 34 | const configuration = context.options[0] || {}; |
35 | 35 | const ignoreCase = configuration.ignoreCase || false; |
36 | | - // const propWrapperFunctions = new Set(context.settings.propWrapperFunctions || []); |
| 36 | + const propWrapperFunctions = new Set(context.settings.propWrapperFunctions || []); |
37 | 37 |
|
38 | 38 | /** |
39 | 39 | * Get properties name |
@@ -73,19 +73,19 @@ module.exports = { |
73 | 73 | * @param {string} name Name of the variable to look for. |
74 | 74 | * @returns {ASTNode|null} Return null if the variable could not be found, ASTNode otherwise. |
75 | 75 | */ |
76 | | - // function findVariableByName(name) { |
77 | | - // const variable = variableUtil.variablesInScope(context).find(item => item.name === name); |
78 | | - // |
79 | | - // if (!variable || !variable.defs[0] || !variable.defs[0].node) { |
80 | | - // return null; |
81 | | - // } |
82 | | - // |
83 | | - // if (variable.defs[0].node.type === 'TypeAlias') { |
84 | | - // return variable.defs[0].node.right; |
85 | | - // } |
86 | | - // |
87 | | - // return variable.defs[0].node.init; |
88 | | - // } |
| 76 | + function findVariableByName(name) { |
| 77 | + const variable = variableUtil.variablesInScope(context).find(item => item.name === name); |
| 78 | + |
| 79 | + if (!variable || !variable.defs[0] || !variable.defs[0].node) { |
| 80 | + return null; |
| 81 | + } |
| 82 | + |
| 83 | + if (variable.defs[0].node.type === 'TypeAlias') { |
| 84 | + return variable.defs[0].node.right; |
| 85 | + } |
| 86 | + |
| 87 | + return variable.defs[0].node.init; |
| 88 | + } |
89 | 89 |
|
90 | 90 | /** |
91 | 91 | * Checks if defaultProps declarations are sorted |
@@ -124,18 +124,18 @@ module.exports = { |
124 | 124 | case 'ObjectExpression': |
125 | 125 | checkSorted(node.properties); |
126 | 126 | break; |
127 | | - // case 'Identifier': |
128 | | - // const propTypesObject = findVariableByName(node.name); |
129 | | - // if (propTypesObject && propTypesObject.properties) { |
130 | | - // checkSorted(propTypesObject.properties); |
131 | | - // } |
132 | | - // break; |
133 | | - // case 'CallExpression': |
134 | | - // const innerNode = node.arguments && node.arguments[0]; |
135 | | - // if (propWrapperFunctions.has(node.callee.name) && innerNode) { |
136 | | - // checkNode(innerNode); |
137 | | - // } |
138 | | - // break; |
| 127 | + case 'Identifier': |
| 128 | + const propTypesObject = findVariableByName(node.name); |
| 129 | + if (propTypesObject && propTypesObject.properties) { |
| 130 | + checkSorted(propTypesObject.properties); |
| 131 | + } |
| 132 | + break; |
| 133 | + case 'CallExpression': |
| 134 | + const innerNode = node.arguments && node.arguments[0]; |
| 135 | + if (propWrapperFunctions.has(node.callee.name) && innerNode) { |
| 136 | + checkNode(innerNode); |
| 137 | + } |
| 138 | + break; |
139 | 139 | default: |
140 | 140 | break; |
141 | 141 | } |
|
0 commit comments