How to use the textlint-rule-helper.RuleHelper function in textlint-rule-helper

To help you get started, we’ve selected a few textlint-rule-helper 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 textlint / textlint / test / fixtures / rules / no-todo.js View on Github external
export default function (context) {
    const helper = new RuleHelper(context);
    const {Syntax, getSource, RuleError, report} = context;
    return {
        /*
            # Header
            Todo: quick fix this.
        */
        [Syntax.Str](node) {
            if (helper.isChildNode(node, [Syntax.Link, Syntax.Image, Syntax.BlockQuote])) {
                return;
            }
            // get text from node
            const text = getSource(node);
            // does text contain "todo:"?
            const match = text.match(/todo:/i);
            if (match) {
                report(node, new RuleError(`Found TODO: '${text}'`, {
github sapegin / textlint-rule-stop-words / index.js View on Github external
function reporter(context, options = {}) {
	const opts = Object.assign({}, DEFAULT_OPTIONS, options);
	const rules = getDict(opts.defaultWords, opts.words, opts.exclude);

	const helper = new RuleHelper(context);
	const { Syntax, RuleError, report, fixer, getSource } = context;
	return {
		[Syntax.Str](node) {
			if (helper.isChildNode(node, opts.skip.map(rule => Syntax[rule]))) {
				return false;
			}

			return new Promise(resolve => {
				const text = getSource(node);

				for (const [word, alternative] of rules) {
					const regExp = getRegExp(word);

					let match;
					// eslint-disable-next-line no-cond-assign
					while ((match = regExp.exec(text))) {
github textlint-rule / textlint-rule-no-dead-link / src / no-dead-link.js View on Github external
function reporter(context, options = {}) {
  const { Syntax, getSource, report, RuleError, fixer, getFilePath } = context;
  const helper = new RuleHelper(context);
  const ruleOptions = { ...DEFAULT_OPTIONS, ...options };
  const isAliveURI = createCheckAliveURL(ruleOptions);
  // 30sec memorized
  const memorizedIsAliveURI = pMemoize(isAliveURI, {
    maxAge: 30 * 1000,
  });
  /**
   * Checks a given URI's availability and report if it is dead.
   * @param {TextLintNode} node TextLintNode the URI belongs to.
   * @param {string} uri a URI string to be linted.
   * @param {number} index column number the URI is located at.
   * @param {number} maxRetryCount retry count of linting
   */
  const lint = async ({ node, uri, index }, maxRetryCount) => {
    if (isIgnored(uri, ruleOptions.ignore)) {
      return;
github azu / textlint-rule-spellcheck-tech-word / spellcheck-tech-word.js View on Github external
function reporter(context) {
    var helper = new RuleHelper(context);
    var exports = {};
    var fixer = context.fixer;
    var Syntax = context.Syntax;
    exports[context.Syntax.Str] = function (node) {
        if (helper.isChildNode(node, [Syntax.Link, Syntax.Image, Syntax.BlockQuote, Syntax.Emphasis])) {
            return;
        }
        var text = context.getSource(node);
        var results = spellCheck(text);
        results.forEach(function (/*SpellCheckResult*/result) {
            // line, column
            var fixCommand = fixer.replaceTextRange([
                result.paddingIndex, result.paddingIndex + result.actual.length
            ], result.expected);
            context.report(node, new context.RuleError(result.actual + " => " + result.expected, {
                index: result.paddingIndex,
github textlint-ja / textlint-rule-preset-JTF-style / src / util / pair-checker.js View on Github external
export function checkPair(context, { left, right }) {
    assert(left);
    assert(right);
    let { Syntax, RuleError, report, getSource } = context;
    let helper = new RuleHelper(context);
    let isInParagraph = false;
    let currentStrInParagraph = [];
    /**
     * `Str` nodeの配列を受け取り、pairが見つからないnodeを返す
     * @param {Object} currentStrInParagraph
     * @returns {{node, index}[]}
     */
    const foundMissingPairNodes = currentStrInParagraph => {
        let foundLeft = false;
        let matchParentheses = [];
        currentStrInParagraph.forEach(node => {
            const text = getSource(node);
            // left を探す
            let leftIndex = -1;
            if (!foundLeft) {
                leftIndex = text.indexOf(left);
github sapegin / textlint-rule-terminology / index.js View on Github external
function reporter(context, options = {}) {
	const opts = Object.assign({}, DEFAULT_OPTIONS, options);
	const terms = getTerms(opts.defaultTerms, opts.terms, opts.exclude);
	const rules = getExactMatchRegExps(terms);

	// Regexp for all possible mistakes
	const allMistakes = rules.map(rule => rule[0]);
	const regExp = getRegExp(allMistakes);

	const helper = new RuleHelper(context);
	const { Syntax, RuleError, report, fixer, getSource } = context;
	return {
		[Syntax.Str](node) {
			if (helper.isChildNode(node, opts.skip.map(rule => Syntax[rule]))) {
				return false;
			}

			return new Promise(resolve => {
				const text = getSource(node);

				let match;
				// eslint-disable-next-line no-cond-assign
				while ((match = regExp.exec(text))) {
					const index = match.index;
					const matched = match[0];
					const rule = getRuleForMatch(rules, matched);
github textlint-rule / textlint-rule-write-good / src / write-good.js View on Github external
function reporter(context, options = {}) {
  const { Syntax, getSource, report, RuleError } = context;
  const helper = new RuleHelper(context);

  return {
    [Syntax.Str](node) {
      if (helper.isChildNode(node, [Syntax.BlockQuote])) {
        return;
      }

      const text = getSource(node);
      const suggestions = writeGood(text, options);

      suggestions.forEach((suggestion) => {
        const { index, reason: message } = suggestion;

        report(node, new RuleError(message, { index }));
      });
    },
github textlint-ja / textlint-rule-preset-JTF-style / src / util / node-util.js View on Github external
export function isUserWrittenNode(node, context) {
    let helper = new RuleHelper(context);
    let Syntax = context.Syntax;
    return !helper.isChildNode(node, [Syntax.Link, Syntax.Image, Syntax.BlockQuote, Syntax.Emphasis]);
}
github textlint-ja / textlint-rule-no-dropping-the-ra / src / no-dropping-the-ra.js View on Github external
module.exports = function(context) {
    const helper = new RuleHelper(context);
    const { Syntax, report, getSource, RuleError } = context;
    return {
        [Syntax.Str](node) {
            if (helper.isChildNode(node, [Syntax.Link, Syntax.Image, Syntax.BlockQuote, Syntax.Emphasis])) {
                return;
            }
            const text = getSource(node);
            return kuromojin(text).then(tokens => {
                tokens.forEach(token => {
                    if (isKoreru(token)) {
                        report(
                            node,
                            new RuleError("ら抜き言葉を使用しています。", {
                                index: token.word_position
                            })
                        );

textlint-rule-helper

A helper library for textlint rule.

MIT
Latest version published 1 year ago

Package Health Score

57 / 100
Full package analysis

Popular textlint-rule-helper functions

Similar packages