Disable eslint `require-jsdoc` for nested functions

  Kiến thức lập trình

I’m trying to disable jsdoc warnings for nested functions. For example, in this file it spits a warning on the commented line.

// Notifications.ts

import * as Device from "expo-device";
import * as Notifications from "expo-notifications";
import { Platform } from "react-native";

export const initNotificationHandler = () => {
  Notifications.setNotificationHandler({
    handleNotification: async () => ({
      shouldShowAlert: true,
      shouldPlaySound: false,
      shouldSetBadge: false,
    }),
  });

  // eslint asks for jsdoc here:
  registerForPushNotificationsAsync().then((token) => token);
};

async function registerForPushNotificationsAsync() {
  let token;

  if (Platform.OS === "android") {
    await Notifications.setNotificationChannelAsync("default", {
      name: "default",
      importance: Notifications.AndroidImportance.MAX,
      vibrationPattern: [0, 250, 250, 250],
      lightColor: "#FF231F7C",
    });
  }

  if (Device.isDevice) {
    const { status: existingStatus } =
      await Notifications.getPermissionsAsync();
    let finalStatus = existingStatus;
    if (existingStatus !== "granted") {
      const { status } = await Notifications.requestPermissionsAsync();
      finalStatus = status;
    }
    if (finalStatus !== "granted") {
      alert("Failed to get push token for push notification!");
      return;
    }
    // Learn more about projectId:
    // https://docs.expo.dev/push-notifications/push-notifications-setup/#configure-projectid
    // EAS projectId is used here.
    try {
      const projectId =
        Constants?.expoConfig?.extra?.eas?.projectId ??
        Constants?.easConfig?.projectId;
      if (!projectId) {
        throw new Error("Project ID not found");
      }
      token = (
        await Notifications.getExpoPushTokenAsync({
          projectId,
        })
      ).data;
      console.log(token);
    } catch (e) {
      token = `${e}`;
    }
  } else {
    alert("Must use physical device for Push Notifications");
  }

  return token;
}

This is the warning:

/Users/slowdown/Documents/Projects/new-myaudiandme-mobile/services/Notifications.ts 16:44 warning Missing JSDoc comment jsdoc/require-jsdoc

And here is the .eslintrc.js:

// https://docs.expo.dev/guides/using-eslint/
// eslint-disable-file
module.exports = {
  extends: ["expo", "prettier"],
  plugins: ["jsdoc", "@typescript-eslint", "prettier"],
  parser: "@typescript-eslint/parser",
  ignorePatterns: [".eslintrc.js"],
  settings: {
    jsdoc: {
      mode: "typescript",
    },
  },
  rules: {
    "prettier/prettier": ["error", { trailingComma: "es5" }],
    "jsdoc/check-tag-names": 1,
    "jsdoc/newline-after-description": "off",
    "jsdoc/require-description": 1,
    "jsdoc/require-param": [1, { checkDestructured: false }],
    "jsdoc/require-param-description": 1,
    "jsdoc/require-param-name": 1,
    "jsdoc/require-param-type": 1,
    "jsdoc/require-returns": 1,
    "jsdoc/require-returns-description": 1,
    "jsdoc/require-yields": 1,
    "jsdoc/require-jsdoc": [
      1,
      {
        contexts: [
          ":not(Property) > ArrowFunctionExpression",
        ],
      },
    ],
    "jsdoc/tag-lines": ["error", "never", { startLines: 1 }],
    "@typescript-eslint/naming-convention": [
      "error",
      {
        selector: "memberLike",
        format: ["camelCase"],
        leadingUnderscore: "forbid",
      },
      {
        selector: "memberLike",
        modifiers: ["private"],
        format: ["camelCase"],
        leadingUnderscore: "require",
      },
    ],
  },
};

I expected eslint to not show a warning in the .then function callback. Do you know a way to fix this?

I tried adding

// ...
contexts: [
          ":not(Property) > ArrowFunctionExpression",
        ],
// ...

to disable warnings on nested arrow functions/callbacks but it keeps showing the warning.

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT