|
| 1 | +/*! |
| 2 | + * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors |
| 3 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
| 4 | + */ |
| 5 | + |
| 6 | +import type { Linter } from 'eslint' |
| 7 | + |
| 8 | +import { ESLint } from 'eslint' |
| 9 | +import { readFile } from 'fs/promises' |
| 10 | +import { join, resolve } from 'path' |
| 11 | +import { expect, test } from 'vitest' |
| 12 | +import * as eslintConfig from '../lib/index.js' |
| 13 | + |
| 14 | +const eslint = new ESLint({ |
| 15 | + overrideConfigFile: true, |
| 16 | + overrideConfig: eslintConfig.recommended as Linter.Config<Linter.RulesRecord>[], |
| 17 | +}) |
| 18 | + |
| 19 | +/** |
| 20 | + * Lint a file with ESLint |
| 21 | + * |
| 22 | + * @param file - File path to lint |
| 23 | + * @return Lint result |
| 24 | + */ |
| 25 | +async function lintFile(file: string) { |
| 26 | + const real = resolve(join(__dirname, file)) |
| 27 | + const content = await readFile(real) |
| 28 | + return await eslint.lintText(content.toString(), { filePath: join('src', file) }) |
| 29 | +} |
| 30 | + |
| 31 | +test('Formatting', async () => { |
| 32 | + const results = await lintFile('fixtures/component-formatting.vue') |
| 33 | + expect(results).toHaveIssueCount(3) |
| 34 | + expect(results).toHaveIssue({ |
| 35 | + ruleId: 'vue/prop-name-casing', |
| 36 | + line: 11, |
| 37 | + }) |
| 38 | + expect(results).toHaveIssue({ |
| 39 | + ruleId: 'vue/custom-event-name-casing', |
| 40 | + line: 31, |
| 41 | + }) |
| 42 | + expect(results).toHaveIssue({ |
| 43 | + ruleId: 'vue/slot-name-casing', |
| 44 | + line: 34, |
| 45 | + }) |
| 46 | +}) |
0 commit comments