# IdentityPython/pyFF

src/pyff/site/static/js/sha1.js

### Summary

D
1 day

#### Function `hex_sha1` has a Cognitive Complexity of 45 (exceeds 5 allowed). Consider refactoring. Open

``````var hex_sha1 = function () {
var fromCharCode = String.fromCharCode;
/*
* Calculate the SHA1 of a raw string
*/``````
Found in src/pyff/site/static/js/sha1.js - About 6 hrs to fix

# Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

### A method's cognitive complexity is based on a few simple rules:

• Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
• Code is considered more complex for each "break in the linear flow of the code"
• Code is considered more complex when "flow breaking structures are nested"

#### Function `hex_sha1` has 122 lines of code (exceeds 25 allowed). Consider refactoring. Open

``````var hex_sha1 = function () {
var fromCharCode = String.fromCharCode;
/*
* Calculate the SHA1 of a raw string
*/``````
Found in src/pyff/site/static/js/sha1.js - About 4 hrs to fix

#### Function `binb_sha1` has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open

``````function binb_sha1(x, len)
{
/* append padding */
x[len >> 5] |= 0x80 << (24 - len % 32);
x[((len + 64 >> 9) << 4) + 15] = len;``````
Found in src/pyff/site/static/js/sha1.js - About 1 hr to fix

#### Function `str2rstr_utf8` has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open

``````function str2rstr_utf8(input)
{
var output = "";
var i = -1;
var x, y;``````
Found in src/pyff/site/static/js/sha1.js - About 1 hr to fix

#### Wrap an immediate function invocation in parentheses. Open

``var hex_sha1 = function () {``
Found in src/pyff/site/static/js/sha1.js by eslint

# Require IIFEs to be Wrapped (wrap-iife)

You can immediately invoke function expressions, but not function declarations. A common technique to create an immediately-invoked function expression (IIFE) is to wrap a function declaration in parentheses. The opening parentheses causes the contained function to be parsed as an expression, rather than a declaration.

``````// function expression could be unwrapped
var x = function () { return { y: 1 };}();

// function declaration must be wrapped
function () { /* side effects */ }(); // SyntaxError``````

## Rule Details

This rule requires all immediately-invoked function expressions to be wrapped in parentheses.

## Options

This rule has two options, a string option and an object option.

String option:

• `"outside"` enforces always wrapping the call expression. The default is `"outside"`.
• `"inside"` enforces always wrapping the function expression.
• `"any"` enforces always wrapping, but allows either style.

Object option:

• `"functionPrototypeMethods": true` additionally enforces wrapping function expressions invoked using `.call` and `.apply`. The default is `false`.

### outside

Examples of incorrect code for the default `"outside"` option:

``````/*eslint wrap-iife: ["error", "outside"]*/

var x = function () { return { y: 1 };}(); // unwrapped
var x = (function () { return { y: 1 };})(); // wrapped function expression``````

Examples of correct code for the default `"outside"` option:

``````/*eslint wrap-iife: ["error", "outside"]*/

var x = (function () { return { y: 1 };}()); // wrapped call expression``````

### inside

Examples of incorrect code for the `"inside"` option:

``````/*eslint wrap-iife: ["error", "inside"]*/

var x = function () { return { y: 1 };}(); // unwrapped
var x = (function () { return { y: 1 };}()); // wrapped call expression``````

Examples of correct code for the `"inside"` option:

``````/*eslint wrap-iife: ["error", "inside"]*/

var x = (function () { return { y: 1 };})(); // wrapped function expression``````

### any

Examples of incorrect code for the `"any"` option:

``````/*eslint wrap-iife: ["error", "any"]*/

var x = function () { return { y: 1 };}(); // unwrapped``````

Examples of correct code for the `"any"` option:

``````/*eslint wrap-iife: ["error", "any"]*/

var x = (function () { return { y: 1 };}()); // wrapped call expression
var x = (function () { return { y: 1 };})(); // wrapped function expression``````

### functionPrototypeMethods

Examples of incorrect code for this rule with the `"inside", { "functionPrototypeMethods": true }` options:

``````/* eslint wrap-iife: [2, "inside", { functionPrototypeMethods: true }] */

var x = function(){ foo(); }()
var x = (function(){ foo(); }())
var x = function(){ foo(); }.call(bar)
var x = (function(){ foo(); }.call(bar))``````

Examples of correct code for this rule with the `"inside", { "functionPrototypeMethods": true }` options:

``````/* eslint wrap-iife: [2, "inside", { functionPrototypeMethods: true }] */

var x = (function(){ foo(); })()
var x = (function(){ foo(); }).call(bar)``````

#### The body of a for-in should be wrapped in an if statement to filter unwanted properties from the prototype. Open

``  for(var i in input)``
Found in src/pyff/site/static/js/sha1.js by eslint

# Require Guarding for-in (guard-for-in)

Looping over objects with a `for in` loop will include properties that are inherited through the prototype chain. This behavior can lead to unexpected items in your for loop.

``````for (key in foo) {
doSomething(key);
}``````

Note that simply checking `foo.hasOwnProperty(key)` is likely to cause an error in some cases; see [no-prototype-builtins](no-prototype-builtins.md).

## Rule Details

This rule is aimed at preventing unexpected behavior that could arise from using a `for in` loop without filtering the results in the loop. As such, it will warn when `for in` loops do not filter their results with an `if` statement.

Examples of incorrect code for this rule:

``````/*eslint guard-for-in: "error"*/

for (key in foo) {
doSomething(key);
}``````

Examples of correct code for this rule:

``````/*eslint guard-for-in: "error"*/

for (key in foo) {
if (Object.prototype.hasOwnProperty.call(foo, key)) {
doSomething(key);
}
if ({}.hasOwnProperty.call(foo, key)) {
doSomething(key);
}
}``````

## Related Rules

• [no-prototype-builtins](no-prototype-builtins.md)