Skip to content

Instantly share code, notes, and snippets.

@priley86
Last active October 6, 2017 17:14
Show Gist options
  • Save priley86/78093a1f37b39242096c13ddfbe3f701 to your computer and use it in GitHub Desktop.
Save priley86/78093a1f37b39242096c13ddfbe3f701 to your computer and use it in GitHub Desktop.
Prettier -> Standard JS Tests

The Prettier Autoformatter fixes many common JS linting rules such those defined by Standard JS.

Total rules tested: 117

Total rules fixed: 49

Total rules not fixed: 68

Percent fixed automatically: 41.8%

The following Standard JS rules were tested with Prettier 1.7.3 and known to be fixed automatically:

Use 2 spaces
Use single quotes for strings
Add a space after keywords.
Add a space before a function declaration's parentheses.
Infix operators must be spaced.
Commas should have a space after them.
Keep else statements on the same line as their curly braces.
For multi-line if statements, use curly braces.
Multiple blank lines not allowed.
For the ternary operator in a multi-line setting, place ? and : on their own lines.
Wrap conditional assignments with additional parentheses.
Add spaces inside single line blocks.
Trailing commas not allowed.
Dot should be on the same line as property.
Files must end with a newline.
No space between function identifiers and their invocations.
Add space between colon and value in key value pairs.
Constructor with no arguments must be invoked with parentheses.
Avoid unnecessary boolean casts.
No unnecessary parentheses around function expressions.
No floating decimals.
No irregular whitespace.
Avoid mixing spaces and tabs for indentation.
Do not use multiple spaces except for indentation.
Avoid multiple spaces in regular expression literals.
Assignments in return statements must be surrounded by parentheses.
Tabs should not be used.
Whitespace not allowed at end of line.
Initializing to undefined is not allowed.
No ternary operators when simpler alternatives exist.
The left operand of relational operators must not be negated.
Avoid using unnecessary computed property keys on objects.
No unnecessary use of escape.
Renaming import, export, and destructured assignments to the same name is not allowed.
No whitespace before properties.
Maintain consistency of newlines between object properties.
No padding within blocks.
No whitespace between spread operators and their expressions.
Semicolons must have a space after and no space before.
Must have a space before blocks.
No spaces inside parentheses.
Unary operators must have a space after.
Use spaces inside comments.
No spacing in template strings.
Immediately Invoked Function Expressions (IIFEs) must be wrapped.
The * in yield*expressions must have a space before and after.
Avoid Yoda conditions.
No semicolons.
Never start a line with (, [, or `.

The following Standard JS rules are not fixed by Prettier (and are typically explicit errors by the user):

No unused variables.
Always use === instead of ==.
Always handle the err function parameter.
Always prefix browser globals with window.
For var declarations, write each declaration in its own statement.
Use camelcase when naming variables and functions.
Commas must be placed at the end of the current line.
Constructor names must begin with a capital letter.
Objects must contain a getter when a setter is defined.
Constructors of derived classes must call super.
Use array literals instead of array constructors.
Avoid using arguments.callee and arguments.caller.
Avoid modifying variables of class declarations.
Avoid modifying variables declared using const.
Avoid using constant expressions in conditions (except loops).
No control characters in regular expressions.
No debugger statements.
No delete operator on variables.
No duplicate arguments in function definitions.
No duplicate name in class members.
No duplicate keys in object literals.
No duplicate case labels in switch statements.
Use a single import statement per module.
No empty character classes in regular expressions.
No empty destructuring patterns.
No using eval().
No reassigning exceptions in catch clauses.
No extending native objects.
Avoid unnecessary function binding.
Use break to prevent fallthrough in switch cases.
Avoid reassigning function declarations.
No reassigning read-only global variables.
No implied eval().
No function declarations in nested blocks.
No invalid regular expression strings in RegExp constructors.
No using iterator.
No labels that share a name with an in scope variable.
No label statements.
No unnecessary nested blocks.
No multiline strings.
No new without assigning object to a variable.
No using the Function constructor.
No using the Object constructor.
No using new require.
No using the Symbol constructor.
No using primitive wrapper instances.
No calling global object properties as functions.
No octal literals.
No octal escape sequences in string literals.
Avoid string concatenation when using __dirname and __filename.
Avoid using proto. Use getPrototypeOf instead.
No redeclaring variables.
Avoid assigning a variable to itself.
Avoid comparing a variable to itself.
Avoid using the comma operator.
Restricted names should not be shadowed.
Sparse arrays are not allowed.
Regular strings must not contain template literal placeholders.
super() must be called before using this.
Only throw an Error object.
No unmodified conditions of loops.
No unreachable code after return, throw, continue, and break statements.
No flow control statements in finally blocks.
Avoid unnecessary use of .call() and .apply().
No unnecessary constructor.
No using with statements.
Use isNaN() when checking for NaN.
typeof must be compared to a valid string.

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