-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Chore(eslint):- Turned no-implicit-coercion
rule to error and fixed all the occurrences
#12476
Conversation
It's not a huge deal, don't sweat it! 😀 Ah, you found a lint rule! Sweet. It seems there are still errors reported by it 🙂 |
@@ -16,7 +16,7 @@ const objs = [ | |||
null, | |||
[0, true, '2', [3.14, {}, null]], | |||
{key1: 'foo', key2: 'bar', key3: {array: [null, {}]}}, | |||
{minusInf: -Infinity, nan: NaN, plusInf: +Infinity}, | |||
{minusInf: Number(Infinity), nan: NaN, plusInf: +Infinity}, |
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.
negative infinity is a valid thing
you could put here Number.NEGATIVE_INFINITY
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.
and Number.POSITIVE_INFINITY
for plusInf
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.
sure
@@ -81,7 +81,9 @@ export default function shouldInstrument( | |||
} | |||
|
|||
if ( | |||
config.coveragePathIgnorePatterns.some(pattern => !!filename.match(pattern)) | |||
config.coveragePathIgnorePatterns.some(pattern => |
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.
Is something putting stuff onto the next line maybe?
these changes do not seem related to the rule itself
I don't mind it, but am wondering if you are using some autofix for this
@@ -64,7 +64,7 @@ function createProcessEnv(): NodeJS.ProcessEnv { | |||
get: isWin32 ? getPropertyWin32 : getProperty, | |||
|
|||
set(_target, key, value) { | |||
const strValue = '' + value; | |||
const strValue = '' + String(value); |
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 seems weird
'' +
will end up as string anyway
maybe just leave String(value)
packages/pretty-format/src/index.ts
Outdated
@@ -128,7 +128,7 @@ function printBasicValue( | |||
escapeString: boolean, | |||
): string | null { | |||
if (val === true || val === false) { | |||
return '' + val; | |||
return '' + String(val); |
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.
Same here, I think you should drop the '' +
part
Yeah i am working on it |
Lots of these |
thanks for that |
@SimenB getting partial errors with Ci anything you can suggest?😐😐 |
It means some behaviour changed I guess |
@SimenB this is good to go , finally was able to made it work :-) |
packages/expect-utils/src/utils.ts
Outdated
@@ -137,7 +137,7 @@ export const getObjectSubset = ( | |||
const IteratorSymbol = Symbol.iterator; | |||
|
|||
const hasIterator = (object: any) => | |||
!!(object != null && object[IteratorSymbol]); | |||
Boolean(object != null && object[IteratorSymbol]); |
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.
object != null
already yields boolean, so it is wrong
you want something like object != null && Boolean(object[IteratorSymbol]);
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 sure
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 think we should do object != null && object[IteratorSymbol] != null
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.
yeah i am sort of confused but this looks good
@@ -109,7 +109,7 @@ it('exposes an equality function to custom matchers', () => { | |||
jestExpect.extend({ | |||
toBeOne() { | |||
expect(this.equals).toBe(equals); | |||
return {pass: !!this.equals(1, 1)}; | |||
return {pass: Boolean(this.equals(1, 1))}; |
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 expect from something that is named like equals
to already return boolean :)
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.
then what should i do here?
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.
that was just a comment that naming of the function is ambiguous, but if it does not return a boolean you did then what you had to
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.equals
does return a boolean, so just remove the !!
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.
sure
@@ -27,7 +27,7 @@ const activeFilters = ( | |||
|
|||
const messages = ['\n' + chalk.bold('Active Filters: ') + filters]; | |||
|
|||
return messages.filter(message => !!message).join(delimiter); | |||
return messages.filter(message => Boolean(message)).join(delimiter); |
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 could have this shorter and receiveBoolean
wrapper as a reference
something like
return messages.filter(Boolean).join(delimiter);
but I guess ts will complain because signatures do not match?
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.
yes i tried to do that 😀
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 think a return messages.filter(message => message.length > 0).join(delimiter);
is better
EOL + | ||
'' + | ||
' */'; | ||
String( |
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 looks like a pure mess :)
I think what you need here is to just wrap EOL
in String wrapper
like String(EOL)
and leave the rest as is
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 sure 😀
'' + | ||
' */'; | ||
String( | ||
String(String('/**' + EOL) + ' * @team foo' + EOL) + |
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.
same here, from readability perspective this is not good
try to wrap just EOL
instances like String(EOL)
@@ -98,10 +98,10 @@ export default class Spec { | |||
static pendingSpecExceptionMessage: string; | |||
|
|||
static isPendingSpecException(e: Error) { | |||
return !!( | |||
return Boolean( |
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 is one eslint rule which imho would help with code blocks with lots of operators
https://eslint.org/docs/rules/operator-linebreak
so it would look like
e
&& e.toString
&& e.toString()...
having stuff at the start of the line is usually easier to keep cognitive complexity on the brain in place.
You can negotiate it with Simen if he wants it, it would be a good issue if you want to tackle it
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.
yeah sure let me just clear this one and then discuss with simen 😀
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.
e.toString?.().includes(Spec.pendingSpecExceptionMessage)
or something probably, but just disable the rule in this (and other packages/jest-jasmine2/src/jasmine/*.ts
files) - they're forked from jasmine and can remain a bit messy 🙂
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.
@SimenB disable no-implicit-coercion
rule?
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.
yes, in this and the other jasmine files
I don't like |
I personally find this rule more noisy than useful :) |
I'm a fan of getting rid of double bangs (they're quite unreadable and very JS specific) in favour of more explicit checks |
@SimenB done :-) with the suggested changes |
@@ -5,4 +5,4 @@ | |||
* LICENSE file in the root directory of this source tree. | |||
*/ | |||
|
|||
globalThis.describeDefined = !!globalThis.describe; | |||
globalThis.describeDefined = Boolean(globalThis.describe); |
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, and other Boolean
should be != null
as mentioned
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
first of all, sorry @SimenB, I messed up my last PR and it's my fault and I know how much annoying this becomes, I will try my best not to repeat this mistake
this PR is extended of #12457, and the rule of
no-implicit-coercion
was already added , i turned it toerror
and fixed the occurrences