Skip to content

Commit 78fdf10

Browse files
authored
build(lint): add vitest eslint rules [AR-47371] (#138)
1 parent 6566e3b commit 78fdf10

4 files changed

Lines changed: 167 additions & 8 deletions

File tree

eslint.config.base.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import tseslint from 'typescript-eslint';
55
import unicorn from 'eslint-plugin-unicorn';
66
import importX, { createNodeResolver } from 'eslint-plugin-import-x';
77
import { createTypeScriptImportResolver } from 'eslint-import-resolver-typescript';
8+
import vitest from '@vitest/eslint-plugin';
89
import globals from 'globals';
910

1011
export default defineConfig(
@@ -128,5 +129,45 @@ export default defineConfig(
128129
},
129130
},
130131

132+
// Test rules.
133+
{
134+
files: ['**/*.@(test|spec).[tj]s?(x)'],
135+
...vitest.configs.recommended,
136+
rules: {
137+
...vitest.configs.recommended.rules,
138+
'vitest/prefer-vi-mocked': 'error',
139+
'vitest/prefer-hooks-on-top': 'error',
140+
'vitest/no-duplicate-hooks': 'error',
141+
'vitest/hoisted-apis-on-top': 'error',
142+
143+
'vitest/consistent-each-for': [
144+
'error',
145+
{
146+
test: 'each',
147+
it: 'each',
148+
describe: 'each',
149+
suite: 'each',
150+
},
151+
],
152+
153+
'vitest/consistent-test-filename': [
154+
'error',
155+
{
156+
pattern: '\\.test\\.[tj]sx?$',
157+
},
158+
],
159+
160+
'vitest/consistent-test-it': [
161+
'error',
162+
{
163+
fn: 'it',
164+
withinDescribe: 'it',
165+
},
166+
],
167+
168+
'vitest/prefer-hooks-in-order': 'error',
169+
},
170+
},
171+
131172
globalIgnores(['**/dist', '**/.turbo']),
132173
);

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"@eslint/core": "^1.1.0",
3333
"@eslint/js": "^9.39.2",
3434
"@types/node": "^25.2.2",
35+
"@vitest/eslint-plugin": "^1.6.7",
3536
"cspell": "^9.6.4",
3637
"eslint": "^9.39.2",
3738
"eslint-import-resolver-typescript": "^4.4.4",

packages/design-system/tests/exports.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ describe('Design System exports', () => {
1212
const actualContent = fs.readFileSync('./src/index.ts', 'utf-8');
1313
const actualLines = actualContent.split('\n').filter((line) => line.trim().length > 0);
1414

15-
expect(actualLines.length).toBe(expectedLines.length);
16-
1715
const tests = expectedLines.map((expectedLine, index) => {
1816
return [actualLines[index], expectedLine];
1917
});
2018

19+
it('should export all components', () => {
20+
expect(actualLines.length).toBe(expectedLines.length);
21+
});
22+
2123
// split expected by line and assert that each line is exported
2224
it.each(tests)('"%s" is exported from the package', (actual, expected) => {
2325
expect(actual).toBe(expected);

pnpm-lock.yaml

Lines changed: 121 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)