Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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;
}
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}`);
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);
})
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);
});
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) {
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;
}
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
});
}
"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");
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 };
}
};
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);
}