How to use the @hint/utils-types.Severity.hint function in @hint/utils-types

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-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 / formatter-codeframe / src / formatter.ts View on Github external
public async format(messages: Problem[], options: FormatterOptions = {}) {
        debug('Formatting results');

        const language: string = options.language!;

        if (messages.length === 0) {
            return;
        }

        const resources: _.Dictionary = _.groupBy(messages, 'resource');
        const totals = {
            [Severity.error.toString()]: 0,
            [Severity.warning.toString()]: 0,
            [Severity.information.toString()]: 0,
            [Severity.hint.toString()]: 0
        };

        let result = _.reduce(resources, (total: string, msgs: Problem[], resource: string) => {
            const sortedMessages: Problem[] = _.sortBy(msgs, ['location.line', 'location.column']);
            const resourceString = chalk.cyan(`${cutString(resource, 80)}`);

            const partialResult = _.reduce(sortedMessages, (subtotal: string, msg: Problem) => {
                let partial: string;
                const color = severityToColor(msg.severity);
                const severity = color(getMessage(`capitalized${Severity[msg.severity].toString()}` as MessageName, language));
                const location = msg.location;

                totals[msg.severity.toString()]++;

                partial = `${getMessage('hintInfo', language, [
                    severity,
github webhintio / hint / packages / formatter-stylish / src / formatter.ts View on Github external
public async format(messages: Problem[], options: FormatterOptions = {}) {
        const language: string = options.language!;

        debug('Formatting results');

        if (messages.length === 0) {
            return;
        }

        const resources: _.Dictionary = _.groupBy(messages, 'resource');
        const totals = {
            [Severity.error.toString()]: 0,
            [Severity.warning.toString()]: 0,
            [Severity.information.toString()]: 0,
            [Severity.hint.toString()]: 0
        };

        let result = _.reduce(resources, (total: string, msgs: Problem[], resource: string) => {
            const partials = {
                [Severity.error.toString()]: 0,
                [Severity.warning.toString()]: 0,
                [Severity.information.toString()]: 0,
                [Severity.hint.toString()]: 0
            };
            const sortedMessages: Problem[] = _.sortBy(msgs, ['location.line', 'location.column']);
            const tableData: string[][] = [];
            let hasPosition: boolean = false;

            let partialResult = `${chalk.cyan(cutString(resource, 80))}\n`;

            _.forEach(sortedMessages, (msg: Problem) => {
github webhintio / hint / packages / hint-no-vulnerable-javascript-libraries / src / hint.ts View on Github external
const toSeverity = (severity: SnykSeverity) => {
            switch (severity) {
                case 'high': return Severity.error;
                case 'medium': return Severity.warning;
                default:
                    return Severity.hint;
            }
        };
github webhintio / hint / packages / formatter-summary / src / formatter.ts View on Github external
public async format(messages: Problem[], options: FormatterOptions = {}) {
        debug('Formatting results');

        if (messages.length === 0) {
            return;
        }

        const tableData: string[][] = [];
        const language: string = options.language!;
        const totals = {
            [Severity.error.toString()]: 0,
            [Severity.warning.toString()]: 0,
            [Severity.information.toString()]: 0,
            [Severity.hint.toString()]: 0
        };
        const resources: _.Dictionary = _.groupBy(messages, 'hintId');
        const sortedResources = Object.entries(resources).sort(([hintA, problemsA], [hintB, problemsB]) => {
            if (problemsA.length < problemsB.length) {
                return -1;
            }

            if (problemsA.length > problemsB.length) {
                return 1;
            }

            return hintA.localeCompare(hintB);
        });

        _.forEach(sortedResources, ([hintId, problems]) => {
            const msgsBySeverity = _.groupBy(problems, 'severity');
github webhintio / hint / packages / hint-no-friendly-error-pages / src / hint.ts View on Github external
*
             * (404 because the following function will most likely
             *  generate a 404 error response, other responses cannot
             *  be generated... so easily).
             */
            if (Object.keys(foundErrorPages).length === 0 || !foundErrorPages[404]) {
                await tryToGenerateErrorPage(href);
            }

            for (const key of Object.keys(foundErrorPages)) {
                const threshold = statusCodesWith512Threshold.includes(Number.parseInt(key)) ? 512 : 256;

                context.report(
                    href,
                    getMessage('responseWithStatus', context.language, [key, threshold.toString()]),
                    { severity: Severity.hint }
                );
            }
        };
github webhintio / hint / packages / formatter-summary / src / formatter.ts View on Github external
_.forEach(sortedResources, ([hintId, problems]) => {
            const msgsBySeverity = _.groupBy(problems, 'severity');
            const errors = msgsBySeverity[Severity.error] ? msgsBySeverity[Severity.error].length : 0;
            const warnings = msgsBySeverity[Severity.warning] ? msgsBySeverity[Severity.warning].length : 0;
            const informations = msgsBySeverity[Severity.information] ? msgsBySeverity[Severity.information].length : 0;
            const hints = msgsBySeverity[Severity.hint] ? msgsBySeverity[Severity.hint].length : 0;
            const red = severityToColor(Severity.error);
            const yellow = severityToColor(Severity.warning);
            const gray = severityToColor(Severity.information);
            const pink = severityToColor(Severity.hint);
            const line: string[] = [chalk.cyan(hintId)];

            if (errors > 0) {
                line.push(red(getMessage(errors === 1 ? 'errorCount' : 'errorsCount', language, errors.toString())));
            }
            if (warnings > 0) {
                line.push(yellow(getMessage(warnings === 1 ? 'warningCount' : 'warningsCount', language, warnings.toString())));
            }
            if (hints > 0) {
                line.push(pink(getMessage(hints === 1 ? 'hintCount' : 'hintsCount', language, hints.toString())));
            }
            if (informations > 0) {