<commit_before>// LICENSE : MIT
"use strict";
const interopRequire = require('interop-require');
const tryResolve = require('try-resolve');
const ObjectAssign = require("object-assign");
const debug = require('debug')('textlint:plugin-loader');
const path = require("path");
export function mapRulesConfig(rulesConfig, pluginName) {
    let mapped = {};
    if (rulesConfig === undefined) {
        return mapped;
    }
    Object.keys(rulesConfig).forEach(key => {
        mapped[`${pluginName}/${key}`] = rulesConfig[key];
    });
    return mapped;
}
// load rulesConfig from plugins
export default function loadRulesConfigFromPlugins(pluginNames = [], {
    baseDir = ".",
    pluginPrefix
    }) {
    var pluginRulesConfig = {};
    pluginNames.forEach(pluginName => {
        const textlintRuleName = `${pluginPrefix}${pluginName}`;
        const pkgPath = tryResolve(path.join(baseDir, textlintRuleName)) || tryResolve(path.join(baseDir, pluginName));
        if (!pkgPath) {
            throw new ReferenceError(`${ pluginName } is not found. Try to load ${path.join(baseDir, pluginName)}`);
        }
        var plugin = interopRequire(pkgPath);
        if (!plugin.hasOwnProperty("rulesConfig")) {
            debug(`${pluginName} has not rulesConfig`);
            return;
        }
        // set config of <rule> to "<plugin>/<rule>"
        ObjectAssign(pluginRulesConfig, mapRulesConfig(plugin.rulesConfig, pluginName));
    });
    return pluginRulesConfig;
}<commit_msg>docs(plugin): fix loading error of plugin<commit_after>// LICENSE : MIT
"use strict";
const interopRequire = require('interop-require');
const tryResolve = require('try-resolve');
const ObjectAssign = require("object-assign");
const debug = require('debug')('textlint:plugin-loader');
const path = require("path");
export function mapRulesConfig(rulesConfig, pluginName) {
    let mapped = {};
    if (rulesConfig === undefined) {
        return mapped;
    }
    Object.keys(rulesConfig).forEach(key => {
        mapped[`${pluginName}/${key}`] = rulesConfig[key];
    });
    return mapped;
}
// load rulesConfig from plugins
export default function loadRulesConfigFromPlugins(pluginNames = [], {
    baseDir = ".",
    pluginPrefix
    }) {
    var pluginRulesConfig = {};
    pluginNames.forEach(pluginName => {
        const textlintRuleName = `${pluginPrefix}${pluginName}`;
        const pkgPath = tryResolve(path.join(baseDir, textlintRuleName)) || tryResolve(path.join(baseDir, pluginName));
        if (!pkgPath) {
            throw new ReferenceError(`plugin:${ pluginName } is not found. Fail to load ${path.join(baseDir, pluginName)}`);
        }
        var plugin = interopRequire(pkgPath);
        if (!plugin.hasOwnProperty("rulesConfig")) {
            debug(`${pluginName} has not rulesConfig`);
            return;
        }
        // set config of <rule> to "<plugin>/<rule>"
        ObjectAssign(pluginRulesConfig, mapRulesConfig(plugin.rulesConfig, pluginName));
    });
    return pluginRulesConfig;
}
{'fraction_non_alphanumeric': 0.14134041141340412, 'fraction_numerical': 0.0, 'mean_word_length': 3.5134730538922154, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7630738', 'n_tokens_mistral': 815, 'n_tokens_neox': 832, 'n_words': 191}