gitmyhub

semi

JavaScript ★ 305 updated 6y ago

To semicolon or not to semicolon; that is the question

A command-line tool that automatically adds or removes semicolons from JavaScript code to match whichever style your team requires.

JavaScriptNode.jssetup: easycomplexity 2/5

What Semi Does

Semi is a tool that automatically adds or removes semicolons from JavaScript code. If you write JavaScript without semicolons but your team requires them (or vice versa), Semi converts your code to match the style you need — all while keeping everything else about your code exactly the same. It's a bridge between personal coding preference and project requirements.

How It Works

Semi reads your JavaScript file and uses a parser to understand where statements end. When you run the add command, it intelligently inserts semicolons where they're needed. When you run rm, it strips them out. The tool handles tricky edge cases too — for instance, JavaScript sometimes needs a "leading" semicolon at the start of a line to avoid ambiguity (like when a line begins with a parenthesis or bracket). Semi knows these rules and handles them automatically.

You can use it from the command line to batch-process files, or call it directly in code if you're building another tool. The README mentions it also works with modern ES6 syntax, so it's not limited to older JavaScript patterns.

Who Would Use This

Any developer who prefers writing without semicolons but works on a team with a semicolon-required style guide. For example, a programmer might write code locally in a clean, semicolon-free style, then run semi add before committing to keep the codebase consistent. The reverse is useful too — if you're moving code from a semicolon-heavy project into one that omits them.

A Note on the Project

The README includes a candid warning: the original author no longer maintains this actively because ESLint (a more widely-used code checker) now has built-in functionality to add or remove semicolons automatically. If you're starting a new project, ESLint's --fix flag might be the more modern choice. That said, Semi still works and may be useful if you're in an environment where ESLint isn't set up yet.

Where it fits