<commit_before>'use strict';

const debug = require('./debug');
const os = require('os');
const path = require('path');
const fs = require('fs-extra');
const yaml = require('js-yaml');

const home = os.homedir();
const defaultConfigFile = path.join(__dirname, '..', '.eazydict.yml');
const userConfigFile = path.join(home, '.eazydict.yml');

// 创建用户配置
if (!fs.pathExistsSync(userConfigFile)) {
  fs.copySync(defaultConfigFile, userConfigFile);
}

let content = fs.readFileSync(userConfigFile, 'utf-8');
let config = {};
let userConfig;

try {
  userConfig = yaml.safeLoad(content);
} catch (err) {
  console.error(err); // eslint-disable-line no-console
  throw new Error(`用户配置文件解析错误: ${userConfigFile}`);
}

debug(`read config from ${userConfigFile}: %O`, userConfig);

// format config
Object.keys(userConfig).forEach(item => {
  let userConfigItem = userConfig[item];

  if (item === 'enable') {
    config[item] = userConfigItem.map(key => {
      return `eazydict-${key}`;
    });
  } else if (item === 'plugins') {
    config['plugins'] = Object.create(null);

    Object.keys(userConfigItem).forEach(key => {
      let value = userConfigItem[key];

      config['plugins'][`eazydict-${key}`] = userConfigItem[key];
    });
  }
});

debug('format config: %O', config);

module.exports = config;<commit_msg>修复eslint同时支持额外的配置<commit_after>'use strict';

const debug = require('./debug');
const os = require('os');
const path = require('path');
const fs = require('fs-extra');
const yaml = require('js-yaml');

const home = os.homedir();
const defaultConfigFile = path.join(__dirname, '..', '.eazydict.yml');
const userConfigFile = path.join(home, '.eazydict.yml');

// 创建用户配置
if (!fs.pathExistsSync(userConfigFile)) {
  fs.copySync(defaultConfigFile, userConfigFile);
}

let content = fs.readFileSync(userConfigFile, 'utf-8');
let config = {};
let userConfig;

try {
  userConfig = yaml.safeLoad(content);
} catch (err) {
  console.error(err); // eslint-disable-line no-console
  throw new Error(`用户配置文件解析错误: ${userConfigFile}`);
}

debug(`read config from ${userConfigFile}: %O`, userConfig);

// format config
Object.keys(userConfig).forEach(item => {
  let userConfigItem = userConfig[item];

  if (item === 'enable') {
    config[item] = userConfigItem.map(key => {
      return `eazydict-${key}`;
    });
  } else if (item === 'plugins') {
    config.plugins = Object.create(null);

    Object.keys(userConfigItem).forEach(key => {
      let value = userConfigItem[key];

      config.plugins[`eazydict-${key}`] = userConfigItem[key];
    });
  } else {
    config[item] = userConfig[item];
  }
});

debug('format config: %O', config);

module.exports = config;
{'fraction_non_alphanumeric': 0.18277153558052434, 'fraction_numerical': 0.000749063670411985, 'mean_word_length': 4.507216494845361, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '6221559', 'n_tokens_mistral': 921, 'n_tokens_neox': 913, 'n_words': 182}