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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rewrite in TypeScript #256
Comments
I've done a first pass of So far, it seems to me like this'll be a bit teeth pully, as I've also encapsulated the actual primary condition into a Finally, off the bat there's already room for improvement, which ties in to everything I've said so far: right now the rule is only checking actual string literals, which means template strings already won't work right off the bat (regardless of if they've got actual embedded expressions or not) This could be improved to support them w/o expressions, but you could also take this further to try and provide basic support for expressions, since you might be able to do a basic search of surrounding nodes in an attempt to see if the expression is a constant, and if it is evaluate its value. All in all, for now I've opted for doing the basics, w/ the idea that people can fill issues requesting improvements, just to keep things simple. I've not made a PR since I saw your previous PRs were reverted following some breaking of peoples builds. Let me know if you're still wanting to go ahead with converting to TS. For now I'm going to continue trying to pick off the easy rules - let me know any thoughts you have :) |
Thanks @G-Rath! Yeah, it seems using the module from typescript-eslint/typescript-eslint#425 requires consumers to use typescript as well, so I need to figure out how we can author rules in TS without consumers noticing at all. I'll try to get to this, but I'm still swamped at work... Feel free to dig into it if you don't mind! |
I don't know enough about the eslint ecosystem to know if its worth using the I'm happy to help write TS, regardless of what it's for, but yeah I think the decision that needs to be made is about converting to TS vs switching to the The former could be started on right now if you wanted, but as you've found out the latter is a breaking change, and thus comes down to pros vs cons which I obviously can't decide for you :) |
We don't want to use the parser in our own rules - we want to use the utils which provide way better types than the ones from DefinitelyTyped as well as some nice utils for options etc. It's also stricter (also called opinionated 馃槢), forcing us to follow some good conventions (fixing both #201 and #202 at once). We do however want to use the parser for linting our own code, but that should not be visible to consumers. The dependency on When a release is out, we can probably retry this (I'll revert my earlier revert). Will need to dig into #268 as well at that point. |
@SimenB I'll pick up a rule, can you tell me where code migrated to typescript is maintained. |
A new try is up here: #305. @M4rk9696 thanks! A PR to that branch ( |
@G-Rath would you be able to PR |
@SimenB I can but try ;P Give me a few minutes (or an hour, depending on the work - I've not actually been following the activity 馃槵) |
There is absolutely no rush 馃檪 |
I've been doing everything in a single generic branch, and have about a quarter of the rules converted. My plan is to just cherry-pick at the end. There are a couple of that don't require Otherwise, I'll finish off the rest off the rules this evening/weekend :) Sorry for all the failing tests - I'll check them out once I'm home, as I'm rushing to catch a train 馃槵 |
Oh wow @G-Rath, that's awesome! Don't worry about the commitlint check on CI - it's confused by the merge commit travis creates. As long as lint and test (with coverage) passes, you're good 馃檪 |
@SimenB just a heads up that the I've been just copying the header for each rule as the I've also not tested any of the fixes - I think they'll work fine but the only thing I'm worry about is what happens if you return an empty array..? I've not written eslint plugins before so don't know what the best practices are. I'm happy to follow your lead on any changes you want made. |
Ah, ok, good to know. I'll verify The fixes are all covered by unit tests, so if the tests pass then we're good. If a violation is not fixable, we should not return a fixer (that way the "n error potentially fixable" message from eslint is not misleading) |
I think we've nearly gotten all the low hanging fruit, so I'm going to look to tackle the converting of the I've actually already done Once that's done, we'll be able to tackle all of the I've got a few more rules to convert & cherry pick first tho - I'm catching a flight in a day or so, so I might go dark for a bit, but at this rate I'd say we should easily be done by the end of month, if not by next week :D |
Haha, this has been awesome, thank you so much for your help! |
TS ESLint had a stable release, so I merged the PR to master. Also updated OP |
Well, this went about as well as I expected - I woke up to about 20 emails for this repo, half of which being semantic bot 馃槀 but seriously it actually did go as expected: the bugs I've seen are pretty much what I expected, and the fixing PRs have been great, and will make everything more stable. I'll look to power through getting the rest of the rules converted over the next couple of days. |
Heh, yeah... It wasn't too bad, though! |
@SimenB Just wanted to let you know I've not forgotten about this 馃槈 I've got 2 rules left to convert, and the new guards + expect parser is working a treat. Life got a bit busy once I got back, but I hope to have a PR for review by midweek. As an example of how nice the new expect stuff is: Now they're just: const isNullEqualityMatcher = (
matcher: ParsedExpectMatcher,
): matcher is ParsedNullEqualityMatcher =>
EqualityMatcher.hasOwnProperty(matcher.name) &&
matcher.node.parent !== undefined &&
matcher.node.parent.type === AST_NODE_TYPES.CallExpression &&
hasOneArgument(matcher.node.parent) &&
isNullLiteral(matcher.node.parent.arguments[0]);
/* in create: */
if (!isExpectCall(node)) {
return;
}
const { matcher } = parseExpectCall(node);
if (matcher && isNullEqualityMatcher(matcher)) {
context.report({
fix(fixer) {
return [
fixer.replaceText(matcher.node.property, 'toBeNull'),
fixer.remove(matcher.node.parent.arguments[0]),
];
},
messageId: 'useToBeNull',
node: matcher.node.property,
});
} |
This is super exciting 馃榾 |
Except I missed the fact that you can chain modifiers (i.e Not a big deal since we only really check for them in |
You can only have |
Interesting. The typescript types allow it, but it fails at runtime: http://puu.sh/DYIn4/7278eb6827.png When I say "linked list" it's not anything complex, just: export const parseExpectCall = (expectCall: ExpectCall): Expectation => {
const expectation: Expectation = { expectCall };
if (!isExpectMember(expectCall.parent)) {
return expectation;
}
let node = expectCall.parent;
let previousModifier: { modifier?: ParsedExpectModifier } = expectation;
while (node.parent && isExpectMember(node.parent)) {
const member = parseExpectMember(node.parent);
if (!isParsedExpectModifier(member)) {
expectation.matcher = member;
break;
}
previousModifier = previousModifier.modifier = member;
node = node.parent;
}
return expectation;
}; It was more a bit of a shock b/c I'd not considered it, and so it wasn't in the output 馃槵 |
That should probably be a type error, yeah. The Jest team doesn't maintain those typings, but Jest's internal typings are probably wrong in this regard as well. I'll make a point to fix it before releasing Jest 25 |
Ahh I see how it is - I had a proper read over everything, and yeah that loop while nice is overkill (plus the types are murder):
So the allowed modifiers are:
However, I'll avoid "fixing" that if possible currently, and instead look into it after I've gotten the remaining rules converted & merged. But in light of this I think the typings can be a lot simpler. I have a few ideas on a couple of different ways it could be typed, and will have a play around to find out what works best :) |
Guess who got
I've now finished I expect to have a PR sometime this weekend 馃槃 (of course after saying that I realised I should re-review the guards for tests, hooks & describe 馃槀) |
This is done! Thank you to everyone who contributed, and especially @G-Rath who did all the hard work 馃帀 |
Now that typescript-eslint/typescript-eslint#425 has been released, it should be relatively straightforward to migrate.
I think porting one and one rule makes the most sense. Feel free to pick one 馃檪
consistent-test-it
- ts-migration/consistent-test-it聽#327expect-expect
- ts-migration/expect-expect聽#325lowercase-name
- chore: port lowercase-name to TypeScript聽#258no-alias-methods
no-commented-out-tests
- chore: convert to TS聽#305no-disabled-tests
- ts-migration/convert-some-utils-functions聽#315no-duplicate-hooks
- ts-migration/no-duplicate-hooks聽#318no-empty-title
no-export
- ts-migration/no-export聽#323no-focused-tests
- ts-migration/no-focused-tests聽#314no-hooks
- ts-migration/no-hooks聽#322no-identical-title
no-if
- ts-migration/no-if聽#324no-jasmine-globals
- ts-migration/convert-some-utils-functions聽#315no-jest-import
- chore: migrate no-jest-import to typescript聽#259no-large-snapshots
no-mocks-import
- ts-migration/no-mocks-import-2聽#309no-test-callback
- ts-migration/no-test-callbacks聽#321no-test-prefixes
- ts-migration/no-test-prefixes聽#328no-test-return-statement
- ts-migration/no-test-return-statement聽#320no-truthy-falsy
prefer-called-with
prefer-expect-assertions
prefer-inline-snapshots
- ts-migration/prefer-inline-snapshots聽#319prefer-spy-on
- ts-migration/prefer-spy-on聽#326prefer-strict-equal
- ts-migration/prefer-strict-equals聽#329prefer-to-be-null
prefer-to-be-undefined
prefer-to-contain
prefer-to-have-length
prefer-todo
- ts-migration/prefer-todo聽#335require-tothrow-message
valid-describe
- chore: migrate valid-describe to ts聽#308valid-expect-in-promise
valid-expect
- WIP: ts-migration/valid-expect聽#333The text was updated successfully, but these errors were encountered: