diff --git a/packages/eslint-plugin-react-native-community/__tests__/platform-colors-test.js b/packages/eslint-plugin-react-native-community/__tests__/platform-colors-test.js index 892b67825dc..81df7cb6a91 100644 --- a/packages/eslint-plugin-react-native-community/__tests__/platform-colors-test.js +++ b/packages/eslint-plugin-react-native-community/__tests__/platform-colors-test.js @@ -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: [ { @@ -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}], }, ], }); diff --git a/packages/eslint-plugin-react-native-community/platform-colors.js b/packages/eslint-plugin-react-native-community/platform-colors.js index fe0999fe048..cfbabd1a923 100644 --- a/packages/eslint-plugin-react-native-community/platform-colors.js +++ b/packages/eslint-plugin-react-native-community/platform-colors.js @@ -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: [], }, @@ -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; + } + }); } }, };