Skip to content

Commit

Permalink
Refactor to jsonFormatter (#7705)
Browse files Browse the repository at this point in the history
  • Loading branch information
Connormiha committed May 23, 2024
1 parent c76a5d3 commit e0d8fdd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 22 deletions.
14 changes: 3 additions & 11 deletions lib/formatters/jsonFormatter.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,9 @@
* @type {import('stylelint').Formatter}
*/
function jsonFormatter(results) {
const cleanedResults = results.map((result) =>
Object.entries(result)
.filter(([key]) => !key.startsWith('_'))
.reduce((/** @type {{ [key: string]: any }} */ obj, [key, value]) => {
obj[key] = value;

return obj;
}, {}),
);

return JSON.stringify(cleanedResults);
return JSON.stringify(results, (key, value) => {
return key[0] === '_' ? undefined : value;
});
}

module.exports = jsonFormatter;
14 changes: 3 additions & 11 deletions lib/formatters/jsonFormatter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,7 @@
* @type {import('stylelint').Formatter}
*/
export default function jsonFormatter(results) {
const cleanedResults = results.map((result) =>
Object.entries(result)
.filter(([key]) => !key.startsWith('_'))
.reduce((/** @type {{ [key: string]: any }} */ obj, [key, value]) => {
obj[key] = value;

return obj;
}, {}),
);

return JSON.stringify(cleanedResults);
return JSON.stringify(results, (key, value) => {
return key[0] === '_' ? undefined : value;
});
}

0 comments on commit e0d8fdd

Please sign in to comment.