Files
gridpilot.gg/core/eslint-rules/no-index-files.test.js
Marc Mintel 0a37454171
Some checks failed
Contract Testing / contract-tests (pull_request) Failing after 5m51s
Contract Testing / contract-snapshot (pull_request) Has been skipped
view data tests
2026-01-22 17:28:09 +01:00

132 lines
3.0 KiB
JavaScript

const { RuleTester } = require('eslint');
const rule = require('./no-index-files');
const ruleTester = new RuleTester({
parser: require.resolve('@typescript-eslint/parser'),
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
ecmaFeatures: {
jsx: false,
},
},
});
ruleTester.run('no-index-files', rule, {
valid: [
// Regular file in domain
{
filename: '/path/to/core/domain/user/User.ts',
code: "export class User {}",
},
// Regular file in application
{
filename: '/path/to/core/application/user/CreateUser.ts',
code: "export class CreateUser {}",
},
// Regular file in shared
{
filename: '/path/to/core/shared/ValueObject.ts',
code: "export class ValueObject {}",
},
// Regular file in ports
{
filename: '/path/to/core/ports/UserRepository.ts',
code: "export interface UserRepository {}",
},
// File with index in the middle of the path
{
filename: '/path/to/core/domain/user/index/User.ts',
code: "export class User {}",
},
// File with index in the name but not at the end
{
filename: '/path/to/core/domain/user/indexHelper.ts',
code: "export class IndexHelper {}",
},
// Root index.ts is allowed
{
filename: '/path/to/core/index.ts',
code: "export * from './domain';",
},
// File with index.ts in the middle of the path
{
filename: '/path/to/core/domain/index/User.ts',
code: "export class User {}",
},
],
invalid: [
// index.ts in domain
{
filename: '/path/to/core/domain/user/index.ts',
code: "export * from './User';",
errors: [
{
messageId: 'indexFile',
},
],
},
// index.ts in application
{
filename: '/path/to/core/application/user/index.ts',
code: "export * from './CreateUser';",
errors: [
{
messageId: 'indexFile',
},
],
},
// index.ts in shared
{
filename: '/path/to/core/shared/index.ts',
code: "export * from './ValueObject';",
errors: [
{
messageId: 'indexFile',
},
],
},
// index.ts in ports
{
filename: '/path/to/core/ports/index.ts',
code: "export * from './UserRepository';",
errors: [
{
messageId: 'indexFile',
},
],
},
// index.ts with Windows path separator
{
filename: 'C:\\path\\to\\core\\domain\\user\\index.ts',
code: "export * from './User';",
errors: [
{
messageId: 'indexFile',
},
],
},
// index.ts at the start of path
{
filename: 'index.ts',
code: "export * from './domain';",
errors: [
{
messageId: 'indexFile',
},
],
},
// index.ts in nested directory
{
filename: '/path/to/core/domain/user/profile/index.ts',
code: "export * from './Profile';",
errors: [
{
messageId: 'indexFile',
},
],
},
],
});