mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/51778 Adds `noflow` to a bunch of ESLint and Babel files that are expected to be evaluated using Node.js without Babel. Additioanlly, these files tend to depend on ESLint and Babel type definitions that are not currently readily available. In the future, these files could be migrated to use `flow strict-local` or `flow strict` using comment syntax for type annotations. But for now, adding `noflow` makes it explicit that these are known to not be typechecked. Changelog: [Internal] Reviewed By: SamChou19815 Differential Revision: D75883642 fbshipit-source-id: 54236d123ca8773de42bce81189dfb5c0671563e
81 lines
2.3 KiB
JavaScript
81 lines
2.3 KiB
JavaScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @format
|
|
* @noflow
|
|
*/
|
|
|
|
module.exports = {
|
|
meta: {
|
|
type: 'problem',
|
|
docs: {
|
|
description:
|
|
'Ensure that PlatformColor() and DynamicColorIOS() are passed literals of the expected shape.',
|
|
},
|
|
messages: {
|
|
platformColorArgsLength:
|
|
'PlatformColor() must have at least one argument that is a literal.',
|
|
platformColorArgTypes:
|
|
'PlatformColor() every argument must be a literal.',
|
|
dynamicColorIOSArg:
|
|
'DynamicColorIOS() must take a single argument of type Object',
|
|
dynamicColorIOSValue:
|
|
'DynamicColorIOS() value must be either a literal or a PlatformColor() call.',
|
|
},
|
|
schema: [],
|
|
},
|
|
|
|
create: function (context) {
|
|
return {
|
|
CallExpression: function (node) {
|
|
if (node.callee.name === 'PlatformColor') {
|
|
const args = node.arguments;
|
|
if (args.length === 0) {
|
|
context.report({
|
|
node,
|
|
messageId: 'platformColorArgsLength',
|
|
});
|
|
return;
|
|
}
|
|
if (!args.every(arg => arg.type === 'Literal')) {
|
|
context.report({
|
|
node,
|
|
messageId: 'platformColorArgTypes',
|
|
});
|
|
return;
|
|
}
|
|
} else if (node.callee.name === 'DynamicColorIOS') {
|
|
const args = node.arguments;
|
|
if (!(args.length === 1 && args[0].type === 'ObjectExpression')) {
|
|
context.report({
|
|
node,
|
|
messageId: 'dynamicColorIOSArg',
|
|
});
|
|
return;
|
|
}
|
|
const properties = args[0].properties;
|
|
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;
|
|
}
|
|
});
|
|
}
|
|
},
|
|
};
|
|
},
|
|
};
|