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

To help you get started, we’ve selected a few @hint/utils-debug 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-jsx / src / parser.ts View on Github external
/**
 * @fileoverview webhint parser needed to analyze HTML contained within JSX files.
 */
import * as parse5 from 'parse5';
import * as htmlparser2Adapter from 'parse5-htmlparser2-tree-adapter';
import { debug as d } from '@hint/utils-debug';
import { DocumentData, ElementData, HTMLDocument, restoreReferences, TextData } from '@hint/utils-dom';
import { Parser } from 'hint/dist/src/lib/types';
import { Engine } from 'hint/dist/src/lib/engine';
import { HTMLEvents } from '@hint/parser-html';
import { JSXAttribute, JSXElement, JSXExpressionContainer, JSXText, Node, ScriptEvents } from '@hint/parser-javascript';

type ChildMap = Map>;
type RootMap = Map;

const debug = d(__filename);

/**
 * Check if the provided `Node` is a native HTML element in JSX.
 */
const isNativeElement = (node: Node) => {
    if (node.type !== 'JSXElement') {
        return false;
    }

    /* istanbul ignore if */
    if (node.openingElement.name.type !== 'JSXIdentifier') {
        return false; // Ignore JSXMemberExpression and JSXNamespacedName.
    }

    const { name } = node.openingElement.name;
github webhintio / hint / packages / hint-amp-validator / src / hint.ts View on Github external
/**
 * @fileoverview Validates if the HTML of a page is AMP valid
 */

import * as path from 'path';

import * as amphtmlValidator from 'amphtml-validator';

import { debug as d } from '@hint/utils-debug';
import { IHint, FetchEnd } from 'hint/dist/src/lib/types';
import { HintContext } from 'hint/dist/src/lib/hint-context';

import meta from './meta';
import { Severity } from '@hint/utils-types';

const debug: debug.IDebugger = d(__filename);

/*
 * ------------------------------------------------------------------------------
 * Public
 * ------------------------------------------------------------------------------
 */

export default class AmpValidatorHint implements IHint {
    public static readonly meta = meta;

    public constructor(context: HintContext) {
        let validPromise: Promise;
        const errorsOnly = context.hintOptions && /* istanbul ignore next */ context.hintOptions['errors-only'] || false;
        let events: FetchEnd[] = [];

        const onFetchEndHTML = (fetchEnd: FetchEnd) => {
github webhintio / hint / packages / parser-less / src / parser.ts View on Github external
const parser = require('postcss-less');

import * as postcss from 'postcss';

import { debug as d } from '@hint/utils-debug';
import { normalizeString } from '@hint/utils-string';
import { HTMLElement } from '@hint/utils-dom';
import { Parser } from 'hint/dist/src/lib/types';
import { StyleEvents } from '@hint/parser-css';
import { Engine } from 'hint';

const debug = d(__filename);

export default class CSSParser extends Parser {
    public constructor(engine: Engine) {
        super(engine, 'less');

        const emitLESS = async (code: string, resource: string, element: HTMLElement | null) => {

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

                const result = await postcss().process(code, { from: resource, parser });
                const ast = result.root!; // always defined even for '' (typings error?)

                await this.engine.emitAsync(`parse::end::css`, {
                    ast,
                    code,
github webhintio / hint / packages / parser-sass / src / parser.ts View on Github external
const sassParser = require('postcss-sass');
const scssParser = require('postcss-scss');

import * as postcss from 'postcss';

import { debug as d } from '@hint/utils-debug';
import { normalizeString } from '@hint/utils-string';
import { HTMLElement } from '@hint/utils-dom';
import { Parser } from 'hint/dist/src/lib/types';
import { StyleEvents } from '@hint/parser-css';
import { Engine } from 'hint';

const debug = d(__filename);

export default class CSSParser extends Parser {
    public constructor(engine: Engine) {
        super(engine, 'sass');

        const emitSASS = async (code: string, parser: postcss.Parser, resource: string, element: HTMLElement | null) => {

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

                const result = await postcss().process(code, { from: resource, parser });
                const ast = result.root!; // always defined even for '' (typings error?)

                await this.engine.emitAsync(`parse::end::css`, {
                    ast,
                    code,
github webhintio / hint / packages / hint-strict-transport-security / src / hint.ts View on Github external
/**
 * @fileoverview Check if responses served over HTTPS also have the Strict-Transport-Security header with a proper value max-age value.
 */
import * as url from 'url';
import { URL } from 'url'; // this is necessary to avoid TypeScript mixes types.

import { isRegularProtocol } from '@hint/utils-network';
import { debug as d } from '@hint/utils-debug';
import { FetchEnd, HintContext, IHint, NetworkData } from 'hint';
import { Severity } from '@hint/utils-types';

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

const debug = d(__filename);

/*
 * ------------------------------------------------------------------------------
 * Public
 * ------------------------------------------------------------------------------
 */

export default class StrictTransportSecurityHint implements IHint {

    public static readonly meta = meta;

    public constructor(context: HintContext) {

        /** The minimum period (in seconds) allowed for `max-age`. */
        let minMaxAgeValue: number;
        /** Whether or not check the preload attribute */
github webhintio / hint / packages / hint-https-only / src / hint.ts View on Github external
/**
 * @fileoverview Verifies if a website is using HTTPS and if it has mixed content.
 */

import * as URL from 'url';

import { ElementFound, FetchEnd, HintContext, IHint, Response } from 'hint';
import { isDataURI, isHTTPS } from '@hint/utils-network';
import { debug as d } from '@hint/utils-debug';

import meta from './meta';
import { getMessage } from './i18n.import';
import { Severity } from '@hint/utils-types';

const debug: debug.IDebugger = d(__filename);

/*
 * ------------------------------------------------------------------------------
 * Public
 * ------------------------------------------------------------------------------
 */

export default class HttpsOnlyHint implements IHint {
    private targetIsServedOverHTTPS: boolean = false;

    public static readonly meta = meta;

    public constructor(context: HintContext) {
        let target: string;
        const reportedUrls: Set = new Set();
github webhintio / hint / packages / hint-no-broken-links / src / hint.ts View on Github external
HintContext,
    IHint,
    NetworkData,
    TraverseEnd
} from 'hint';
import { Severity } from '@hint/utils-types';
import { isRegularProtocol } from '@hint/utils-network';
import { HTMLElement } from '@hint/utils-dom';
import { debug as d } from '@hint/utils-debug';
import { Requester } from '@hint/utils-connector-tools';
import { CoreOptions } from 'request';

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

const debug: debug.IDebugger = d(__filename);

/*
 * ------------------------------------------------------------------------------
 * Public
 * ------------------------------------------------------------------------------
 */

export default class NoBrokenLinksHint implements IHint {
    public static readonly meta = meta;

    public constructor(context: HintContext) {

        const options: CoreOptions = { method: context.hintOptions && context.hintOptions.method ? context.hintOptions.method : 'GET' };
        const requester = new Requester(options);
        const brokenStatusCodes = [404, 410, 500, 503];
github webhintio / hint / packages / hint-no-p3p / src / hint.ts View on Github external
/**
 * @fileoverview `no-p3p` disallows the use of `P3P`
 */

import { URL } from 'url';

import { ElementFound, FetchEnd, HintContext, IHint, ScanStart } from 'hint';
import { normalizeString } from '@hint/utils-string';
import { includedHeaders } from '@hint/utils-network';
import { debug as d } from '@hint/utils-debug';
import { Severity } from '@hint/utils-types';

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

const debug: debug.IDebugger = d(__filename);

/*
 * ------------------------------------------------------------------------------
 * Public
 * ------------------------------------------------------------------------------
 */

export default class NoP3pHint implements IHint {

    public static readonly meta = meta;

    public constructor(context: HintContext) {

        const errorMessage = getMessage('p3pDeprecated', context.language);
        /**
         * Verifies the server doesn't respond with any content to the well-known location
github webhintio / hint / packages / hint-apple-touch-icons / src / hint.ts View on Github external
/**
 * @fileoverview Check for correct usage of `apple-touch-icon`.
 */
import { imageSize as getImageData } from 'image-size';

import { normalizeString } from '@hint/utils-string';
import { isRegularProtocol } from '@hint/utils-network';
import { debug as d } from '@hint/utils-debug';
import { HintContext, IHint, NetworkData, TraverseEnd } from 'hint';
import { HTMLDocument, HTMLElement } from '@hint/utils-dom';
import { Severity } from '@hint/utils-types';

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

const debug: debug.IDebugger = d(__filename);

/*
 * ------------------------------------------------------------------------------
 * Public
 * ------------------------------------------------------------------------------
 */

export default class AppleTouchIconsHint implements IHint {

    public static readonly meta = meta;

    public constructor(context: HintContext) {

        /*
         * This function exists because not all connector (e.g.: jsdom)
         * support matching attribute values case-insensitively.
github webhintio / hint / packages / hint-html-checker / src / hint.ts View on Github external
* ------------------------------------------------------------------------------
 */

import uniqBy = require('lodash/uniqBy');
import { OptionsWithUrl } from 'request';

import { debug as d } from '@hint/utils-debug';
import { HintContext, IHint } from 'hint';
import { ProblemLocation, Severity } from '@hint/utils-types';

import { HTMLEvents, HTMLParse } from '@hint/parser-html';

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

const debug: debug.IDebugger = d(__filename);

type CheckerData = {
    event: HTMLParse;
    failed: boolean;
    promise: Promise;
};

/*
 * ------------------------------------------------------------------------------
 * Public
 * ------------------------------------------------------------------------------
 */

export default class HtmlCheckerHint implements IHint {

    public static readonly meta = meta;

@hint/utils-debug

debug messages util

Apache-2.0
Latest version published 11 months ago

Package Health Score

88 / 100
Full package analysis

Popular @hint/utils-debug functions