prettier-plugin-insert-comma 1.1.4 → 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.
- package/dist/index.js +10 -3
- package/package.json +2 -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,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
|
-
|
|
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.
|
|
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",
|
|
@@ -36,6 +36,7 @@
|
|
|
36
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": {
|