Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ vendor/
source.toml

# Tests and fixtures.
js/__tests__/
js/eslint/__tests__/
js/eslint/rules/__tests__/
tests/
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,10 @@ export default [...typeChecked, ...vue];
```

The Vue layer registers the single-file-component parser, resolves `<script lang="ts">` through the TypeScript
parser, and requires kebab-case component filenames. It also carries the template layout rules, set to a four-space
indent, because Biome cannot format `.vue` markup.
parser, and requires PascalCase component filenames (`UserCard.vue`). It also carries the template layout rules, set to
a four-space indent, because Biome cannot format `.vue` markup. To match, the shared Biome config accepts PascalCase as
well as kebab-case under any `components/` directory, so a component's tests and stories can share its name
(`UserCard.test.ts`).

Through Qlty, the eslint plugin sandbox installs only `eslint`, `jest` and `prettier` by default, so the config's
imports fail to resolve. Widen the install filter in your `.qlty/qlty.toml`:
Expand Down
71 changes: 71 additions & 0 deletions js/__tests__/biome.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
* Tests for the shared Biome config's filename convention, run through the
* Biome version the README has consumers pin.
*
* @author Ben Carey <bdmc@sinemacula.co.uk>
* @copyright 2026 Sine Macula Limited
*/

import { execFileSync } from 'node:child_process';
import { copyFileSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { afterAll, beforeAll, describe, expect, it } from 'vitest';

const ROOT = join(dirname(fileURLToPath(import.meta.url)), '../..');
const BIOME = join(ROOT, 'node_modules/.bin/biome');

let consumer;

beforeAll(() => {
consumer = mkdtempSync(join(tmpdir(), 'coding-standards-biome-'));
copyFileSync(join(ROOT, 'js/biome.shared.json'), join(consumer, 'biome.shared.json'));
writeFileSync(join(consumer, 'biome.json'), JSON.stringify({ root: true, extends: ['./biome.shared.json'] }));
});

afterAll(() => {
rmSync(consumer, { recursive: true, force: true });
});

/** The filename diagnostics Biome reports for a file at the given path. */
function filenameDiagnostics(path) {
mkdirSync(dirname(join(consumer, path)), { recursive: true });
writeFileSync(join(consumer, path), 'export const value = 1;\n');

// The rule only warns, so Biome exits cleanly either way.
const output = execFileSync(BIOME, ['lint', '--reporter=rdjson', path], { cwd: consumer, encoding: 'utf8' });

return JSON.parse(output).diagnostics.filter(
diagnostic => diagnostic.code.value === 'lint/style/useFilenamingConvention',
);
}

describe('filenames', () => {
it('accepts kebab-case anywhere', () => {
for (const path of ['src/lib/date-format.ts', 'src/components/UserCard/use-hover.ts']) {
expect(filenameDiagnostics(path)).toEqual([]);
}
});

it('accepts PascalCase under a components directory, including consecutive capitals', () => {
for (const path of [
'src/components/UserCard/UserCard.test.ts',
'src/components/UserCard/UserCard.stories.ts',
'src/components/UIButton/UIButton.test.ts',
'src/components/AccountCard.tsx',
]) {
expect(filenameDiagnostics(path)).toEqual([]);
}
});

it('rejects PascalCase outside a components directory', () => {
expect(filenameDiagnostics('src/lib/DateFormat.ts')).toHaveLength(1);
});

it('rejects other casings under a components directory', () => {
for (const path of ['src/components/UserCard/useHover.ts', 'src/components/UserCard/User_Card.ts']) {
expect(filenameDiagnostics(path)).toHaveLength(1);
}
});
});
20 changes: 19 additions & 1 deletion js/biome.shared.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,5 +135,23 @@
"trailingCommas": "none",
"bracketSpacing": true
}
}
},
"overrides": [
{
"includes": ["**/components/**"],
"linter": {
"rules": {
"style": {
"useFilenamingConvention": {
"level": "warn",
"options": {
"strictCase": false,
"filenameCases": ["kebab-case", "PascalCase"]
}
}
}
}
}
}
]
}
40 changes: 40 additions & 0 deletions js/eslint/__tests__/vue.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* Tests for the Vue layer's component filename convention.
*
* @author Ben Carey <bdmc@sinemacula.co.uk>
* @copyright 2026 Sine Macula Limited
*/

import { Linter } from 'eslint';
import { describe, expect, it } from 'vitest';
import config from '../vue.js';

const linter = new Linter({ configType: 'flat' });

const COMPONENT = [
'<template>',
' <button type="button">',
' <slot />',
' </button>',
'</template>',
'',
].join('\n');

/** The distinct rules that reported on the component linted as the given filename. */
function report(filename) {
return [...new Set(linter.verify(COMPONENT, config, filename).map(message => message.ruleId))];
}

describe('component filenames', () => {
it('accepts PascalCase, including consecutive capitals', () => {
for (const filename of ['src/components/UserCard/UserCard.vue', 'src/components/UIButton.vue']) {
expect(report(filename)).toEqual([]);
}
});

it('rejects every other casing', () => {
for (const filename of ['user-card.vue', 'userCard.vue', 'user_card.vue']) {
expect(report(filename)).toContain('check-file/filename-naming-convention');
}
});
});
2 changes: 1 addition & 1 deletion js/eslint/vue.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default [
'vue/html-indent': ['error', 4],

'check-file/filename-naming-convention': ['error', {
'**/*.vue': 'KEBAB_CASE',
'**/*.vue': 'PASCAL_CASE',
}, {
ignoreMiddleExtensions: true,
}],
Expand Down
176 changes: 176 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"README.md",
"LICENSE",
"NOTICE",
"!js/__tests__",
"!js/eslint/__tests__",
"!js/eslint/rules/__tests__"
],
Expand All @@ -52,6 +53,7 @@
"lint:js": "eslint ."
},
"devDependencies": {
"@biomejs/biome": "2.5.6",
"@typescript-eslint/rule-tester": "^8.0.0",
"@typescript-eslint/utils": "^8.0.0",
"eslint": "^9.0.0",
Expand Down
2 changes: 1 addition & 1 deletion vitest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { defineConfig } from 'vitest/config';

export default defineConfig({
test: {
include: ['js/eslint/**/*.test.js'],
include: ['js/**/*.test.js'],
passWithNoTests: true,
},
});
Loading