Skip to content

Commit

Permalink
respond to feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
samanpwbb committed Sep 25, 2019
1 parent 844ed78 commit b7b444e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/style-spec/bin/gl-style-validate
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ function help() {
console.log('');
console.log('options:');
console.log('--json output errors as json');
console.log('--mapbox-api-supported validate compatibility with Mapbox Styles API');
console.log('--mapbox-api-supported validate compatibility with Mapbox Styles API');
}
7 changes: 3 additions & 4 deletions src/style-spec/read_style.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ import ParsingError from './error/parsing_error';
import jsonlint from '@mapbox/jsonlint-lines-primitives';

export default function readStyle(style) {
let s = style;
if (s instanceof String || typeof s === 'string' || s instanceof Buffer) {
if (style instanceof String || typeof style === 'string' || style instanceof Buffer) {
try {
s = jsonlint.parse(s.toString());
return jsonlint.parse(style.toString());
} catch (e) {
throw new ParsingError(e);
}
}

return s;
return style;
}
11 changes: 5 additions & 6 deletions src/style-spec/validate_mapbox_api_supported.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ function isValid(value: ?string, regex: RegExp): boolean {
return !!value.match(regex);
}

function getSourceCount(source: Object) {
function getSourceCount(source: Object): number {
if (source.url) {
return source.url.replace('mapbox://', '').split(',').length;
return source.url.split(',').length;
} else {
return 0;
}
Expand Down Expand Up @@ -134,7 +134,7 @@ function getRootErrors(style: Object, specKeys: Array<any>): Array<?ValidationEr
* "private"
* "public"
*/
const visibilityPattern = /^(public|private)/;
const visibilityPattern = /^(public|private)$/;
if (!isValid(style.visibility, visibilityPattern)) {
errors.push(new ValidationError('visibility', style.visibility, 'Style visibility must be public or private'));
}
Expand All @@ -160,9 +160,8 @@ export default function validateMapboxApiSupported(style: Object): Array<?Valida
return [e];
}

let errors = validateStyle(s, v8);

errors = errors.concat(getRootErrors(s, Object.keys(v8.$root)));
let errors = validateStyle(s, v8)
.concat(getRootErrors(s, Object.keys(v8.$root)));

if (s.sources) {
errors = errors.concat(getSourcesErrors(s.sources));
Expand Down
7 changes: 2 additions & 5 deletions src/style-spec/validate_style.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,14 @@ import readStyle from './read_style';
* or `Buffer` is provided, the returned errors will contain line numbers.
* @param {Object} [styleSpec] The style specification to validate against.
* If omitted, the spec version is inferred from the stylesheet.
* @param {Object} options
* @param {boolean} [options.mapboxApiSupported] If true, assert that
* style can be uploaded to the Mapbox Styles API.
* @returns {Array<ValidationError|ParsingError>}
* @example
* var validate = require('mapbox-gl-style-spec').validate;
* var style = fs.readFileSync('./style.json', 'utf8');
* var errors = validate(style);
*/

export default function validateStyle(style, styleSpec = v8, options) {
export default function validateStyle(style, styleSpec = v8) {
let s = style;

try {
Expand All @@ -31,7 +28,7 @@ export default function validateStyle(style, styleSpec = v8, options) {
return [e];
}

return validateStyleMin(s, styleSpec, options);
return validateStyleMin(s, styleSpec);
}

export const source = validateStyleMin.source;
Expand Down

0 comments on commit b7b444e

Please sign in to comment.