UNPKG

@nextcloud/eslint-config

Version:

Eslint shared config for nextcloud apps and libraries

39 lines (38 loc) 1.51 kB
/*! * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later */ import { extname } from 'node:path'; /** * Register the given visitor to parser services. * If the parser service of `vue-eslint-parser` was not found, * this generates a warning. * * @param context - The rule context to use parser services. * @param templateBodyVisitor - The visitor to traverse the template body. * @param scriptVisitor - The visitor to traverse the script. * @param options - The options. * * @return The merged visitor. * @see https://github.com/vuejs/eslint-plugin-vue/blob/745fd4e1f3719c3a2f93bd3531da5e886c16f008/lib/utils/index.js#L2281-L2315 */ export function defineTemplateBodyVisitor(context, templateBodyVisitor, scriptVisitor, options) { const sourceCode = context.sourceCode; if (!sourceCode.parserServices?.defineTemplateBodyVisitor) { const filename = context.filename; if (extname(filename) === '.vue') { context.report({ loc: { line: 1, column: 0, }, message: 'Use the latest vue-eslint-parser. See also https://eslint.vuejs.org/user-guide/#what-is-the-use-the-latest-vue-eslint-parser-error.', }); } else { return scriptVisitor ?? {}; } } return sourceCode.parserServices .defineTemplateBodyVisitor(templateBodyVisitor, scriptVisitor, options); }