-
-
Notifications
You must be signed in to change notification settings - Fork 95
Conversation
744fb11
to
d779ff4
Compare
package.json
Outdated
@@ -58,47 +58,54 @@ | |||
"default": false, | |||
"order": 1 | |||
}, | |||
"formatOnSaveSilentError": { | |||
"title": "On format on Save, Don't show error message", | |||
"description": "Don't show error if accour on format on save", |
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.
Typo? accour
package.json
Outdated
@@ -58,47 +58,54 @@ | |||
"default": false, | |||
"order": 1 | |||
}, | |||
"formatOnSaveSilentError": { | |||
"title": "On format on Save, Don't show error message", |
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.
There's some inconsistent capitalization going on here
lib/helpers.js
Outdated
|
||
format(null, { | ||
ignoreSelection: true, | ||
ignoreErrors: !formatOnSaveSilentError, |
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 would just inline the call to getConfigOption
, or at least name the variablje ignoreErrors
so you can just use property shorthand
editor.getSelectedBufferRanges().forEach(range => { | ||
transformRange(editor, range); | ||
editor.getSelectedBufferRanges().forEach((range) => { | ||
transformRange(editor, range, { ignoreErrors: options.ignoreErrors }); |
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.
we should just pass options
instead of redefining a new object every time like this
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.
But the options of format
contains options which aren't related to transformRange
. I prefer to pass to a function only properties that are relevant to that function
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.
ok fair enough
}); | ||
} else { | ||
transformRange(editor, bufferRange); | ||
transformRange(editor, bufferRange, { ignoreErrors: options.ignoreErrors }); |
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.
we should just pass options
instead of redefining a new object every time like this
const range = new iter.range.constructor(startModified, end); | ||
transformRange(editor, range); | ||
transformRange(editor, range, { ignoreErrors: options.ignoreErrors }); |
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.
we should just pass options
instead of redefining a new object every time like this
lib/helpers.js
Outdated
@@ -24,22 +21,24 @@ const getFormatOptions = () => PRETTIER_CORE_OPTIONS.reduce(setConfigOption, {}) | |||
|
|||
const getCurrentScope = () => atom.workspace.getActiveTextEditor().getGrammar().scopeName; | |||
|
|||
const executePrettier = (text, formatOptions) => { | |||
const executePrettier = (text, formatOptions, options = { ignoreErrors: false }) => { | |||
try { | |||
return prettier.format(text, formatOptions); | |||
} catch (e) { | |||
const message = `prettier-atom: ${e.toString()}`; |
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.
we should use a guard clause instead that way it's clear what code goes with what:
console.log('Error executing Prettier:', e);
if (!options.ignoreErrors) {
const message = `prettier-atom: ${e.toString()}`;
const detail = e.stack.toString();
atom.notifications.addError(message, { detail, dismissable: true });
}
return false;
}
By the way tell when code is ready so I'll rebase history it before merge |
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.
Okay, ready to go! Thanks so much! Let me know when you've squashed and I will merge!
Added checkbox to menu Ignore errors on save when formatOnSaveSilentError is true
f49b6af
to
244dfae
Compare
Done |
Continuation of #45
Please review the code. I'm sure you might want to solve this problem differently