Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into feature/add-jsdoc-annotations
  • Loading branch information
y-hsgw committed Aug 11, 2024
2 parents 6e0c30f + a2306e7 commit d687e25
Show file tree
Hide file tree
Showing 60 changed files with 668 additions and 601 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange

## Unreleased

### Fixed
* [`jsx-curly-brace-presence`]: do not trigger on strings containing a quote character ([#3798][] @akulsr0)

[#3798]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3798

## [7.35.0] - 2024.07.19

### Added
Expand Down
53 changes: 28 additions & 25 deletions lib/rules/boolean-prop-naming.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const values = require('object.values');

const Components = require('../util/Components');
const propsUtil = require('../util/props');
const astUtil = require('../util/ast');
const docsUrl = require('../util/docsUrl');
const propWrapperUtil = require('../util/propWrapper');
const report = require('../util/report');
Expand All @@ -18,6 +19,18 @@ const eslintUtil = require('../util/eslint');
const getSourceCode = eslintUtil.getSourceCode;
const getText = eslintUtil.getText;

/**
* Checks if prop is nested
* @param {Object} prop Property object, single prop type declaration
* @returns {boolean}
*/
function nestedPropTypes(prop) {
return (
prop.type === 'Property'
&& astUtil.isCallExpression(prop.value)
);
}

// ------------------------------------------------------------------------------
// Rule Definition
// ------------------------------------------------------------------------------
Expand Down Expand Up @@ -128,7 +141,7 @@ module.exports = {
/**
* Checks if prop is declared in flow way
* @param {Object} prop Property object, single prop type declaration
* @returns {Boolean}
* @returns {boolean}
*/
function flowCheck(prop) {
return (
Expand All @@ -141,7 +154,7 @@ module.exports = {
/**
* Checks if prop is declared in regular way
* @param {Object} prop Property object, single prop type declaration
* @returns {Boolean}
* @returns {boolean}
*/
function regularCheck(prop) {
const propKey = getPropKey(prop);
Expand All @@ -162,33 +175,23 @@ module.exports = {
);
}

/**
* Checks if prop is nested
* @param {Object} prop Property object, single prop type declaration
* @returns {Boolean}
*/
function nestedPropTypes(prop) {
return (
prop.type === 'Property'
&& prop.value.type === 'CallExpression'
);
}

/**
* Runs recursive check on all proptypes
* @param {Array} proptypes A list of Property object (for each proptype defined)
* @param {Function} addInvalidProp callback to run for each error
*/
function runCheck(proptypes, addInvalidProp) {
(proptypes || []).forEach((prop) => {
if (config.validateNested && nestedPropTypes(prop)) {
runCheck(prop.value.arguments[0].properties, addInvalidProp);
return;
}
if (flowCheck(prop) || regularCheck(prop) || tsCheck(prop)) {
addInvalidProp(prop);
}
});
if (proptypes) {
proptypes.forEach((prop) => {
if (config.validateNested && nestedPropTypes(prop)) {
runCheck(prop.value.arguments[0].properties, addInvalidProp);
return;
}
if (flowCheck(prop) || regularCheck(prop) || tsCheck(prop)) {
addInvalidProp(prop);
}
});
}
}

/**
Expand Down Expand Up @@ -309,7 +312,7 @@ module.exports = {
}
if (
node.value
&& node.value.type === 'CallExpression'
&& astUtil.isCallExpression(node.value)
&& propWrapperUtil.isPropWrapperFunction(
context,
getText(context, node.value.callee)
Expand All @@ -335,7 +338,7 @@ module.exports = {
}
const right = node.parent.right;
if (
right.type === 'CallExpression'
astUtil.isCallExpression(right)
&& propWrapperUtil.isPropWrapperFunction(
context,
getText(context, right.callee)
Expand Down
13 changes: 7 additions & 6 deletions lib/rules/display-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,13 @@ module.exports = {
/**
* Checks if React.forwardRef is nested inside React.memo
* @param {ASTNode} node The AST node being checked.
* @returns {Boolean} True if React.forwardRef is nested inside React.memo, false if not.
* @returns {boolean} True if React.forwardRef is nested inside React.memo, false if not.
*/
function isNestedMemo(node) {
const argumentIsCallExpression = node.arguments && node.arguments[0] && node.arguments[0].type === 'CallExpression';

return node.type === 'CallExpression' && argumentIsCallExpression && utils.isPragmaComponentWrapper(node);
return astUtil.isCallExpression(node)
&& node.arguments
&& astUtil.isCallExpression(node.arguments[0])
&& utils.isPragmaComponentWrapper(node);
}

/**
Expand Down Expand Up @@ -111,7 +112,7 @@ module.exports = {
/**
* Checks if the component have a name set by the transpiler
* @param {ASTNode} node The AST node being checked.
* @returns {Boolean} True if component has a name, false if not.
* @returns {boolean} True if component has a name, false if not.
*/
function hasTranspilerName(node) {
const namedObjectAssignment = (
Expand Down Expand Up @@ -198,7 +199,7 @@ module.exports = {
if (!component) {
return;
}
markDisplayNameAsDeclared(component.node.type === 'TSAsExpression' ? component.node.expression : component.node);
markDisplayNameAsDeclared(astUtil.unwrapTSAsExpression(component.node));
},

'FunctionExpression, FunctionDeclaration, ArrowFunctionExpression'(node) {
Expand Down
38 changes: 17 additions & 21 deletions lib/rules/forbid-prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ module.exports = {
) {
value = value.object;
}
if (value.type === 'CallExpression') {
if (astUtil.isCallExpression(value)) {
if (!isPropTypesPackage(value.callee)) {
return;
}
Expand All @@ -159,29 +159,25 @@ module.exports = {
}

function checkNode(node) {
switch (node && node.type) {
case 'ObjectExpression':
checkProperties(node.properties);
break;
case 'Identifier': {
const propTypesObject = variableUtil.findVariableByName(context, node, node.name);
if (propTypesObject && propTypesObject.properties) {
checkProperties(propTypesObject.properties);
}
break;
if (!node) {
return;
}

if (node.type === 'ObjectExpression') {
checkProperties(node.properties);
} else if (node.type === 'Identifier') {
const propTypesObject = variableUtil.findVariableByName(context, node, node.name);
if (propTypesObject && propTypesObject.properties) {
checkProperties(propTypesObject.properties);
}
case 'CallExpression': {
const innerNode = node.arguments && node.arguments[0];
if (
propWrapperUtil.isPropWrapperFunction(context, getText(context, node.callee))
} else if (astUtil.isCallExpression(node)) {
const innerNode = node.arguments && node.arguments[0];
if (
propWrapperUtil.isPropWrapperFunction(context, getText(context, node.callee))
&& innerNode
) {
checkNode(innerNode);
}
break;
) {
checkNode(innerNode);
}
default:
break;
}
}

Expand Down
16 changes: 8 additions & 8 deletions lib/rules/jsx-closing-bracket-location.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ module.exports = {
/**
* Get expected location for the closing bracket
* @param {Object} tokens Locations of the opening bracket, closing bracket and last prop
* @return {String} Expected location for the closing bracket
* @return {string} Expected location for the closing bracket
*/
function getExpectedLocation(tokens) {
let location;
Expand All @@ -122,7 +122,7 @@ module.exports = {
* Get the correct 0-indexed column for the closing bracket, given the
* expected location.
* @param {Object} tokens Locations of the opening bracket, closing bracket and last prop
* @param {String} expectedLocation Expected location for the closing bracket
* @param {string} expectedLocation Expected location for the closing bracket
* @return {?Number} The correct column for the closing bracket, or null
*/
function getCorrectColumn(tokens, expectedLocation) {
Expand All @@ -141,8 +141,8 @@ module.exports = {
/**
* Check if the closing bracket is correctly located
* @param {Object} tokens Locations of the opening bracket, closing bracket and last prop
* @param {String} expectedLocation Expected location for the closing bracket
* @return {Boolean} True if the closing bracket is correctly located, false if not
* @param {string} expectedLocation Expected location for the closing bracket
* @return {boolean} True if the closing bracket is correctly located, false if not
*/
function hasCorrectLocation(tokens, expectedLocation) {
switch (expectedLocation) {
Expand All @@ -164,9 +164,9 @@ module.exports = {
/**
* Get the characters used for indentation on the line to be matched
* @param {Object} tokens Locations of the opening bracket, closing bracket and last prop
* @param {String} expectedLocation Expected location for the closing bracket
* @param {Number} [correctColumn] Expected column for the closing bracket. Default to 0
* @return {String} The characters used for indentation
* @param {string} expectedLocation Expected location for the closing bracket
* @param {number} [correctColumn] Expected column for the closing bracket. Default to 0
* @return {string} The characters used for indentation
*/
function getIndentation(tokens, expectedLocation, correctColumn) {
const newColumn = correctColumn || 0;
Expand Down Expand Up @@ -236,7 +236,7 @@ module.exports = {
* Get an unique ID for a given JSXOpeningElement
*
* @param {ASTNode} node The AST node being checked.
* @returns {String} Unique ID (based on its range)
* @returns {string} Unique ID (based on its range)
*/
function getOpeningElementId(node) {
return node.range.join(':');
Expand Down
Loading

0 comments on commit d687e25

Please sign in to comment.