xiaody/adblock-minus

View on GitHub

Showing 15 of 15 total issues

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

test('lib:Blocker matcher support regexp', (t) => {
  const {blocker} = t.context
  const target = 'https://zhihu-web-analytics.zhihu.com/api/v1/logs/batch'
  blocker.add('/\\bzhihu-web-analytics\\b/')
  t.true(blocker.match(target))
Severity: Major
Found in __tests__/Blocker.spec.js and 1 other location - About 3 hrs to fix
__tests__/Blocker.spec.js on lines 72..80

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 98.

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

test('lib:Blocker matcher no keywords', (t) => {
  const {blocker} = t.context
  const target = 'https://zhihu-web-analytics.zhihu.com/a/b/c/d.gif'
  blocker.add('/a/b/c/d.')
  t.true(blocker.match(target))
Severity: Major
Found in __tests__/Blocker.spec.js and 1 other location - About 3 hrs to fix
__tests__/Blocker.spec.js on lines 62..70

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 98.

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 fromText has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

  static fromText (text) {
    let blocking = true

    if (text.indexOf('@@') === 0) {
      blocking = false
Severity: Minor
Found in lib/FilterClasses.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 calcDomains has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
Open

  calcDomains () {
    if (this.domainSource) {
      this.domains = new Map()
      let domains = this.domainSource.split(this.domainSeparator)
      if (domains.length === 1 && domains[0][0] !== '~') {
Severity: Minor
Found in lib/FilterClasses.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 onBeforeRequest has 43 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function onBeforeRequest (details) {
  let url = details.url.toLowerCase()
  let tabId = details.tabId
  let type = details.type

Severity: Minor
Found in chrome/background.js - About 1 hr to fix

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

      static fromText (text) {
        let blocking = true
    
        if (text.indexOf('@@') === 0) {
          blocking = false
    Severity: Minor
    Found in lib/FilterClasses.js - About 1 hr to fix

      Function onBeforeRequest has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

      function onBeforeRequest (details) {
        let url = details.url.toLowerCase()
        let tabId = details.tabId
        let type = details.type
      
      
      Severity: Minor
      Found in chrome/background.js - About 1 hr 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 matchFilter has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

        matchFilter (location, contentType, docDomain) {
          let keywords = location.toLowerCase().match(/[a-z0-9%]{3,}/g) || []
          keywords.unshift('')
      
          let map = this.filterByKeyword
      Severity: Minor
      Found in lib/Blocker.js - About 1 hr 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 addRemote has 27 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        addRemote (name, url) {
          return new Promise((resolve, reject) => {
            storage.get(url, (info) => {
              if (info[url]) {
                this.add(url, info[url].content)
      Severity: Minor
      Found in chrome/background.js - About 1 hr to fix

        Function findKeyword has 26 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          findKeyword (filter) {
            let text = filter.regexpSrc
            let defaultResult = ''
        
            if (text.length > 2 && text.startsWith('/') && text.endsWith('/')) {
        Severity: Minor
        Found in lib/Blocker.js - About 1 hr to fix

          Function onBeforeSendHeaders has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

          function onBeforeSendHeaders (details) {
            let url = details.url.toLowerCase()
            let type = details.type
          
            if (type === 'main_frame') {
          Severity: Minor
          Found in chrome/background.js - About 55 mins 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 isActiveOnDomain has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

            isActiveOnDomain (docDomain = '') {
              if (this.domainSource) this.calcDomains()
              if (!this.domains) return true
              docDomain = docDomain.toUpperCase()
              let nextDot
          Severity: Minor
          Found in lib/FilterClasses.js - About 35 mins 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 match has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

            match (url, type, documentHost) {
              if (this.isInWhitelist(documentHost)) return
              let ret = false
              for (const blocker of this.blockers.values()) {
                const code = blocker.matchStatus(url, type, documentHost)
          Severity: Minor
          Found in chrome/background.js - About 25 mins 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 fromText has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

            fromText (text = '') {
              text = text.trim()
              if (!text || text.startsWith('!') || text.includes('#@#')) return
              if (/^\[Adblock Plus/i.test(text)) return
          
          
          Severity: Minor
          Found in lib/FilterClasses.js - About 25 mins 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 selectors has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

            * selectors (domain) {
              const hotSelectors = this._getSelectorsInHotfilters(domain)
              if (hotSelectors.length) {
                yield hotSelectors
              }
          Severity: Minor
          Found in lib/Blocker.js - About 25 mins 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

          Severity
          Category
          Status
          Source
          Language