Skip to content

Instantly share code, notes, and snippets.

@jonchurch
Last active February 28, 2023 03:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonchurch/ecf040b1543c1b2423ccb2f4913d076b to your computer and use it in GitHub Desktop.
Save jonchurch/ecf040b1543c1b2423ccb2f4913d076b to your computer and use it in GitHub Desktop.
Yoda style eslint rule example code
/*eslint yoda: "error"*/
const youveBecome = "powerful";
if ("powerful" === youveBecome) {
// yoda style
// value comes before variable
}
if (youveBecome === "powerful") {
// non-yoda
// variable comes before value
}
@maxqper
Copy link

maxqper commented Feb 28, 2023

Yoda speak is better. If there's a typo, compiler will catch it.

if ("powerful" = youvebcome) { // compiler error

if (youvebecome = "powerful") { // no error

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