Skip to content

Commit d687e25

Browse files
committed
Merge branch 'master' of https://github.com/y-hsgw/eslint-plugin-react into feature/add-jsdoc-annotations
2 parents 6e0c30f + a2306e7 commit d687e25

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+668
-601
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
55

66
## Unreleased
77

8+
### Fixed
9+
* [`jsx-curly-brace-presence`]: do not trigger on strings containing a quote character ([#3798][] @akulsr0)
10+
11+
[#3798]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3798
12+
813
## [7.35.0] - 2024.07.19
914

1015
### Added

lib/rules/boolean-prop-naming.js

+28-25
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const values = require('object.values');
1010

1111
const Components = require('../util/Components');
1212
const propsUtil = require('../util/props');
13+
const astUtil = require('../util/ast');
1314
const docsUrl = require('../util/docsUrl');
1415
const propWrapperUtil = require('../util/propWrapper');
1516
const report = require('../util/report');
@@ -18,6 +19,18 @@ const eslintUtil = require('../util/eslint');
1819
const getSourceCode = eslintUtil.getSourceCode;
1920
const getText = eslintUtil.getText;
2021

22+
/**
23+
* Checks if prop is nested
24+
* @param {Object} prop Property object, single prop type declaration
25+
* @returns {boolean}
26+
*/
27+
function nestedPropTypes(prop) {
28+
return (
29+
prop.type === 'Property'
30+
&& astUtil.isCallExpression(prop.value)
31+
);
32+
}
33+
2134
// ------------------------------------------------------------------------------
2235
// Rule Definition
2336
// ------------------------------------------------------------------------------
@@ -128,7 +141,7 @@ module.exports = {
128141
/**
129142
* Checks if prop is declared in flow way
130143
* @param {Object} prop Property object, single prop type declaration
131-
* @returns {Boolean}
144+
* @returns {boolean}
132145
*/
133146
function flowCheck(prop) {
134147
return (
@@ -141,7 +154,7 @@ module.exports = {
141154
/**
142155
* Checks if prop is declared in regular way
143156
* @param {Object} prop Property object, single prop type declaration
144-
* @returns {Boolean}
157+
* @returns {boolean}
145158
*/
146159
function regularCheck(prop) {
147160
const propKey = getPropKey(prop);
@@ -162,33 +175,23 @@ module.exports = {
162175
);
163176
}
164177

165-
/**
166-
* Checks if prop is nested
167-
* @param {Object} prop Property object, single prop type declaration
168-
* @returns {Boolean}
169-
*/
170-
function nestedPropTypes(prop) {
171-
return (
172-
prop.type === 'Property'
173-
&& prop.value.type === 'CallExpression'
174-
);
175-
}
176-
177178
/**
178179
* Runs recursive check on all proptypes
179180
* @param {Array} proptypes A list of Property object (for each proptype defined)
180181
* @param {Function} addInvalidProp callback to run for each error
181182
*/
182183
function runCheck(proptypes, addInvalidProp) {
183-
(proptypes || []).forEach((prop) => {
184-
if (config.validateNested && nestedPropTypes(prop)) {
185-
runCheck(prop.value.arguments[0].properties, addInvalidProp);
186-
return;
187-
}
188-
if (flowCheck(prop) || regularCheck(prop) || tsCheck(prop)) {
189-
addInvalidProp(prop);
190-
}
191-
});
184+
if (proptypes) {
185+
proptypes.forEach((prop) => {
186+
if (config.validateNested && nestedPropTypes(prop)) {
187+
runCheck(prop.value.arguments[0].properties, addInvalidProp);
188+
return;
189+
}
190+
if (flowCheck(prop) || regularCheck(prop) || tsCheck(prop)) {
191+
addInvalidProp(prop);
192+
}
193+
});
194+
}
192195
}
193196

194197
/**
@@ -309,7 +312,7 @@ module.exports = {
309312
}
310313
if (
311314
node.value
312-
&& node.value.type === 'CallExpression'
315+
&& astUtil.isCallExpression(node.value)
313316
&& propWrapperUtil.isPropWrapperFunction(
314317
context,
315318
getText(context, node.value.callee)
@@ -335,7 +338,7 @@ module.exports = {
335338
}
336339
const right = node.parent.right;
337340
if (
338-
right.type === 'CallExpression'
341+
astUtil.isCallExpression(right)
339342
&& propWrapperUtil.isPropWrapperFunction(
340343
context,
341344
getText(context, right.callee)

lib/rules/display-name.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,13 @@ module.exports = {
7373
/**
7474
* Checks if React.forwardRef is nested inside React.memo
7575
* @param {ASTNode} node The AST node being checked.
76-
* @returns {Boolean} True if React.forwardRef is nested inside React.memo, false if not.
76+
* @returns {boolean} True if React.forwardRef is nested inside React.memo, false if not.
7777
*/
7878
function isNestedMemo(node) {
79-
const argumentIsCallExpression = node.arguments && node.arguments[0] && node.arguments[0].type === 'CallExpression';
80-
81-
return node.type === 'CallExpression' && argumentIsCallExpression && utils.isPragmaComponentWrapper(node);
79+
return astUtil.isCallExpression(node)
80+
&& node.arguments
81+
&& astUtil.isCallExpression(node.arguments[0])
82+
&& utils.isPragmaComponentWrapper(node);
8283
}
8384

8485
/**
@@ -111,7 +112,7 @@ module.exports = {
111112
/**
112113
* Checks if the component have a name set by the transpiler
113114
* @param {ASTNode} node The AST node being checked.
114-
* @returns {Boolean} True if component has a name, false if not.
115+
* @returns {boolean} True if component has a name, false if not.
115116
*/
116117
function hasTranspilerName(node) {
117118
const namedObjectAssignment = (
@@ -198,7 +199,7 @@ module.exports = {
198199
if (!component) {
199200
return;
200201
}
201-
markDisplayNameAsDeclared(component.node.type === 'TSAsExpression' ? component.node.expression : component.node);
202+
markDisplayNameAsDeclared(astUtil.unwrapTSAsExpression(component.node));
202203
},
203204

204205
'FunctionExpression, FunctionDeclaration, ArrowFunctionExpression'(node) {

lib/rules/forbid-prop-types.js

+17-21
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ module.exports = {
135135
) {
136136
value = value.object;
137137
}
138-
if (value.type === 'CallExpression') {
138+
if (astUtil.isCallExpression(value)) {
139139
if (!isPropTypesPackage(value.callee)) {
140140
return;
141141
}
@@ -159,29 +159,25 @@ module.exports = {
159159
}
160160

161161
function checkNode(node) {
162-
switch (node && node.type) {
163-
case 'ObjectExpression':
164-
checkProperties(node.properties);
165-
break;
166-
case 'Identifier': {
167-
const propTypesObject = variableUtil.findVariableByName(context, node, node.name);
168-
if (propTypesObject && propTypesObject.properties) {
169-
checkProperties(propTypesObject.properties);
170-
}
171-
break;
162+
if (!node) {
163+
return;
164+
}
165+
166+
if (node.type === 'ObjectExpression') {
167+
checkProperties(node.properties);
168+
} else if (node.type === 'Identifier') {
169+
const propTypesObject = variableUtil.findVariableByName(context, node, node.name);
170+
if (propTypesObject && propTypesObject.properties) {
171+
checkProperties(propTypesObject.properties);
172172
}
173-
case 'CallExpression': {
174-
const innerNode = node.arguments && node.arguments[0];
175-
if (
176-
propWrapperUtil.isPropWrapperFunction(context, getText(context, node.callee))
173+
} else if (astUtil.isCallExpression(node)) {
174+
const innerNode = node.arguments && node.arguments[0];
175+
if (
176+
propWrapperUtil.isPropWrapperFunction(context, getText(context, node.callee))
177177
&& innerNode
178-
) {
179-
checkNode(innerNode);
180-
}
181-
break;
178+
) {
179+
checkNode(innerNode);
182180
}
183-
default:
184-
break;
185181
}
186182
}
187183

lib/rules/jsx-closing-bracket-location.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ module.exports = {
101101
/**
102102
* Get expected location for the closing bracket
103103
* @param {Object} tokens Locations of the opening bracket, closing bracket and last prop
104-
* @return {String} Expected location for the closing bracket
104+
* @return {string} Expected location for the closing bracket
105105
*/
106106
function getExpectedLocation(tokens) {
107107
let location;
@@ -122,7 +122,7 @@ module.exports = {
122122
* Get the correct 0-indexed column for the closing bracket, given the
123123
* expected location.
124124
* @param {Object} tokens Locations of the opening bracket, closing bracket and last prop
125-
* @param {String} expectedLocation Expected location for the closing bracket
125+
* @param {string} expectedLocation Expected location for the closing bracket
126126
* @return {?Number} The correct column for the closing bracket, or null
127127
*/
128128
function getCorrectColumn(tokens, expectedLocation) {
@@ -141,8 +141,8 @@ module.exports = {
141141
/**
142142
* Check if the closing bracket is correctly located
143143
* @param {Object} tokens Locations of the opening bracket, closing bracket and last prop
144-
* @param {String} expectedLocation Expected location for the closing bracket
145-
* @return {Boolean} True if the closing bracket is correctly located, false if not
144+
* @param {string} expectedLocation Expected location for the closing bracket
145+
* @return {boolean} True if the closing bracket is correctly located, false if not
146146
*/
147147
function hasCorrectLocation(tokens, expectedLocation) {
148148
switch (expectedLocation) {
@@ -164,9 +164,9 @@ module.exports = {
164164
/**
165165
* Get the characters used for indentation on the line to be matched
166166
* @param {Object} tokens Locations of the opening bracket, closing bracket and last prop
167-
* @param {String} expectedLocation Expected location for the closing bracket
168-
* @param {Number} [correctColumn] Expected column for the closing bracket. Default to 0
169-
* @return {String} The characters used for indentation
167+
* @param {string} expectedLocation Expected location for the closing bracket
168+
* @param {number} [correctColumn] Expected column for the closing bracket. Default to 0
169+
* @return {string} The characters used for indentation
170170
*/
171171
function getIndentation(tokens, expectedLocation, correctColumn) {
172172
const newColumn = correctColumn || 0;
@@ -236,7 +236,7 @@ module.exports = {
236236
* Get an unique ID for a given JSXOpeningElement
237237
*
238238
* @param {ASTNode} node The AST node being checked.
239-
* @returns {String} Unique ID (based on its range)
239+
* @returns {string} Unique ID (based on its range)
240240
*/
241241
function getOpeningElementId(node) {
242242
return node.range.join(':');

0 commit comments

Comments
 (0)