Skip to content

Commit

Permalink
Simplify fog validation checks for expression(s)
Browse files Browse the repository at this point in the history
  • Loading branch information
karimnaaji committed May 4, 2021
1 parent 74eb058 commit 742e6c2
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/style-spec/validate/validate_fog.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import ValidationError from '../error/validation_error.js';
import validate from './validate.js';
import getType from '../util/get_type.js';
import {isExpression} from '../expression/index.js';
import {deepUnbundle} from '../util/unbundle_jsonlint.js';
import {parseCSSColor} from 'csscolorparser';

export default function validateFog(options) {
Expand All @@ -19,18 +21,15 @@ export default function validateFog(options) {
return errors;
}

if (fog.color && !Array.isArray(fog.color)) {
if (fog.color && !isExpression(deepUnbundle(fog.color))) {
const fogColor = parseCSSColor(fog.color);
if (fogColor && fogColor[3] === 0) {
errors = errors.concat([new ValidationError('fog', fog, 'fog.color alpha must be nonzero.')]);
}
}

if (fog.range) {
const isExpression = fog.range[0] instanceof String;
if (!isExpression && fog.range[0] >= fog.range[1]) {
errors = errors.concat([new ValidationError('fog', fog, 'fog.range[0] can\'t be greater than or equal to fog.range[1]')]);
}
if (fog.range && !isExpression(deepUnbundle(fog.range)) && fog.range[0] >= fog.range[1]) {
errors = errors.concat([new ValidationError('fog', fog, 'fog.range[0] can\'t be greater than or equal to fog.range[1]')]);
}

for (const key in fog) {
Expand Down

0 comments on commit 742e6c2

Please sign in to comment.