How to use the editorconfig/src/lib/ini.parseString function in editorconfig

To help you get started, we’ve selected a few editorconfig 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 gitlabhq / gitlabhq / app / assets / javascripts / ide / lib / editorconfig / parser.js View on Github external
function getRulesWithConfigs(filePath, configFiles = [], rules = {}) {
  if (!configFiles.length) return rules;

  const [{ content, path: configPath }, ...nextConfigs] = configFiles;
  const configDir = dirname(configPath);

  if (!filePath.startsWith(configDir)) return rules;

  const parsed = parseString(content);
  const isRoot = isRootConfig(parsed);
  const relativeFilePath = filePath.slice(configDir.length);

  const sectionRules = parsed.reduce(
    (acc, section) => Object.assign(acc, getRulesForSection(relativeFilePath, section)),
    {},
  );

  // prefer existing rules by overwriting to section rules
  const result = Object.assign(sectionRules, rules);

  return isRoot ? result : getRulesWithConfigs(filePath, nextConfigs, result);
}