How to use the @hint/utils-fs.readFileAsync function in @hint/utils-fs

To help you get started, we’ve selected a few @hint/utils-fs 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 / utils-tests-helpers / src / hint-runner.ts View on Github external
const requestSource = async (url: string, connector: string): Promise => {
    try {
        if (connector === 'local') {
            return await readFileAsync(asPathString(getAsUri(url)!));
        }

        /*
         * Allow us to use our self-signed cert for testing.
         * https://github.com/request/request/issues/418#issuecomment-23058601
         */
        return await requestAsync({
            rejectUnauthorized: false,
            strictSSL: false,
            url
        });
    } catch (e) {
        // Some tests deliberately use invalid URLs (e.g. `test:`).
        return '';
    }
};
github webhintio / hint / packages / connector-local / src / connector.ts View on Github external
private async getGitIgnore() {
        try {
            const rawList = await readFileAsync(path.join(cwd(), '.gitignore'));
            const splitList = rawList.split('\n');

            const result = splitList.reduce((total: string[], ignore: string) => {
                const value: string = ignore.trim();

                /* istanbul ignore if */
                if (!value) {
                    return total;
                }

                /* istanbul ignore if */
                if (value[0] === '/') {
                    total.push(value.substr(1));
                } else {
                    total.push(value);
                }
github webhintio / hint / packages / connector-puppeteer / src / lib / lifecycle.ts View on Github external
const getBrowserInfo = async (): Promise => {
    let result = { browserWSEndpoint: '' };

    try {
        result = JSON.parse((await readFileAsync(infoFile)).trim());
    } catch (e) /* istanbul ignore next */ {
        debug(`Error reading ${infoFile}`);
        debug(e);

        return null;
    }

    return result;
};
github webhintio / hint / packages / formatter-html / src / formatter.ts View on Github external
const getScriptsContent = async (files: string[]): Promise => {
    const result: FileContent[] = [];

    for (const file of files) {
        const regex = /<\/script>/g;
        const content = await readFileAsync(path.resolve(__dirname, 'assets', file));

        result.push({
            // Replace the string  to avoid problems in the website.
            content: content.replace(regex, ''),
            file
        });
    }

    return result;
};
github webhintio / hint / packages / hint-no-vulnerable-javascript-libraries / src / hint.ts View on Github external
const createScript = async (): Promise => {
            debug('Creating script to inject');
            const libraryDetector = await readFileAsync(require.resolve('js-library-detector'));

            const script = `/*RunInPageContext*/
            (function (){
                ${libraryDetector};

                const libraries = Object.entries(d41d8cd98f00b204e9800998ecf8427e_LibraryDetectorTests);
                const detectedLibraries = libraries.reduce((detected, [name, lib]) => {
                    try {
                        const result = lib.test(window);
                        if (result) {
                            detected.push({
                                name,
                                version: result.version,
                                npmPkgName: lib.npm
                            });
                        }
github webhintio / hint / packages / create-hint / src / handlebars-utils.ts View on Github external
export const compileTemplate = async (filePath: string, data: any): Promise => {
    let templateContent;

    try {
        templateContent = await readFileAsync(filePath);
    } catch (err) {
        throw (err);
    }

    const template = Handlebars.compile(templateContent);

    return template(data);
};
github webhintio / hint / packages / hint-axe / src / util / axe.ts View on Github external
import { CheckResult, AxeResults, ImpactValue, NodeResult as AxeNodeResult } from 'axe-core';

import { HTMLDocument, HTMLElement } from '@hint/utils-dom';
import { readFileAsync } from '@hint/utils-fs';
import { CanEvaluateScript } from 'hint/dist/src/lib/types';
import { HintContext } from 'hint/dist/src/lib/hint-context';
import { Severity } from '@hint/utils-types';

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

const axeCorePromise = readFileAsync(require.resolve('axe-core'));

type EngineKey = object;

type Options = {
    [ruleId: string]: keyof typeof Severity;
} | string[];

type Registration = {
    context: HintContext;
    enabledRules: string[];
    options: { [ruleId: string]: keyof typeof Severity };
    event: CanEvaluateScript;
};

type RegistrationMap = Map>;
github webhintio / hint / packages / create-parser / src / handlebars-utils.ts View on Github external
export const compileTemplate = async (filePath: string, data: any): Promise => {
    let templateContent;

    try {
        templateContent = await readFileAsync(filePath);
    } catch (err) {
        throw (err);
    }

    const template = Handlebars.compile(templateContent);

    return template(data);
};