Showing 49 of 55 total issues
Function send
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
export default function send(result) {
if (!result) {
result = '';
} else if (typeof result === 'object') {
this.setHeader('Content-Type', 'application/json; charset=utf-8');
Function onListenHandler
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
const onListenHandler = (token) => {
if (typeof host === 'string') {
config.host = host;
} else {
config.host = 'localhost';
Function upgrade
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
async upgrade(res, req, context) {
const secWsKey = req.getHeader('sec-websocket-key');
const secWsProtocol = req.getHeader('sec-websocket-protocol');
const secWsExtensions = req.getHeader('sec-websocket-extensions');
Function babelCompilerManipulationNormalize
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
const babelCompilerManipulationNormalize = (content) => {
if (content.includes('const {\n') || content.includes('let {\n')) {
return content.split('\n').reduce((all, currLine, index) => {
if (currLine.includes('{') && index > 0) {
all += '\n';
- Read upRead up
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"
Further reading
Function listen
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
listen(port, host) {
const {
_config: config,
_app: app,
_routeCalled,
- Read upRead up
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"
Further reading
Function modifyEnd
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
export default function modifyEnd() {
if (!this._modifiedEnd) {
const _oldEnd = this.end;
this.end = function modifiedEnd(chunk, encoding) {
Consider simplifying this complex logical expression. Open
if (
req.headers &&
((!isRaw && bodyAllowedMethod && res.onData) ||
req.headers['transfer-encoding'] ||
(req.headers['content-length'] &&
Function exposeAppMethodHOC
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
const exposeAppMethodHOC = (method) =>
function exposeAppMethod(path, ...fns) {
const { _app, _route, _anyRouteCalled } = this;
if (fns.length > 0) {
- Read upRead up
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"
Further reading
Avoid deeply nested control flow statements. Open
if (!value.schema) {
schema[typeName][httpCode].content[contentType] = { schema: value };
}
Avoid deeply nested control flow statements. Open
if (_errors[type]) {
_errors[type].push(...validator.errors.map((err) => err.message));
} else {
_errors[type] = validator.errors.map((err) => err.message);
}
Avoid deeply nested control flow statements. Open
if (value.description && !parent.description) {
parent.description = value.description;
}
Avoid deeply nested control flow statements. Open
if (!errors) {
errors = {
type: 'errors',
errors: { [type]: [`${type} is not missing`] }
};
Avoid deeply nested control flow statements. Open
} else if (line.includes('setHeader')) {
contentLines += line.replace('setHeader', 'writeHeader');
} else if (line.includes('status(')) {
const statusPrepare = line.substr(line.indexOf('status(') + 7);
const code = parseInt(
Avoid deeply nested control flow statements. Open
if (paramKeyIndex !== -1) {
const paramKey = line
.substr(paramKeyIndex + 11)
.replace(HEADER_PARAM_KEY_REGEX, '');
const paramIndex = preparedParams[paramKey];
Avoid deeply nested control flow statements. Open
if (middleware._middlewares !== _middlewares) {
middleware._middlewares = _middlewares
.concat(middleware._middlewares)
.filter(
(currentMiddleware, index, self) =>
Avoid deeply nested control flow statements. Open
if (code === _statusCode) {
result = fastJsonFunc(result);
} else if (code.indexOf('X') !== -1) {
for (let i = 0; i < 3; i += 1) {
if (code.charAt(i) === 'X') {
Avoid deeply nested control flow statements. Open
if (line.charAt(headerKeyIndex + 11) === '.') {
contentLines += line.replace(
`req.headers.${headerKey}`,
`req.getHeader('${headerKey}')`
);
Avoid deeply nested control flow statements. Open
if (!valid) {
ws.emit(
'message',
{
type: 'websocket.message',
Avoid deeply nested control flow statements. Open
if (!value.content) {
schema[typeName][httpCode] = { content: { [contentType]: value } };
parent = schema[typeName][httpCode];
value = parent.content[contentType];
}
Function applyHeadersAndStatus
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
export default function applyHeadersAndStatus() {
const { _headers, statusCode } = this;
if (typeof statusCode === 'string') {
this.writeStatus(statusCode);
- Read upRead up
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"