🐊Putout not only improves working code but also fixes broken code.
function declaration half converted from arrow expression
-function parse(source) => {
+function parse(source) {
return source;
}
broken string
-const a = 'hello;
+const a = 'hello';
-const b = ‘hello world’;
+const b = 'hello world';
-x('hello);
+x('hello');
const m = {
- z: x('hello
+ z: x('hello'),
}
forgotten round braces in if statement
-if a > 5 {
+if (a > 5) {
alert();
}
add missing async
-function get(url) {
+async function get(url) {
return await fetch(url);
}
add missing *
-function hello() {
+function* hello() {
yield 'world';
}
-function func2() {
+function* func2() {
yield* func1();
}
declare before reference
-const {remove} = operator;
const {types, operator} = require('putout');
+const {remove} = operator;
assignment to constant variable
-const a = 5;
+let a = 5;
a = 3;
constant variable without initializer
-const a;
+let a;
declare undefined variables
+import {readFile} from 'fs/promises';
readFile('./hello.js', 'utf8');
missing initializer
-const {code, places} await samadhi(source);
+const {code, places} = await samadhi(source);
remove uselessdelete
-delete abc;
remove illegalstrict-mode
function x1(...a) {
- 'use strict';
}
remove getter arguments
export interface IParamsConstructor {
- get fromArray(name: string): IParams;
+ get fromArray(): IParams;
}
remove setter return type
export interface IParamsConstructor {
- set fromArray(name: string): IParams;
+ set fromArray(name: string);
}
import identifier
-import hello from hello;
+import hello from 'hello';
comma after statement
function x() {
- return 'hello',
+ return 'hello';
}
-const a = 5,
+const a = 5;
useless comma
const a = {
- b: 'hello',,
+ b: 'hello',
}
const a = class {
- b() {},
+ b() {}
}
useless semicolon
const a = {
- b: 'hello';
+ b: 'hello',
}
assign from
-const a = from 'a';
+const a = require('a');
convert assignment to declaration
-a = 5;
+const a = 5;
add missing parens
-getConsoleLog?.()``;
-String?.raw``;
-String?.raw!``;
+(getConsoleLog?.())``;
+(String?.raw)``;
+(String?.raw!)``;
export without const
-export x = () => {};
+export const x = () => {};
SyntaxError: missing formal parameter
-(__a + __b) => __b + __a;
+(__a, __b) => __b + __a;
wrong brace
-import a from 'a');
+import a from 'a';
add missing brace
a && b = a;
a && (b = a);
wrap with block
-if (a)
+if (a) {
const b = 5;
+}
extract keywords from variables
-export const isTemplateMiddle = (a) => a?.type === 'TemplateMiddle',
+export const isTemplateMiddle = (a) => a?.type === 'TemplateMiddle';
export const isTemplateTail = (a) => a?.type === 'TemplateTail';
-export const a = 1,
+export const a = 1;
const b = 5;
convert break
to return
function get() {
if (b)
- break;
+ return;
}
convert continue
to return
function get() {
if (b)
- continue;
+ return;
}
remove useless parens
for params
-const a = ((b)) => c;
+const a = (b) => c;
Argument name clash
-const a = ({b, b, ...c}) => {};
+const a = ({b, ...c}) => {};