# 🛠️ Syntax Errors
🐊**Putout** not only improves working code but also fixes broken code.
function declaration half converted from arrow expression
```diff
-function parse(source) => {
+function parse(source) {
return source;
}
```
broken string
```diff
-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
```diff
-if a > 5 {
+if (a > 5) {
alert();
}
```
add missing async
```diff
-function get(url) {
+async function get(url) {
return await fetch(url);
}
```
add missing *
```diff
-function hello() {
+function* hello() {
yield 'world';
}
-function func2() {
+function* func2() {
yield* func1();
}
```
declare before reference
```diff
-const {remove} = operator;
const {types, operator} = require('putout');
+const {remove} = operator;
```
assignment to constant variable
```diff
-const a = 5;
+let a = 5;
a = 3;
```
constant variable without initializer
```diff
-const a;
+let a;
```
declare undefined variables
```diff
+import {readFile} from 'fs/promises';
readFile('./hello.js', 'utf8');
```
missing initializer
```diff
-const {code, places} await samadhi(source);
+const {code, places} = await samadhi(source);
```
remove uselessdelete
```diff
-delete abc;
```
remove illegalstrict-mode
```diff
function x1(...a) {
- 'use strict';
}
```
remove getter arguments
```diff
export interface IParamsConstructor {
- get fromArray(name: string): IParams;
+ get fromArray(): IParams;
}
```
remove setter return type
```diff
export interface IParamsConstructor {
- set fromArray(name: string): IParams;
+ set fromArray(name: string);
}
```
import identifier
```diff
-import hello from hello;
+import hello from 'hello';
```
comma after statement
```diff
function x() {
- return 'hello',
+ return 'hello';
}
-const a = 5,
+const a = 5;
```
useless comma
```diff
const a = {
- b: 'hello',,
+ b: 'hello',
}
const a = class {
- b() {},
+ b() {}
}
```
useless semicolon
```diff
const a = {
- b: 'hello';
+ b: 'hello',
}
```
assign from
```diff
-const a = from 'a';
+const a = require('a');
```
convert assignment to declaration
```diff
-a = 5;
+const a = 5;
```
add missing parens
```diff
-getConsoleLog?.()``;
-String?.raw``;
-String?.raw!``;
+(getConsoleLog?.())``;
+(String?.raw)``;
+(String?.raw!)``;
```
export without const
```diff
-export x = () => {};
+export const x = () => {};
```
SyntaxError: missing formal parameter
```diff
-(__a + __b) => __b + __a;
+(__a, __b) => __b + __a;
```
wrong brace
```diff
-import a from 'a');
+import a from 'a';
```
add missing brace
```diff
a && b = a;
a && (b = a);
```
wrap with block
```diff
-if (a)
+if (a) {
const b = 5;
+}
```
extract keywords from variables
```diff
-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
```diff
function get() {
if (b)
- break;
+ return;
}
```
convert continue to return
```diff
function get() {
if (b)
- continue;
+ return;
}
```
remove useless parens for params
```diff
-const a = ((b)) => c;
+const a = (b) => c;
```
argument name clash
```diff
-const a = ({b, b, ...c}) => {};
+const a = ({b, ...c}) => {};
```
convert colon to comma
```diff
export const rules = [
- ['apply-nesting': applyNesting],
+ ['apply-nesting', applyNesting],
];
```
remove useless export specifier
```diff
export const hello = () => 'world';
export const {
- hello,
}
```
replaceAll() called with a non-global RegExpargument
```diff
-'hello'.replaceAll(/hello/, 'world')
+'hello'.replaceAll(/hello/g, 'world')
```
convert module to namespace
```diff
-module M {
+namespace M {
var x: string;
}
```
remove duplicate to parameter
```diff
-const s = (a, a) => {};
+const s = (a) => {};
```
split namespace with specifiers
```diff
-import * as plugin, {CUT} from './plugin.js';
+import as plugin from './plugin.js';
+const {CUT} = plugin;
```
Uncaught SyntaxError: Unexpected token ','
```diff
-renameFileWithLog('hello', ,'world');
+renameFileWithLog('hello', 'world');
```
convert const to import
```diff
-const {Server} from 'socket.io';
+import {Server} from 'socket.io';
```