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))
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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))
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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
- 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 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] !== '~') {
- 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 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
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
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
- 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 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
- 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 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)
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('/')) {
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') {
- 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 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
- 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 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)
- 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 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
- 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 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
}
- 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"