chore: enable `eqeqeq` lint rule (#15182)

This commit is contained in:
Simen Bekkhus 2024-07-12 09:16:53 +02:00 committed by GitHub
parent 19b3bccd16
commit afd1c202bb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 55 additions and 66 deletions

View File

@ -476,7 +476,7 @@ module.exports = {
'constructor-super': 'error',
'default-case': 'off',
'dot-notation': 'off',
eqeqeq: ['off', 'allow-null'],
eqeqeq: ['error', 'smart'],
'eslint-comments/disable-enable-pair': ['error', {allowWholeFile: true}],
'eslint-comments/no-unused-disable': 'error',
'func-names': 'off',

View File

@ -789,7 +789,7 @@ For example, let's say that `drinkFlavor` is coded like this:
```js
function drinkFlavor(flavor) {
if (flavor == 'octopus') {
if (flavor === 'octopus') {
throw new DisgustingFlavorError('yuck, octopus flavor');
}
// Do some other stuff
@ -827,7 +827,7 @@ For example, let's say you have a `drinkFlavor` function that throws whenever th
```js
function drinkFlavor(flavor) {
if (flavor == 'octopus') {
if (flavor === 'octopus') {
throw new DisgustingFlavorError('yuck, octopus flavor');
}
// Do some other stuff
@ -1505,7 +1505,7 @@ expect.extend({
expect.extend({
async toBeDivisibleByExternalValue(received) {
const externalValue = await getExternalValueFromRemoteSource();
const pass = received % externalValue == 0;
const pass = received % externalValue === 0;
if (pass) {
return {
message: () =>

View File

@ -46,28 +46,28 @@ describe('JSON Reporter', () => {
expect(jsonResult.numPendingTests).toBe(1);
const noAncestors = jsonResult.testResults[0].assertionResults.find(
item => item.title == 'no ancestors',
item => item.title === 'no ancestors',
);
let expected = {ancestorTitles: [] as Array<string>};
expect(noAncestors).toEqual(expect.objectContaining(expected));
expect(noAncestors).toHaveProperty('duration', expect.any(Number));
const addsNumbers = jsonResult.testResults[0].assertionResults.find(
item => item.title == 'adds numbers',
item => item.title === 'adds numbers',
);
expected = {ancestorTitles: ['sum']};
expect(addsNumbers).toEqual(expect.objectContaining(expected));
expect(addsNumbers).toHaveProperty('duration', expect.any(Number));
const failsTheTest = jsonResult.testResults[0].assertionResults.find(
item => item.title == 'fails the test',
item => item.title === 'fails the test',
);
expected = {ancestorTitles: ['sum', 'failing tests']};
expect(failsTheTest).toEqual(expect.objectContaining(expected));
expect(failsTheTest).toHaveProperty('duration', expect.any(Number));
const skipedTest = jsonResult.testResults[0].assertionResults.find(
item => item.title == 'skipped test',
item => item.title === 'skipped test',
);
expect(skipedTest).toHaveProperty('duration', null);
});
@ -99,19 +99,19 @@ describe('JSON Reporter', () => {
expect(jsonResult.numPendingTests).toBe(1);
const noAncestors = jsonResult.testResults[0].assertionResults.find(
item => item.title == 'no ancestors',
item => item.title === 'no ancestors',
);
let expected = {ancestorTitles: [] as Array<string>};
expect(noAncestors).toEqual(expect.objectContaining(expected));
const addsNumbers = jsonResult.testResults[0].assertionResults.find(
item => item.title == 'adds numbers',
item => item.title === 'adds numbers',
);
expected = {ancestorTitles: ['sum']};
expect(addsNumbers).toEqual(expect.objectContaining(expected));
const failsTheTest = jsonResult.testResults[0].assertionResults.find(
item => item.title == 'fails the test',
item => item.title === 'fails the test',
);
expected = {ancestorTitles: ['sum', 'failing tests']};
expect(failsTheTest).toEqual(expect.objectContaining(expected));

View File

@ -84,7 +84,7 @@ function eq(
}
if (a instanceof Error && b instanceof Error) {
return a.message == b.message;
return a.message === b.message;
}
if (Object.is(a, b)) {
@ -95,7 +95,7 @@ function eq(
return false;
}
const className = Object.prototype.toString.call(a);
if (className != Object.prototype.toString.call(b)) {
if (className !== Object.prototype.toString.call(b)) {
return false;
}
switch (className) {
@ -116,7 +116,7 @@ function eq(
// Coerce dates to numeric primitive values. Dates are compared by their
// millisecond representations. Note that invalid dates with millisecond representations
// of `NaN` are not equivalent.
return +a == +b;
return +a === +b;
// RegExps are compared by their source patterns and flags.
case '[object RegExp]':
return a.source === b.source && a.flags === b.flags;
@ -151,7 +151,7 @@ function eq(
bStack.push(b);
// Recursively compare objects and arrays.
// Compare array lengths to determine if a deep comparison is necessary.
if (strictCheck && className == '[object Array]' && a.length !== b.length) {
if (strictCheck && className === '[object Array]' && a.length !== b.length) {
return false;
}

View File

@ -41,18 +41,6 @@ const utils = Object.freeze({
subsetEquality,
});
function getPrototype(obj: object) {
if (Object.getPrototypeOf) {
return Object.getPrototypeOf(obj);
}
if (obj.constructor.prototype == obj) {
return null;
}
return obj.constructor.prototype;
}
export function hasProperty(
obj: object | null,
property: string | symbol,
@ -65,7 +53,7 @@ export function hasProperty(
return true;
}
return hasProperty(getPrototype(obj), property);
return hasProperty(Object.getPrototypeOf(obj), property);
}
export abstract class AsymmetricMatcher<T>
@ -108,35 +96,35 @@ class Any extends AsymmetricMatcher<any> {
}
asymmetricMatch(other: unknown) {
if (this.sample == String) {
return typeof other == 'string' || other instanceof String;
if (this.sample === String) {
return typeof other === 'string' || other instanceof String;
}
if (this.sample == Number) {
return typeof other == 'number' || other instanceof Number;
if (this.sample === Number) {
return typeof other === 'number' || other instanceof Number;
}
if (this.sample == Function) {
return typeof other == 'function' || other instanceof Function;
if (this.sample === Function) {
return typeof other === 'function' || other instanceof Function;
}
if (this.sample == Boolean) {
return typeof other == 'boolean' || other instanceof Boolean;
if (this.sample === Boolean) {
return typeof other === 'boolean' || other instanceof Boolean;
}
if (this.sample == BigInt) {
return typeof other == 'bigint' || other instanceof BigInt;
if (this.sample === BigInt) {
return typeof other === 'bigint' || other instanceof BigInt;
}
if (this.sample == Symbol) {
return typeof other == 'symbol' || other instanceof Symbol;
if (this.sample === Symbol) {
return typeof other === 'symbol' || other instanceof Symbol;
}
if (this.sample == Object) {
return typeof other == 'object';
if (this.sample === Object) {
return typeof other === 'object';
}
if (this.sample == Array) {
if (this.sample === Array) {
return Array.isArray(other);
}
@ -148,27 +136,27 @@ class Any extends AsymmetricMatcher<any> {
}
override getExpectedType() {
if (this.sample == String) {
if (this.sample === String) {
return 'string';
}
if (this.sample == Number) {
if (this.sample === Number) {
return 'number';
}
if (this.sample == Function) {
if (this.sample === Function) {
return 'function';
}
if (this.sample == Object) {
if (this.sample === Object) {
return 'object';
}
if (this.sample == Boolean) {
if (this.sample === Boolean) {
return 'boolean';
}
if (Array.isArray(this.sample)) {
if (this.sample === Array) {
return 'array';
}

View File

@ -105,7 +105,7 @@ jest.mock('graceful-fs', () => {
]),
0,
);
} else if (slash(dir) == '/error') {
} else if (slash(dir) === '/error') {
setTimeout(() => callback({code: 'ENOTDIR'}, undefined), 0);
}
}),

View File

@ -48,7 +48,7 @@ export async function run(
return;
}
if (argv.version == true) {
if (argv.version === true) {
console.log(`v${VERSION}\n`);
return;
}

View File

@ -24,14 +24,14 @@ export default function wrapAnsiString(
while ((match = ANSI_REGEXP.exec(string))) {
const ansi = match[0];
const index = match.index;
if (index != lastIndex) {
if (index !== lastIndex) {
tokens.push(['string', string.slice(lastIndex, index)]);
}
tokens.push(['ansi', ansi]);
lastIndex = index + ansi.length;
}
if (lastIndex != string.length - 1) {
if (lastIndex !== string.length - 1) {
tokens.push(['string', string.slice(lastIndex, string.length)]);
}

View File

@ -202,9 +202,10 @@ export default class TestSequencer {
const failedA = this.hasFailed(testA);
const failedB = this.hasFailed(testB);
const hasTimeA = testA.duration != null;
const hasTimeB = testB.duration != null;
if (failedA !== failedB) {
return failedA ? -1 : 1;
} else if (hasTimeA != (testB.duration != null)) {
} else if (hasTimeA !== hasTimeB) {
// If only one of two tests has timing information, run it last
return hasTimeA ? 1 : -1;
} else if (testA.duration != null && testB.duration != null) {

View File

@ -811,7 +811,7 @@ For example, let's say that `drinkFlavor` is coded like this:
```js
function drinkFlavor(flavor) {
if (flavor == 'octopus') {
if (flavor === 'octopus') {
throw new DisgustingFlavorError('yuck, octopus flavor');
}
// Do some other stuff
@ -849,7 +849,7 @@ For example, let's say you have a `drinkFlavor` function that throws whenever th
```js
function drinkFlavor(flavor) {
if (flavor == 'octopus') {
if (flavor === 'octopus') {
throw new DisgustingFlavorError('yuck, octopus flavor');
}
// Do some other stuff
@ -1527,7 +1527,7 @@ expect.extend({
expect.extend({
async toBeDivisibleByExternalValue(received) {
const externalValue = await getExternalValueFromRemoteSource();
const pass = received % externalValue == 0;
const pass = received % externalValue === 0;
if (pass) {
return {
message: () =>

View File

@ -811,7 +811,7 @@ For example, let's say that `drinkFlavor` is coded like this:
```js
function drinkFlavor(flavor) {
if (flavor == 'octopus') {
if (flavor === 'octopus') {
throw new DisgustingFlavorError('yuck, octopus flavor');
}
// Do some other stuff
@ -849,7 +849,7 @@ For example, let's say you have a `drinkFlavor` function that throws whenever th
```js
function drinkFlavor(flavor) {
if (flavor == 'octopus') {
if (flavor === 'octopus') {
throw new DisgustingFlavorError('yuck, octopus flavor');
}
// Do some other stuff
@ -1527,7 +1527,7 @@ expect.extend({
expect.extend({
async toBeDivisibleByExternalValue(received) {
const externalValue = await getExternalValueFromRemoteSource();
const pass = received % externalValue == 0;
const pass = received % externalValue === 0;
if (pass) {
return {
message: () =>

View File

@ -811,7 +811,7 @@ For example, let's say that `drinkFlavor` is coded like this:
```js
function drinkFlavor(flavor) {
if (flavor == 'octopus') {
if (flavor === 'octopus') {
throw new DisgustingFlavorError('yuck, octopus flavor');
}
// Do some other stuff
@ -849,7 +849,7 @@ For example, let's say you have a `drinkFlavor` function that throws whenever th
```js
function drinkFlavor(flavor) {
if (flavor == 'octopus') {
if (flavor === 'octopus') {
throw new DisgustingFlavorError('yuck, octopus flavor');
}
// Do some other stuff
@ -1527,7 +1527,7 @@ expect.extend({
expect.extend({
async toBeDivisibleByExternalValue(received) {
const externalValue = await getExternalValueFromRemoteSource();
const pass = received % externalValue == 0;
const pass = received % externalValue === 0;
if (pass) {
return {
message: () =>

View File

@ -811,7 +811,7 @@ For example, let's say that `drinkFlavor` is coded like this:
```js
function drinkFlavor(flavor) {
if (flavor == 'octopus') {
if (flavor === 'octopus') {
throw new DisgustingFlavorError('yuck, octopus flavor');
}
// Do some other stuff
@ -849,7 +849,7 @@ For example, let's say you have a `drinkFlavor` function that throws whenever th
```js
function drinkFlavor(flavor) {
if (flavor == 'octopus') {
if (flavor === 'octopus') {
throw new DisgustingFlavorError('yuck, octopus flavor');
}
// Do some other stuff
@ -1527,7 +1527,7 @@ expect.extend({
expect.extend({
async toBeDivisibleByExternalValue(received) {
const externalValue = await getExternalValueFromRemoteSource();
const pass = received % externalValue == 0;
const pass = received % externalValue === 0;
if (pass) {
return {
message: () =>