Remove lint restricting properties on `DynamicColorIOS` (#33182)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/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
This commit is contained in:
Родитель
4b1c8584e1
Коммит
13b0b06522
|
@ -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}],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
Загрузка…
Ссылка в новой задаче