How to use markdownlint - 10 common examples

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 splunk / splunk-cloud-sdk-js / ci / generate_3rdparty.js View on Github external
throw error;
            }
            const allRes = {
                ...res,
                ...resDev,
            };
            const thirdPartyCredits = createMarkdown(allRes);
            const markdownlintOptions = {
                strings: { thirdPartyCredits },
                config: {
                    'line-length': false,
                    'no-multiple-blanks': false,
                }
            };

            const markdownErrors = markdownlint.sync(markdownlintOptions);
            if (markdownErrors.thirdPartyCredits.length > 0) {
                console.log(markdownErrors.toString());
                throw new Error('Invalid markdown');
            }

            const currentFile = fs.readFileSync(thirdPartyLicenseFile).toString();
            if (currentFile === thirdPartyCredits) {
                console.log(`Nothing to update in ${thirdPartyLicenseFileName}.`);
            } else {
                // If running in CI, fail if this file is stale
                if (process.env.CI) {
                    throw new Error(`${thirdPartyLicenseFileName} is stale, please run 'yarn third-party-licenses'.`);
                }
                else {
                    fs.writeFileSync(thirdPartyLicenseFile, thirdPartyCredits);
                    console.log(`Successfully updated ${thirdPartyLicenseFileName}`);
github microsoft / TypeScript-Handbook / lint.js View on Github external
MD030: true, // Spaces after list markers
    MD031: true, // Fenced code blocks should be surrounded by blank lines
    MD032: true, // Lists should be surrounded by blank lines
    MD033: false, // Inline HTML
    MD034: true, // Bare URL used
    MD035: "---", // Horizontal rule style
    MD036: false, // Emphasis used instead of a header
    MD037: true, // Spaces inside emphasis markers
    MD038: false, // Spaces inside code span elements
    MD039: true, // Spaces inside link text
    MD040: true, // Fenced code blocks should have a language specified
    MD041: false, // First line in file should be a top level header
  }
};

var result = markdownlint.sync(options);
console.log(result.toString());

var exitCode = 0;
Object.keys(result).forEach(function (file) {
    var fileResults = result[file];
    Object.keys(fileResults).forEach(function (rule) {
        var ruleResults = fileResults[rule];
        exitCode += ruleResults.length;
    });
});

inputFiles.forEach(function(fileName) {
    var text = fs.readFileSync(fileName, "utf8")
    exitCode += checkForImproperlyIndentedFencedCodeBlocks(fileName, text);
})
github zhongsp / TypeScript / lint.js View on Github external
MD030: true, // Spaces after list markers
    MD031: true, // Fenced code blocks should be surrounded by blank lines
    MD032: true, // Lists should be surrounded by blank lines
    MD033: false, // Inline HTML
    MD034: true, // Bare URL used
    MD035: "---", // Horizontal rule style
    MD036: false, // Emphasis used instead of a header
    MD037: true, // Spaces inside emphasis markers
    MD038: false, // Spaces inside code span elements
    MD039: true, // Spaces inside link text
    MD040: true, // Fenced code blocks should have a language specified
    MD041: false, // First line in file should be a top level header
  }
};

var result = markdownlint.sync(options);
console.log(result.toString());

var exitCode = 0;
Object.keys(result).forEach(function (file) {
    var fileResults = result[file];
    Object.keys(fileResults).forEach(function (rule) {
        var ruleResults = fileResults[rule];
        exitCode += ruleResults.length;
    });
});

inputFiles.forEach(function(fileName) {
    var text = fs.readFileSync(fileName, "utf8")
    exitCode += checkForImproperlyIndentedFencedCodeBlocks(fileName, text);
});
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
	});
}
github DavidAnson / vscode-markdownlint / generate-config-schema.js View on Github external
"use strict";

const fs = require("fs");
const packageJsonPath = "./package.json";
const packageJson = require(packageJsonPath);
const configurationSchema = require("./node_modules/markdownlint/schema/markdownlint-config-schema.json");
const defaultConfig = require("./default-config.json");

// Update package.json
const configurationRoot = packageJson.contributes.configuration.properties["markdownlint.config"];
configurationRoot.default = defaultConfig;
configurationRoot.properties = configurationSchema.properties;
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, "\t") + "\n");
github eslint / eslint / Makefile.js View on Github external
function lintMarkdown(files) {
    const config = yaml.safeLoad(fs.readFileSync(path.join(__dirname, "./.markdownlint.yml"), "utf8")),
        result = markdownlint.sync({
            files,
            config,
            resultVersion: 1
        }),
        resultString = result.toString(),
        returnCode = resultString ? 1 : 0;

    if (resultString) {
        console.error(resultString);
    }
    return { code: returnCode };
}
github igorshubovych / markdownlint-cli / markdownlint.js View on Github external
};
    files.forEach(file => {
      fixOptions.files = [file];
      const fixResult = markdownlint.sync(fixOptions);
      const fixes = fixResult[file].filter(error => error.fixInfo);
      if (fixes.length > 0) {
        const originalText = fs.readFileSync(file, fsOptions);
        const fixedText = markdownlintRuleHelpers.applyFixes(originalText, fixes);
        if (originalText !== fixedText) {
          fs.writeFileSync(file, fixedText, fsOptions);
        }
      }
    });
  }

  const lintResult = markdownlint.sync(lintOptions);
  printResult(lintResult);
}

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