Skip to content

Commit

Permalink
More tests updated
Browse files Browse the repository at this point in the history
  • Loading branch information
MatiPl01 committed Apr 29, 2024
1 parent 7539e1f commit 515ba98
Show file tree
Hide file tree
Showing 19 changed files with 129 additions and 430 deletions.
4 changes: 2 additions & 2 deletions lib/rules/no-access-state-in-setstate.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ module.exports = {
const vars = [];
return {
CallExpression(node) {
if (!isClassComponent()) {
if (!isClassComponent(node)) {
return;
}
// Appends all the methods that are calling another
Expand Down Expand Up @@ -107,7 +107,7 @@ module.exports = {
if (
node.property.name === 'state'
&& node.object.type === 'ThisExpression'
&& isClassComponent()
&& isClassComponent(node)
) {
let current = node;
while (current.type !== 'Program') {
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/no-direct-mutation-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ module.exports = {
},

AssignmentExpression(node) {
const component = components.get(utils.getParentComponent());
const component = components.get(utils.getParentComponent(node));
if (shouldIgnoreComponent(component) || !node.left || !node.left.object) {
return;
}
Expand All @@ -114,7 +114,7 @@ module.exports = {
},

UpdateExpression(node) {
const component = components.get(utils.getParentComponent());
const component = components.get(utils.getParentComponent(node));
if (shouldIgnoreComponent(component) || node.argument.type !== 'MemberExpression') {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-set-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ module.exports = {
) {
return;
}
const component = components.get(utils.getParentComponent());
const component = components.get(utils.getParentComponent(node));
const setStateUsages = (component && component.setStateUsages) || [];
setStateUsages.push(callee);
components.set(node, {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-this-in-sfc.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.exports = {
create: Components.detect((context, components, utils) => ({
MemberExpression(node) {
if (node.object.type === 'ThisExpression') {
const component = components.get(utils.getParentStatelessComponent());
const component = components.get(utils.getParentStatelessComponent(node));
if (!component || (component.node && component.node.parent && component.node.parent.type === 'Property')) {
return;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/rules/no-unstable-nested-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ module.exports = {
* @returns {Boolean} True if node is inside class component's render block, false if not
*/
function isInsideRenderMethod(node) {
const parentComponent = utils.getParentComponent();
const parentComponent = utils.getParentComponent(node);

if (!parentComponent || parentComponent.type !== 'ClassDeclaration') {
return false;
Expand Down Expand Up @@ -334,8 +334,8 @@ module.exports = {
* @returns {Boolean} True if given node a function component declared inside class component, false if not
*/
function isFunctionComponentInsideClassComponent(node) {
const parentComponent = utils.getParentComponent();
const parentStatelessComponent = utils.getParentStatelessComponent();
const parentComponent = utils.getParentComponent(node);
const parentStatelessComponent = utils.getParentStatelessComponent(node);

return (
parentComponent
Expand Down
5 changes: 4 additions & 1 deletion lib/util/propTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,10 @@ module.exports = function propTypesInstructions(context, components, utils) {
ignorePropsValidation = true;
break;
}
const parentProp = context.getSource(propTypes.parent.left.object).replace(/^.*\.propTypes\./, '');
const parentProp = eslintUtil
.getSourceCode(context)
.getText(propTypes.parent.left.object)
.replace(/^.*\.propTypes\./, '');
const types = buildReactDeclarationTypes(
propTypes.parent.right,
parentProp
Expand Down
4 changes: 2 additions & 2 deletions lib/util/usedPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ module.exports = function usedPropTypesInstructions(context, components, utils)
// let {firstname} = props
if (
isCommonVariableNameForProps(unwrappedInitNode.name)
&& (utils.getParentStatelessComponent() || isInLifeCycleMethod(node, checkAsyncSafeLifeCycles))
&& (utils.getParentStatelessComponent(node) || isInLifeCycleMethod(node, checkAsyncSafeLifeCycles))
) {
markPropTypesAsUsed(node.id);
return;
Expand Down Expand Up @@ -546,7 +546,7 @@ module.exports = function usedPropTypesInstructions(context, components, utils)
'FunctionExpression:exit': popScope,

JSXSpreadAttribute(node) {
const component = components.get(utils.getParentComponent());
const component = components.get(utils.getParentComponent(node));
components.set(component ? component.node : node, {
ignoreUnusedPropTypesValidation: node.argument.type !== 'ObjectExpression',
});
Expand Down
183 changes: 0 additions & 183 deletions tests/helpers/parsers-old.js

This file was deleted.

12 changes: 0 additions & 12 deletions tests/lib/rules/destructuring-assignment.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,18 +376,6 @@ ruleTester.run('destructuring-assignment', rule, {
code: `
import { useContext } from 'react';
const MyComponent = (props) => {
const {foo} = useContext(aContext);
return <div>{foo}</div>
};
`,
options: ['always'],
settings: { react: { version: '16.9.0' } },
},
{
code: `
import { useContext } from 'react';
const MyComponent = (props) => {
const foo = useContext(aContext);
return <div>{foo.test}</div>
Expand Down
33 changes: 0 additions & 33 deletions tests/lib/rules/display-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,39 +371,6 @@ ruleTester.run('display-name', rule, {
};
`,
},
{
code: `
import React, {createElement} from "react";
const SomeComponent = (props) => {
const {foo, bar} = props;
return someComponentFactory({
onClick: () => foo(bar("x"))
});
};
`,
},
{
code: `
import React, {Component} from "react";
function someDecorator(ComposedComponent) {
return class MyDecorator extends Component {
render() {return <ComposedComponent {...this.props} />;}
};
}
module.exports = someDecorator;
`,
},
{
code: `
import React, {Component} from "react";
function someDecorator(ComposedComponent) {
return class MyDecorator extends Component {
render() {return <ComposedComponent {...this.props} />;}
};
}
module.exports = someDecorator;
`,
},
{
code: `
const element = (
Expand Down
22 changes: 0 additions & 22 deletions tests/lib/rules/function-component-definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -809,11 +809,6 @@ ruleTester.run('function-component-definition', rule, {
return <div/>;
}
`,
output: `
var Hello: React.FC<Test> = function(props) {
return <div/>;
}
`,
options: [{ namedComponents: 'function-declaration' }],
errors: [{ messageId: 'function-declaration' }],
features: ['types'],
Expand All @@ -824,11 +819,6 @@ ruleTester.run('function-component-definition', rule, {
return <div/>;
};
`,
output: `
var Hello: React.FC<Test> = (props) => {
return <div/>;
};
`,
options: [{ namedComponents: 'function-declaration' }],
errors: [{ messageId: 'function-declaration' }],
features: ['types'],
Expand All @@ -854,11 +844,6 @@ ruleTester.run('function-component-definition', rule, {
return <div/>;
}
`,
output: `
function Hello<Test>(props: Test) {
return <div/>;
}
`,
options: [{ namedComponents: 'arrow-function' }],
errors: [{ messageId: 'arrow-function' }],
features: ['types'],
Expand Down Expand Up @@ -965,13 +950,6 @@ ruleTester.run('function-component-definition', rule, {
}
}
`,
output: `
function wrap(Component) {
return function<Test>(props) {
return <div><Component {...props}/></div>
}
}
`,
errors: [{ messageId: 'arrow-function' }],
options: [{ unnamedComponents: 'arrow-function' }],
features: ['types'],
Expand Down

0 comments on commit 515ba98

Please sign in to comment.