How to use the markdownlint.sync 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 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 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);
}
github DavidAnson / vscode-markdownlint / extension.js View on Github external
function markdownlintWrapper (name, text, config) {
	const options = {
		"strings": {
			[name]: text
		},
		config,
		"customRules": getCustomRules(),
		"handleRuleFailures": true,
		"markdownItPlugins": [ [ require("markdown-it-katex") ] ],
		"resultVersion": 3
	};
	let results = [];
	try {
		results = markdownlint.sync(options)[name];
	} catch (ex) {
		outputLine("ERROR: Exception while linting:\n" + ex.stack, true);
	}
	return results;
}
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);
        }
      }
    });
  }

markdownlint

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

MIT
Latest version published 8 days ago

Package Health Score

88 / 100
Full package analysis