This repository has been archived by the owner on Jun 16, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
4a53a77
commit 96c0eef
Showing
23,585 changed files
with
3,088,908 additions
and
3 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...db43bc05d667ada3fcd8e4bbece2847684cfea95a01e30db9c3868cc3c106c118513973c630b7a64aeec274c7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict'; | ||
|
||
var testArray = function testArray(t, actual, expected, msg) { | ||
t.deepEqual(actual, expected, msg); | ||
t.equal(actual.length, expected.length, 'expected ' + expected.length + ', got ' + actual.length); | ||
}; | ||
|
||
module.exports = function (flat, t) { | ||
t.test('flattens', function (st) { | ||
testArray(st, flat([1, [2], [[3]], [[['four']]]]), [1, 2, [3], [['four']]], 'missing depth only flattens 1 deep'); | ||
|
||
testArray(st, flat([1, [2], [[3]], [[['four']]]], 1), [1, 2, [3], [['four']]], 'depth of 1 only flattens 1 deep'); | ||
st.notDeepEqual(flat([1, [2], [[3]], [[['four']]]], 1), [1, 2, 3, ['four']], 'depth of 1 only flattens 1 deep: sanity check'); | ||
|
||
testArray(st, flat([1, [2], [[3]], [[['four']]]], 2), [1, 2, 3, ['four']], 'depth of 2 only flattens 2 deep'); | ||
st.notDeepEqual(flat([1, [2], [[3]], [[['four']]]], 2), [1, 2, 3, 'four'], 'depth of 2 only flattens 2 deep: sanity check'); | ||
|
||
testArray(st, flat([1, [2], [[3]], [[['four']]]], 3), [1, 2, 3, 'four'], 'depth of 3 only flattens 3 deep'); | ||
testArray(st, flat([1, [2], [[3]], [[['four']]]], Infinity), [1, 2, 3, 'four'], 'depth of Infinity flattens all the way'); | ||
|
||
st.end(); | ||
}); | ||
|
||
t.test('sparse arrays', function (st) { | ||
// eslint-disable-next-line no-sparse-arrays | ||
st.deepEqual(flat([, [1]]), flat([[], [1]]), 'an array hole is treated the same as an empty array'); | ||
|
||
st.end(); | ||
}); | ||
}; |
29 changes: 29 additions & 0 deletions
29
...d24403d1e1fcb694e8c3c7cd5019b0ba04e57c4c4f0d358886d8cfba709e05619f45cbb6d1f89031a3acbc4a8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { concat as concatStatic } from '../observable/concat'; | ||
import { Observable } from '../Observable'; | ||
import { ObservableInput, OperatorFunction, MonoTypeOperatorFunction, SchedulerLike } from '../types'; | ||
|
||
/* tslint:disable:max-line-length */ | ||
/** @deprecated Deprecated in favor of static concat. */ | ||
export function concat<T>(scheduler?: SchedulerLike): MonoTypeOperatorFunction<T>; | ||
/** @deprecated Deprecated in favor of static concat. */ | ||
export function concat<T, T2>(v2: ObservableInput<T2>, scheduler?: SchedulerLike): OperatorFunction<T, T | T2>; | ||
/** @deprecated Deprecated in favor of static concat. */ | ||
export function concat<T, T2, T3>(v2: ObservableInput<T2>, v3: ObservableInput<T3>, scheduler?: SchedulerLike): OperatorFunction<T, T | T2 | T3>; | ||
/** @deprecated Deprecated in favor of static concat. */ | ||
export function concat<T, T2, T3, T4>(v2: ObservableInput<T2>, v3: ObservableInput<T3>, v4: ObservableInput<T4>, scheduler?: SchedulerLike): OperatorFunction<T, T | T2 | T3 | T4>; | ||
/** @deprecated Deprecated in favor of static concat. */ | ||
export function concat<T, T2, T3, T4, T5>(v2: ObservableInput<T2>, v3: ObservableInput<T3>, v4: ObservableInput<T4>, v5: ObservableInput<T5>, scheduler?: SchedulerLike): OperatorFunction<T, T | T2 | T3 | T4 | T5>; | ||
/** @deprecated Deprecated in favor of static concat. */ | ||
export function concat<T, T2, T3, T4, T5, T6>(v2: ObservableInput<T2>, v3: ObservableInput<T3>, v4: ObservableInput<T4>, v5: ObservableInput<T5>, v6: ObservableInput<T6>, scheduler?: SchedulerLike): OperatorFunction<T, T | T2 | T3 | T4 | T5 | T6>; | ||
/** @deprecated Deprecated in favor of static concat. */ | ||
export function concat<T>(...observables: Array<ObservableInput<T> | SchedulerLike>): MonoTypeOperatorFunction<T>; | ||
/** @deprecated Deprecated in favor of static concat. */ | ||
export function concat<T, R>(...observables: Array<ObservableInput<any> | SchedulerLike>): OperatorFunction<T, R>; | ||
/* tslint:enable:max-line-length */ | ||
|
||
/** | ||
* @deprecated Deprecated in favor of static {@link concat}. | ||
*/ | ||
export function concat<T, R>(...observables: Array<ObservableInput<any> | SchedulerLike>): OperatorFunction<T, R> { | ||
return (source: Observable<T>) => source.lift.call(concatStatic(source, ...observables)); | ||
} |
165 changes: 165 additions & 0 deletions
165
...0c05f7c6272da2d72addd55210fcfedf6622ad4b7604a234b6466b8904f73d9b7fda23dd7e921f750765443bb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const utils_1 = require("@typescript-eslint/utils"); | ||
const ts = __importStar(require("typescript")); | ||
const util = __importStar(require("../util")); | ||
var Usefulness; | ||
(function (Usefulness) { | ||
Usefulness[Usefulness["Always"] = 0] = "Always"; | ||
Usefulness["Never"] = "will"; | ||
Usefulness["Sometimes"] = "may"; | ||
})(Usefulness || (Usefulness = {})); | ||
exports.default = util.createRule({ | ||
name: 'no-base-to-string', | ||
meta: { | ||
docs: { | ||
description: 'Requires that `.toString()` is only called on objects which provide useful information when stringified', | ||
recommended: 'strict', | ||
requiresTypeChecking: true, | ||
}, | ||
messages: { | ||
baseToString: "'{{name}} {{certainty}} evaluate to '[object Object]' when stringified.", | ||
}, | ||
schema: [ | ||
{ | ||
type: 'object', | ||
properties: { | ||
ignoredTypeNames: { | ||
type: 'array', | ||
items: { | ||
type: 'string', | ||
}, | ||
}, | ||
}, | ||
additionalProperties: false, | ||
}, | ||
], | ||
type: 'suggestion', | ||
}, | ||
defaultOptions: [ | ||
{ | ||
ignoredTypeNames: ['RegExp'], | ||
}, | ||
], | ||
create(context, [option]) { | ||
var _a; | ||
const parserServices = util.getParserServices(context); | ||
const typeChecker = parserServices.program.getTypeChecker(); | ||
const ignoredTypeNames = (_a = option.ignoredTypeNames) !== null && _a !== void 0 ? _a : []; | ||
function checkExpression(node, type) { | ||
if (node.type === utils_1.AST_NODE_TYPES.Literal) { | ||
return; | ||
} | ||
const certainty = collectToStringCertainty(type !== null && type !== void 0 ? type : typeChecker.getTypeAtLocation(parserServices.esTreeNodeToTSNodeMap.get(node))); | ||
if (certainty === Usefulness.Always) { | ||
return; | ||
} | ||
context.report({ | ||
data: { | ||
certainty, | ||
name: context.getSourceCode().getText(node), | ||
}, | ||
messageId: 'baseToString', | ||
node, | ||
}); | ||
} | ||
function collectToStringCertainty(type) { | ||
const toString = typeChecker.getPropertyOfType(type, 'toString'); | ||
const declarations = toString === null || toString === void 0 ? void 0 : toString.getDeclarations(); | ||
if (!toString || !declarations || declarations.length === 0) { | ||
return Usefulness.Always; | ||
} | ||
// Patch for old version TypeScript, the Boolean type definition missing toString() | ||
if (type.flags & ts.TypeFlags.Boolean || | ||
type.flags & ts.TypeFlags.BooleanLiteral) { | ||
return Usefulness.Always; | ||
} | ||
if (ignoredTypeNames.includes(util.getTypeName(typeChecker, type))) { | ||
return Usefulness.Always; | ||
} | ||
if (declarations.every(({ parent }) => !ts.isInterfaceDeclaration(parent) || parent.name.text !== 'Object')) { | ||
return Usefulness.Always; | ||
} | ||
if (type.isIntersection()) { | ||
for (const subType of type.types) { | ||
const subtypeUsefulness = collectToStringCertainty(subType); | ||
if (subtypeUsefulness === Usefulness.Always) { | ||
return Usefulness.Always; | ||
} | ||
} | ||
return Usefulness.Never; | ||
} | ||
if (!type.isUnion()) { | ||
return Usefulness.Never; | ||
} | ||
let allSubtypesUseful = true; | ||
let someSubtypeUseful = false; | ||
for (const subType of type.types) { | ||
const subtypeUsefulness = collectToStringCertainty(subType); | ||
if (subtypeUsefulness !== Usefulness.Always && allSubtypesUseful) { | ||
allSubtypesUseful = false; | ||
} | ||
if (subtypeUsefulness !== Usefulness.Never && !someSubtypeUseful) { | ||
someSubtypeUseful = true; | ||
} | ||
} | ||
if (allSubtypesUseful && someSubtypeUseful) { | ||
return Usefulness.Always; | ||
} | ||
if (someSubtypeUseful) { | ||
return Usefulness.Sometimes; | ||
} | ||
return Usefulness.Never; | ||
} | ||
return { | ||
'AssignmentExpression[operator = "+="], BinaryExpression[operator = "+"]'(node) { | ||
const leftType = typeChecker.getTypeAtLocation(parserServices.esTreeNodeToTSNodeMap.get(node.left)); | ||
const rightType = typeChecker.getTypeAtLocation(parserServices.esTreeNodeToTSNodeMap.get(node.right)); | ||
if (util.getTypeName(typeChecker, leftType) === 'string') { | ||
checkExpression(node.right, rightType); | ||
} | ||
else if (util.getTypeName(typeChecker, rightType) === 'string' && | ||
node.left.type !== utils_1.AST_NODE_TYPES.PrivateIdentifier) { | ||
checkExpression(node.left, leftType); | ||
} | ||
}, | ||
'CallExpression > MemberExpression.callee > Identifier[name = "toString"].property'(node) { | ||
const memberExpr = node.parent; | ||
checkExpression(memberExpr.object); | ||
}, | ||
TemplateLiteral(node) { | ||
if (node.parent && | ||
node.parent.type === utils_1.AST_NODE_TYPES.TaggedTemplateExpression) { | ||
return; | ||
} | ||
for (const expression of node.expressions) { | ||
checkExpression(expression); | ||
} | ||
}, | ||
}; | ||
}, | ||
}); | ||
//# sourceMappingURL=no-base-to-string.js.map |
Oops, something went wrong.