prettier-plugin-insert-comma 1.1.4 → 1.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +10 -3
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import typescriptParser from 'prettier/plugins/typescript';
2
2
  import babelParser from 'prettier/plugins/babel';
3
- function fixMissingCommas(code) {
3
+ function fixMissingCommas(code, skipTrailing = false) {
4
4
  let depth = 0;
5
5
  let inString = false;
6
6
  let quote = null;
@@ -81,11 +81,18 @@ function fixMissingCommas(code) {
81
81
  const isPrevSeparator = prev === ',' ||
82
82
  prev === '{' ||
83
83
  prev === '[' ||
84
+ prev === '(' ||
84
85
  prev === ':' ||
85
86
  prev === ';' ||
87
+ prev === '>' ||
88
+ prev === '=' ||
89
+ prev === '?' ||
86
90
  prev === undefined;
87
91
  if (isNextKeyOrClosing && !isPrevSeparator && !lastWasComment) {
88
- out += ',';
92
+ const isTrailing = nextSlice[0] === '}' || nextSlice[0] === ']';
93
+ if (!skipTrailing || !isTrailing) {
94
+ out += ',';
95
+ }
89
96
  }
90
97
  }
91
98
  out += ch;
@@ -104,7 +111,7 @@ function wrapParser(parser) {
104
111
  const result = await parser.preprocess(text, options);
105
112
  next = result;
106
113
  }
107
- return fixMissingCommas(next);
114
+ return fixMissingCommas(next, options.trailingComma === 'none');
108
115
  },
109
116
  };
110
117
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "prettier-plugin-insert-comma",
4
- "version": "1.1.4",
4
+ "version": "1.1.6",
5
5
  "description": "A Prettier plugin for inserting missing commas in multi-line objects.",
6
6
  "funding": "https://github.com/sponsors/refirst11",
7
7
  "author": "Refirst11",