-
-
Notifications
You must be signed in to change notification settings - Fork 83
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
feat: use "prettier-tslint" and "prettier-eslint" when they exist #54
Conversation
PS: You can add me as a maintainer here, too. ;) |
src/formatFiles.js
Outdated
function loadFormat(rootDirectory, formatName, exportName) { | ||
let entry; | ||
try { | ||
entry = require.resolve(join(rootDirectory, 'node_modules', formatName)); |
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.
This won't work with yarn PnP.
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.
Are you saying it breaks pretty-quick
for Yarn PnP installs, or just that prettier-eslint
and prettier-tslint
won't be found?
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.
Have you actually tested this with Yarn PnP?
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.
The latter. Projects using PnP don't have node_modules
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, that's fine. We can patch PnP support for this feature in a later patch.
Thinking I'd favour a more explicit API, like We can also make it work with PnP that way. |
Why would replacing implicit loading with an explicit flag make PnP work? We already wrap the |
We can just do |
Can you explain why someone would want We can remove the hard-coded |
I've improved the implicit behavior by ensuring the resolved |
src/formatFiles.js
Outdated
); | ||
|
||
const format = | ||
(/\.(mjs|jsx?)$/.test(file) && (eslintFormat || tslintFormat)) || |
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.
This won't work for files with shebangs (which prettier supports). Maybe using prettier.getFileInfo
would be better?
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.
You're talking about executable files with no file extension that contain Javascript and begin with a shebang, yes?
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.
Absolutely.
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 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.
Let's support shebangs in a later patch. No biggie if they don't get linted for now.
When the scm root has "./node_modules/prettier-tslint" and/or "./node_modules/prettier-eslint", we use them on applicable modules.
So we can use the `getFileInfo` export.
I've added shebang support (using Like I said, we can add Yarn PnP support in the future. I think we would take this approach. Specifically, importing LGTM! :) |
Hmm.. Looks like Travis is using a version of Prettier that doesn't include Even though I updated @azz Could you take a look? |
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.
Sorry I haven't had a chance to look at the build issue. Christmas is a busy time! Left a few comments
format === prettierFormat | ||
? format(input, ((options.filepath = file), options)) | ||
: format({ | ||
text: input, |
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.
Could you add a test for this code path?
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've tested locally (and you can too) with:
git clone -b feat1-test https://github.com/aleclarson/pretty-quick
cd pretty-quick
cat README.md
I'll try to get around to writing a test when I can.
|
||
const parser = getFileInfo.sync(file).inferredParser; | ||
const format = | ||
(parser === 'babylon' && (eslintFormat || tslintFormat)) || |
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.
Or flow
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.
Does eslint support flow? edit: Nope!
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.
babylon
supports flow language too. You can write JavaScript and still use the flow
parser.
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, but passing Flow-typed JavaScript into eslint
does not work.
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.
Are you saying there's a chance that file
will contain Flow-typed JavaScript when parser === 'babylon'
?
I deleted the build caches and restarted the build. Hopefully that helps. |
- rename "isSupportedExtension" function to "isFileSupported" - use `prettier.getFileInfo` to detect shebangs - upgrade prettier to 1.15.0+ (where shebang support was added)
Once tests are added, this is ready to merge. Things to fix later:
|
Any news on this one? 🤔 Ping @aleclarson @azz |
No thanks, but you can looking forward to https://github.com/prettier-eslint/prettier-plugin. |
When the scm root has
./node_modules/prettier-tslint
and/or./node_modules/prettier-eslint
, we use them on any applicable modules.We prefer
prettier-eslint
for.js
,.jsx
, and.mjs
modules. Ifprettier-eslint
does not exist, we tryprettier-tslint
and thenprettier
alone.We prefer
prettier-tslint
for.ts
and.tsx
. Ifprettier-tslint
does not exist, we tryprettier-eslint
and thenprettier
alone.All other file types use
prettier
only.