Prettier Plugin
prettier-plugin-noshift.js is an official Prettier plugin that formats .nsjs files.
Installation
Install the plugin as a dev dependency alongside Prettier:
npm install --save-dev prettier prettier-plugin-noshift.js Configuration
Add the plugin to your .prettierrc (or equivalent config file):
{
"semi": true,
"singleQuote": false,
"plugins": ["prettier-plugin-noshift.js"]
} If you scaffold a project with nsc create, the Prettier plugin is automatically installed and configured.
How It Works
The plugin converts .nsjs code to JavaScript, formats it with Prettier's built-in JavaScript formatter, then converts the result back to NoShift.js syntax. All standard Prettier options (e.g., semi, singleQuote, tabWidth) are forwarded.
Pipeline
.nsjs→ JavaScript (convert)- JavaScript → formatted JavaScript (Prettier)
- formatted JavaScript →
.nsjs(reverse convert)
Example
Before:
const x = 1 ;
function greet^8name^9 ^[
const msg=^2^3hello, ^2^;name;
console.log^8msg^9 ;
return msg ;
^] After formatting:
const x ^- 1;
function greet^8name^9 ^[
const msg ^- ^2^3hello, ^2 ^; name;
console.log^8msg^9;
return msg;
^] Supported Options
All standard Prettier options are supported. Common ones include:
| Option | Default | Description |
|---|---|---|
semi | true | Add semicolons at the end of statements |
singleQuote | false | Use single quotes instead of double quotes |
tabWidth | 2 | Indentation width |
trailingComma | "all" | Trailing commas |
printWidth | 80 | Max line width |
bracketSpacing | true | Spaces inside object braces |