"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "packages/hoppscotch-app/helpers/ternlint.js" between
hoppscotch-2.2.1.tar.gz and hoppscotch-3.0.0.tar.gz

About: Hoppscotch is a light-weight, web based API development suite.

ternlint.js  (hoppscotch-2.2.1):ternlint.js  (hoppscotch-3.0.0)
/* eslint-disable */ /* eslint-disable */
import infer from "tern/lib/infer" import infer from "tern/lib/infer"
import tern from "tern/lib/tern" import tern from "tern/lib/tern"
import * as walk from "acorn-walk"
const walk = require("acorn-walk")
var defaultRules = { var defaultRules = {
UnknownProperty: { severity: "warning" }, UnknownProperty: { severity: "warning" },
UnknownIdentifier: { severity: "warning" }, UnknownIdentifier: { severity: "warning" },
NotAFunction: { severity: "error" }, NotAFunction: { severity: "error" },
InvalidArgument: { severity: "error" }, InvalidArgument: { severity: "error" },
UnusedVariable: { severity: "warning" }, UnusedVariable: { severity: "warning" },
UnknownModule: { severity: "error" }, UnknownModule: { severity: "error" },
MixedReturnTypes: { severity: "warning" }, MixedReturnTypes: { severity: "warning" },
ObjectLiteral: { severity: "error" }, ObjectLiteral: { severity: "error" },
skipping to change at line 317 skipping to change at line 316
) )
} }
} }
} }
} }
} }
} }
} }
} }
function validateAssignement(nodeLeft, nodeRight, rule, state) { function validateAssignment(nodeLeft, nodeRight, rule, state) {
if (!nodeLeft || !nodeRight) return if (!nodeLeft || !nodeRight) return
if (!rule) return if (!rule) return
var leftType = infer.expressionType({ node: nodeLeft, state: state }), var leftType = infer.expressionType({ node: nodeLeft, state: state }),
rightType = infer.expressionType({ node: nodeRight, state: state }) rightType = infer.expressionType({ node: nodeRight, state: state })
if (!compareType(leftType, rightType)) { if (!compareType(leftType, rightType)) {
addMessage( addMessage(
nodeRight, nodeRight,
"Type mismatch: cannot convert from " + "Type mismatch: cannot convert from " +
getTypeName(leftType) + getTypeName(leftType) +
" to " + " to " +
skipping to change at line 390 skipping to change at line 389
if (varNode.name != "✖") { if (varNode.name != "✖") {
// unused variable // unused variable
if (unusedRule && !isUsedVariable(varNode, state, file, server)) if (unusedRule && !isUsedVariable(varNode, state, file, server))
addMessage( addMessage(
varNode, varNode,
"Unused variable '" + getNodeName(varNode) + "'", "Unused variable '" + getNodeName(varNode) + "'",
unusedRule.severity unusedRule.severity
) )
// type mismatch? // type mismatch?
if (mismatchRule) if (mismatchRule)
validateAssignement(varNode, decl.init, mismatchRule, state) validateAssignment(varNode, decl.init, mismatchRule, state)
} }
} }
break break
case "FunctionDeclaration": case "FunctionDeclaration":
if (unusedRule) { if (unusedRule) {
var varNode = node.id var varNode = node.id
if ( if (
varNode.name != "✖" && varNode.name != "✖" &&
!isUsedVariable(varNode, state, file, server) !isUsedVariable(varNode, state, file, server)
) )
skipping to change at line 528 skipping to change at line 527
// This is typically the case for built-in identifiers (e.g. window or d ocument). // This is typically the case for built-in identifiers (e.g. window or d ocument).
} }
}, },
// Detects function calls. // Detects function calls.
// `node.callee` is the expression (Identifier or MemberExpression) // `node.callee` is the expression (Identifier or MemberExpression)
// the is called as a function. // the is called as a function.
NewExpression: validateCallExpression, NewExpression: validateCallExpression,
CallExpression: validateCallExpression, CallExpression: validateCallExpression,
AssignmentExpression: function (node, state, c) { AssignmentExpression: function (node, state, c) {
var rule = getRule("TypeMismatch") var rule = getRule("TypeMismatch")
validateAssignement(node.left, node.right, rule, state) validateAssignment(node.left, node.right, rule, state)
}, },
ObjectExpression: function (node, state, c) { ObjectExpression: function (node, state, c) {
// validate properties of the object literal // validate properties of the object literal
var rule = getRule("ObjectLiteral") var rule = getRule("ObjectLiteral")
if (!rule) return if (!rule) return
var actualType = node.objType var actualType = node.objType
var ctxType = infer.typeFromContext(file.ast, { var ctxType = infer.typeFromContext(file.ast, {
node: node, node: node,
state: state, state: state,
}), }),
skipping to change at line 554 skipping to change at line 553
if (objType && objType.getObjType()) { if (objType && objType.getObjType()) {
expectedType = objType.getObjType() expectedType = objType.getObjType()
} }
} }
if (expectedType && expectedType != actualType) { if (expectedType && expectedType != actualType) {
// expected type is known. Ex: config object of RequireJS // expected type is known. Ex: config object of RequireJS
checkPropsInObject(node, expectedType, actualType, rule) checkPropsInObject(node, expectedType, actualType, rule)
} }
}, },
ArrayExpression: function (node, state, c) { ArrayExpression: function (node, state, c) {
// validate elements of the Arrray // validate elements of the Array
var rule = getRule("Array") var rule = getRule("Array")
if (!rule) return if (!rule) return
//var actualType = infer.expressionType({node: node, state: state}); //var actualType = infer.expressionType({node: node, state: state});
var ctxType = infer.typeFromContext(file.ast, { var ctxType = infer.typeFromContext(file.ast, {
node: node, node: node,
state: state, state: state,
}), }),
expectedType = getArrType(ctxType) expectedType = getArrType(ctxType)
if (expectedType /*&& expectedType != actualType*/) { if (expectedType /*&& expectedType != actualType*/) {
// expected type is known. Ex: config object of RequireJS // expected type is known. Ex: config object of RequireJS
 End of changes. 5 change blocks. 
6 lines changed or deleted 5 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)