<commit_before>import merge from 'lodash.merge';
import findup from 'findup-sync';
import json from 'json-extra';
import path from 'path';
import os from 'os';
import fs from 'fs';

const cwd = process.cwd();
const homedir = os.homedir();

// eslint-disable-next-line global-require, import/no-dynamic-require
const safeRequire = (jsPath) => fs.existsSync(jsPath) && require(jsPath);

// params just for testing
const getConfig = (altPath, fileName = '.sgcrc') => {
  const pathString = findup(fileName, { cwd: altPath || cwd });
  const localeConfigJS = safeRequire(findup('sgc.config.js', { cwd }));
  const localeConfig = json.readToObjSync(pathString);
  const globalConfigJS = safeRequire(path.join(homedir, 'sgc.config.js'));
  const globalConfig = json.readToObjSync(path.join(homedir, '.sgcrc'));
  const packageConfig = json.readToObjSync(path.join(cwd, 'package.json')).sgc;
  const sgcrcDefaultConfig = json.readToObjSync(path.join(__dirname, '..', '.sgcrc'));
  const sgcrcTestDefaultConfig = json.readToObjSync(path.join(__dirname, '..', '.sgcrc_default'));

  const sgcrcDefault = sgcrcDefaultConfig || sgcrcTestDefaultConfig;<commit_msg>Feat: also bubble up with package.json (cc: #64)<commit_after>import merge from 'lodash.merge';
import findup from 'findup-sync';
import json from 'json-extra';
import path from 'path';
import os from 'os';
import fs from 'fs';

const cwd = process.cwd();
const homedir = os.homedir();

// eslint-disable-next-line global-require, import/no-dynamic-require
const safeRequire = (jsPath) => fs.existsSync(jsPath) && require(jsPath);

// params just for testing
const getConfig = (altPath, fileName = '.sgcrc') => {
  const pathString = findup(fileName, { cwd: altPath || cwd });
  const localeConfigJS = safeRequire(findup('sgc.config.js', { cwd }));
  const localeConfig = json.readToObjSync(pathString);
  const globalConfigJS = safeRequire(path.join(homedir, 'sgc.config.js'));
  const globalConfig = json.readToObjSync(path.join(homedir, '.sgcrc'));
  const packageConfig = json.readToObjSync(findup('package.json', { cwd })).sgc;
  const sgcrcDefaultConfig = json.readToObjSync(path.join(__dirname, '..', '.sgcrc'));
  const sgcrcTestDefaultConfig = json.readToObjSync(path.join(__dirname, '..', '.sgcrc_default'));

  const sgcrcDefault = sgcrcDefaultConfig || sgcrcTestDefaultConfig;
{'fraction_non_alphanumeric': 0.15085470085470085, 'fraction_numerical': 0.0008547008547008547, 'mean_word_length': 5.539106145251397, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '3344167', 'n_tokens_mistral': 775, 'n_tokens_neox': 774, 'n_words': 175}