Require const declarations for variables that are never reassigned after being declared. If a variable is never reassigned, using the const declaration is better. const declaration tells readers, “this variable is never reassigned,” reducing cognitive load and improving maintainability.
17 lines
497 B
JavaScript
17 lines
497 B
JavaScript
const TargetEnvironmentValidator = () => (targets) => {
|
|
if (!targets) {
|
|
return undefined;
|
|
}
|
|
|
|
// at least one of the target environments must
|
|
// be set to true. This reduces the value to
|
|
// a single boolean which is a flag for whether
|
|
// at least one target has been selected or not
|
|
const valid = Object.values(targets).reduce(
|
|
(prev, curr) => curr || prev,
|
|
false
|
|
);
|
|
return !valid ? 'Please select an image' : undefined;
|
|
};
|
|
|
|
export default TargetEnvironmentValidator;
|