Closed Zacqary closed 6 years ago
@Zacqary I'm not sure what would cause this, can you open the Atom dev tools and make sure prettier-atom is not reporting an error or anything?
The only thing the dev tools are logging is this pair of errors:
That happens when I hit Cmd+S to save, but it also seems to be happening whenever <atom-text-editor>
comes into focus (e.g. clicking on the dev tools, then clicking back on the main text editor).
Hmm, could be a red herring, not sure. If there was a problem where the save
event handler was not getting fired, then that could explain why formatOnSave
is not called. Can you try running Atom in safe mode (atom --safe
) and see if you still get that error in your dev tools?
If not, can you enable only prettier-atom and see if the behavior still happens?
Well I think that error is definitely a red herring, because it stopped happening. Unfortunately, disabling all other packages but prettier-atom
didn't solve the issue. I tried selectively re-enabling other packages, but nothing seemed to work.
Atom version: 1.21.0
prettier-atom version: 0.40.0
prettier version: 1.7.0
prettier-eslint version: 8.1.1
prettier-atom configuration: {
"formatOnSaveOptions": {
"enabled": true,
"isDisabledIfNoConfigFile": true,
"respectEslintignore": true,
"showInStatusBar": false,
"javascriptScopes": [
"source.js",
"source.jsx",
"source.js.jsx",
"source.babel",
"source.js-semantic",
"text.html.basic",
"text.html.vue"
],
"typescriptScopes": [
"source.ts",
"source.tsx",
"source.ts.tsx"
],
"cssScopes": [
"source.css",
"source.less",
"source.css.less",
"source.scss",
"source.css.scss"
],
"jsonScopes": [
"source.json"
],
"graphQlScopes": [
"source.graphql"
],
"excludedGlobs": [],
"whitelistedGlobs": [],
"isDisabledIfNotInPackageJson": false
},
"prettierOptions": {
"printWidth": 200,
"singleQuote": true,
"trailingComma": "all",
"bracketSpacing": true,
"semi": true,
"useTabs": false,
"jsxBracketSameLine": false,
"tabWidth": "auto",
"parser": "babylon"
},
"useEslint": true,
"useEditorConfig": true,
"prettierEslintOptions": {
"prettierLast": false
}
}
Either of the options ("if found in package.json" and "if config file found") stop prettier from formatting on save (without them checked, it formats):
Also, this is happening in console:
indieDelegate
is null
:
I found the repro steps and the cause: missing cache invalidation (the hardest problem in computer science 😜 ).
Set the options to Only format if a Prettier config is found
:
Open a project without (!) a .prettierrc
file.
Add a .prettierrc
file, for example:
{
"printWidth": 80
}
Open a .js
file from the project, make changes, hit Save
.
Expected: Prettier applied, changes saved. Actual: Prettier not applied, changes saved.
prettier-atom
uses prettier.resolveConfig.sync
to find and load the Prettier config files; prettier
in turn uses a mem
oized instance of cosmiconfig
"explorer" to find and load the files.
If this directoryCache
is populated before the .prettierrc
file is created, it doesn't get cleared and reports that there are no files to read, so this result
of the load
is null
, and this isPrettierConfigPresent
returns false
.
prettier-atom
should detect the directory and file changes and clear the caches.
prettier
exports the clearConfigCache
function which should dispose the mem
oized instance of cosmiconfig
"explorer" and this should dispose the caches in cosmiconfig
because they are stored in closures bound to the "explorer" instance methods.
I couldn't reproduce the ignorance of package.json
dependencies
/devDependencies
using the same steps (installing after opening the project); also, lodash/fp
is a hell to debug, especially when e.g. _.flow
or _.cond
is not wrapped with a function where you can set a breakpoint.
Seems like this turned out to be the problem as described in https://github.com/prettier/prettier-atom/issues/270?
lodash/fp is a hell to debug, especially when e.g. .flow or .cond is not wrapped with a function where you can set a breakpoint.
I think it's easier! Just use _.tap(console.log)
and move it around to whichever step you want introspection on.
const myFunc = _.flow(
doA,
doB,
_.tap(console.log),
doC,
);
Also, I have this as a snippet:
'bug':
'prefix': 'bug'
'body': '(() => { console.log(${0}); })() ||'
So if you want to see what myVar
is in the following before calling doSomething
:
const myFunc = (myVar) => doSomething(myVar);
You just insert the snippet. You can also put debugger
there if you prefer
const myFunc = (myVar) => (() => { console.log(myVar); })() || doSomething(myVar);
^ This is especially useful if you use SFCs in React
@robwise
1) Yes, for .prettierrc
(and the config files) it looks like https://github.com/prettier/prettier-atom/issues/270 – but I'm not sure about package.json
dependencies, from the first glance there was something else.
2) Thank you for the debugging tips. Yes, I found _.tap
and could use it for debugging, but this requires code changes, and every time the code needs to change, Atom needs to be restarted. I wanted to put "taps" on demand in the debugger without code change and restarting, and this was easy for the "flows" wrapped into named functions, but those functions which seemed to have issues aren't wrapped, so I had to step through every bits lodash/fp code like for an hour (that's where I lost patience to find the package.json issue). I'll get back to this.
Not sure if this is related, but the 'Only format if Prettier is found in your project's dependencies' option when checked (and dependency exists) prevents formatting on save.
Gonna try and take a look myself and see what I can do!
So, it appears this issue has a bunch of smaller issues all bundled into one. I'm going to tackle each one at a time and sort them through separate issues so we can keep conversations clear.
I'm going to start with the issues of reloading Prettier configurations which lives over on #270.
Hey @Zacqary, could you please let me know if you're still having issues and possibly provide anymore information? I'm not seeing anything we will be able to do to help with the issues you're having. I did find this issue, it appears something in your Atom installation got corrupted and you may need to reinstall.
The only other issue I see from this discussion is that when enabling 'Only format' options, formatting on save is completely disabled. I'll create a dedicated issue for that shortly so we can get to the root of that as well.
I'd also like to look more into your linter integration issue, @sompylasar. Can you give me a list of your installed packages? Is this still something you can reproduce?
@SavePointSam Firstly, many thanks for working on this. Secondly, I don't use Prettier now on a daily basis (because of this issue and because we as a team haven't adopted it) and I have a few rush days/weeks/releases now so I won't be able to reproduce timely.
After update, it works, thx a lot
Sadly still not working for me after the update.
@leepowellcouk I would suggest watching #360 for updates relating specifically to your issue. This issue is more a master issues for a set of issues people were experiencing.
If you could also provide more information in that issue, it would be very much appreciated. Thanks!
Due to the exact purpose of this issue being a bit unclear, and other issues have been created and referenced for underlying issues discussed, I’ll be closing this conversation here.
If you’re experiencing any of the discussed issues, please refer to the other linked issues to view their individual status.
If what is happening to you doesn’t appear to be included in those linked issues, please feel free to create a new ticket.
@sompylasar, once you’re able to reproduce your issue, could you please open a new ticket so we can diagnose and solve?
Thank you everyone!
Format on save seems to have stopped working for me after updating to 0.40.0. Nothing happens when I save my unformatted file. Formatting from the keyboard shortcut still works.
Prettier:Debug: