Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@fimbul/mimir

Package Overview
Dependencies
Maintainers
2
Versions
125
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fimbul/mimir - npm Package Compare versions

Comparing version 0.22.0 to 0.23.0-dev.20201218

4

package.json
{
"name": "@fimbul/mimir",
"version": "0.22.0",
"version": "0.23.0-dev.20201218",
"description": "Core rules of the Fimbullinter project",

@@ -29,3 +29,3 @@ "main": "recommended.yaml",

"dependencies": {
"@fimbul/ymir": "^0.22.0",
"@fimbul/ymir": "0.22.0",
"chalk": "^4.0.0",

@@ -32,0 +32,0 @@ "debug": "^4.0.0",

@@ -19,3 +19,3 @@ "use strict";

return;
const type = this.checker.getApparentType(this.checker.getTypeAtLocation(node.expression));
const type = this.checker.getApparentType(this.checker.getTypeAtLocation(node.expression)).getNonNullableType();
for (const { symbol, name } of utils_1.propertiesOfType(type, names))

@@ -22,0 +22,0 @@ this.checkSymbol(symbol, name, node, node.expression, type);

@@ -50,2 +50,3 @@ "use strict";

case ts.SyntaxKind.CommaToken:
case ts.SyntaxKind.QuestionQuestionToken:
break outer;

@@ -52,0 +53,0 @@ }

@@ -39,5 +39,6 @@ "use strict";

if (node.exclamationToken !== undefined &&
node.initializer === undefined && (!tsutils_1.isStrictCompilerOptionEnabled(this.context.compilerOptions, 'strictNullChecks') ||
getNullableFlags(this.checker.getTypeAtLocation(node.name), true) & ts.TypeFlags.Undefined // type does not allow undefined
))
node.initializer === undefined &&
!utils_1.isAmbientVariableDeclaration(node) && (!tsutils_1.isStrictCompilerOptionEnabled(this.context.compilerOptions, 'strictNullChecks') ||
// type does not allow undefined
getNullableFlagsOfReceiver(this.checker.getTypeAtLocation(node.name)) & ts.TypeFlags.Undefined))
this.addFinding(node.exclamationToken.end - 1, node.exclamationToken.end, FAIL_DEFINITE_ASSIGNMENT, ymir_1.Replacement.delete(node.exclamationToken.pos, node.exclamationToken.end));

@@ -49,5 +50,8 @@ }

node.initializer === undefined &&
!tsutils_1.hasModifier(node.modifiers, ts.SyntaxKind.AbstractKeyword) && (node.name.kind !== ts.SyntaxKind.Identifier || // properties with string or computed name are not checked
!utils_1.isAmbientPropertyDeclaration(node) &&
!tsutils_1.hasModifier(node.modifiers, ts.SyntaxKind.AbstractKeyword, ts.SyntaxKind.StaticKeyword) && (
// properties with string or computed name are not checked
node.name.kind !== ts.SyntaxKind.Identifier && node.name.kind !== ts.SyntaxKind.PrivateIdentifier ||
!tsutils_1.isStrictCompilerOptionEnabled(this.context.compilerOptions, 'strictPropertyInitialization') ||
getNullableFlags(this.checker.getTypeAtLocation(node), true) & ts.TypeFlags.Undefined // type does not allow undefined
getNullableFlagsOfReceiver(this.checker.getTypeAtLocation(node)) & ts.TypeFlags.Undefined // type allows undefined
))

@@ -60,6 +64,8 @@ this.addFinding(node.exclamationToken.end - 1, node.exclamationToken.end, FAIL_DEFINITE_ASSIGNMENT, ymir_1.Replacement.delete(node.exclamationToken.pos, node.exclamationToken.end));

const originalType = this.checker.getTypeAtLocation(node.expression);
const flags = getNullableFlags(this.checker.getBaseConstraintOfType(originalType) || originalType);
const flags = getNullableFlags(this.checker.getBaseConstraintOfType(originalType) || originalType, ts.isOptionalChain(node)
? (t) => isOptionalChainingMarkerType(this.checker, t) ? 0 : t.flags
: undefined);
if (flags !== 0) { // type is nullable
const contextualType = this.getSafeContextualType(node);
if (contextualType === undefined || (flags & ~getNullableFlags(contextualType, true)))
if (contextualType === undefined || (flags & ~getNullableFlagsOfReceiver(contextualType)))
return;

@@ -143,8 +149,11 @@ message = `This assertion is unnecessary as the receiver accepts ${formatNullableFlags(flags)} values.`;

exports.Rule = Rule;
function getNullableFlags(type, receiver) {
function getNullableFlags(type, selector) {
let flags = 0;
for (const t of tsutils_1.unionTypeParts(type))
flags |= t.flags;
return ((receiver && flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown)) ? -1 : flags) & (ts.TypeFlags.Null | ts.TypeFlags.Undefined);
flags |= selector !== undefined ? selector(t) : t.flags;
return flags & (ts.TypeFlags.Null | ts.TypeFlags.Undefined);
}
function getNullableFlagsOfReceiver(type) {
return getNullableFlags(type, (t) => t.flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown) ? -1 : t.flags);
}
function formatNullableFlags(flags) {

@@ -175,3 +184,3 @@ switch (flags) {

function maybeUsedBeforeBeingAssigned(node, type, checker) {
if (node.kind !== ts.SyntaxKind.Identifier || getNullableFlags(type, true) & ts.TypeFlags.Undefined)
if (node.kind !== ts.SyntaxKind.Identifier || getNullableFlagsOfReceiver(type) & ts.TypeFlags.Undefined)
return false;

@@ -209,2 +218,5 @@ const symbol = checker.getSymbolAtLocation(node);

}
function isOptionalChainingMarkerType(checker, t) {
return tsutils_1.isTypeFlagSet(t, ts.TypeFlags.Undefined) && checker.getNullableType(t.getNonNullableType(), ts.TypeFlags.Undefined) !== t;
}
//# sourceMappingURL=no-useless-assertion.js.map

@@ -266,3 +266,3 @@ "use strict";

return type;
if (!tsutils_1.isPropertyAccessExpression(node) && !tsutils_1.isElementAccessExpression(node))
if ((!tsutils_1.isPropertyAccessExpression(node) || node.name.kind === ts.SyntaxKind.PrivateIdentifier) && !tsutils_1.isElementAccessExpression(node))
return type;

@@ -269,0 +269,0 @@ const objectType = this.checker.getApparentType(this.checker.getTypeAtLocation(node.expression));

@@ -25,3 +25,3 @@ "use strict";

]
: ymir_1.Replacement.replace(node.expression.end, node.end, '.' + text));
: ymir_1.Replacement.replace(node.expression.end, node.end, (node.questionDotToken !== undefined ? '?.' : '.') + text));
}

@@ -28,0 +28,0 @@ };

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatPseudoBigInt = exports.hasDirectivePrologue = exports.propertiesOfType = exports.elementAccessSymbols = exports.typesAreEqual = exports.objectLiteralNeedsParens = exports.expressionNeedsParensWhenReplacingNode = exports.childStatements = exports.isVariableReassignment = exports.isAsyncFunction = exports.tryStatements = exports.switchStatements = void 0;
exports.isAmbientVariableDeclaration = exports.isAmbientPropertyDeclaration = exports.formatPseudoBigInt = exports.hasDirectivePrologue = exports.propertiesOfType = exports.elementAccessSymbols = exports.typesAreEqual = exports.objectLiteralNeedsParens = exports.expressionNeedsParensWhenReplacingNode = exports.childStatements = exports.isVariableReassignment = exports.isAsyncFunction = exports.tryStatements = exports.switchStatements = void 0;
const ts = require("typescript");

@@ -160,3 +160,3 @@ const tsutils_1 = require("tsutils");

return;
yield* propertiesOfType(checker.getApparentType(checker.getTypeAtLocation(node.expression)), names);
yield* propertiesOfType(checker.getApparentType(checker.getTypeAtLocation(node.expression)).getNonNullableType(), names);
}

@@ -199,2 +199,15 @@ exports.elementAccessSymbols = elementAccessSymbols;

exports.formatPseudoBigInt = formatPseudoBigInt;
/** Determines whether a property has the `declare` modifier or the containing class is ambient. */
function isAmbientPropertyDeclaration(node) {
return tsutils_1.hasModifier(node.modifiers, ts.SyntaxKind.DeclareKeyword) ||
node.parent.kind === ts.SyntaxKind.ClassDeclaration && tsutils_1.isStatementInAmbientContext(node.parent);
}
exports.isAmbientPropertyDeclaration = isAmbientPropertyDeclaration;
/** Determines whether the given variable declaration is ambient. */
function isAmbientVariableDeclaration(node) {
return node.parent.kind === ts.SyntaxKind.VariableDeclarationList &&
node.parent.parent.kind === ts.SyntaxKind.VariableStatement &&
tsutils_1.isStatementInAmbientContext(node.parent.parent);
}
exports.isAmbientVariableDeclaration = isAmbientVariableDeclaration;
//# sourceMappingURL=utils.js.map

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc