Showing 88 of 88 total issues
Function getSocketIORouterAdapter
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
function getSocketIORouterAdapter(router: Router, log: Logger): (socket: Socket) => void {
return function socketIORouterAdapter(socket: Socket): void {
socket.onAny(async (actionName: string, params: unknown, callback: CallableFunction): Promise<void> => {
// @todo if (callback !== undefined && typeof callback !== 'function') {
if (typeof callback !== 'function') {
Function reformatError
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
const reformatError = (error: any) => {
let statusCode
let errorMessage
const { errors } = error
Function handleIncomingMessages
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
private handleIncomingMessages(messages: Message[]): void {
const { unacknowledgedTracker, autoStore } = this
if (!this.consumerDisconnected()) {
this.consumer.pause(this.consumer.assignments())
Function processAndEmit
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
private async processAndEmit(collection: ns.StartStopTree, event: string, priority = ConnectorsPriority): Promise<any[]> {
const responses = []
for (const connectorType of priority) {
const connectors: ns.PluginConnector[] | void = collection[connectorType]
if (!connectors) {
- 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 startupHandlers
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
const startupHandlers = (
service: Microfleet,
nano: CouchDB.ServerScope,
database: string,
indices: Config['indexDefinitions'] = []
- 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 attachRouter
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
export default function attachRouter(service: Microfleet, config: RouterHapiPluginConfig): ServerRegisterPluginObject<any> {
return {
plugin: {
name: 'microfleetRouter',
version: '1.0.0',
Function _wait
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
consul.Lock.prototype._wait = function (ctx: any) {
const retry = () => {
utils.setTimeoutContext(() => {
this._run(ctx)
}, ctx, ctx.lockRetryTime)
Function retrieveStrategy
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
function retrieveStrategy(request: ServiceRequest, strategies: AuthConfig['strategies']): AuthStrategyConfig {
const { action } = request
const { auth: authConfig } = action
// for ```MicrofleetAction.auth = (request) => assert(request.param)```
Function socketIORouterAdapter
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
return function socketIORouterAdapter(socket: Socket): void {
socket.onAny(async (actionName: string, params: unknown, callback: CallableFunction): Promise<void> => {
// @todo if (callback !== undefined && typeof callback !== 'function') {
if (typeof callback !== 'function') {
// ignore malformed rpc call
Function addRoute
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
public addRoute(route: string, handler: ServiceAction): void {
const { routes, config } = this
let name: string = route
if (config !== undefined) {
Function connect
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
async connect() {
assert(!service.couchdb, 'couchdb has already been initialized')
const db = nano.use(database)
const establishConnection = async () => {
Similar blocks of code found in 2 locations. Consider refactoring. Open
public addConnector(type: ns.ConnectorsTypes, handler: ns.PluginConnector, plugin?: string): void {
this.addHandler(CONNECTORS_PROPERTY, type, handler, plugin)
}
- 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 57.
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
public addDestructor(type: ns.ConnectorsTypes, handler: ns.PluginConnector, plugin?: string): void {
this.addHandler(DESTRUCTORS_PROPERTY, type, handler, plugin)
}
- 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 57.
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 transformFileToAction
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
export const transformFileToAction = (input: any, handler?: any): ServiceAction => {
const omitProps = ['length', 'name', 'default', '__esModule']
const props = Object.getOwnPropertyNames(input)
const action = Object.create(null)
for (const prop of props) {
- 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 getAMQPRouterAdapter
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
function getAMQPRouterAdapter(
service: Microfleet,
config: RouterAMQPPluginConfig,
onComplete?: (this: Microfleet, err: Error | null | undefined, data: any, actionName: string, raw: Message) => Promise<any>
): MessageConsumer {
- 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 handleOffsetCommit
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
private async handleOffsetCommit(err: LibrdKafkaError | null | undefined , partitions: TopicPartitionOffset[]): Promise<void> {
if (err) {
const wrappedError = new OffsetCommitError(partitions, this.trackerMeta, err)
this.log?.warn({ err: wrappedError }, '[commit] offset commit error')
- 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 checkEof
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
private async checkEof(): Promise<void> {
if (this.inDestroyingState() || !this.config.stopOnPartitionsEOF) {
this.log?.debug('checkEof: destroying')
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 loadLuaScripts
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
export async function loadLuaScripts<T extends Redis.Redis | Redis.Cluster>(
ctx: Microfleet,
dir: string | string[],
redis: T
): Promise<void> {
- 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 whatBump
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
const whatBump = (commits) => {
let level = undefined
let breakings = 0
let features = 0
let patches = 0
Function handleOffsetCommit
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
private async handleOffsetCommit(err: LibrdKafkaError | null | undefined , partitions: TopicPartitionOffset[]): Promise<void> {
if (err) {
const wrappedError = new OffsetCommitError(partitions, this.trackerMeta, err)
this.log?.warn({ err: wrappedError }, '[commit] offset commit error')