srveit/mechanize-js

View on GitHub

Showing 28 of 28 total issues

Function newAgent has a Cognitive Complexity of 60 (exceeds 5 allowed). Consider refactoring.
Open

export function newAgent() {
  let logDir
  let userAgent = USER_AGENTS.Mechanize

  const agent = {}
Severity: Minor
Found in lib/mechanize/agent.js - About 1 day 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"

Further reading

Function newAgent has 219 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export function newAgent() {
  let logDir
  let userAgent = USER_AGENTS.Mechanize

  const agent = {}
Severity: Major
Found in lib/mechanize/agent.js - About 1 day to fix

    Function newForm has 194 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    export function newForm(page, node) {
      const fields = []
      const form = {}
      const action = nodeAttr(node, 'action')
      const boundary = randomString(20)
    Severity: Major
    Found in lib/mechanize/form.js - About 7 hrs to fix

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

      export function newFrame(node, page) {
        const link = newLink(node, page)
        // eslint-disable-next-line no-warning-comments, capitalized-comments
        // TODO: implement
        return Object.freeze({
      Severity: Major
      Found in lib/mechanize/page/frame.js and 1 other location - About 6 hrs to fix
      lib/mechanize/page/meta_refresh.js on lines 3..22

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 160.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

      export function newMetaRefresh(node, page) {
        const link = newLink(node, page)
        // eslint-disable-next-line no-warning-comments, capitalized-comments
        // TODO: implement
        return Object.freeze({
      Severity: Major
      Found in lib/mechanize/page/meta_refresh.js and 1 other location - About 6 hrs to fix
      lib/mechanize/page/frame.js on lines 3..22

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 160.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 4 locations. Consider refactoring.
      Open

      export function newReset(node, initialValue) {
        const button = newButton(node, initialValue)
        const fieldType = 'reset'
      
        return Object.freeze({
      Severity: Major
      Found in lib/mechanize/form/reset.js and 3 other locations - About 4 hrs to fix
      lib/mechanize/form/button.js on lines 12..28
      lib/mechanize/form/hidden.js on lines 12..28
      lib/mechanize/form/text.js on lines 12..28

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 130.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 4 locations. Consider refactoring.
      Open

      export function newText(node, initialValue) {
        const field = newField(node, initialValue)
        const fieldType = 'text'
      
        return Object.freeze({
      Severity: Major
      Found in lib/mechanize/form/text.js and 3 other locations - About 4 hrs to fix
      lib/mechanize/form/button.js on lines 12..28
      lib/mechanize/form/hidden.js on lines 12..28
      lib/mechanize/form/reset.js on lines 12..28

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 130.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 4 locations. Consider refactoring.
      Open

      export function newHidden(node, initialValue) {
        const field = newField(node, initialValue)
        const fieldType = 'hidden'
      
        return Object.freeze({
      Severity: Major
      Found in lib/mechanize/form/hidden.js and 3 other locations - About 4 hrs to fix
      lib/mechanize/form/button.js on lines 12..28
      lib/mechanize/form/reset.js on lines 12..28
      lib/mechanize/form/text.js on lines 12..28

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 130.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 4 locations. Consider refactoring.
      Open

      export function newButton(node, initialValue) {
        const field = newField(node, initialValue)
        const fieldType = 'button'
      
        return Object.freeze({
      Severity: Major
      Found in lib/mechanize/form/button.js and 3 other locations - About 4 hrs to fix
      lib/mechanize/form/hidden.js on lines 12..28
      lib/mechanize/form/reset.js on lines 12..28
      lib/mechanize/form/text.js on lines 12..28

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 130.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

        return Object.freeze({
          disabled: field.disabled,
          domId: field.domId,
          fieldType,
          getAttribute: field.getAttribute,
      Severity: Major
      Found in lib/mechanize/form/multi_select_list.js and 1 other location - About 3 hrs to fix
      lib/mechanize/form/select_list.js on lines 19..30

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 101.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

        return Object.freeze({
          disabled: multiSelectList.disabled,
          domId: multiSelectList.domId,
          fieldType,
          getAttribute: multiSelectList.getAttribute,
      Severity: Major
      Found in lib/mechanize/form/select_list.js and 1 other location - About 3 hrs to fix
      lib/mechanize/form/multi_select_list.js on lines 19..30

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 101.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Function initializeFields has 63 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        const initializeFields = () => {
          if (node) {
            search(node, '//input').forEach((node) => {
              const type = (nodeAttr(node, 'type') || 'text').toLocaleLowerCase()
              switch (type) {
      Severity: Major
      Found in lib/mechanize/form.js - About 2 hrs to fix

        Function newForm has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
        Open

        export function newForm(page, node) {
          const fields = []
          const form = {}
          const action = nodeAttr(node, 'action')
          const boundary = randomString(20)
        Severity: Minor
        Found in lib/mechanize/form.js - About 2 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"

        Further reading

        Function fetchPage has 55 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          const fetchPage = async (options) => {
            const reqOptions = await requestOptions(options)
            const uri = reqOptions.uri
            const response = await fetch(uri, reqOptions)
        
        
        Severity: Major
        Found in lib/mechanize/agent.js - About 2 hrs to fix

          File form.js has 251 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          import { newButton } from './form/button.js'
          import { newCheckbox } from './form/checkbox.js'
          import { newField } from './form/field.js'
          import { newFileUpload } from './form/file_upload.js'
          import { newHidden } from './form/hidden.js'
          Severity: Minor
          Found in lib/mechanize/form.js - About 2 hrs to fix

            Function newRadioButton has 49 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            export function newRadioButton(node, form) {
              const field = newField(node)
              let checked = Boolean(field.getAttribute('checked'))
              const fieldType = 'radioButton'
              const uncheckPeers = () =>
            Severity: Minor
            Found in lib/mechanize/form/radio_button.js - About 1 hr to fix

              Function newSubmit has 46 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              export function newSubmit(node, initialValue) {
                const button = newButton(node, initialValue)
                const fieldType = 'submit'
                const formAction = button.getAttribute('formaction')
                const formTarget = button.getAttribute('formtarget')
              Severity: Minor
              Found in lib/mechanize/form/submit.js - About 1 hr to fix

                Function newLink has 40 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                export function newLink(node, page) {
                  const agent = page.agent
                  const link = {}
                  const href = nodeAttr(node, 'href')
                  const relVal = nodeAttr(node, 'rel')
                Severity: Minor
                Found in lib/mechanize/page/link.js - About 1 hr to fix

                  Function newImageButton has 37 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  export function newImageButton(node, initialValue) {
                    const button = newSubmit(node, initialValue)
                    let theX, theY
                    const fieldType = 'imageButton'
                  
                  
                  Severity: Minor
                  Found in lib/mechanize/form/image_button.js - About 1 hr to fix

                    Function requestHeaders has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      const requestHeaders = async (options) => {
                        const headers = {
                          'User-Agent': userAgent,
                          Accept: '*/*',
                          connection: 'keep-alive',
                    Severity: Minor
                    Found in lib/mechanize/agent.js - About 1 hr to fix
                      Severity
                      Category
                      Status
                      Source
                      Language