How to use the markdownlint.readConfigSync function in markdownlint

To help you get started, we’ve selected a few markdownlint 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 igorshubovych / markdownlint-cli / markdownlint.js View on Github external
fs.accessSync(projectConfigFile, fs.R_OK);
      const projectConfig = markdownlint.readConfigSync(projectConfigFile, configFileParsers);
      config = extend(config, projectConfig);
      break;
    } catch (error) {
      // Ignore failure
    }
  }
  // Normally parsing this file is not needed,
  // because it is already parsed by rc package.
  // However I have to do it to overwrite configuration
  // from .markdownlint.{json,yaml,yml}.

  if (userConfigFile) {
    try {
      const userConfig = markdownlint.readConfigSync(userConfigFile, configFileParsers);
      config = extend(config, userConfig);
    } catch (error) {
      console.warn('Cannot read or parse config file ' + args.config + ': ' + error.message);
    }
  }

  return config;
}
github igorshubovych / markdownlint-cli / markdownlint.js View on Github external
function readConfiguration(args) {
  let config = rc('markdownlint', {});
  const userConfigFile = args.config;
  for (const projectConfigFile of projectConfigFiles) {
    try {
      fs.accessSync(projectConfigFile, fs.R_OK);
      const projectConfig = markdownlint.readConfigSync(projectConfigFile, configFileParsers);
      config = extend(config, projectConfig);
      break;
    } catch (error) {
      // Ignore failure
    }
  }
  // Normally parsing this file is not needed,
  // because it is already parsed by rc package.
  // However I have to do it to overwrite configuration
  // from .markdownlint.{json,yaml,yml}.

  if (userConfigFile) {
    try {
      const userConfig = markdownlint.readConfigSync(userConfigFile, configFileParsers);
      config = extend(config, userConfig);
    } catch (error) {
github DavidAnson / vscode-markdownlint / extension.js View on Github external
while (vscode.workspace.getWorkspaceFolder(vscode.Uri.file(dir))) {
		workspaceDetail = "no configuration file in workspace folder";
		// Use cached configuration if present for directory
		if (configMap[dir]) {
			return configMap[dir];
		}
		if (configMap[dir] === undefined) {
			// Look for config file in current directory
			for (const configFileName of configFileNames) {
				const configFilePath = path.join(dir, configFileName);
				if (fs.existsSync(configFilePath)) {
					outputLine("INFO: Loading custom configuration from \"" + configFilePath +
						"\", overrides user/workspace/custom configuration for directory and its children.");
					try {
						return (configMap[dir] = {
							"config": markdownlint.readConfigSync(configFilePath, configParsers),
							"source": configFilePath
						});
					} catch (ex) {
						outputLine("ERROR: Unable to read configuration file \"" +
							configFilePath + "\" (" + (ex.message || ex.toString()) + ").", true);
					}
				}
			}
			// Remember missing or invalid file
			configMap[dir] = null;
		}
		const parent = path.dirname(dir);
		// Move to parent directory, stop if no parent
		if (dir === parent) {
			break;
		}
github DavidAnson / vscode-markdownlint / extension.js View on Github external
const userWorkspaceConfigMetadata = configuration.inspect(sectionConfig);
	let source = null;
	if (userWorkspaceConfigMetadata.workspaceFolderValue && (vscode.workspace.workspaceFolders.length > 1)) {
		// Length check to work around https://github.com/Microsoft/vscode/issues/34386
		source = openFolderSettingsCommand;
	} else if (userWorkspaceConfigMetadata.workspaceValue) {
		source = openWorkspaceSettingsCommand;
	} else if (userWorkspaceConfigMetadata.globalValue) {
		source = openGlobalSettingsCommand;
	}

	// Bootstrap extend behavior into readConfigSync
	if (userWorkspaceConfig && userWorkspaceConfig.extends) {
		const extendPath = path.resolve(require("os").homedir(), userWorkspaceConfig.extends);
		try {
			const extendConfig = markdownlint.readConfigSync(extendPath, configParsers);
			userWorkspaceConfig = {
				...extendConfig,
				...userWorkspaceConfig
			};
		} catch (ex) {
			outputLine("ERROR: Unable to extend configuration file \"" +
				extendPath + "\" (" + (ex.message || ex.toString()) + ").", true);
		}
	}
	return (configMap[name] = {
		"config": userWorkspaceConfig,
		source
	});
}

markdownlint

A Node.js style checker and lint tool for Markdown/CommonMark files.

MIT
Latest version published 3 days ago

Package Health Score

88 / 100
Full package analysis