prettier-plugin-insert-comma 1.0.2 → 1.1.0
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 +20 -2
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import typescriptParser from 'prettier/parser-typescript';
|
|
2
2
|
import babelParser from 'prettier/parser-babel';
|
|
3
|
+
function isCheckMode() {
|
|
4
|
+
return process.argv.some((arg) => arg === '--check' || arg === '-c');
|
|
5
|
+
}
|
|
3
6
|
function fixMissingCommas(code) {
|
|
4
7
|
let depth = 0;
|
|
5
8
|
let inString = false;
|
|
@@ -59,8 +62,21 @@ function fixMissingCommas(code) {
|
|
|
59
62
|
}
|
|
60
63
|
const prev = out[lastCharIdx];
|
|
61
64
|
let nextStartIdx = i + 1;
|
|
62
|
-
while (nextStartIdx < code.length
|
|
63
|
-
nextStartIdx
|
|
65
|
+
while (nextStartIdx < code.length) {
|
|
66
|
+
while (nextStartIdx < code.length && /\s/.test(code[nextStartIdx])) {
|
|
67
|
+
nextStartIdx++;
|
|
68
|
+
}
|
|
69
|
+
if (code[nextStartIdx] === '/' && code[nextStartIdx + 1] === '/') {
|
|
70
|
+
const lineEnd = code.indexOf('\n', nextStartIdx);
|
|
71
|
+
nextStartIdx = lineEnd === -1 ? code.length : lineEnd + 1;
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (code[nextStartIdx] === '/' && code[nextStartIdx + 1] === '*') {
|
|
75
|
+
const endIdx = code.indexOf('*/', nextStartIdx + 2);
|
|
76
|
+
nextStartIdx = endIdx === -1 ? code.length : endIdx + 2;
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
break;
|
|
64
80
|
}
|
|
65
81
|
const nextSlice = code.slice(nextStartIdx);
|
|
66
82
|
const isNextKeyOrClosing = nextSlice[0] === '}' ||
|
|
@@ -107,6 +123,8 @@ function wrapParser(parser) {
|
|
|
107
123
|
return {
|
|
108
124
|
...parser,
|
|
109
125
|
async preprocess(text, options) {
|
|
126
|
+
if (isCheckMode())
|
|
127
|
+
return text;
|
|
110
128
|
let next = text;
|
|
111
129
|
if (parser.preprocess) {
|
|
112
130
|
const result = await parser.preprocess(text, options);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "prettier-plugin-insert-comma",
|
|
4
|
-
"version": "1.0
|
|
4
|
+
"version": "1.1.0",
|
|
5
5
|
"description": "A Prettier plugin for inserting missing commas in objects.",
|
|
6
6
|
"funding": "https://github.com/sponsors/refirst11",
|
|
7
7
|
"author": "Refirst11",
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"prettier": "^3.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
+
"@types/node": "^25.3.3",
|
|
39
40
|
"typescript": "^5.9.3"
|
|
40
41
|
},
|
|
41
42
|
"publishConfig": {
|