Example #1
0
        readFile(filename, 'utf8', (read_err: Error, content: string) => {
            if (read_err) {
                console.error(read_err);
                return;
            }

            const opts = {
                strings: {
                    [filename]: content,
                },
                config: this.options,
            };

            markdownlint(opts, (err: Error, result: any) => {
                if (err) {
                    return;
                }
                const is_space = /\s+/;
                const messages = result.toString()
                                .split('\n')
                                .filter((msg: string) => msg !== '')
                                .map(function(msg: string): LinterMessage {
                                    const m = msg.match(is_space);
                                    if (!m) {
                                        return {header: '', body: msg};
                                    }

                                    return {
                                        header: msg.slice(0, m.index),
                                        body: msg.slice(m.index),
                                    };
                                });
                this.sendResult(messages);
            });
        });
};

const options: markdownlint.MarkdownlintOptions = {
    files: ['README.md'],
    strings: { 'file.md': 'Header' },
    config,
    noInlineConfig: false,
    resultVersion: 1,
};

// $ExpectType MarkdownlintResults
const results = markdownlint.sync(options);

markdownlint(options, (err, results) => {
    // $ExpectType Error | null
    err;

    // $ExpectType MarkdownlintResults
    results;

    const resultString: string = results.toString();
    // $ExpectError
    results.toString() as markdownlint.MarkdownlintResult[];

    const fileErrors: markdownlint.MarkdownlintResult[] = results[
        'file.md'
    ] as markdownlint.MarkdownlintResult[];
    const firstFileError: markdownlint.MarkdownlintResult = fileErrors[0];
    const firstFileErrorRule: string = firstFileError.ruleName;
});