ngduc/node-rem

View on GitHub

Showing 21 of 21 total issues

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

export const apiPost = (path: string, options?: AxiosRequestConfig): Promise<ResponseInterface> => {
  const url = path.startsWith('http') ? path : `${BaseApiUrl}${path}`;
  // TODO: sanitize data, track xhr errors, analytics... here
  return axiosApi({ url, method: 'POST', ...options }).catch(onError);
};
Severity: Major
Found in ui/src/utils/apiUtil.ts and 1 other location - About 3 hrs to fix
ui/src/utils/apiUtil.ts on lines 86..90

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

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 const apiGet = (path: string, options?: AxiosRequestConfig): Promise<ResponseInterface> => {
  const url = path.startsWith('http') ? path : `${BaseApiUrl}${path}`;
  // TODO: sanitize data, track xhr errors, analytics... here
  return axiosApi({ url, method: 'GET', ...options }).catch(onError);
};
Severity: Major
Found in ui/src/utils/apiUtil.ts and 1 other location - About 3 hrs to fix
ui/src/utils/apiUtil.ts on lines 93..97

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

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 Home has 89 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export function Home() {
  const [error, setError] = React.useState<any>(null);
  const [items, setItems] = React.useState<any[] | null>(null);
  const [showCreateModal, setShowCreateModal] = React.useState(false);
  const [newTitle, setNewTitle] = React.useState('');
Severity: Major
Found in ui/src/components/Home/Home.tsx - About 3 hrs to fix

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

            {mode === Mode.LOGIN && (
              <footer>
                <button type="button" onClick={this.onLoginClick}>
                  {mode}
                </button>
    Severity: Major
    Found in ui/src/components/Login/LoginBox.tsx and 1 other location - About 2 hrs to fix
    ui/src/components/Login/LoginBox.tsx on lines 173..180

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

    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

            {mode === Mode.REGISTER && (
              <footer>
                <button type="button" onClick={this.onLoginClick}>
                  {mode}
                </button>
    Severity: Major
    Found in ui/src/components/Login/LoginBox.tsx and 1 other location - About 2 hrs to fix
    ui/src/components/Login/LoginBox.tsx on lines 165..172

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

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

    const handleJWT = (req: any, res: any, next: any, roles: any) => async (err: any, user: any, info: any) => {
      const error = err || info;
      const logIn: any = Bluebird.promisify(req.logIn);
      const apiError = new APIError({
        message: error ? error.message : 'Unauthorized',
    Severity: Minor
    Found in src/api/middlewares/auth.ts - 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 render has 46 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      render() {
        const { action, actionRegister, renderTitle, showError = true } = this.props;
        const { mode, username, password, name, error } = this.state;
    
        let formAction = mode === Mode.LOGIN && action ? action : '';
    Severity: Minor
    Found in ui/src/components/Login/LoginBox.tsx - About 1 hr to fix

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

        async findAndGenerateToken(options: any) {
          const { email, password, refreshObject } = options;
          if (!email) {
            throw new APIError({ message: 'An email is required to generate a token' });
          }
      Severity: Minor
      Found in src/api/models/user.model.ts - 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 apiJson has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

      export async function apiJson({ req, res, data, model, meta = {}, json = false }: apiJsonTypes) {
        const queryObj = getPageQuery(req.query);
        const metaData = { ...queryObj, ...meta };
      
        if (model) {
      Severity: Minor
      Found in src/api/utils/Utils.ts - 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 Login has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

      export function Login({ onLogin }: { onLogin?: () => void }) {
        const [errorMsg, setErrorMsg] = React.useState('');
        const navigate = useNavigate();
      
        const onSubmit = async (formData: any) => {
      Severity: Minor
      Found in ui/src/components/Login/Login.tsx - 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 App has 31 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function App() {
        const [loggedInEmail, setLoggedInEmail] = React.useState('');
      
        const refreshEmail = () => {
          const { userEmail } = getLoginData();
      Severity: Minor
      Found in ui/src/App.tsx - About 1 hr to fix

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

        const handleJWT = (req: any, res: any, next: any, roles: any) => async (err: any, user: any, info: any) => {
          const error = err || info;
          const logIn: any = Bluebird.promisify(req.logIn);
          const apiError = new APIError({
            message: error ? error.message : 'Unauthorized',
        Severity: Minor
        Found in src/api/middlewares/auth.ts - About 1 hr to fix

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

          function registerValidSW(swUrl: string, config?: Config) {
            navigator.serviceWorker
              .register(swUrl)
              .then(registration => {
                registration.onupdatefound = () => {
          Severity: Minor
          Found in ui/src/serviceWorker.ts - About 1 hr to fix

            Function getSortQuery has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

            export function getSortQuery(sortStr: string, defaultKey = 'createdAt') {
              let arr = [sortStr || defaultKey];
              if (sortStr && sortStr.indexOf(',')) {
                arr = sortStr.split(',');
              }
            Severity: Minor
            Found in src/api/utils/Utils.ts - 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

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

              transform({ query = {} }: { query?: any } = {}) {
                // transform every record (only respond allowed fields and "&fields=" in query)
                return transformData(this, query, ALLOWED_FIELDS);
              }
            Severity: Minor
            Found in src/api/models/userNote.model.ts and 1 other location - About 45 mins to fix
            src/api/models/user.model.ts on lines 99..102

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

            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

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

              transform({ query = {} }: { query?: any } = {}) {
                // transform every record (only respond allowed fields and "&fields=" in query)
                return transformData(this, query, ALLOWED_FIELDS);
              },
            Severity: Minor
            Found in src/api/models/user.model.ts and 1 other location - About 45 mins to fix
            src/api/models/userNote.model.ts on lines 18..21

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

            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

                if (mode === Mode.LOGIN && !this.validateLogin()) {
                  this.setError({
                    code: 'REQUIRED_LOGIN_FIELDS',
                    error: `Please enter ${this.usernameLabel} and ${this.passwordLabel}.`
                  });
            Severity: Minor
            Found in ui/src/components/Login/LoginBox.tsx and 1 other location - About 35 mins to fix
            ui/src/components/Login/LoginBox.tsx on lines 96..109

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

            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

                } else if (mode === Mode.REGISTER && !this.validateRegister()) {
                  this.setError({
                    code: 'REQUIRED_REGISTER_FIELDS',
                    error: `Please enter ${this.usernameLabel}, ${this.passwordLabel} and Name.`
                  });
            Severity: Minor
            Found in ui/src/components/Login/LoginBox.tsx and 1 other location - About 35 mins to fix
            ui/src/components/Login/LoginBox.tsx on lines 91..109

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

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

            export function Home() {
              const [error, setError] = React.useState<any>(null);
              const [items, setItems] = React.useState<any[] | null>(null);
              const [showCreateModal, setShowCreateModal] = React.useState(false);
              const [newTitle, setNewTitle] = React.useState('');
            Severity: Minor
            Found in ui/src/components/Home/Home.tsx - 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

            Avoid too many return statements within this function.
            Open

              return next();
            Severity: Major
            Found in src/api/middlewares/auth.ts - About 30 mins to fix
              Severity
              Category
              Status
              Source
              Language