Skip to content

Commit

Permalink
Remove lint restricting properties on DynamicColorIOS (#33182)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #33182

This information can be checked by the type system + `DynamicColorIOS` supports other properties now.

Changelog: [Removed][iOS] - Removed lint restricting `DynamicColorIOS` to only two properties

Reviewed By: cortinico

Differential Revision: D34475985

fbshipit-source-id: c4190adad05e68b0a38a6ec89862372d9af55894
  • Loading branch information
Andrei Shikov authored and facebook-github-bot committed Feb 25, 2022
1 parent 4b1c858 commit 13b0b06
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ eslintTester.run('../platform-colors', rule, {
"const color = PlatformColor('controlAccentColor', 'controlColor');",
"const color = DynamicColorIOS({light: 'black', dark: 'white'});",
"const color = DynamicColorIOS({light: PlatformColor('black'), dark: PlatformColor('white')});",
"const color = DynamicColorIOS({light: PlatformColor('black'), dark: PlatformColor('white'), highContrastLight: PlatformColor('black'), highContrastDark: PlatformColor('white')});",
],
invalid: [
{
Expand All @@ -38,11 +39,11 @@ eslintTester.run('../platform-colors', rule, {
},
{
code: "const black = 'black'; const color = DynamicColorIOS({light: black, dark: 'white'});",
errors: [{message: rule.meta.messages.dynamicColorIOSLight}],
errors: [{message: rule.meta.messages.dynamicColorIOSValue}],
},
{
code: "const white = 'white'; const color = DynamicColorIOS({light: 'black', dark: white});",
errors: [{message: rule.meta.messages.dynamicColorIOSDark}],
errors: [{message: rule.meta.messages.dynamicColorIOSValue}],
},
],
});
66 changes: 19 additions & 47 deletions packages/eslint-plugin-react-native-community/platform-colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ module.exports = {
platformColorArgTypes:
'PlatformColor() every argument must be a literal.',
dynamicColorIOSArg:
'DynamicColorIOS() must take a single argument of type Object containing two keys: light and dark.',
dynamicColorIOSLight:
'DynamicColorIOS() light value must be either a literal or a PlatformColor() call.',
dynamicColorIOSDark:
'DynamicColorIOS() dark value must be either a literal or a PlatformColor() call.',
'DynamicColorIOS() must take a single argument of type Object',
dynamicColorIOSValue:
'DynamicColorIOS() value must be either a literal or a PlatformColor() call.',
},
schema: [],
},
Expand Down Expand Up @@ -58,48 +56,22 @@ module.exports = {
return;
}
const properties = args[0].properties;
if (
!(
properties[0].type === 'Property' &&
properties[0].key.name === 'light' &&
properties[1].type === 'Property' &&
properties[1].key.name === 'dark'
)
) {
context.report({
node,
messageId: 'dynamicColorIOSArg',
});
return;
}
const light = properties[0];
if (
!(
light.value.type === 'Literal' ||
(light.value.type === 'CallExpression' &&
light.value.callee.name === 'PlatformColor')
)
) {
context.report({
node,
messageId: 'dynamicColorIOSLight',
});
return;
}
const dark = properties[1];
if (
!(
dark.value.type === 'Literal' ||
(dark.value.type === 'CallExpression' &&
dark.value.callee.name === 'PlatformColor')
)
) {
context.report({
node,
messageId: 'dynamicColorIOSDark',
});
return;
}
properties.forEach(property => {
if (
!(
property.type === 'Property' &&
(property.value.type === 'Literal' ||
(property.value.type === 'CallExpression' &&
property.value.callee.name === 'PlatformColor'))
)
) {
context.report({
node,
messageId: 'dynamicColorIOSValue',
});
return;
}
});
}
},
};
Expand Down

0 comments on commit 13b0b06

Please sign in to comment.