Skip to content

Commit

Permalink
chore: enable eqeqeq internally (#6228)
Browse files Browse the repository at this point in the history
* chore: enable eqeqeq internally

* Switch to null: never

* Why not add some test coverage
  • Loading branch information
JoshuaKGoldberg committed Jan 31, 2023
1 parent 2c61bdb commit fbe811c
Show file tree
Hide file tree
Showing 38 changed files with 89 additions and 57 deletions.
7 changes: 7 additions & 0 deletions .eslintrc.js
Expand Up @@ -106,6 +106,13 @@ module.exports = {
//

curly: ['error', 'all'],
eqeqeq: [
'error',
'always',
{
null: 'never',
},
],
'no-mixed-operators': 'error',
'no-console': 'error',
'no-process-exit': 'error',
Expand Down
Expand Up @@ -65,7 +65,7 @@ export default util.createRule({
case AST_NODE_TYPES.TSDeclareFunction:
case AST_NODE_TYPES.FunctionDeclaration: {
const name = member.id?.name ?? null;
if (name === null) {
if (name == null) {
return null;
}
return {
Expand Down Expand Up @@ -143,7 +143,7 @@ export default util.createRule({

members.forEach(member => {
const method = getMemberMethod(member);
if (method === null) {
if (method == null) {
lastMethod = null;
return;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/ban-types.ts
Expand Up @@ -36,7 +36,7 @@ function stringifyNode(
function getCustomMessage(
bannedType: null | string | { message?: string; fixWith?: string },
): string {
if (bannedType === null) {
if (bannedType == null) {
return '';
}

Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/comma-spacing.ts
Expand Up @@ -68,7 +68,7 @@ export default createRule<Options, MessageIds>({
let previousToken = sourceCode.getFirstToken(node);
for (const element of node.elements) {
let token: TSESTree.Token | null;
if (element === null) {
if (element == null) {
token = sourceCode.getTokenAfter(previousToken!);
if (token && isCommaToken(token)) {
ignoredTokens.add(token);
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-plugin/src/rules/member-ordering.ts
Expand Up @@ -489,7 +489,7 @@ function getRank(
): number {
const type = getNodeType(node);

if (type === null) {
if (type == null) {
// shouldn't happen but just in case, put it on the end
return orderConfig.length - 1;
}
Expand Down Expand Up @@ -842,7 +842,7 @@ export default util.createRule<Options, MessageIds>({
supportsModifiers,
);

if (grouped === null) {
if (grouped == null) {
return false;
}

Expand Down
Expand Up @@ -101,25 +101,25 @@ function createValidator(
let name: string | null = originalName;

name = validateUnderscore('leading', config, name, node, originalName);
if (name === null) {
if (name == null) {
// fail
return;
}

name = validateUnderscore('trailing', config, name, node, originalName);
if (name === null) {
if (name == null) {
// fail
return;
}

name = validateAffix('prefix', config, name, node, originalName);
if (name === null) {
if (name == null) {
// fail
return;
}

name = validateAffix('suffix', config, name, node, originalName);
if (name === null) {
if (name == null) {
// fail
return;
}
Expand Down Expand Up @@ -383,7 +383,7 @@ function createValidator(
modifiers: Set<Modifiers>,
): boolean {
const formats = config.format;
if (formats === null || formats.length === 0) {
if (!formats?.length) {
return true;
}

Expand Down Expand Up @@ -427,7 +427,7 @@ function isCorrectType(
context: Context,
selector: Selectors,
): boolean {
if (config.types === null) {
if (config.types == null) {
return true;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-plugin/src/rules/naming-convention.ts
Expand Up @@ -271,7 +271,7 @@ export default util.createRule<Options, MessageIds>({
| TSESTree.FunctionExpression,
): void {
const validator = validators.function;
if (!validator || node.id === null) {
if (!validator || node.id == null) {
return;
}

Expand Down Expand Up @@ -491,7 +491,7 @@ export default util.createRule<Options, MessageIds>({
}

const id = node.id;
if (id === null) {
if (id == null) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/no-implied-eval.ts
Expand Up @@ -135,7 +135,7 @@ export default util.createRule({
node: TSESTree.NewExpression | TSESTree.CallExpression,
): void {
const calleeName = getCalleeName(node.callee);
if (calleeName === null) {
if (calleeName == null) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/no-inferrable-types.ts
Expand Up @@ -147,7 +147,7 @@ export default util.createRule<Options, MessageIds>({
}

case AST_NODE_TYPES.TSNullKeyword:
return init.type === AST_NODE_TYPES.Literal && init.value === null;
return init.type === AST_NODE_TYPES.Literal && init.value == null;

case AST_NODE_TYPES.TSStringKeyword:
return (
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/no-loss-of-precision.ts
Expand Up @@ -25,7 +25,7 @@ export default util.createRule<Options, MessageIds>({
},
defaultOptions: [],
create(context) {
/* istanbul ignore if */ if (baseRule === null) {
/* istanbul ignore if */ if (baseRule == null) {
throw new Error(
'@typescript-eslint/no-loss-of-precision requires at least ESLint v7.1.0',
);
Expand Down
6 changes: 3 additions & 3 deletions packages/eslint-plugin/src/rules/no-misused-promises.ts
Expand Up @@ -250,7 +250,7 @@ export default util.createRule<Options, MessageId>({

function checkVariableDeclaration(node: TSESTree.VariableDeclarator): void {
const tsNode = parserServices.esTreeNodeToTSNodeMap.get(node);
if (tsNode.initializer === undefined || node.init === null) {
if (tsNode.initializer === undefined || node.init == null) {
return;
}
const varType = checker.getTypeAtLocation(tsNode.name);
Expand Down Expand Up @@ -344,7 +344,7 @@ export default util.createRule<Options, MessageId>({

function checkReturnStatement(node: TSESTree.ReturnStatement): void {
const tsNode = parserServices.esTreeNodeToTSNodeMap.get(node);
if (tsNode.expression === undefined || node.argument === null) {
if (tsNode.expression === undefined || node.argument == null) {
return;
}
const contextualType = checker.getContextualType(tsNode.expression);
Expand All @@ -368,7 +368,7 @@ export default util.createRule<Options, MessageId>({
const tsNode = parserServices.esTreeNodeToTSNodeMap.get(node);
const value = tsNode.initializer;
if (
node.value === null ||
node.value == null ||
value === undefined ||
!ts.isJsxExpression(value) ||
value.expression === undefined
Expand Down
Expand Up @@ -27,7 +27,7 @@ function isDefinitionWithAssignment(definition: Definition): boolean {

const variableDeclarator = definition.node;
return (
variableDeclarator.definite === true || variableDeclarator.init !== null
variableDeclarator.definite === true || variableDeclarator.init != null
);
}

Expand Down
Expand Up @@ -384,7 +384,7 @@ export default createRule<Options, MessageId>({
| TSESTree.ForStatement
| TSESTree.WhileStatement,
): void {
if (node.test === null) {
if (node.test == null) {
// e.g. `for(;;)`
return;
}
Expand Down
Expand Up @@ -53,7 +53,7 @@ export default util.createRule({

const alias = tryGetAliasedSymbol(symbol, checker);

return alias !== null && symbolIsNamespaceInScope(alias);
return alias != null && symbolIsNamespaceInScope(alias);
}

function getSymbolInScope(
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-plugin/src/rules/no-use-before-define.ts
Expand Up @@ -21,7 +21,7 @@ function parseOptions(options: string | Config | null): Required<Config> {

if (typeof options === 'string') {
functions = options !== 'nofunc';
} else if (typeof options === 'object' && options !== null) {
} else if (typeof options === 'object' && options != null) {
functions = options.functions !== false;
classes = options.classes !== false;
enums = options.enums !== false;
Expand Down Expand Up @@ -64,7 +64,7 @@ function isOuterEnum(
reference: TSESLint.Scope.Reference,
): boolean {
return (
variable.defs[0].type == DefinitionType.TSEnumName &&
variable.defs[0].type === DefinitionType.TSEnumName &&
variable.scope.variableScope !== reference.from.variableScope
);
}
Expand Down
8 changes: 3 additions & 5 deletions packages/eslint-plugin/src/rules/prefer-for-of.ts
Expand Up @@ -24,8 +24,7 @@ export default util.createRule({
node: TSESTree.Node | null,
): node is TSESTree.VariableDeclaration {
return (
node !== null &&
node.type === AST_NODE_TYPES.VariableDeclaration &&
node?.type === AST_NODE_TYPES.VariableDeclaration &&
node.kind !== 'const' &&
node.declarations.length === 1
);
Expand All @@ -39,7 +38,7 @@ export default util.createRule({
}

function isZeroInitialized(node: TSESTree.VariableDeclarator): boolean {
return node.init !== null && isLiteral(node.init, 0);
return node.init != null && isLiteral(node.init, 0);
}

function isMatchingIdentifier(
Expand All @@ -54,8 +53,7 @@ export default util.createRule({
name: string,
): TSESTree.Expression | null {
if (
node !== null &&
node.type === AST_NODE_TYPES.BinaryExpression &&
node?.type === AST_NODE_TYPES.BinaryExpression &&
node.operator === '<' &&
isMatchingIdentifier(node.left, name) &&
node.right.type === AST_NODE_TYPES.MemberExpression &&
Expand Down
5 changes: 2 additions & 3 deletions packages/eslint-plugin/src/rules/prefer-function-type.ts
Expand Up @@ -82,8 +82,7 @@ export default util.createRule({
typeof member.returnType !== 'undefined'
) {
if (
tsThisTypes !== null &&
tsThisTypes.length > 0 &&
tsThisTypes?.length &&
node.type === AST_NODE_TYPES.TSInterfaceDeclaration
) {
// the message can be confusing if we don't point directly to the `this` node instead of the whole member
Expand Down Expand Up @@ -205,7 +204,7 @@ export default util.createRule({
// inside an interface keep track of all ThisType references.
// unless it's inside a nested type literal in which case it's invalid code anyway
// we don't want to incorrectly say "it refers to name" while typescript says it's completely invalid.
if (literalNesting === 0 && tsThisTypes !== null) {
if (literalNesting === 0 && tsThisTypes != null) {
tsThisTypes.push(node);
}
},
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/prefer-includes.ts
Expand Up @@ -38,7 +38,7 @@ export default createRule({

function isNumber(node: TSESTree.Node, value: number): boolean {
const evaluated = getStaticValue(node, globalScope);
return evaluated !== null && evaluated.value === value;
return evaluated != null && evaluated.value === value;
}

function isPositiveCheck(node: TSESTree.BinaryExpression): boolean {
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/prefer-regexp-exec.ts
Expand Up @@ -123,7 +123,7 @@ export default createRule({

if (
argumentNode.type === AST_NODE_TYPES.Literal &&
typeof argumentNode.value == 'string'
typeof argumentNode.value === 'string'
) {
const regExp = RegExp(argumentNode.value);
return context.report({
Expand Down
Expand Up @@ -60,7 +60,7 @@ export default createRule({
*/
function isNull(node: TSESTree.Node): node is TSESTree.Literal {
const evaluated = getStaticValue(node, globalScope);
return evaluated != null && evaluated.value === null;
return evaluated != null && evaluated.value == null;
}

/**
Expand Down
Expand Up @@ -121,7 +121,7 @@ export default createRule({
const unionTypes = unionTypeParts(discriminantType);
const caseTypes: Set<ts.Type> = new Set();
for (const switchCase of node.cases) {
if (switchCase.test === null) {
if (switchCase.test == null) {
// Switch has 'default' branch - do nothing.
return;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/triple-slash-reference.ts
Expand Up @@ -87,7 +87,7 @@ export default util.createRule<Options, MessageIds>({
}
},
Program(node): void {
if (lib === 'always' && path === 'always' && types == 'always') {
if (lib === 'always' && path === 'always' && types === 'always') {
return;
}
programNode = node;
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/util/isNullLiteral.ts
Expand Up @@ -2,5 +2,5 @@ import type { TSESTree } from '@typescript-eslint/utils';
import { AST_NODE_TYPES } from '@typescript-eslint/utils';

export function isNullLiteral(i: TSESTree.Node): boolean {
return i.type === AST_NODE_TYPES.Literal && i.value === null;
return i.type === AST_NODE_TYPES.Literal && i.value == null;
}
2 changes: 1 addition & 1 deletion packages/eslint-plugin/tests/rules/indent/indent.test.ts
Expand Up @@ -638,7 +638,7 @@ type Foo = string | {
})
.filter(
(error): error is TSESLint.TestCaseError<MessageIds> =>
error !== null,
error != null,
),
};
if (invalid.errors.length > 0) {
Expand Down
Expand Up @@ -1083,7 +1083,7 @@ function addOptional<
function makeOptional(code: string): string;
function makeOptional(code: string | null | undefined): string | null;
function makeOptional(code: string | null | undefined): string | null {
if (code === null || code === undefined) {
if (code == null) {
return null;
}
return (
Expand Down
2 changes: 1 addition & 1 deletion packages/scope-manager/src/ScopeManager.ts
Expand Up @@ -140,7 +140,7 @@ class ScopeManager {
protected nestScope<T extends Scope>(scope: T): T;
protected nestScope(scope: Scope): Scope {
if (scope instanceof GlobalScope) {
assert(this.currentScope === null);
assert(this.currentScope == null);
this.globalScope = scope;
}
this.currentScope = scope;
Expand Down
2 changes: 1 addition & 1 deletion packages/scope-manager/src/referencer/ClassVisitor.ts
Expand Up @@ -163,7 +163,7 @@ class ClassVisitor extends Visitor {
* }
*/
if (
keyName !== null &&
keyName != null &&
this.#classNode.body.body.find(
(node): node is TSESTree.MethodDefinition =>
node !== methodNode &&
Expand Down
5 changes: 1 addition & 4 deletions packages/scope-manager/src/referencer/PatternVisitor.ts
Expand Up @@ -97,10 +97,7 @@ class PatternVisitor extends VisitorBase {

this.#callback(pattern, {
topLevel: pattern === this.#rootPattern,
rest:
lastRestElement !== null &&
lastRestElement !== undefined &&
lastRestElement.argument === pattern,
rest: lastRestElement != null && lastRestElement.argument === pattern,
assignments: this.#assignments,
});
}
Expand Down
4 changes: 2 additions & 2 deletions packages/scope-manager/src/referencer/Referencer.ts
Expand Up @@ -124,7 +124,7 @@ class Referencer extends Visitor {
}

private referenceJsxPragma(): void {
if (this.#jsxPragma === null || this.#hasReferencedJsxFactory) {
if (this.#jsxPragma == null || this.#hasReferencedJsxFactory) {
return;
}
this.#hasReferencedJsxFactory = this.referenceInSomeUpperScope(
Expand All @@ -134,7 +134,7 @@ class Referencer extends Visitor {

private referenceJsxFragment(): void {
if (
this.#jsxFragmentName === null ||
this.#jsxFragmentName == null ||
this.#hasReferencedJsxFragmentFactory
) {
return;
Expand Down

0 comments on commit fbe811c

Please sign in to comment.