Skip to content

prop-deprecation - required prop - support method and member #1510

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 25 additions & 11 deletions eslint-rules/lib/rules/component-prop-deprecation.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,28 @@ module.exports = {
function testAttributeForDeprecation(attribute, deprecatedPropList, componentName) {
let wasFound = false;
if (attribute.type === 'JSXAttribute') {
wasFound = checkPropDeprecation(attribute, attribute.name, attribute.name.name, deprecatedPropList, componentName);
wasFound = checkPropDeprecation(
attribute,
attribute.name,
attribute.name.name,
deprecatedPropList,
componentName
);
} else if (attribute.type === 'JSXSpreadAttribute') {
const spreadSource = findValueNodeOfIdentifier(attribute.argument.name, context.getScope());
const identifierName =
_.get(attribute, 'argument.name') ||
_.get(attribute, 'argument.callee.name') ||
_.get(attribute, 'argument.property.name');
const spreadSource = findValueNodeOfIdentifier(identifierName, context.getScope());
if (spreadSource) {
_.forEach(spreadSource.properties, property => {
const key = _.get(property, 'key');
const propName = _.get(property, 'key.name');
wasFound = checkPropDeprecation(key, key, propName, deprecatedPropList, componentName);
});
const properties = _.get(spreadSource, 'properties') || _.get(spreadSource, 'body.properties');
if (properties) {
_.forEach(properties, property => {
const key = _.get(property, 'key');
const propName = _.get(property, 'key.name');
wasFound = checkPropDeprecation(key, key, propName, deprecatedPropList, componentName);
});
}
}
}
return wasFound;
Expand Down Expand Up @@ -160,12 +173,13 @@ module.exports = {
/* handle required props */
let foundAttribute = false;
attributes.forEach(attribute => {
foundAttribute = foundAttribute || testAttributeForDeprecation(attribute, requiredPropList, componentName);
foundAttribute =
foundAttribute || testAttributeForDeprecation(attribute, requiredPropList, componentName);
});
if (!foundAttribute && requiredPropList[0]) {

if (!foundAttribute && requiredPropList[0]) {
const prop = requiredPropList[0];
reportRequiredProps({node, name: componentName, prop: prop.prop, message: prop.message})
reportRequiredProps({node, name: componentName, prop: prop.prop, message: prop.message});
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion eslint-rules/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-uilib",
"version": "2.1.3",
"version": "2.1.4",
"description": "uilib set of eslint rules",
"keywords": [
"eslint",
Expand Down
18 changes: 17 additions & 1 deletion eslint-rules/tests/lib/rules/component-prop-deprecation.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,22 @@ ruleTester.run('component-prop-deprecation', rule, {
options: ruleOptions,
code: 'import {Picker} from \'module-with-deprecations\'; pickerProps = {t: "title", s:"subtitle", migrate: true}; <Picker {...pickerProps}/>'
},
{
options: ruleOptions,
code: `
import {Picker} from 'module-with-deprecations';
const getPickerProps = () => ({t: "title", s:"subtitle", migrate: true});
<Picker {...getPickerProps()}/>
`
},
{
options: ruleOptions,
code: `
import {Picker} from 'module-with-deprecations';
pickerProps = {t: "title", s:"subtitle", migrate: true};
<Picker {...this.pickerProps}/>
`
}
],
invalid: [
{
Expand Down Expand Up @@ -367,7 +383,7 @@ ruleTester.run('component-prop-deprecation', rule, {
options: ruleOptions,
code: 'import {Picker} from \'module-with-deprecations\'; <Picker t="title" s="subtitle"/>',
errors: [
{message: "The 'Picker' component's prop 'migrate' is required. Please make sure to pass the 'migrate' prop."},
{message: "The 'Picker' component's prop 'migrate' is required. Please make sure to pass the 'migrate' prop."}
]
}
]
Expand Down