How to use @textlint/utils - 9 common examples

To help you get started, we’ve selected a few @textlint/utils 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 / packages / textlint / src / engine / textlint-module-loader.ts View on Github external
/*
           Task
             - check already define
             - resolve package name
             - load package
             - emit rule
        */
        // ignore already defined rule
        // ignore rules from rulePaths because avoid ReferenceError is that try to require.
        if (isFile(ruleName)) {
            const ruleCreator = moduleInterop(require(ruleName));
            const ruleEntry = [ruleName, ruleCreator];
            this.emit(TextLintModuleLoader.Event.filterRule, ruleEntry);
            return;
        }
        const definedRuleName = normalizeTextlintFilterRuleKey(ruleName);
        // ignore plugin's rule
        if (isPluginRuleKey(definedRuleName)) {
            Logger.warn(`${definedRuleName} is Plugin's rule. This is unknown case, please report issue.`);
            return;
        }
        const pkgPath = this.moduleResolver.resolveFilterRulePackageName(ruleName);
        debug("Loading filter rules from %s", pkgPath);
        const ruleCreator = moduleInterop(require(pkgPath));
        const ruleEntry = [definedRuleName, ruleCreator];
        this.emit(TextLintModuleLoader.Event.filterRule, ruleEntry);
    }
}
github textlint / textlint / packages / textlint / src / engine / textlint-module-loader.ts View on Github external
loadPlugin(pluginName: string) {
        const pkgPath = this.moduleResolver.resolvePluginPackageName(pluginName);
        debug("Loading rules from plugin: %s", pkgPath);
        const plugin = moduleInterop(require(pkgPath));
        const pluginNameWithoutPrefix = normalizeTextlintPluginKey(pluginName);
        // Notes: plugins not support "rules" and "rulesConfig"
        // https://github.com/textlint/textlint/issues/291
        if (plugin.hasOwnProperty("rules")) {
            throw new Error(`textlint plugins not support "rules" and "rulesConfig".
But ${pluginName} has these filed.
For more details, See https://github.com/textlint/textlint/issues/291`);
        }
        // register plugin.Processor
        if (!plugin.hasOwnProperty("Processor")) {
            throw new Error(`textlint plugin should have "Processor".
For more details. See https://github.com/textlint/textlint/blob/master/docs/plugin.md`);
        }
        const pluginEntry = [pluginNameWithoutPrefix, plugin];
        this.emit(TextLintModuleLoader.Event.plugin, pluginEntry);
    }
github textlint / textlint / packages / textlint / src / engine / textlint-module-loader.ts View on Github external
Task
             - check already define
             - resolve package name
             - load package
             - emit rule
        */
        // ruleName is filePath
        if (isFile(ruleName)) {
            const ruleCreator = moduleInterop(require(ruleName));
            const ruleEntry = [ruleName, ruleCreator];
            this.emit(TextLintModuleLoader.Event.rule, ruleEntry);
            return;
        }
        // ignore already defined rule
        // ignore rules from rulePaths because avoid ReferenceError is that try to require.
        const definedRuleName = normalizeTextlintRuleKey(ruleName);
        // ignore plugin's rule
        if (isPluginRuleKey(definedRuleName)) {
            Logger.warn(`${definedRuleName} is Plugin's rule. This is unknown case, please report issue.`);
            return;
        }
        const pkgPath = this.moduleResolver.resolveRulePackageName(ruleName);
        debug("Loading rules from %s", pkgPath);
        const ruleCreator = moduleInterop(require(pkgPath));
        const ruleEntry = [definedRuleName, ruleCreator];
        this.emit(TextLintModuleLoader.Event.rule, ruleEntry);
    }
github textlint / textlint / packages / textlint / src / engine / textlint-module-loader.ts View on Github external
loadPreset(presetName: string) {
        /*
         Caution: Rules of preset are defined as following.
             {
                "rules": {
                    "preset-gizmo": {
                        "ruleA": false

                }
            }

        It mean that "ruleA" is defined as "preset-gizmo/ruleA"

         */
        const presetRuleNameWithoutPrefix = normalizeTextlintRulePresetKey(presetName);
        // ignore plugin's rule
        if (isPluginRuleKey(presetRuleNameWithoutPrefix)) {
            Logger.warn(`${presetRuleNameWithoutPrefix} is Plugin's rule. This is unknown case, please report issue.`);
            return;
        }

        const pkgPath = this.moduleResolver.resolvePresetPackageName(presetName);
        debug("Loading rules from preset: %s", pkgPath);
        const preset = moduleInterop(require(pkgPath));
        const entities = TextLintModuleMapper.createEntities(preset.rules, presetRuleNameWithoutPrefix);
        entities.forEach(entry => {
            this.emit(TextLintModuleLoader.Event.rule, entry);
        });
    }
github textlint / textlint / packages / textlint / src / config / config-initializer.ts View on Github external
return pkgNames.filter(pkgName => {
                const ruleOrFilter =
                    pkgName.indexOf(TextlintPackageNamePrefix.filterRule) !== -1 ||
                    pkgName.indexOf(TextlintPackageNamePrefix.rule) !== -1;
                if (pkgName === "textlint-rule-helper") {
                    return false;
                }
                return ruleOrFilter;
            });
        })
github textlint / textlint / packages / textlint / src / config / config-initializer.ts View on Github external
.filter(pkgName => {
                return pkgName.indexOf(TextlintPackageNamePrefix.filterRule) !== -1;
            })
            .map(filterName => {
github textlint / textlint / packages / textlint / src / config / config-initializer.ts View on Github external
return pkgNames.filter(pkgName => {
                const ruleOrFilter =
                    pkgName.indexOf(TextlintPackageNamePrefix.filterRule) !== -1 ||
                    pkgName.indexOf(TextlintPackageNamePrefix.rule) !== -1;
                if (pkgName === "textlint-rule-helper") {
                    return false;
                }
                return ruleOrFilter;
            });
        })
github textlint / textlint / packages / textlint / src / config / config-initializer.ts View on Github external
.filter(pkgName => {
                return pkgName.indexOf(TextlintPackageNamePrefix.rule) !== -1;
            })
            .map(filterName => {
github textlint / textlint / packages / textlint / src / config / preset-loader.ts View on Github external
Object.keys(rulesConfig).forEach(ruleName => {
        const normalizedKey = normalizeTextlintPresetSubRuleKey({ preset: presetName, rule: ruleName });
        mapped[normalizedKey] = rulesConfig[ruleName];
    });
    return mapped;