Search code examples
javascripteslinteslint-config-airbnb

eslint max-line-per-function disable for object-shorthand


const mailParams = ({
  ToAddresses,
  CcAddresses,
  subject,
  sourceEmail,
  mailTemplate
}) => ({
  Destination: {
    ToAddresses,
    CcAddresses
  },
  Message: {
    Body: {
      Html: {
        Charset: 'UTF-8',
        Data: mailTemplate
      }
    },
    Subject: {
      Charset: 'UTF-8',
      Data: `${subject}`
    }
  },
  Source: `${sourceEmail}`
});

showing Arrow function has too many lines (25). Maximum allowed is 15.eslint(max-lines-per-function) eslint counting everything as a new line.how can we suppress object-shorthand and function-paren-newline": ["error", { "minItems": 3 }] line to be considered as one ie: total number of lines sholud be 5 or 2


Solution

  • You can break your function into smaller chunks. Idea is to have functions doing 1 task only. That makes it more reusable and flexible.

    const getSenderDetails = (ToAddresses, CcAddresses) => ({ ToAddresses, CcAddresses });
    const getMessageDetails = (subject, mailTeplate) => {
      const CharSet = 'UTF-8';
      return {
        Body: {
          Html: {
            Charset,
            Data: mailTemplate
          }
        },
        Subject: {
          Charset,
          Data: `${subject}`
        }
      }
    }
    const mailParams = ({
      ToAddresses,
      CcAddresses,
      subject,
      sourceEmail,
      mailTemplate
    }) => ({
      Destination: getSenderDetails(ToAddresses, CcAddresses),
      message: getMessageDetail(subject, mailTemplate),
      Source: `${sourceEmail}`
    });