Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: do not lint markdown ignored files #16057

Closed
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 30 additions & 3 deletions Makefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ const NODE = "node ", // intentional extra space
// Files
RULE_FILES = glob.sync("lib/rules/*.js").filter(filePath => path.basename(filePath) !== "index.js"),
JSON_FILES = find("conf/").filter(fileType("json")),
MARKDOWNLINT_IGNORED_FILES = fs.readFileSync(path.join(__dirname, ".markdownlintignore"), "utf-8").split("\n"),
MARKDOWN_FILES_ARRAY = find("docs/").concat(ls(".")).filter(fileType("md")).filter(file => !MARKDOWNLINT_IGNORED_FILES.includes(file)),
MARKDOWNLINT_IGNORED = fs.readFileSync(path.join(__dirname, ".markdownlintignore"), "utf-8").split("\n"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Content of .markdownlintignore are gitignore patterns. We can use the ignore library we already have as a dependency to filter out ignored files. That would be easier and more reliable than a custom implementation.

Ideally, we would use a glob library that supports gitignore patterns so that it doesn't traverse ignored directories at all, but that could be another enhancement.

And I'm not sure why are we using markdownlint API here instead of markdownlint CLI which could handle .markdownlintignore by itself.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can I try adding the glob library or can we use markdownlint CLI instead of markdownlint API?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would try with markdownlint CLI. That looks a lot simpler and I don't see any specific reasons to use API for our use case.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I will update.

TEST_FILES = "\"tests/{bin,conf,lib,tools}/**/*.js\"",
PERF_ESLINTRC = path.join(PERF_TMP_DIR, "eslintrc.yml"),
PERF_MULTIFILES_TARGET_DIR = path.join(PERF_TMP_DIR, "eslint"),
Expand All @@ -85,6 +84,31 @@ const NODE = "node ", // intentional extra space
// Helpers
//------------------------------------------------------------------------------

/**
* Generate all files needs to be ignored.
* @param {Array} markdownlintIgnored ignored files name.
* @throws Error If file is not found.
* @returns {Array} all ignored files.
*/
function getIgnoredFiles(markdownlintIgnored) {
const ignoredFiles = [];

markdownlintIgnored.filter(file => file.trim()).forEach(file => {
if (fs.existsSync(`docs/${file}`)) {
if (fs.lstatSync(`docs/${file}`).isDirectory()) {

const files = find(`docs/${file}`).concat(ls(".")).filter(fileType("md"));

ignoredFiles.push(...files);
} else {
console.log(file);
ignoredFiles.push(file);
}
}
});
return ignoredFiles;
}

/**
* Simple JSON file validation that relies on ES JSON parser.
* @param {string} filePath Path to JSON.
Expand Down Expand Up @@ -530,7 +554,10 @@ target.lint = function([fix = false] = []) {
JSON_FILES.forEach(validateJsonFile);

echo("Validating Markdown Files");
lastReturn = lintMarkdown(MARKDOWN_FILES_ARRAY);
const ignoredFiles = getIgnoredFiles(MARKDOWNLINT_IGNORED),
markdownFilesArray = find("docs/").concat(ls(".")).filter(fileType("md")).filter(file => !ignoredFiles.includes(file));

lastReturn = lintMarkdown(markdownFilesArray);
if (lastReturn.code !== 0) {
errors++;
}
Expand Down