Showing 6 of 8 total issues
Function normalize
has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring. Open
Open
async function normalize(url, opts) {
opts = Object.assign(
{ protocol: 'http:', path: '', encoding: 'utf8', redirectCount: 10 },
typeof url === 'string' ? urlParse(prependHTTP(url), true) : url,
opts
- 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 request
has 85 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
function request(opts, resolve, reject, redirectCount) {
const fn = (opts.protocol === 'https:') ? https : http;
const req = fn.request(opts, (res) => {
const { statusCode } = res;
if (isRedirect(statusCode) && 'location' in res.headers) {
Function req
has 66 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
const req = fn.request(opts, (res) => {
const { statusCode } = res;
if (isRedirect(statusCode) && 'location' in res.headers) {
if (opts.forceRedirect || isRedirectAll(statusCode) || (opts.method === 'GET' || opts.method === 'HEAD')) {
if (++redirectCount > opts.redirectCount) {
Function normalize
has 62 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
async function normalize(url, opts) {
opts = Object.assign(
{ protocol: 'http:', path: '', encoding: 'utf8', redirectCount: 10 },
typeof url === 'string' ? urlParse(prependHTTP(url), true) : url,
opts
Function request
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
Open
function request(opts, resolve, reject, redirectCount) {
const fn = (opts.protocol === 'https:') ? https : http;
const req = fn.request(opts, (res) => {
const { statusCode } = res;
if (isRedirect(statusCode) && 'location' in res.headers) {
- 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
Consider simplifying this complex logical expression. Open
Open
if (
!isString(opts.body) && !Buffer.isBuffer(opts.body) && !(opts.form || opts.json)
&& !(isObject(opts.body) && opts.multipart)
) {
throw new TypeError('options.body must be a String, Buffer or plain Object');