Merge branch 'master' into pseudo-random-bytes

This commit is contained in:
Max Schaefer
2018-12-12 08:19:57 +00:00
committed by GitHub
22 changed files with 92 additions and 16 deletions

View File

@@ -10,6 +10,7 @@
*/
import javascript
import semmle.javascript.RestrictedLocations
predicate isRepeatedDependency(AngularJS::InjectableFunction f, string name, ASTNode location) {
exists(int i, int j | i < j and
@@ -20,4 +21,4 @@ predicate isRepeatedDependency(AngularJS::InjectableFunction f, string name, AST
from AngularJS::InjectableFunction f, ASTNode node, string name
where isRepeatedDependency(f, name, node) and
not count(f.asFunction().getParameterByName(name)) > 1 // avoid duplicating reports from js/duplicate-parameter-name
select f, "This function has a duplicate dependency '$@'.", node, name
select (FirstLineOf)f.asFunction(), "This function has a duplicate dependency '$@'.", node, name

View File

@@ -10,8 +10,9 @@
*/
import javascript
import semmle.javascript.RestrictedLocations
from AngularJS::InjectableFunction f, ASTNode explicitInjection
where count(f.getAnExplicitDependencyInjection()) > 1 and
explicitInjection = f.getAnExplicitDependencyInjection()
select f.asFunction(), "This function has $@ defined in multiple places.", explicitInjection, "dependency injections"
select (FirstLineOf)f.asFunction(), "This function has $@ defined in multiple places.", explicitInjection, "dependency injections"

View File

@@ -11,6 +11,7 @@
import javascript
import Declarations.UnusedParameter
import semmle.javascript.RestrictedLocations
predicate isUnusedParameter(Function f, string msg, Parameter parameter) {
exists(Variable pv |
@@ -36,4 +37,4 @@ predicate isMissingParameter(AngularJS::InjectableFunction f, string msg, ASTNod
from AngularJS::InjectableFunction f, string message, ASTNode location
where isUnusedParameter(f.asFunction(), message, location) or isMissingParameter(f, message, location)
select location, message
select (FirstLineOf)location, message

View File

@@ -9,7 +9,7 @@
*/
import javascript
import UnusedParameter // local library
import UnusedParameter
from Parameter p
where isAnAccidentallyUnusedParameter(p)

View File

@@ -46,7 +46,9 @@ predicate isUnused(Function f, Parameter p, Variable pv, int i) {
// functions without a body cannot use their parameters
f.hasBody() and
// field parameters are used to initialize a field
not p instanceof FieldParameter
not p instanceof FieldParameter and
// common convention: parameters with leading underscore are intentionally unused
pv.getName().charAt(0) != "_"
}
/**

View File

@@ -22,7 +22,9 @@ class UnusedLocal extends LocalVariable {
not exists(FunctionExpr fe | this = fe.getVariable()) and
not exists(ClassExpr ce | this = ce.getVariable()) and
not exists(ExportDeclaration ed | ed.exportsAs(this, _)) and
not exists(LocalVarTypeAccess type | type.getVariable() = this)
not exists(LocalVarTypeAccess type | type.getVariable() = this) and
// common convention: variables with leading underscore are intentionally unused
getName().charAt(0) != "_"
}
}