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

Add fixable status to verbose and github formatters #6183

Merged
merged 5 commits into from
Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 2 additions & 2 deletions lib/formatters/__tests__/githubFormatter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ test('githubFormatter', () => {
const returnValue = {
ruleMetadata: {
foo: { url: 'https://stylelint.io/rules/foo' },
bar: {},
bar: { fixable: true },
},
};

expect(githubFormatter(results, returnValue))
.toBe(`::error file=path/to/file.css,line=1,col=2,endLine=1,endColumn=5,title=Stylelint problem::Unexpected "foo" (foo) - https://stylelint.io/rules/foo
::warning file=a.css,line=10,col=20,title=Stylelint problem::Unexpected "bar" (bar)`);
::warning file=a.css,line=10,col=20,title=Stylelint problem::Unexpected "bar" (bar) [maybe fixable]`);
});
4 changes: 2 additions & 2 deletions lib/formatters/__tests__/prepareFormatterOutput.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ symbolConversions.set('✔', '√');
symbolConversions.set('⚠', '‼');
symbolConversions.set('✖', '×');

module.exports = function (results, formatter) {
const returnValue = {
module.exports = function (results, formatter, returnValue) {
returnValue = returnValue || {
ruleMetadata: {},
};
let output = stripAnsi(formatter(results, returnValue)).trim();
Expand Down
16 changes: 7 additions & 9 deletions lib/formatters/__tests__/verboseFormatter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,17 +340,15 @@ describe('verboseFormatter', () => {
],
deprecations: [],
invalidOptionWarnings: [],
_postcssResult: {
stylelint: {
ruleMetadata: {
'no-foo': { url: 'https://stylelint.io' },
},
},
},
},
];
const returnValue = {
ruleMetadata: {
'no-foo': { url: 'https://stylelint.io', fixable: true },
},
};

const output = prepareFormatterOutput(results, verboseFormatter);
const output = prepareFormatterOutput(results, verboseFormatter, returnValue);

expect(output).toBe(stripIndent`
file.css
Expand All @@ -362,6 +360,6 @@ describe('verboseFormatter', () => {
file.css

1 error found
no-foo: 1`);
no-foo: 1 (maybe fixable)`);
});
});
5 changes: 3 additions & 2 deletions lib/formatters/githubFormatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ module.exports = function githubFormatter(results, returnValue) {
function buildMessage(msg, metadata) {
if (!metadata) return msg;

if (!metadata.url) return msg;
const url = metadata.url ? ` - ${metadata.url}` : '';
const fixable = metadata.fixable ? ' [maybe fixable]' : '';

return `${msg} - ${metadata.url}`;
return `${msg}${fixable}${url}`;
}
5 changes: 4 additions & 1 deletion lib/formatters/verboseFormatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ module.exports = function verboseFormatter(results, returnValue) {
const metadata = returnValue.ruleMetadata;

for (const [rule, list] of Object.entries(problemsByRule)) {
output += dim(` ${ruleLink(rule, metadata[rule])}: ${list.length}\n`);
const meta = metadata[rule];
const fixable = meta && meta.fixable ? ' (maybe fixable)' : '';

output += dim(` ${ruleLink(rule, meta)}: ${list.length}${fixable}\n`);
}
};

Expand Down
3 changes: 2 additions & 1 deletion scripts/visual-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"message": "Expected custom property name to be kebab-case",
"severity": "warning"
}
]
],
"import-notation": "string"
}
}
2 changes: 2 additions & 0 deletions scripts/visual.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import url("foo.css");

.foo {
color:#4f;
}
Expand Down