prettier-plugin-insert-comma 1.1.3 → 1.1.5

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.
@@ -4,6 +4,10 @@ A [Prettier](https://prettier.io/) plugin that automatically inserts missing com
4
4
 
5
5
  Prettier cannot format code with syntax errors like missing commas in objects. This plugin runs as a preprocessor to insert commas between properties, allowing Prettier to format your code successfully.
6
6
 
7
+ ## Requirements
8
+
9
+ - Prettier 3.7.0 or higher
10
+
7
11
  ## Example
8
12
 
9
13
  **Before** — Prettier would throw a parse error:
@@ -68,10 +72,10 @@ For JSON files, you need to specify the parser explicitly with `overrides`:
68
72
  }
69
73
  ```
70
74
 
71
- ## Supported Parsers
75
+ ## Supported Languages
72
76
 
73
- | Parser | Languages |
74
- | ------------ | --------------- |
75
- | `typescript` | TypeScript, TSX |
76
- | `babel` | JavaScript, JSX |
77
- | `json` | JSON |
77
+ | Language |
78
+ | --------------- |
79
+ | TypeScript, TSX |
80
+ | JavaScript, JSX |
81
+ | JSON |
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import typescriptParser from 'prettier/parser-typescript';
2
- import babelParser from 'prettier/parser-babel';
3
- function fixMissingCommas(code) {
1
+ import typescriptParser from 'prettier/plugins/typescript';
2
+ import babelParser from 'prettier/plugins/babel';
3
+ function fixMissingCommas(code, skipTrailing = false) {
4
4
  let depth = 0;
5
5
  let inString = false;
6
6
  let quote = null;
@@ -81,11 +81,15 @@ function fixMissingCommas(code) {
81
81
  const isPrevSeparator = prev === ',' ||
82
82
  prev === '{' ||
83
83
  prev === '[' ||
84
+ prev === '(' ||
84
85
  prev === ':' ||
85
86
  prev === ';' ||
86
87
  prev === undefined;
87
88
  if (isNextKeyOrClosing && !isPrevSeparator && !lastWasComment) {
88
- out += ',';
89
+ const isTrailing = nextSlice[0] === '}' || nextSlice[0] === ']';
90
+ if (!skipTrailing || !isTrailing) {
91
+ out += ',';
92
+ }
89
93
  }
90
94
  }
91
95
  out += ch;
@@ -96,15 +100,18 @@ function fixMissingCommas(code) {
96
100
  return out;
97
101
  }
98
102
  function wrapParser(parser) {
103
+ const isRunningCLI = process.argv[1]?.includes('prettier');
99
104
  return {
100
105
  ...parser,
101
106
  async preprocess(text, options) {
107
+ if (isRunningCLI)
108
+ return text;
102
109
  let next = text;
103
110
  if (parser.preprocess) {
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.3",
4
+ "version": "1.1.5",
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",
@@ -33,9 +33,10 @@
33
33
  "build": "pnpm tsc"
34
34
  },
35
35
  "peerDependencies": {
36
- "prettier": "^3.0"
36
+ "prettier": "^3.7.0"
37
37
  },
38
38
  "devDependencies": {
39
+ "@types/node": "^25.3.5",
39
40
  "typescript": "^5.9.3"
40
41
  },
41
42
  "publishConfig": {