value: function loadFilterRule(ruleName) {
     /*
        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 (existSync(ruleName)) {
         var _ruleCreator2 = interopRequire(ruleName);
         var _ruleEntry2 = [ruleName, _ruleCreator2];
         this.emit(TextLintModuleLoader.Event.filterRule, _ruleEntry2);
         return;
     }
     var RULE_NAME_PREFIX = this.config.constructor.FILTER_RULE_NAME_PREFIX;
     var prefixMatch = new RegExp("^" + RULE_NAME_PREFIX);
     var definedRuleName = ruleName.replace(prefixMatch, "");
     // ignore plugin's rule
     if ((0, _configUtil.isPluginRuleKey)(definedRuleName)) {
         _logger2.default.warn(definedRuleName + " is Plugin's rule. This is unknown case, please report issue.");
         return;
     }
     var pkgPath = this.moduleResolver.resolveFilterRulePackageName(ruleName);
     debug("Loading filter rules from %s", pkgPath);
     var ruleCreator = interopRequire(pkgPath);
     var ruleEntry = [definedRuleName, ruleCreator];
     this.emit(TextLintModuleLoader.Event.filterRule, ruleEntry);
 }
 fs.readdirSync(rulesDirAbsolutePath).forEach(function (file) {
     if (path.extname(file) !== '.js') {
         return;
     }
     var withoutExt = file.slice(0, -3);
     rules[withoutExt] = interopRequire(path.join(rulesDirAbsolutePath, file));
 });
function createFormatter(formatterConfig) {
    var formatterName = formatterConfig.formatterName;
    debug("try formatterName: " + formatterName);
    var formatter = undefined;
    var formatterPath = undefined;
    if (fs.existsSync(formatterName)) {
        formatterPath = formatterName;
    } else if (fs.existsSync(path.resolve(process.cwd(), formatterName))) {
        formatterPath = path.resolve(process.cwd(), formatterName);
    } else {
        var builtinFormatterPath = path.join(__dirname, "formatters/", formatterName) + ".js";
        if (existSync(builtinFormatterPath)) {
            formatterPath = builtinFormatterPath;
        } else {
            var pkgPath = tryResolve("textlint-formatter-" + formatterName) || tryResolve(formatterName);
            if (pkgPath) {
                formatterPath = pkgPath;
            }
        }
    }
    try {
        formatter = interopRequire(formatterPath);
    } catch (ex) {
        throw new Error("Could not find formatter " + formatterName + "\nSee https://github.com/textlint/textlint/issues/148\n" + ex);
    }
    debug("use formatter: " + formatterPath);
    return function (results) {
        return formatter(results, formatterConfig);
    };
}
        value: function loadPreset(presetName) {
            var _this4 = this;

            /*
             Caution: Rules of preset are defined as following.
                 {
                    "rules": {
                        "preset-gizmo": {
                            "ruleA": false
                     }
                }
             It mean that "ruleA" is defined as "preset-gizmo/ruleA"
              */
            var RULE_NAME_PREFIX = this.config.constructor.RULE_NAME_PREFIX;
            // Strip **rule** prefix
            // textlint-rule-preset-gizmo -> preset-gizmo
            var prefixMatch = new RegExp("^" + RULE_NAME_PREFIX);
            var presetRuleNameWithoutPrefix = presetName.replace(prefixMatch, "");
            // ignore plugin's rule
            if ((0, _configUtil.isPluginRuleKey)(presetRuleNameWithoutPrefix)) {
                _logger2.default.warn(presetRuleNameWithoutPrefix + " is Plugin's rule. This is unknown case, please report issue.");
                return;
            }

            var pkgPath = this.moduleResolver.resolvePresetPackageName(presetName);
            debug("Loading rules from preset: %s", pkgPath);
            var preset = interopRequire(pkgPath);
            var entities = _textlintModuleMapper2.default.createEntities(preset.rules, presetRuleNameWithoutPrefix);
            entities.forEach(function (entry) {
                _this4.emit(TextLintModuleLoader.Event.rule, entry);
            });
        }
Example #5
0
 fs.readdirSync(rulesDirAbsolutePath).forEach(function (file) {
     if (path.extname(file) !== extname) {
         return;
     }
     var withoutExt = path.basename(file, extname);
     rules[withoutExt] = interopRequire(path.join(rulesDirAbsolutePath, file));
 });
 pluginNames.forEach(function (pluginName) {
     var pkgPath = moduleResolver.resolvePluginPackageName(pluginName);
     var plugin = interopRequire(pkgPath);
     if (!plugin.hasOwnProperty("rulesConfig")) {
         return;
     }
     debug(pluginName + " has rulesConfig");
     // set config of <rule> to "<plugin>/<rule>"
     ObjectAssign(pluginRulesConfig, mapRulesConfig(plugin.rulesConfig, pluginName));
 });
 pluginNames.forEach(function (pluginName) {
     var pkgPath = moduleResolver.resolvePluginPackageName(pluginName);
     var plugin = interopRequire(pkgPath);
     if (!plugin.hasOwnProperty("Processor")) {
         return;
     }
     var Processor = plugin.Processor;
     debug(pluginName + " has Processor");
     assert(typeof Processor.availableExtensions === "function", "Processor.availableExtensions() should be implemented");
     availableExtensions.push.apply(availableExtensions, _toConsumableArray(Processor.availableExtensions()));
 });
Example #8
0
export default function load(configFilePath, {configFileName, configPackagePrefix}) {
    if (isConfigModule(configFilePath, configPackagePrefix)) {
        // config as a module - shared config
        // FIXME: not tested function
        return interopRequire(tryResolve(configFilePath));
    } else {
        // auto or specify config file
        const config = configFilePath ? {config: configFilePath} : null;
        return rc(configFileName, {}, config);
    }
}
Example #9
0
 ruleNames.forEach(ruleName => {
     const pkgPath = resolver.resolvePresetPackageName(ruleName);
     const preset = interopRequire(pkgPath);
     if (!preset.hasOwnProperty("rules")) {
         throw new Error(`${ruleName} has not rules`);
     }
     if (!preset.hasOwnProperty("rulesConfig")) {
         throw new Error(`${ruleName} has not rulesConfig`);
     }
     // set config of <rule> to "<preset>/<rule>"
     ObjectAssign(presetRulesConfig, mapRulesConfig(preset.rulesConfig, ruleName));
 });
    filePaths.forEach(filePath => {
      const name = toCamelCase(
        path.basename(filePath, '.js')
      );
      const decorator = interopRequire(filePath);
      should.exist(decorators[name], `@${name} should be exported`);
      decorators[name].should.equal(decorator, `export @${name} is the expected function`);

      markAsSeen(name);
      if (aliasKeys.indexOf(name) !== -1) {
        markAsSeen(aliases[name]);
      }
    });
 pluginNames.forEach(function (pluginName) {
     var textlintRuleName = '' + pluginPrefix + pluginName;
     var pkgPath = tryResolve(path.join(baseDir, textlintRuleName)) || tryResolve(path.join(baseDir, pluginName));
     if (!pkgPath) {
         throw new ReferenceError('plugin:' + pluginName + ' is not found.\nFail 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));
 });
Example #12
0
function load(configFilePath, _ref) {
    var configFileName = _ref.configFileName;
    var configPackagePrefix = _ref.configPackagePrefix;

    if (isConfigModule(configFilePath, configPackagePrefix)) {
        // config as a module - shared config
        // FIXME: not tested function
        return interopRequire(tryResolve(configFilePath));
    } else {
        // auto or specify config file
        var config = configFilePath ? { config: configFilePath } : null;
        return rc(configFileName, {}, config);
    }
}
    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));
    });
 ruleNames.forEach(ruleName => {
     const textlintRuleName = `${rulePrefix}${ ruleName }`;
     const pkgPath = tryResolve(path.join(baseDir, textlintRuleName)) || tryResolve(path.join(baseDir, ruleName));
     if (!pkgPath) {
         throw new ReferenceError(`${ ruleName } is not found`);
     }
     var preset = interopRequire(pkgPath);
     if (!preset.hasOwnProperty("rules")) {
         throw new Error(`${ruleName} has not rules`);
     }
     if (!preset.hasOwnProperty("rulesConfig")) {
         throw new Error(`${ruleName} has not rulesConfig`);
     }
     // set config of <rule> to "<preset>/<rule>"
     ObjectAssign(presetRulesConfig, mapRulesConfig(preset.rulesConfig, ruleName));
 });
Example #15
0
function load(configFilePath, _ref) {
    var configFileName = _ref.configFileName;
    var moduleResolver = _ref.moduleResolver;

    // if specify Config module, use it
    if (configFilePath) {
        try {
            var modulePath = moduleResolver.resolveConfigPackageName(configFilePath);
            return interopRequire(modulePath);
        } catch (error) {
            // not found config module
        }
    }
    // auto or specify path to config file
    var config = configFilePath ? { config: configFilePath } : null;
    return rc(configFileName, {}, config);
}
 /**
  * load rule from plugin name.
  * plugin module has `rules` object and define rule with plugin prefix.
  * @param {string} pluginName
  */
 loadPlugin(pluginName) {
     // TODO: ignore already loaded plugin
     const PLUGIN_NAME_PREFIX = this.config.constructor.PLUGIN_NAME_PREFIX;
     const prefixMatch = new RegExp("^" + PLUGIN_NAME_PREFIX);
     const pluginNameWithoutPrefix = pluginName.replace(prefixMatch, '');
     const baseDir = this.config.rulesBaseDirectory || '';
     const textlintRuleName = `${PLUGIN_NAME_PREFIX}${ pluginName }`;
     const pkgPath = tryResolve(path.join(baseDir, textlintRuleName)) || tryResolve(path.join(baseDir, pluginName));
     if (!pkgPath) {
         throw new ReferenceError(`plugin: ${ pluginName } is not found`);
     }
     debug('Loading rules from plugin: %s', pkgPath);
     const plugin = interopRequire(pkgPath);
     // Processor plugin doesn't define rules
     if (plugin.hasOwnProperty("rules")) {
         this.ruleManager.importPlugin(plugin.rules, pluginNameWithoutPrefix);
     }
     return plugin;
 }
        value: function loadPlugin(pluginName) {
            var _this3 = this;

            var pkgPath = this.moduleResolver.resolvePluginPackageName(pluginName);
            debug("Loading rules from plugin: %s", pkgPath);
            var plugin = interopRequire(pkgPath);
            var PLUGIN_NAME_PREFIX = this.config.constructor.PLUGIN_NAME_PREFIX;
            var prefixMatch = new RegExp("^" + PLUGIN_NAME_PREFIX);
            var pluginNameWithoutPrefix = pluginName.replace(prefixMatch, "");
            // Processor plugin doesn't define rules
            if (plugin.hasOwnProperty("rules")) {
                var entities = _textlintModuleMapper2.default.createEntities(plugin.rules, pluginNameWithoutPrefix);
                entities.forEach(function (entry) {
                    _this3.emit(TextLintModuleLoader.Event.rule, entry);
                });
            }
            // register plugin.Processor
            if (plugin.hasOwnProperty("Processor")) {
                var processorEntry = [pluginNameWithoutPrefix, plugin.Processor];
                this.emit(TextLintModuleLoader.Event.processor, processorEntry);
            }
        }
 loadPreset(presetName) {
     // ignore already defined rule
     // ignore rules from rulePaths because avoid ReferenceError is that try to require.
     const RULE_NAME_PREFIX = this.config.constructor.RULE_NAME_PREFIX;
     const prefixMatch = new RegExp("^" + RULE_NAME_PREFIX);
     const presetRuleNameWithoutPrefix = presetName.replace(prefixMatch, '');
     // ignore plugin's rule
     if (isPluginRuleKey(presetRuleNameWithoutPrefix)) {
         console.warn(`${presetRuleNameWithoutPrefix} is Plugin's rule. This is unknown case, please report issue.`);
         return;
     }
     const baseDir = this.config.rulesBaseDirectory || '';
     const textlintRuleName = `${RULE_NAME_PREFIX}${ presetRuleNameWithoutPrefix }`;
     const pkgPath = tryResolve(path.join(baseDir, textlintRuleName)) || tryResolve(path.join(baseDir, presetName));
     if (!pkgPath) {
         throw new ReferenceError(`preset: ${ presetRuleNameWithoutPrefix } is not found`);
     }
     debug('Loading rules from preset: %s', pkgPath);
     const preset = interopRequire(pkgPath);
     // Processor plugin doesn't define rules
     this.ruleManager.importPlugin(preset.rules, presetRuleNameWithoutPrefix);
     return preset;
 }
 value: function loadPreset(presetName) {
     // ignore already defined rule
     // ignore rules from rulePaths because avoid ReferenceError is that try to require.
     var RULE_NAME_PREFIX = this.config.constructor.RULE_NAME_PREFIX;
     var prefixMatch = new RegExp("^" + RULE_NAME_PREFIX);
     var presetRuleNameWithoutPrefix = presetName.replace(prefixMatch, '');
     // ignore plugin's rule
     if ((0, _utilConfigUtil.isPluginRuleKey)(presetRuleNameWithoutPrefix)) {
         console.warn(presetRuleNameWithoutPrefix + ' is Plugin\'s rule. This is unknown case, please report issue.');
         return;
     }
     var baseDir = this.config.rulesBaseDirectory || '';
     var textlintRuleName = '' + RULE_NAME_PREFIX + presetRuleNameWithoutPrefix;
     var pkgPath = tryResolve(path.join(baseDir, textlintRuleName)) || tryResolve(path.join(baseDir, presetName));
     if (!pkgPath) {
         throw new ReferenceError('preset: ' + presetRuleNameWithoutPrefix + ' is not found');
     }
     debug('Loading rules from preset: %s', pkgPath);
     var preset = interopRequire(pkgPath);
     // Processor plugin doesn't define rules
     this.ruleManager.importPlugin(preset.rules, presetRuleNameWithoutPrefix);
     return preset;
 }
 /**
  * load rule file with `ruleName` and define rule.
  * if rule is not found, then throw ReferenceError.
  * if already rule is loaded, do not anything.
  * @param {string} ruleName
  */
 loadRule(ruleName) {
     // ignore already defined rule
     // ignore rules from rulePaths because avoid ReferenceError is that try to require.
     const RULE_NAME_PREFIX = this.config.constructor.RULE_NAME_PREFIX;
     const prefixMatch = new RegExp("^" + RULE_NAME_PREFIX);
     const definedRuleName = ruleName.replace(prefixMatch, '');
     // ignore plugin's rule
     if (isPluginRuleKey(definedRuleName)) {
         console.warn(`${definedRuleName} is Plugin's rule. This is unknown case, please report issue.`);
         return;
     }
     if (this.ruleManager.isDefinedRule(definedRuleName)) {
         return;
     }
     const baseDir = this.config.rulesBaseDirectory || '';
     const textlintRuleName = `${RULE_NAME_PREFIX}${ ruleName }`;
     const pkgPath = tryResolve(path.join(baseDir, textlintRuleName)) || tryResolve(path.join(baseDir, ruleName));
     if (!pkgPath) {
         throw new ReferenceError(`rule: ${ ruleName } is not found`);
     }
     debug('Loading rules from %s', pkgPath);
     const ruleCreator = interopRequire(pkgPath);
     this.ruleManager.defineRule(definedRuleName, ruleCreator);
 }
 value: function loadRule(ruleName) {
     // ignore already defined rule
     // ignore rules from rulePaths because avoid ReferenceError is that try to require.
     var RULE_NAME_PREFIX = this.config.constructor.RULE_NAME_PREFIX;
     var prefixMatch = new RegExp("^" + RULE_NAME_PREFIX);
     var definedRuleName = ruleName.replace(prefixMatch, '');
     // ignore plugin's rule
     if ((0, _utilConfigUtil.isPluginRuleKey)(definedRuleName)) {
         console.warn(definedRuleName + ' is Plugin\'s rule. This is unknown case, please report issue.');
         return;
     }
     if (this.ruleManager.isDefinedRule(definedRuleName)) {
         return;
     }
     var baseDir = this.config.rulesBaseDirectory || '';
     var textlintRuleName = '' + RULE_NAME_PREFIX + ruleName;
     var pkgPath = tryResolve(path.join(baseDir, textlintRuleName)) || tryResolve(path.join(baseDir, ruleName));
     if (!pkgPath) {
         throw new ReferenceError('rule: ' + ruleName + ' is not found');
     }
     debug('Loading rules from %s', pkgPath);
     var ruleCreator = interopRequire(pkgPath);
     this.ruleManager.defineRule(definedRuleName, ruleCreator);
 }
"use strict";
const interopRequire = require("interop-require");
const jtfRules = require("textlint-rule-preset-jtf-style").rules;
module.exports = {
    rules: {
        "sentence-length": interopRequire("textlint-rule-sentence-length"),
        "max-comma": interopRequire("textlint-rule-max-comma"),
        "max-ten": interopRequire("textlint-rule-max-ten"),
        "max-kanji-continuous-len": interopRequire("textlint-rule-max-kanji-continuous-len"),
        "no-mix-dearu-desumasu": interopRequire("textlint-rule-no-mix-dearu-desumasu"),
        "ja-no-mixed-period": interopRequire("textlint-rule-ja-no-mixed-period"),
        "arabic-kanji-numbers": jtfRules["2.2.2.算用数字と漢数字の使い分け"],
        "no-doubled-conjunction": interopRequire("textlint-rule-no-doubled-conjunction"),
        "no-doubled-conjunctive-particle-ga": interopRequire("textlint-rule-no-doubled-conjunctive-particle-ga"),
        "no-double-negative-ja": interopRequire("textlint-rule-no-double-negative-ja"),
        "no-doubled-joshi": interopRequire("textlint-rule-no-doubled-joshi"),
        "no-dropping-the-ra": interopRequire("textlint-rule-no-dropping-the-ra"),
        "no-nfd": interopRequire("textlint-rule-no-nfd"),
        "no-exclamation-question-mark": interopRequire("textlint-rule-no-exclamation-question-mark"),
        "no-hankaku-kana": interopRequire("textlint-rule-no-hankaku-kana"),
        "no-invalid-control-character": interopRequire("@textlint-rule/textlint-rule-no-invalid-control-character"),
        "ja-no-weak-phrase": interopRequire("textlint-rule-ja-no-weak-phrase"),
        "ja-no-successive-word": interopRequire("textlint-rule-ja-no-successive-word"),
        "ja-no-abusage": interopRequire("textlint-rule-ja-no-abusage"),
        "ja-no-redundant-expression": interopRequire("textlint-rule-ja-no-redundant-expression"),
        "ja-unnatural-alphabet": interopRequire("textlint-rule-ja-unnatural-alphabet")
    },
    rulesConfig: {
        // # 1文の長さは100文字以下とする
        // https://github.com/azu/textlint-rule-sentence-length
        "sentence-length": {
Example #23
0
'use strict';

const interopRequire = require('interop-require');

module.exports = exports = {

  /**
   * require a file
   * @param  {String} filepath fullpath
   * @return {Object} exports
   */
  loadFile(filepath) {
    let exports;
    try {
      exports = interopRequire(filepath);
    } catch (err) {
      err.message = 'load file: ' + filepath + ', error: ' + err.message;
      throw err;
    }
    return exports;
  },

  /**
   * 判断模块是否存在
   * @method Util#existsModule
   * @param {String} path - 模块路径
   * @return {boolean} 如果模块存在则返回 `true`,否则返回 `false`。
   */
  existsModule(path) {
    try {
      require.resolve(path);