Skip to content

Commit

Permalink
Merge branch 'master' into akul/no-danger-allow-custom-components
Browse files Browse the repository at this point in the history
  • Loading branch information
akulsr0 authored May 24, 2024
2 parents a7a3fe8 + 014ee05 commit fdd934d
Show file tree
Hide file tree
Showing 92 changed files with 940 additions and 503 deletions.
158 changes: 79 additions & 79 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,82 +1,82 @@
{
"root": true,
"extends": ["airbnb-base", "plugin:eslint-plugin/recommended"],
"plugins": ["eslint-plugin"],
"env": {
"es6": true,
"node": true
},
"parserOptions": {
"ecmaVersion": 6,
"ecmaFeatures": {
"jsx": true
},
"sourceType": "script",
},
"ignorePatterns": [
"coverage/",
".nyc_output/",
],
"rules": {
"comma-dangle": [2, "always-multiline"],
"object-shorthand": [2, "always", {
"ignoreConstructors": false,
"avoidQuotes": false, // this is the override vs airbnb
}],
"max-len": [2, 120, {
"ignoreStrings": true,
"ignoreTemplateLiterals": true,
"ignoreComments": true,
}],
"consistent-return": 0,
"root": true,
"extends": ["airbnb-base", "plugin:eslint-plugin/recommended"],
"plugins": ["eslint-plugin"],
"env": {
"es6": true,
"node": true
},
"parserOptions": {
"ecmaVersion": 6,
"ecmaFeatures": {
"jsx": true
},
"sourceType": "script",
},
"ignorePatterns": [
"coverage/",
".nyc_output/",
],
"rules": {
"comma-dangle": [2, "always-multiline"],
"object-shorthand": [2, "always", {
"ignoreConstructors": false,
"avoidQuotes": false, // this is the override vs airbnb
}],
"max-len": [2, 120, {
"ignoreStrings": true,
"ignoreTemplateLiterals": true,
"ignoreComments": true,
}],
"consistent-return": 0,

"prefer-destructuring": [2, { "array": false, "object": false }, { "enforceForRenamedProperties": false }],
"prefer-object-spread": 0, // until node 8 is required
"prefer-rest-params": 0, // until node 6 is required
"prefer-spread": 0, // until node 6 is required
"function-call-argument-newline": 1, // TODO: enable
"function-paren-newline": 0,
"no-plusplus": [2, {"allowForLoopAfterthoughts": true}],
"no-param-reassign": 1,
"no-restricted-syntax": [2, {
"selector": "ObjectPattern",
"message": "Object destructuring is not compatible with Node v4"
}],
"strict": [2, "safe"],
"valid-jsdoc": [2, {
"requireReturn": false,
"requireParamDescription": false,
"requireReturnDescription": false,
}],
"prefer-destructuring": [2, { "array": false, "object": false }, { "enforceForRenamedProperties": false }],
"prefer-object-spread": 0, // until node 8 is required
"prefer-rest-params": 0, // until node 6 is required
"prefer-spread": 0, // until node 6 is required
"function-call-argument-newline": 1, // TODO: enable
"function-paren-newline": 0,
"no-plusplus": [2, {"allowForLoopAfterthoughts": true}],
"no-param-reassign": 1,
"no-restricted-syntax": [2, {
"selector": "ObjectPattern",
"message": "Object destructuring is not compatible with Node v4"
}],
"strict": [2, "safe"],
"valid-jsdoc": [2, {
"requireReturn": false,
"requireParamDescription": false,
"requireReturnDescription": false,
}],

"eslint-plugin/consistent-output": 0,
"eslint-plugin/require-meta-docs-description": [2, { "pattern": "^(Enforce|Require|Disallow)" }],
"eslint-plugin/require-meta-schema": 0,
"eslint-plugin/require-meta-type": 0
},
"overrides": [
{
"files": "tests/**",
"rules": {
"no-template-curly-in-string": 1,
},
},
{
"files": "markdown.config.js",
"rules": {
"no-console": 0,
},
},
{
"files": ".github/workflows/*.js",
"parserOptions": {
"ecmaVersion": 2019,
},
"rules": {
"camelcase": 0,
"no-console": 0,
"no-restricted-syntax": 0,
},
},
],
}
"eslint-plugin/consistent-output": 0,
"eslint-plugin/require-meta-docs-description": [2, { "pattern": "^(Enforce|Require|Disallow)" }],
"eslint-plugin/require-meta-schema": 0,
"eslint-plugin/require-meta-type": 0
},
"overrides": [
{
"files": "tests/**",
"rules": {
"no-template-curly-in-string": 1,
},
},
{
"files": "markdown.config.js",
"rules": {
"no-console": 0,
},
},
{
"files": ".github/workflows/*.js",
"parserOptions": {
"ecmaVersion": 2019,
},
"rules": {
"camelcase": 0,
"no-console": 0,
"no-restricted-syntax": 0,
},
},
],
}
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange

### Fixed
* [`boolean-prop-naming`]: avoid a crash with a non-TSTypeReference type ([#3718][] @developer-bandi)
* [`jsx-no-leaked-render`]: invalid report if left side is boolean ([#3746][] @akulsr0)
* [`jsx-closing-bracket-location`]: message shows `{{details}}` when there are no details ([#3759][] @mdjermanovic)
* [`no-invalid-html-attribute`]: ensure error messages are correct ([#3759][] @mdjermanovic, @ljharb)

[#3759]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3759
[#3746]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3746
[#3718]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3718

## [7.34.1] - 2024.03.15
Expand Down
10 changes: 7 additions & 3 deletions lib/rules/boolean-prop-naming.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ const propsUtil = require('../util/props');
const docsUrl = require('../util/docsUrl');
const propWrapperUtil = require('../util/propWrapper');
const report = require('../util/report');
const eslintUtil = require('../util/eslint');

const getSourceCode = eslintUtil.getSourceCode;
const getText = eslintUtil.getText;

// ------------------------------------------------------------------------------
// Rule Definition
Expand Down Expand Up @@ -115,7 +119,7 @@ module.exports = {
// we can't get the name of the Flow object key name. So we have
// to hack around it for now.
if (node.type === 'ObjectTypeProperty') {
return context.getSourceCode().getFirstToken(node).value;
return getSourceCode(context).getFirstToken(node).value;
}

return node.key.name;
Expand Down Expand Up @@ -308,7 +312,7 @@ module.exports = {
&& node.value.type === 'CallExpression'
&& propWrapperUtil.isPropWrapperFunction(
context,
context.getSourceCode().getText(node.value.callee)
getText(context, node.value.callee)
)
) {
checkPropWrapperArguments(node, node.value.arguments);
Expand All @@ -334,7 +338,7 @@ module.exports = {
right.type === 'CallExpression'
&& propWrapperUtil.isPropWrapperFunction(
context,
context.getSourceCode().getText(right.callee)
getText(context, right.callee)
)
) {
checkPropWrapperArguments(component.node, right.arguments);
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/button-has-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ module.exports = {
checkValue(node, propValue);
},
CallExpression(node) {
if (!isCreateElement(node, context) || node.arguments.length < 1) {
if (!isCreateElement(context, node) || node.arguments.length < 1) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/checked-requires-onchange-or-readonly.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ module.exports = {
checkAttributesAndReport(node, propSet);
},
CallExpression(node) {
if (!isCreateElement(node, context)) {
if (!isCreateElement(context, node)) {
return;
}

Expand Down
16 changes: 10 additions & 6 deletions lib/rules/destructuring-assignment.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@

const Components = require('../util/Components');
const docsUrl = require('../util/docsUrl');
const eslintUtil = require('../util/eslint');
const isAssignmentLHS = require('../util/ast').isAssignmentLHS;
const report = require('../util/report');

const getScope = eslintUtil.getScope;
const getText = eslintUtil.getText;

const DEFAULT_OPTION = 'always';

function createSFCParams() {
Expand Down Expand Up @@ -102,7 +106,7 @@ module.exports = {
function handleStatelessComponent(node) {
const params = evalParams(node.params);

const SFCComponent = components.get(context.getScope(node).block);
const SFCComponent = components.get(getScope(context, node).block);
if (!SFCComponent) {
return;
}
Expand All @@ -120,7 +124,7 @@ module.exports = {
}

function handleStatelessComponentExit(node) {
const SFCComponent = components.get(context.getScope(node).block);
const SFCComponent = components.get(getScope(context, node).block);
if (SFCComponent) {
sfcParams.pop();
}
Expand Down Expand Up @@ -192,7 +196,7 @@ module.exports = {
'FunctionExpression:exit': handleStatelessComponentExit,

MemberExpression(node) {
let scope = context.getScope(node);
let scope = getScope(context, node);
let SFCComponent = components.get(scope.block);
while (!SFCComponent && scope.upper && scope.upper !== scope) {
SFCComponent = components.get(scope.upper.block);
Expand All @@ -210,7 +214,7 @@ module.exports = {

VariableDeclarator(node) {
const classComponent = utils.getParentComponent(node);
const SFCComponent = components.get(context.getScope(node).block);
const SFCComponent = components.get(getScope(context, node).block);

const destructuring = (node.init && node.id && node.id.type === 'ObjectPattern');
// let {foo} = props;
Expand Down Expand Up @@ -248,7 +252,7 @@ module.exports = {
&& destructureInSignature === 'always'
&& node.init.name === 'props'
) {
const scopeSetProps = context.getScope().set.get('props');
const scopeSetProps = getScope(context, node).set.get('props');
const propsRefs = scopeSetProps && scopeSetProps.references;
if (!propsRefs) {
return;
Expand All @@ -269,7 +273,7 @@ module.exports = {
param.typeAnnotation ? param.typeAnnotation.range[0] : param.range[1],
];
return [
fixer.replaceTextRange(replaceRange, context.getSourceCode().getText(node.id)),
fixer.replaceTextRange(replaceRange, getText(context, node.id)),
fixer.remove(node.parent),
];
},
Expand Down
7 changes: 4 additions & 3 deletions lib/rules/forbid-elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

const has = require('object.hasown/polyfill')();
const docsUrl = require('../util/docsUrl');
const getText = require('../util/eslint').getText;
const isCreateElement = require('../util/isCreateElement');
const report = require('../util/report');

Expand Down Expand Up @@ -90,11 +91,11 @@ module.exports = {

return {
JSXOpeningElement(node) {
reportIfForbidden(context.getSourceCode().getText(node.name), node.name);
reportIfForbidden(getText(context, node.name), node.name);
},

CallExpression(node) {
if (!isCreateElement(node, context)) {
if (!isCreateElement(context, node)) {
return;
}

Expand All @@ -110,7 +111,7 @@ module.exports = {
} else if (argType === 'Literal' && /^[a-z][^.]*$/.test(argument.value)) {
reportIfForbidden(argument.value, argument);
} else if (argType === 'MemberExpression') {
reportIfForbidden(context.getSourceCode().getText(argument), argument);
reportIfForbidden(getText(context, argument), argument);
}
},
};
Expand Down
5 changes: 3 additions & 2 deletions lib/rules/forbid-prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const astUtil = require('../util/ast');
const docsUrl = require('../util/docsUrl');
const propWrapperUtil = require('../util/propWrapper');
const report = require('../util/report');
const getText = require('../util/eslint').getText;

// ------------------------------------------------------------------------------
// Constants
Expand Down Expand Up @@ -162,7 +163,7 @@ module.exports = {
checkProperties(node.properties);
break;
case 'Identifier': {
const propTypesObject = variableUtil.findVariableByName(context, node.name);
const propTypesObject = variableUtil.findVariableByName(context, node, node.name);
if (propTypesObject && propTypesObject.properties) {
checkProperties(propTypesObject.properties);
}
Expand All @@ -171,7 +172,7 @@ module.exports = {
case 'CallExpression': {
const innerNode = node.arguments && node.arguments[0];
if (
propWrapperUtil.isPropWrapperFunction(context, context.getSourceCode().getText(node.callee))
propWrapperUtil.isPropWrapperFunction(context, getText(context, node.callee))
&& innerNode
) {
checkNode(innerNode);
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/function-component-definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const arrayIncludes = require('array-includes');
const Components = require('../util/Components');
const docsUrl = require('../util/docsUrl');
const reportC = require('../util/report');
const getText = require('../util/eslint').getText;

// ------------------------------------------------------------------------------
// Rule Definition
Expand Down Expand Up @@ -181,8 +182,7 @@ module.exports = {
);

function getFixer(node, options) {
const sourceCode = context.getSourceCode();
const source = sourceCode.getText();
const source = getText(context);

const typeAnnotation = getTypeAnnotation(node, source);

Expand Down
7 changes: 4 additions & 3 deletions lib/rules/hook-use-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const Components = require('../util/Components');
const docsUrl = require('../util/docsUrl');
const report = require('../util/report');
const getMessageData = require('../util/message');
const getText = require('../util/eslint').getText;

// ------------------------------------------------------------------------------
// Rule Definition
Expand Down Expand Up @@ -160,14 +161,14 @@ module.exports = {
fix: (fixer) => [
// Add useMemo import, if necessary
useStateReactImportSpecifier
&& (!useMemoReactImportSpecifier || defaultReactImportName)
&& fixer.insertTextAfter(useStateReactImportSpecifier, ', useMemo'),
&& (!useMemoReactImportSpecifier || defaultReactImportName)
&& fixer.insertTextAfter(useStateReactImportSpecifier, ', useMemo'),
// Convert single-value destructure to simple assignment
fixer.replaceTextRange(node.parent.id.range, valueVariableName),
// Convert useState call to useMemo + arrow function + dependency array
fixer.replaceTextRange(
node.range,
`${useMemoCode}(() => ${context.getSourceCode().getText(node.arguments[0])}, [])`
`${useMemoCode}(() => ${getText(context, node.arguments[0])}, [])`
),
].filter(Boolean),
}
Expand Down
Loading

0 comments on commit fdd934d

Please sign in to comment.