-
-
Notifications
You must be signed in to change notification settings - Fork 292
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
Add TypeScript support #426
Conversation
Can you make it handle Per issue description:
I don't have that many actual TypeScript projects, but I have hundreds of JS packages with a |
Can you make it handle .d.ts too? It should lint |
Good point. I was out on my phone and didn't check yet. |
There's a problem with
It works if I manually copy the XO directory into |
However, then there are some parse errors:
|
There's also a problem with reading Here's the error:
|
The loading is probably related to how ESlint resolve config/plugin names. I'll look into it to see if something can done (maybe passing absolute path to ESlint?) I'll check the parsing errors and the comment in tsconfig.json tomorrow. |
Non-TS projects with a |
I'm not sure it's possible. We look at the |
|
lib/options-manager.js
Outdated
@@ -47,6 +55,8 @@ const mergeFn = (previousValue, value) => { | |||
} | |||
}; | |||
|
|||
const isTypescript = file => TYPESCRIPT_EXTENSION.includes(path.extname(file).replace('.', '')); |
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.
const isTypescript = file => TYPESCRIPT_EXTENSION.includes(path.extname(file).replace('.', '')); | |
const isTypescript = file => TYPESCRIPT_EXTENSION.includes(path.extname(file).slice(1)); |
Since you know what extname
will always return a string with .
in front or an empty string. It should be safer than just replacing the first dot.
I can't reproduce the issue you are having on https://github.com/sindresorhus/make-dir I cloned the repo, then {
"include": ["**/*.ts"]
} Then running xo:
It seems that a
Maybe we can try to figure out which rules require Another solution is to enable the Typescript rules only when a |
Yeah, I don't think that's a realistic solution.
That would severely limit the usefulness of this. There are much more projects with |
Hmm, an idea. We could just write out a tsconfig file to a temp directory and point |
For info typescript-eslint/typescript-eslint#406 which is essentially the same as the one you opened hasn't been answered. Also see typescript-eslint/typescript-eslint#689. It seems the tsconfig.json file is used at a minimum to read the To be honest I though a If we add a default |
We should only do it for |
Hmm, maybe we could fix xojs/eslint-config-xo-typescript#15 at the same time (It's a huge pain-point). Often the tsconfig file contains more files than you actually want to lint. We could read the tsconfig file and switch out // @fregante |
After doing a lot of tests, we can create a temporary one and pass it to This will not work: {
"include": ["**/*.ts"]
} This will work: {
"include": ["/users/pvdlg/project/**/*.ts", "/users/pvdlg/project/**/*.tsx"]
} So we could do:
I think it should solve both xojs/eslint-config-xo-typescript#15 and projects without a That seems like a clunky workaround, but it's the only solution I've found. |
I'm not sure how Also, here we should inject some sensible defaults: https://github.com/sindresorhus/tsconfig/blob/9c49b210a7e7dee5a0feeb8433c8cc165f6319bb/tsconfig.json#L15-L19
I'm totally fine with it being clunky if it fixes the problem. |
@sindresorhus I updated the PR per our discussion. Note that in the case of project without a This problem will not happen if you have a |
Can you also ensure the generated tsconfig is strict by adding this config to it?
|
Can you mention in the readme that it works for |
I've been testing this on a bunch of projects and it seems to work great. 👌 |
I made the requested changes. I added the default config only when no |
Oh yeah. Definitely. I meant when there’s no tsconfjg file. |
Manually tested it again and seems to work great. |
Woooot! Really awesome that you decided to implement this. 🎉✨ Should I do a new release? |
Very excited for these changes. Thanks so much @pvdlg! |
Yes that would be awesome! |
Fix #373
Fix xojs/eslint-config-xo-typescript#15
Xo will now automatically lint
.ts
and.tsx
with the config fromeslint-config-xo-typescript
. No configuration needed!IssueHunt Summary
Referenced issues
This pull request has been submitted to:
IssueHunt has been backed by the following sponsors. Become a sponsor