RocketChat/Rocket.Chat

View on GitHub

Showing 9,144 of 9,144 total issues

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

export const MockedSettingsContext = ({
    settings,
    children,
}: {
    children: React.ReactNode;
Severity: Minor
Found in packages/mock-providers/src/MockedSettingsContext.tsx and 1 other location - About 30 mins to fix
packages/mock-providers/src/MockedUserContext.tsx on lines 35..43

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

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

    async getChannels(cursor = null) {
        let channels = [];
        const request = await fetch('https://slack.com/api/conversations.list', {
            headers: {
                Authorization: `Bearer ${this.token}`,
Severity: Minor
Found in apps/meteor/app/slackbridge/server/SlackAPI.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 protectAvatars has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

export const protectAvatars = async (req, res, next) => {
    if (!(await userCanAccessAvatar(req))) {
        let roomOrUsername;

        if (req.url.startsWith('/room')) {
Severity: Minor
Found in apps/meteor/server/routes/avatar/middlewares/auth.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 componentDidUpdate has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    async componentDidUpdate(prevProps) {
        const { messages, dispatch, user } = this.props;
        const { messages: prevMessages, alerts: prevAlerts } = prevProps;

        const renderedMessages = messages.filter((message) => canRenderMessage(message));
Severity: Minor
Found in packages/livechat/src/routes/Chat/container.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 postDeleteMessage has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    async postDeleteMessage(rocketMessage) {
        if (rocketMessage) {
            const slackChannel = this.getSlackChannel(rocketMessage.rid);

            if (slackChannel != null) {
Severity: Minor
Found in apps/meteor/app/slackbridge/server/SlackAdapter.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 processPinnedItemMessage has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    async processPinnedItemMessage(rocketChannel, rocketUser, slackMessage, isImporting) {
        if (slackMessage.attachments && slackMessage.attachments[0] && slackMessage.attachments[0].text) {
            // TODO: refactor this logic to use the service to send this system message instead of using sendMessage
            const rocketMsgObj = {
                rid: rocketChannel._id,
Severity: Minor
Found in apps/meteor/app/slackbridge/server/SlackAdapter.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 getMembers has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    async getMembers(channelId) {
        const { num_members } = this.getRoomInfo(channelId);
        const MAX_MEMBERS_PER_CALL = 100;
        let members = [];
        let currentCursor = '';
Severity: Minor
Found in apps/meteor/app/slackbridge/server/SlackAPI.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 populateMembershipChannelMapByChannels has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    async populateMembershipChannelMapByChannels() {
        const channels = await this.slackAPI.getChannels();
        if (!channels || channels.length <= 0) {
            return;
        }
Severity: Minor
Found in apps/meteor/app/slackbridge/server/SlackAdapter.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 getLinkedInName has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

const getLinkedInName = ({ firstName, lastName }) => {
    const { preferredLocale, localized: firstNameLocalized } = firstName;
    const { localized: lastNameLocalized } = lastName;

    // LinkedIn new format
Severity: Minor
Found in apps/meteor/app/authentication/server/startup/index.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 handleNickname has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

const handleNickname = (updateUser, nickname) => {
    if (nickname && nickname.trim()) {
        if (nickname.length > MAX_NICKNAME_LENGTH) {
            throw new Meteor.Error('error-nickname-size-exceeded', `Nickname size exceeds ${MAX_NICKNAME_LENGTH} characters`, {
                method: 'saveUserProfile',
Severity: Minor
Found in apps/meteor/app/lib/server/functions/saveUser.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 populateMembershipChannelMapByGroups has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    async populateMembershipChannelMapByGroups() {
        const groups = await this.slackAPI.getGroups();
        if (!groups || groups.length <= 0) {
            return;
        }
Severity: Minor
Found in apps/meteor/app/slackbridge/server/SlackAdapter.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 processGroupJoinMessage has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    async processGroupJoinMessage(rocketChannel, rocketUser, slackMessage, isImporting) {
        if (slackMessage.inviter) {
            const inviter = slackMessage.inviter
                ? (await this.rocket.findUser(slackMessage.inviter)) || (await this.rocket.addUser(slackMessage.inviter))
                : null;
Severity: Minor
Found in apps/meteor/app/slackbridge/server/SlackAdapter.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 handleBio has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

const handleBio = (updateUser, bio) => {
    if (bio && bio.trim()) {
        if (bio.length > MAX_BIO_LENGTH) {
            throw new Meteor.Error('error-bio-size-exceeded', `Bio size exceeds ${MAX_BIO_LENGTH} characters`, {
                method: 'saveUserProfile',
Severity: Minor
Found in apps/meteor/app/lib/server/functions/saveUser.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 constructor has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    constructor(selfId, room, autoAccept = false) {
        this.config = {
            iceServers: [],
        };
        this.debug = false;
Severity: Minor
Found in apps/meteor/app/webrtc/client/WebRTCClass.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 onRemoteJoin has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    onRemoteJoin(data, ...args) {
        if (this.active !== true) {
            return;
        }
        this.log('onRemoteJoin', [data, ...args]);
Severity: Minor
Found in apps/meteor/app/webrtc/client/WebRTCClass.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 getFetchAgent has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

function getFetchAgent(url: string, allowSelfSignedCerts?: boolean): http.Agent | https.Agent | null | HttpsProxyAgent | HttpProxyAgent {
    const isHttps = /^https/.test(url);

    const proxy = getProxyForUrl(url);
    if (proxy) {
Severity: Minor
Found in packages/server-fetch/src/index.ts - 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 buildFormData has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

function buildFormData(data?: Record<string, any> | void, formData = new FormData(), parentKey?: string): FormData {
    if (data instanceof FormData) {
        return data;
    }
    if (!data) {
Severity: Minor
Found in packages/api-client/src/index.ts - 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 RoomBanner has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

export const RoomBanner = ({ onClick, className, ...props }: ComponentProps<typeof Box>) => {
    const { isMobile } = useLayout();

    return (
        <>
Severity: Minor
Found in packages/ui-client/src/components/RoomBanner/RoomBanner.tsx - 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 ironRouterSendErrorToResponse has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

export function ironRouterSendErrorToResponse(err, req, res) {
    if (res.statusCode < 400) res.statusCode = 500;

    if (err.status) res.statusCode = err.status;

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

Router.prototype._invalidateTracker = function () {
    var self = this;
    this.safeToRun++;
    this._tracker.invalidate();
    // After the invalidation we need to flush to make changes imediately
Severity: Minor
Found in apps/meteor/packages/flow-router/client/router.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