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

Pass returnValue to formatter with needlessDisables + invalidScopeDisables #4393

Merged
merged 8 commits into from Nov 5, 2019

Conversation

shawnbot
Copy link
Contributor

@shawnbot shawnbot commented Oct 31, 2019

Fixes #4136. I've shuffled things around in the standalone prepareReturnValue() function so that the output is set last and the formatting function gets the returnValue object as its second argument, so that needless disables can be accessed like so in a custom formatter:

module.exports = function customFormatter(results, returnValue) {
  const errors = formatErrors(results)
  if (returnValue.needlessDisables) {
    errors.push(...formatNeedlessDisables(returnValue.needlessDisables))
  }
  return errors.join('\n')
}

The returnValue object includes:

  • the errored flag
  • a needlessDisables array if configured with reportNeedlessDisables: true
  • an invalidScopeDisables array if configured with reportInvalidScopeDisables: true
  • a maxWarningsExceeded object if configured with maxWarnings

output: formatterFunction(stylelintResults),
results: stylelintResults,
results: [],
output: '',
Copy link
Contributor Author

@shawnbot shawnbot Oct 31, 2019

Choose a reason for hiding this comment

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

Initializing these with empty values appears to have been necessary to appease the lint:types script (tsc). I'm not familiar with TypeScript, but I imagine there's a way to do this in the @type comment instead?

Copy link
Member

Choose a reason for hiding this comment

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

I thinks it is fine to initialize with empty fields

Copy link
Member

@vankop vankop left a comment

Choose a reason for hiding this comment

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

👍

Copy link
Member

@hudochenkov hudochenkov left a comment

Choose a reason for hiding this comment

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

Thank you for fixing this problem!

Could you update documentation, please? https://github.com/stylelint/stylelint/blob/master/docs/developer-guide/formatters.md

lib/__tests__/standalone-formatter.test.js Outdated Show resolved Hide resolved
@github-actions
Copy link
Contributor

github-actions bot commented Nov 5, 2019

Coverage Status

Coverage increased (+0.0006%) to 96.875% when pulling b318ea1 on primer:format-needless-disables into 85174c7 on stylelint:master.

@shawnbot
Copy link
Contributor Author

shawnbot commented Nov 5, 2019

Okay, docs updated in 2982fa1; preview here.

@hudochenkov hudochenkov merged commit 16ba7e4 into stylelint:master Nov 5, 2019
@shawnbot shawnbot deleted the format-needless-disables branch November 5, 2019 22:17
@hudochenkov
Copy link
Member

  • Added: more information for custom formatters (#4393).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Fix custom formatters access to needless disables results
4 participants