-
Notifications
You must be signed in to change notification settings - Fork 0
Run prettier on the remainder of the Repo #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: rob/v2-prettier
Are you sure you want to change the base?
Conversation
So this prettier run mangles Original const inlineRegexSourcePlugin: Plugin = {
name: 'inline-regex-source',
renderChunk(code) {
const str = new MagicString(code);
str.replace(
/\/((?:[^\n\r[\\\/]|\\.|\[(?:[^\n\r\\\]]|\\.)*\])+)\/\s*\.\s*source\b/g,
(m, source: string) => {
// escape backslashes
source = source.replace(/\\(.)|\[(?:\\s\\S|\\S\\s)\]/g, (m, g1: string) => {
if (g1) {
// characters like /\n/ can just be kept as "\n" instead of being escaped to "\\n"
if (/[nrt0/]/.test(g1)) {
return m;
}
if ('\\' === g1) {
return '\\\\\\\\'; // escape using 4 backslashes
}
return '\\\\' + g1;
} else {
return '[^]';
}
});
// escape single quotes
source = source.replace(/'/g, "\\'");
// wrap source in single quotes
return "'" + source + "'";
}
);
return toRenderedChunk(str);
},
}; Mangled by prettier: const inlineRegexSourcePlugin: Plugin = {
name: 'inline-regex-source',
renderChunk (code) {
const str = new MagicString(code);
str.replace(
/\/((?:[^\n\r[\\\/]|\\.|\[(?:[^\n\r\\\]]|\\.)*\])+)\/\s*\.\s*source\b/g,
(m, source: string) => {
// escape backslashes
source = source.replace(/\\(.)|\[(?:\\s\\S|\\S\\s)\]/g, (m, g1: string) => {
if (g1) {
// characters like /\n/ can just be kept as "\n" instead of being escaped to "\\n"
if (/[nrt0/]/.test(g1)) {
return m;
}
if ('\\' === g1) {
return '\\\\\\\\'; // escape using 4 backslashes
}
return '\\\\' + g1;
}
else {
return '[^]';
}
if ('\\' === g1) {
return '\\\\\\\\'; // escape using 4 backslashes
}
return '\\\\' + g1;
} else {
return '[^]';
}
});
// escape single quotes
source = source.replace(/'/g, "\\'");
// wrap source in single quotes
return "'" + source + "'";
});
return toRenderedChunk(str);
},
}; |
How about adding // prettier-ignore
const inlineRegexSourcePlugin: Plugin = { Could you please check if it works not “on my machine” only? 🙂 |
f9c7eda
to
2f249df
Compare
I did one better and applied it just to the lambda that gets mangled : ) |
I tried another approach that might be slightly better. I noticed that none of the plugins mangle the files by themselves. It only happens when we expect them to be applied sequentially. I already knew plugin order matters, and the one we use here plays well in our other project. But it seems we should swap the {
"plugins": [
"prettier-plugin-space-before-function-paren",
"prettier-plugin-brace-style",
"prettier-plugin-merge"
],
...
} Could you please check it? |
Actually, it is weird that we have to do that. It's more like we are working around a bug in our plugin (which adds a space before the function paren). We need to fix the plugin first. I’ll work on it. |
It turned out it's not an issue with the I have another issue to file concerning the merge plugin. It might be when that issue is fixed, we won't need any workarounds. 🤞 UPDATE: I hope to update the UPDATE 2: Another option would be adding |
It's published: https://www.npmjs.com/package/prettier-plugin-space-before-function-paren |
Unfortunately still seeing the same issue. I did check |
Correct that changing plugin order does fix it though! |
fb0b389
to
84f1b0d
Compare
Yeah, it is more for other issues that weren't previously addressed. I filed an issue for the one that causes files to be mangled. I hope they can give me a hint of why we might face it at all. |
} | ||
] | ||
] | ||
"presets": [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we could actually skip babel and minification entirely in v2. If folks need broader browser support than what we provide or to minify, they can do their own transformations.
Okay, the issue with the Speaking of the plugin order, we still need our plugin to come after the "plugins": [
"prettier-plugin-brace-style",
"prettier-plugin-space-before-function-paren",
"prettier-plugin-merge"
] |
84f1b0d
to
5170359
Compare
Ok, updated to new version, and update order. Everything is looking groovy : ) |
343aa88
to
58c53e5
Compare
5170359
to
bc14a86
Compare
0071f98
to
f390aec
Compare
…3876) Note that prettier sync is being imported in order to enable us to format test code during tests. It should not be used anywhere else Updated eslint rules to work with prettier, including removing redundant rules.
a95fa3a
to
6637d4d
Compare
6637d4d
to
49db546
Compare
49db546
to
3395022
Compare
2aed9fc
to
f5a8a46
Compare
f5a8a46
to
bbadd78
Compare
No description provided.