Skip to content

Add a rule to enforce test code cases are auto-formatted #486

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

Open
JoshuaKGoldberg opened this issue Jul 25, 2024 · 2 comments
Open

Add a rule to enforce test code cases are auto-formatted #486

JoshuaKGoldberg opened this issue Jul 25, 2024 · 2 comments
Labels
accepted needs design Important details about this change need to be discussed rule

Comments

@JoshuaKGoldberg
Copy link
Contributor

Coming over from @bradzacher's typescript-eslint Discord comment about RuleTester usage around suggestions -> typescript-eslint/typescript-eslint#9639: typescript-eslint has an internal lint rule for test formatting which enforces things like "a template string must be either indented 0 or indented template indent + 2" and "all cases must be prettier formatted". This is really useful for keeping rule test code clean and readable.

Incorrect:

ruleTester.run("my-rule", {
  invalid: [ /* ... */ ],
  valid: [
    `console.log ( "some code" ) `
  ],
});

Correct:

ruleTester.run("my-rule", {
  invalid: [ /* ... */ ],
  valid: [
    `console.log("some code");`
  ],
});

Rule source: https://github.com/typescript-eslint/typescript-eslint/blob/eb76e34876ea973c462fad7073c134652f83c41b/packages/eslint-plugin-internal/src/rules/plugin-test-formatting.ts

This also isn't really specific to typescript-eslint. I could see a use case for any arbitrary plugin to want it.

Proposal: would you be interested in taking this rule into eslint-plugin-eslint-plugin?

@JoshuaKGoldberg
Copy link
Contributor Author

Sorry to bother you @aladdin-add, but is this something you have bandwidth to triage?

Context: I'm interested in implementing this to close out typescript-eslint/typescript-eslint#9639. I'd be happy to send a PR here if the project would accept it.

@aladdin-add
Copy link
Contributor

sounds useful; I'm just a little concerned about whether it should depend on prettier - not all the projects using it. maybe can be configured settings:

import prettier from "prettier";

export default [{
  settings: {"eslint-plugin": {formatter: prettier}}
}];

@aladdin-add aladdin-add added accepted rule needs design Important details about this change need to be discussed labels May 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted needs design Important details about this change need to be discussed rule
Projects
None yet
Development

No branches or pull requests

2 participants