-1

Is there a formatter similar to Prettier that can format Node.js code with aligned variable declarations like this?

const PRICE_BUTTER = 1.00;
const PRICE_MILK=3.00;
const PRICE_EGGS=6.95;

To:

const PRICE_BUTTER = 1.00;
const PRICE_MILK   = 3.00;
const PRICE_EGGS   = 6.95;

Prettier doesn't have this options

2 Answers 2

1

Here is the tool and approaches that can help:

ESLint + plugin or manual rules While ESLint is mainly for linting, some plugins can help with alignment, like:

eslint-plugin-align-assignments This plugin aligns = and : in variable declarations and object literals.

Install:

npm install --save-dev eslint eslint-plugin-align-assignments

Add to your .eslintrc.js:

module.exports = {
  plugins: ['align-assignments'],
  rules: {
    'align-assignments/align-assignments': ['error', { requiresOnly: false }],
  },
};

Then run:

npx eslint --fix yourfile.js
Sign up to request clarification or add additional context in comments.

Comments

-3

You are asking for a formatter which generates unuseful 'whitespaces' in your code!!!

But the expert recommendation is to avoid useless 'whitespacing' as much as possible, and that is what the formatters out there follows while formatting your code.

According to my knowledge there is not such a extension/tool that can meet your desires.

But if there's a formatter like that, which u want, and that is a BIG IFFFF, that's gotta be a hell of a development mistake...

2 Comments

in this case you might as well rename your variables with a single letter like A, B, C… to further reduce memory space and make your code even more unreadable. 🙂
@MisterJojo 🤦‍♂️ Leave it, it's not ur fault. BTW thanks for the suggestion.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.