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

To help you get started, we’ve selected a few @hint/utils-types 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 / hint-stylesheet-limits / src / hint.ts View on Github external
const validateScanEnd = async (event: CanEvaluateScript) => {

            const results = await context.evaluate(`(${injectedCode})()`);

            // Report once we hit a limit to support flagging on platforms which will drop subsequent rules.

            // Only check `maxImports` if a limit has been specified
            if (hasImportLimit && results.imports >= maxImports) {
                context.report(
                    event.resource,
                    getMessage('maximumNested', context.language, [maxImports.toString(), results.imports.toString()]),
                    { severity: Severity.error }
                );
            }

            if (hasRuleLimit && results.rules >= maxRules) {
                context.report(
                    event.resource,
                    getMessage('maximumRules', context.language, [maxRules.toString(), results.rules.toString()]),
                    { severity: Severity.error }
                );
            }

            if (hasSheetLimit && results.sheets >= maxSheets) {
                context.report(
                    event.resource,
                    getMessage('maximumStylesheets', context.language, [maxSheets.toString(), results.sheets.toString()]),
                    { severity: Severity.error }
github webhintio / hint / packages / hint-meta-viewport / src / hint.ts View on Github external
const checkContentValue = (contentValue: string | null, resource: string, viewportMetaElement: HTMLElement) => {

            if (!contentValue) {
                const message = getMessage('metaElementNonEmptyContent', context.language);

                context.report(
                    resource,
                    message,
                    {
                        element: viewportMetaElement,
                        severity: Severity.error
                    }
                );

                return;
            }

            const content = parseMetaViewPortContent(contentValue);

            // Check for unknown properties and invalid values.

            for (const key of Object.keys(content.unknownProperties)) {
                const message = getMessage('metaElementUnknownProperty', context.language, key);

                context.report(
                    resource,
                    message,
github webhintio / hint / packages / hint-html-checker / src / hint.ts View on Github external
const toSeverity = (message: HtmlError) => {
            if (message.type === 'info') {
                if (message.subType === 'warning') {
                    return Severity.warning;
                }

                // "Otherwise, the message is taken to generally informative."
                return Severity.information;
            }

            if (message.type === 'error') {
                return Severity.error;
            }

            // Internal errors by the validator, io, etc.
            return Severity.warning;
        };
github webhintio / hint / packages / hint-axe / src / util / axe.ts View on Github external
const toSeverity = (impact?: ImpactValue) => {
    if (impact === 'minor') {
        return Severity.hint;
    }

    if (impact === 'moderate' || impact === 'serious') {
        return Severity.warning;
    }

    if (impact === 'critical') {
        return Severity.error;
    }

    // In case axe adds a new `impact` that is not tracked above
    return Severity.warning;
};
github webhintio / hint / packages / hint-button-type / src / hint.ts View on Github external
const validateElement = (elementFound: ElementFound) => {

            const { resource } = elementFound;
            const allowedTypes = ['submit', 'reset', 'button'];

            debug('Validating hint button-type');

            const element = elementFound.element;
            const elementType = element.getAttribute('type');

            if (element.isAttributeAnExpression('type')) {
                // Assume template expressions will map to a valid value.
            } else if (elementType === null || elementType === '') {
                const severity = inAForm(element) ?
                    Severity.warning :
                    Severity.hint;

                context.report(
                    resource,
                    getMessage('attributeNotSet', context.language),
                    { element, severity }
                );
            } else if (!allowedTypes.includes(elementType.toLowerCase())) {
                context.report(
                    resource,
                    getMessage('invalidType', context.language, elementType),
                    { element, severity: Severity.error });
            }
        };
github webhintio / hint / packages / hint-manifest-file-extension / src / hint.ts View on Github external
const validate = ({ element, resource }: ElementFound) => {
            if (normalizeString(element.getAttribute('rel')) === 'manifest') {
                const href = element.resolveUrl(element.getAttribute('href') || /* istanbul ignore next */ '');
                const fileExtension: string = getFileExtension(normalizeString(href) || /* istanbul ignore next */ '');

                if (fileExtension !== standardManifestFileExtension) {
                    let message: string;
                    let severity: Severity;

                    if (fileExtension) {
                        message = getMessage('shouldHaveFileExtensionNot', context.language, [standardManifestFileExtension, fileExtension]);

                        severity = fileExtension === 'json' ?
                            Severity.hint :
                            Severity.warning;
                    } else {
                        message = getMessage('shouldHaveFileExtension', context.language, standardManifestFileExtension);
                        severity = Severity.warning;
                    }

                    context.report(resource, message, { content: fileExtension, element, severity });
                }
            }
        };
github webhintio / hint / packages / hint-http-cache / src / hint.ts View on Github external
const codeSnippet = `Cache-Control: ${header}`;
            const codeLanguage = 'http';

            const longCache = compareToMaxAge(usedDirectives, maxAgeResource) >= 0;
            const immutable = usedDirectives.has('immutable');


            const isCacheBusted = usesFileRevving(directives, fetchEnd);

            let validates = true;

            // We want long caches with "immutable" for static resources
            if (usedDirectives.has('no-cache') || !longCache) {
                const message: string = getMessage('staticResourceCacheValue', context.language, [maxAgeResource, header]);

                const severity = isCacheBusted ? Severity.warning : Severity.hint;

                context.report(resource, message, { codeLanguage, codeSnippet, severity });

                validates = false;
            }

            if (!immutable) {

                const message: string = getMessage('staticNotImmutable', context.language, header);
                const severity = immutableSupported && isCacheBusted ? Severity.warning : Severity.hint;

                context.report(resource, message, { codeLanguage, codeSnippet, severity });

                validates = false;
            }
github webhintio / hint / packages / hint-axe / src / meta / language.ts View on Github external
// autogenerated by scripts/create/create-metas.js
import { Category } from '@hint/utils-types';
import { HintScope } from 'hint/dist/src/lib/enums/hint-scope';
import { HintMetadata } from 'hint/dist/src/lib/types';

import { getMessage } from '../i18n.import';

const meta: HintMetadata = {
    docs: {
        category: Category.accessibility,
        description: getMessage('language_description', 'en'),
        name: getMessage('language_name', 'en')
    },
    /* istanbul ignore next */
    getDescription(language: string) {
        return getMessage('language_description', language);
    },
    /* istanbul ignore next */
    getName(language: string) {
        return getMessage('language_name', language);
    },
    id: 'axe/language',
    schema: [
        {
            additionalProperties: false,
            properties: {
github webhintio / hint / packages / hint-axe / src / meta / sensory-and-visual-cues.ts View on Github external
// autogenerated by scripts/create/create-metas.js
import { Category } from '@hint/utils-types';
import { HintScope } from 'hint/dist/src/lib/enums/hint-scope';
import { HintMetadata } from 'hint/dist/src/lib/types';

import { getMessage } from '../i18n.import';

const meta: HintMetadata = {
    docs: {
        category: Category.accessibility,
        description: getMessage('sensoryAndVisualCues_description', 'en'),
        name: getMessage('sensoryAndVisualCues_name', 'en')
    },
    /* istanbul ignore next */
    getDescription(language: string) {
        return getMessage('sensoryAndVisualCues_description', language);
    },
    /* istanbul ignore next */
    getName(language: string) {
        return getMessage('sensoryAndVisualCues_name', language);
    },
    id: 'axe/sensory-and-visual-cues',
    schema: [
        {
            additionalProperties: false,
            properties: {
github webhintio / hint / packages / hint-axe / src / meta / text-alternatives.ts View on Github external
// autogenerated by scripts/create/create-metas.js
import { Category } from '@hint/utils-types';
import { HintScope } from 'hint/dist/src/lib/enums/hint-scope';
import { HintMetadata } from 'hint/dist/src/lib/types';

import { getMessage } from '../i18n.import';

const meta: HintMetadata = {
    docs: {
        category: Category.accessibility,
        description: getMessage('textAlternatives_description', 'en'),
        name: getMessage('textAlternatives_name', 'en')
    },
    /* istanbul ignore next */
    getDescription(language: string) {
        return getMessage('textAlternatives_description', language);
    },
    /* istanbul ignore next */
    getName(language: string) {
        return getMessage('textAlternatives_name', language);
    },
    id: 'axe/text-alternatives',
    schema: [
        {
            additionalProperties: false,
            properties: {