electrovir / prettier-plugin-multiline-arrays

Prettier plugin to force array elements to wrap onto new lines.
https://www.npmjs.com/package/prettier-plugin-multiline-arrays
Creative Commons Zero v1.0 Universal
137 stars 6 forks source link

don't wrap last array item when trailingComma is 'none' #41

Open artembelik opened 3 months ago

artembelik commented 3 months ago

Hi, thanks for the awesome plugin, but I noticed a strange behavior when trailingComma is 'none'

.prettierrc

{
    printWidth: 120,
    tabWidth: 4,
    useTabs: false,
    singleQuote: true,
    trailingComma: 'none', // <---
    plugins: ['prettier-plugin-multiline-arrays'],
}

source:

const { join } = require('path');

const arr = [
    join('...', '...'),
    join('...', '...')
]; // <---

after prettier --write:

const { join } = require('path');

const arr = [
    join('...', '...'),
    join('...', '...')]; // <---
electrovir commented 3 months ago

Nice catch! I'll try to repro and fix.

electrovir commented 3 months ago

Note: this also happens in JSON (since JSON doesn't allow trailing commas)

adiroiban commented 2 weeks ago

I have the same issue with trailingComma: 'es5'

Original code

{
    "files": [],
    "references": [
        {"path": "./tsconfig.app.json"},
        {"path": "./tsconfig.node.json"}
    ]
}

after this plugin is executed, I ended up with

{
    "files": [],
    "references": [
        {"path": "./tsconfig.app.json"},
        {"path": "./tsconfig.node.json"}]
}