UNPKG

@truenine/eslint9-config

Version:

ESLint 9 configuration package for Compose Client projects with TypeScript, Vue, and modern JavaScript support

47 lines (45 loc) 1.44 kB
import { createRequire } from "node:module"; //#region src/rules/code-style/brace-style.ts const require = createRequire(import.meta.url); let originalRule = {}; try { originalRule = require("@stylistic/eslint-plugin").rules["brace-style"]; } catch (e) { console.error("Failed to load @stylistic/eslint-plugin/brace-style", e); } const rule = { meta: { ...originalRule?.meta, docs: { ...originalRule?.meta?.docs, description: "Custom brace style that enforces 1tbs but allows separate lines for try-catch-finally" } }, create(context) { if (!originalRule?.create) return {}; const { sourceCode } = context; return originalRule.create(Object.create(context, { report: { value: (descriptor) => { const { node, loc } = descriptor; const startLoc = loc ? loc.start : node ? node.loc.start : null; if (startLoc) { const index = sourceCode.getIndexFromLoc(startLoc); const token = sourceCode.getTokenByRangeStart(index); if (token) { if (token.value === "catch" || token.value === "finally") return; if (token.value === "}") { const nextToken = sourceCode.getTokenAfter(token); if (nextToken && (nextToken.value === "catch" || nextToken.value === "finally")) return; } } } context.report(descriptor); }, writable: false, configurable: false } })); } }; //#endregion export { rule as default }; //# sourceMappingURL=brace-style.mjs.map