Skip to content

Enable eslint rule no-extra-boolean-cast #55137

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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@
"no-constant-condition": "off",
"no-control-regex": "off",
"no-debugger": "off",
"no-extra-boolean-cast": "off",
"no-inner-declarations": "off",
"no-useless-escape": "off",
"prefer-rest-params": "off",
Expand Down
8 changes: 4 additions & 4 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24852,7 +24852,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
if (constraintType.flags & TypeFlags.TypeParameter) {
// We're inferring from some source type S to a mapped type { [P in K]: X }, where K is a type
// parameter. First infer from 'keyof S' to K.
inferWithPriority(getIndexType(source, /*indexFlags*/ !!source.pattern ? IndexFlags.NoIndexSignatures : IndexFlags.None), constraintType, InferencePriority.MappedTypeConstraint);
inferWithPriority(getIndexType(source, /*indexFlags*/ source.pattern ? IndexFlags.NoIndexSignatures : IndexFlags.None), constraintType, InferencePriority.MappedTypeConstraint);
// If K is constrained to a type C, also infer to C. Thus, for a mapped type { [P in K]: X },
// where K extends keyof T, we make the same inferences as for a homomorphic mapped type
// { [P in keyof T]: X }. This enables us to make meaningful inferences when the target is a
Expand Down Expand Up @@ -31394,7 +31394,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {

// Lookup the private identifier lexically.
function lookupSymbolForPrivateIdentifierDeclaration(propName: __String, location: Node): Symbol | undefined {
for (let containingClass = getContainingClassExcludingClassDecorators(location); !!containingClass; containingClass = getContainingClass(containingClass)) {
for (let containingClass = getContainingClassExcludingClassDecorators(location); containingClass; containingClass = getContainingClass(containingClass)) {
const { symbol } = containingClass;
const name = getSymbolNameForPrivateIdentifier(symbol, propName);
const prop = (symbol.members && symbol.members.get(name)) || (symbol.exports && symbol.exports.get(name));
Expand Down Expand Up @@ -38551,7 +38551,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {

function setNodeLinksForPrivateIdentifierScope(node: PropertyDeclaration | PropertySignature | MethodDeclaration | MethodSignature | AccessorDeclaration) {
if (isPrivateIdentifier(node.name) && languageVersion < ScriptTarget.ESNext) {
for (let lexicalScope = getEnclosingBlockScopeContainer(node); !!lexicalScope; lexicalScope = getEnclosingBlockScopeContainer(lexicalScope)) {
for (let lexicalScope = getEnclosingBlockScopeContainer(node); lexicalScope; lexicalScope = getEnclosingBlockScopeContainer(lexicalScope)) {
getNodeLinks(lexicalScope).flags |= NodeCheckFlags.ContainsClassWithPrivateIdentifiers;
}

Expand Down Expand Up @@ -49175,7 +49175,7 @@ export function signatureHasLiteralTypes(s: Signature) {

function createBasicNodeBuilderModuleSpecifierResolutionHost(host: TypeCheckerHost): ModuleSpecifierResolutionHost & { getCommonSourceDirectory(): string } {
return {
getCommonSourceDirectory: !!(host as Program).getCommonSourceDirectory ? () => (host as Program).getCommonSourceDirectory() : () => "",
getCommonSourceDirectory: (host as Program).getCommonSourceDirectory ? () => (host as Program).getCommonSourceDirectory() : () => "",
getCurrentDirectory: () => host.getCurrentDirectory(),
getSymlinkCache: maybeBind(host, host.getSymlinkCache),
getPackageJsonInfoCache: () => host.getPackageJsonInfoCache?.(),
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2494,7 +2494,7 @@ export function convertToTSConfig(configParseResult: ParsedCommandLine, configFi
include: filterSameAsDefaultInclude(configParseResult.options.configFile.configFileSpecs.validatedIncludeSpecs),
exclude: configParseResult.options.configFile.configFileSpecs.validatedExcludeSpecs
} : {}),
compileOnSave: !!configParseResult.compileOnSave ? true : undefined
compileOnSave: configParseResult.compileOnSave ? true : undefined
};
return config;
}
Expand Down
10 changes: 5 additions & 5 deletions src/compiler/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1153,7 +1153,7 @@ export function rangeEquals<T>(array1: readonly T[], array2: readonly T[], pos:
*
* @internal
*/
export const elementAt: <T>(array: readonly T[] | undefined, offset: number) => T | undefined = !!Array.prototype.at
export const elementAt: <T>(array: readonly T[] | undefined, offset: number) => T | undefined = Array.prototype.at
? (array, offset) => array?.at(offset)
: (array, offset) => {
if (array) {
Expand Down Expand Up @@ -2058,7 +2058,7 @@ export function memoizeCached<A extends any[], T>(callback: (...args: A) => T, c
export function compose<T>(...args: ((t: T) => T)[]): (t: T) => T;
/** @internal */
export function compose<T>(a: (t: T) => T, b: (t: T) => T, c: (t: T) => T, d: (t: T) => T, e: (t: T) => T): (t: T) => T {
if (!!e) {
if (e) {
const args: ((t: T) => T)[] = [];
for (let i = 0; i < arguments.length; i++) {
args[i] = arguments[i];
Expand Down Expand Up @@ -2838,21 +2838,21 @@ export function skipWhile<T, U extends T>(array: readonly T[] | undefined, predi
*
* @internal
*/
export const trimString = !!String.prototype.trim ? ((s: string) => s.trim()) : (s: string) => trimStringEnd(trimStringStart(s));
export const trimString = String.prototype.trim ? ((s: string) => s.trim()) : (s: string) => trimStringEnd(trimStringStart(s));

/**
* Returns a copy with trailing whitespace removed.
*
* @internal
*/
export const trimStringEnd = !!String.prototype.trimEnd ? ((s: string) => s.trimEnd()) : trimEndImpl;
export const trimStringEnd = String.prototype.trimEnd ? ((s: string) => s.trimEnd()) : trimEndImpl;

/**
* Returns a copy with leading whitespace removed.
*
* @internal
*/
export const trimStringStart = !!String.prototype.trimStart ? ((s: string) => s.trimStart()) : (s: string) => s.replace(/^\s+/g, "");
export const trimStringStart = String.prototype.trimStart ? ((s: string) => s.trimStart()) : (s: string) => s.replace(/^\s+/g, "");

/**
* https://jsbench.me/gjkoxld4au/1
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/sys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1475,7 +1475,7 @@ export let sys: System = (() => {

const platform: string = _os.platform();
const useCaseSensitiveFileNames = isFileSystemCaseSensitive();
const fsRealpath = !!_fs.realpathSync.native ? process.platform === "win32" ? fsRealPathHandlingLongPath : _fs.realpathSync.native : _fs.realpathSync;
const fsRealpath = _fs.realpathSync.native ? process.platform === "win32" ? fsRealPathHandlingLongPath : _fs.realpathSync.native : _fs.realpathSync;

// If our filename is "sys.js", then we are executing unbundled on the raw tsc output.
// In that case, simulate a faked path in the directory where a bundle would normally
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/transformers/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export function getExportNeedsImportStarHelper(node: ExportDeclaration): boolean

/** @internal */
export function getImportNeedsImportStarHelper(node: ImportDeclaration): boolean {
if (!!getNamespaceDeclarationNode(node)) {
if (getNamespaceDeclarationNode(node)) {
return true;
}
const bindings = node.importClause && node.importClause.namedBindings;
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/tsbuildPublic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2027,7 +2027,7 @@ function updateOutputTimestampsWorker<T extends BuilderProgram>(
// For incremental projects, only buildinfo needs to be upto date with timestamp check
// as we dont check output files for up-to-date ness
if (!skipOutputs?.has(toPath(state, buildInfoPath))) {
if (!!state.options.verbose) reportStatus(state, verboseMessage, proj.options.configFilePath!);
if (state.options.verbose) reportStatus(state, verboseMessage, proj.options.configFilePath!);
state.host.setModifiedTime(buildInfoPath, now = getCurrentTime(state.host));
getBuildInfoCacheEntry(state, buildInfoPath, projectPath)!.modifiedTime = now;
}
Expand Down
2 changes: 1 addition & 1 deletion src/executeCommandLine/executeCommandLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ function shouldBePretty(sys: System, options: CompilerOptions | BuildOptions) {

function getOptionsForHelp(commandLine: ParsedCommandLine) {
// Sort our options by their names, (e.g. "--noImplicitAny" comes before "--watch")
return !!commandLine.options.all ?
return commandLine.options.all ?
sort(optionDeclarations, (a, b) => compareStringsCaseInsensitive(a.name, b.name)) :
filter(optionDeclarations.slice(), v => !!v.showInSimplifiedHelpView);
}
Expand Down
2 changes: 1 addition & 1 deletion src/server/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2915,7 +2915,7 @@ export class ConfiguredProject extends Project {
* @internal
*/
hasOpenRef() {
if (!!this.externalProjectRefCount) {
if (this.externalProjectRefCount) {
return true;
}

Expand Down
6 changes: 3 additions & 3 deletions src/server/scriptInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,11 @@ export class TextStorage {
* telemetry falsely indicating size 0 would be counter-productive.
*/
public getTelemetryFileSize(): number {
return !!this.fileSize
return this.fileSize
? this.fileSize
: !!this.text // Check text before svc because its length is cheaper
: this.text // Check text before svc because its length is cheaper
? this.text.length // Could be wrong if this.pendingReloadFromDisk
: !!this.svc
: this.svc
? this.svc.getSnapshot().getLength() // Could be wrong if this.pendingReloadFromDisk
: this.getSnapshot().getLength(); // Should be strictly correct
}
Expand Down
2 changes: 1 addition & 1 deletion src/services/codefixes/convertToAsyncFunction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ function transformCallbackArgument(func: Expression, hasContinuation: boolean, c

function getPossiblyAwaitedRightHandSide(checker: TypeChecker, type: Type, expr: Expression): AwaitExpression | Expression {
const rightHandSide = getSynthesizedDeepClone(expr);
return !!checker.getPromisedTypeOfPromise(type) ? factory.createAwaitExpression(rightHandSide) : rightHandSide;
return checker.getPromisedTypeOfPromise(type) ? factory.createAwaitExpression(rightHandSide) : rightHandSide;
}

function getLastCallSignature(type: Type, checker: TypeChecker): Signature | undefined {
Expand Down
4 changes: 2 additions & 2 deletions src/services/findAllReferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ export function isDeclarationOfSymbol(node: Node, target: Symbol | undefined): b
*/
function declarationIsWriteAccess(decl: Declaration): boolean {
// Consider anything in an ambient declaration to be a write access since it may be coming from JS.
if (!!(decl.flags & NodeFlags.Ambient)) return true;
if (decl.flags & NodeFlags.Ambient) return true;

switch (decl.kind) {
case SyntaxKind.BinaryExpression:
Expand Down Expand Up @@ -2664,7 +2664,7 @@ export namespace Core {
}

function isImplementation(node: Node): boolean {
return !!(node.flags & NodeFlags.Ambient) ? !(isInterfaceDeclaration(node) || isTypeAliasDeclaration(node)) :
return node.flags & NodeFlags.Ambient ? !(isInterfaceDeclaration(node) || isTypeAliasDeclaration(node)) :
(isVariableLike(node) ? hasInitializer(node) :
isFunctionLikeDeclaration(node) ? !!node.body :
isClassLike(node) || isModuleOrEnumDeclaration(node));
Expand Down
2 changes: 1 addition & 1 deletion src/services/refactors/extractSymbol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1476,7 +1476,7 @@ function extractConstantInScope(
// If no function signature, maybe there was an error, do nothing
if (!functionSignature) return { variableType, initializer };
// If the function signature has generic type parameters we don't attempt to move the parameters
if (!!functionSignature.getTypeParameters()) return { variableType, initializer };
if (functionSignature.getTypeParameters()) return { variableType, initializer };

// We add parameter types if needed
const parameters: ParameterDeclaration[] = [];
Expand Down