New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@magicspace/tslint-rules

Package Overview
Dependencies
Maintainers
2
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@magicspace/tslint-rules - npm Package Compare versions

Comparing version 0.1.10 to 0.1.11

11

bld/@lang.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BASE_TYPES = [
"boolean",
"number",
"string",
"array",
"tuple",
"null",
"undefined",
"never",
"void"
];
//# sourceMappingURL=@lang.js.map

72

bld/rules/explicitReturnTypeRule.js

@@ -6,13 +6,22 @@ "use strict";

const typescript_1 = require("typescript");
const _lang_1 = require("../@lang");
const failure_manager_1 = require("../utils/failure-manager");
const ERROR_MESSAGE_EXPLICIT_RETURN_TYPE_REQUIRED = 'This function requires explicit return type.';
let typeChecker;
class Rule extends tslint_1.Rules.AbstractRule {
exports.BASE_TYPE_STRING_SET = new Set([
'boolean',
'number',
'string',
'array',
'tuple',
'null',
'undefined',
'never',
'void',
]);
class Rule extends tslint_1.Rules.TypedRule {
constructor(options) {
super(options);
this.parseOptions = options.ruleArguments[0] || { complexTypeFixer: false };
this.parsedOptions = options.ruleArguments[0] || { complexTypeFixer: false };
}
apply(sourceFile) {
return this.applyWithWalker(new ExplicitReturnTypeWalker(sourceFile, Rule.metadata.ruleName, this.parseOptions));
applyWithProgram(sourceFile, program) {
return this.applyWithWalker(new ExplicitReturnTypeWalker(sourceFile, this.ruleName, this.parsedOptions, program.getTypeChecker()));
}

@@ -26,20 +35,16 @@ }

properties: {
complexTypeFixer: { type: 'boolean' }
}
complexTypeFixer: { type: 'boolean' },
},
},
type: 'maintainability',
hasFix: true,
typescriptOnly: false,
typescriptOnly: true,
requiresTypeInfo: true,
};
exports.Rule = Rule;
class ExplicitReturnTypeWalker extends tslint_1.AbstractWalker {
constructor(sourceFile, ruleName, options) {
constructor(sourceFile, ruleName, options, typeChecker) {
super(sourceFile, ruleName, options);
this.typeChecker = typeChecker;
this.failureManager = new failure_manager_1.FailureManager(this);
this.typeChecker = typeChecker || (typeChecker = typescript_1.createProgram([this.sourceFile.fileName], {
noEmitOnError: true,
noImplicitAny: true,
target: typescript_1.ScriptTarget.Latest,
module: typescript_1.ModuleKind.CommonJS,
}).getTypeChecker());
}

@@ -66,23 +71,30 @@ walk(sourceFile) {

}
getReturnType(node) {
getMissingReturnTypeString(node) {
let nodeType;
try {
let type = this.typeChecker.typeToString(this.typeChecker.getTypeAtLocation(node).getCallSignatures()[0].getReturnType());
if (!this.options.complexTypeFixer && !_lang_1.BASE_TYPES.some(v => v === type)) {
return undefined;
}
return type;
nodeType = this.typeChecker.getTypeAtLocation(node);
}
catch (e) {
catch (error) {
return undefined;
}
let returnType = nodeType.getCallSignatures()[0].getReturnType();
let returnTypeString = this.typeChecker.typeToString(returnType);
if (!this.options.complexTypeFixer &&
!exports.BASE_TYPE_STRING_SET.has(returnTypeString)) {
return undefined;
}
return returnTypeString;
}
buildFixer(node) {
function typeFactory(type) {
return `: ${type} `;
if (!node.body) {
return undefined;
}
let body = node.body;
let returnType = this.getReturnType(node);
return body && returnType
? new tslint_1.Replacement(node.getChildren().find(v => v.getText() === ")").getEnd(), 0, typeFactory(returnType))
: undefined;
let missingReturnTypeString = this.getMissingReturnTypeString(node);
if (!missingReturnTypeString) {
return undefined;
}
return new tslint_1.Replacement(node
.getChildren()
.find(v => v.getText() === ')')
.getEnd(), 0, `: ${missingReturnTypeString}`);
}

@@ -89,0 +101,0 @@ checkReturnType(node) {

{
"name": "@magicspace/tslint-rules",
"version": "0.1.10",
"version": "0.1.11",
"description": "Custom TSLint rules for MagicSpace.",

@@ -5,0 +5,0 @@ "repository": "https://github.com/makeflow/magicspace.git",

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