How to use @hint/utils-json - 10 common examples

To help you get started, we’ve selected a few @hint/utils-json examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github webhintio / hint / packages / parser-babel-config / src / parser.ts View on Github external
private async parseBabelConfig(fetchEnd: FetchEnd) {
        const resource = fetchEnd.resource;
        const resourceFileName = path.basename(resource);
        const isPackageJson: boolean = resourceFileName === 'package.json';
        const isBabelrc: boolean = resourceFileName === '.babelrc';

        if (!isBabelrc && !isPackageJson) {
            return;
        }

        let config: BabelConfig;

        try {
            const response = fetchEnd.response;
            // When using local connector to read local files, 'content' is empty.
            let result = parseJSON(response.body.content, 'extends');

            if (isPackageJson && !result.data.babel) {
                return;
            }

            await this.engine.emitAsync('parse::start::babel-config', { resource });

            // `result.scope('babel')` won't be null since `result.data.babel` was confirmed to exist above.
            result = isPackageJson ? result.scope('babel')! : result;
            config = result.data;

            const originalConfig: BabelConfig = cloneDeep(config);

            const finalConfig = calculateFinalConfig(config, resource);

            if (finalConfig instanceof Error) {
github webhintio / hint / packages / parser-babel-config / src / parser.ts View on Github external
// When using local connector to read local files, 'content' is empty.
            let result = parseJSON(response.body.content, 'extends');

            if (isPackageJson && !result.data.babel) {
                return;
            }

            await this.engine.emitAsync('parse::start::babel-config', { resource });

            // `result.scope('babel')` won't be null since `result.data.babel` was confirmed to exist above.
            result = isPackageJson ? result.scope('babel')! : result;
            config = result.data;

            const originalConfig: BabelConfig = cloneDeep(config);

            const finalConfig = calculateFinalConfig(config, resource);

            if (finalConfig instanceof Error) {
                await this.engine.emitAsync(`parse::error::babel-config::extends`,
                    {
                        error: finalConfig,
                        getLocation: result.getLocation,
                        resource
                    });

                return;
            }

            if (!finalConfig) {
                return;
            }
github webhintio / hint / packages / parser-babel-config / src / parser.ts View on Github external
private async validateSchema(config: BabelConfig, resource: string, result: IJSONResult): Promise {
        const validationResult = validate(this.schema, config, result.getLocation);

        const valid = validationResult.valid;

        if (!valid) {
            await this.engine.emitAsync('parse::error::babel-config::schema', {
                error: new Error('Invalid Babel configuration'),
                errors: validationResult.errors,
                groupedErrors: validationResult.groupedErrors,
                prettifiedErrors: validationResult.prettifiedErrors,
                resource
            });
        }

        return validationResult;
    }
github webhintio / hint / packages / parser-manifest / src / parser.ts View on Github external
} catch (e) {

            await this.engine.emitAsync(this.parseJSONErrorEventName, {
                error: e,
                resource
            });

            return;
        }

        /*
         * Try to see if the content of the web app manifest file
         * is a valid acording to the schema.
         */

        const validationResult: SchemaValidationResult = validate(schema, result.data, result.getLocation);

        if (!validationResult.valid) {

            await this.engine.emitAsync(this.parseErrorSchemaEventName, {
                error: new Error('Invalid manifest'),
                errors: validationResult.errors,
                groupedErrors: validationResult.groupedErrors,
                prettifiedErrors: validationResult.prettifiedErrors,
                resource
            });

            return;
        }

        /*
         * If it is, return the parsed content among with
github webhintio / hint / packages / hint / src / lib / config / config-hints.ts View on Github external
const validateHint = (schema: object, hintConfig: object): boolean => {
    return schemaValidator(schema, hintConfig).valid;
};
github webhintio / hint / packages / parser-typescript-config / src / parser.ts View on Github external
private async validateSchema(config: TypeScriptConfig, resource: string, result: IJSONResult): Promise {
        const validationResult = validate(this.schema, config, result.getLocation);

        const valid = validationResult.valid;

        if (!valid) {
            await this.engine.emitAsync(`parse::error::typescript-config::schema`, {
                error: new Error('Invalid TypeScript configuration'),
                errors: validationResult.errors,
                groupedErrors: validationResult.groupedErrors,
                prettifiedErrors: validationResult.prettifiedErrors,
                resource
            });
        }

        return validationResult;
    }
github webhintio / hint / packages / parser-package-json / src / parser.ts View on Github external
private validateSchema(config: IJsonSchemaForNpmPackageJsonFiles, resource: string, result: IJSONResult): SchemaValidationResult {
        return validate(this.schema, config, result.getLocation);
    }
github webhintio / hint / packages / hint / src / lib / config.ts View on Github external
public static validateConnectorConfig(config: Configuration) {
        const connectorId = config.connector!.name;

        debug(`Validating ${connectorId} connector`);

        const Connector = loadResource(connectorId, ResourceType.connector) as IConnectorConstructor;

        debug(`Connector schema:`);
        debug(Connector.schema);
        debug(`User configuration:`);
        debug(config.connector!.options!);

        return schemaValidator(Connector.schema, config.connector!.options!).valid;
    }
github webhintio / hint / packages / parser-manifest / src / parser.ts View on Github external
if (response.statusCode >= 400) {
            return;
        }

        await this.engine.emitAsync(`parse::start::manifest`, { resource });

        let result: IJSONResult;

        /*
         * Try to see if the content of the web app manifest file
         * is a valid JSON.
         */

        try {
            result = parseJSON(response.body.content);
        } catch (e) {

            await this.engine.emitAsync(this.parseJSONErrorEventName, {
                error: e,
                resource
            });

            return;
        }

        /*
         * Try to see if the content of the web app manifest file
         * is a valid acording to the schema.
         */

        const validationResult: SchemaValidationResult = validate(schema, result.data, result.getLocation);
github webhintio / hint / packages / parser-package-json / src / parser.ts View on Github external
private async parsePackageJson(fetchEnd: FetchEnd) {
        const resource = fetchEnd.resource;
        const resourceFileName = path.basename(resource);
        const isPackageJson: boolean = resourceFileName === 'package.json';

        if (!isPackageJson) {
            return;
        }

        try {
            const response = fetchEnd.response;
            const result = parseJSON(response.body.content);

            await this.engine.emitAsync('parse::start::package-json', { resource });

            const config: IJsonSchemaForNpmPackageJsonFiles = result.data;

            const validationResult: SchemaValidationResult = await this.validateSchema(config, resource, result);

            if (!validationResult.valid) {
                await this.emitInvalidPackageJson(validationResult, resource);

                return;
            }

            await this.engine.emitAsync('parse::end::package-json', {
                config: validationResult.data,
                getLocation: result.getLocation,

@hint/utils-json

utils for JSON

Apache-2.0
Latest version published 10 months ago

Package Health Score

88 / 100
Full package analysis