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

Build: gensite passes rulesMeta to formatter rendering #11567

Merged
merged 2 commits into from Mar 30, 2019
Merged
Changes from all commits
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
30 changes: 21 additions & 9 deletions Makefile.js
Expand Up @@ -430,16 +430,17 @@ function getFormatterResults() {
const stripAnsi = require("strip-ansi");

const formatterFiles = fs.readdirSync("./lib/formatters/"),
rules = {
"no-else-return": "warn",
indent: ["warn", 4],
"space-unary-ops": "error",
semi: ["warn", "always"],
"consistent-return": "error"
},
cli = new CLIEngine({
useEslintrc: false,
baseConfig: { extends: "eslint:recommended" },
rules: {
"no-else-return": 1,
indent: [1, 4],
"space-unary-ops": 2,
semi: [1, "always"],
"consistent-return": 2
}
rules
}),
codeString = [
"function addOne(i) {",
Expand All @@ -450,15 +451,26 @@ function getFormatterResults() {
" }",
"};"
].join("\n"),
rawMessages = cli.executeOnText(codeString, "fullOfProblems.js", true);
rawMessages = cli.executeOnText(codeString, "fullOfProblems.js", true),
rulesMap = cli.getRules(),
rulesMeta = {};

Object.keys(rules).forEach(ruleId => {
rulesMeta[ruleId] = rulesMap.get(ruleId).meta;
});

return formatterFiles.reduce((data, filename) => {
const fileExt = path.extname(filename),
name = path.basename(filename, fileExt);

if (fileExt === ".js") {
const formattedOutput = cli.getFormatter(name)(
rawMessages.results,
{ rulesMeta }
);

data.formatterResults[name] = {
result: stripAnsi(cli.getFormatter(name)(rawMessages.results))
result: stripAnsi(formattedOutput)
};
}
return data;
Expand Down