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
13 changes: 13 additions & 0 deletions packages/eslint-plugin-internal/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { noUselessStoryAnnotations } from './rules/no-useless-story-annotations'
import { noUselessTsxExtension } from './rules/no-useless-tsx-extension';
import { noVitestBrowserReact } from './rules/no-vitest-browser-react';
import { noVitestInStories } from './rules/no-vitest-in-stories';
import { noVitestInternal } from './rules/no-vitest-internal';
import { requireStoryMetaAnnotations } from './rules/require-story-meta-annotations';

const plugin = {
Expand All @@ -28,6 +29,7 @@ const plugin = {
'no-useless-tsx-extension': noUselessTsxExtension,
'no-vitest-browser-react': noVitestBrowserReact,
'no-vitest-in-stories': noVitestInStories,
'no-vitest-internal': noVitestInternal,
'require-story-meta-annotations': requireStoryMetaAnnotations,
},

Expand Down Expand Up @@ -70,6 +72,17 @@ Object.assign(plugin.configs, {
},
},

{
name: 'ds-internal/recommended/tests',
plugins: {
'@drivenets/ds-internal': plugin,
},
files: ['**/*.test.ts?(x)'],
rules: {
'@drivenets/ds-internal/no-vitest-internal': 'error',
},
},

{
name: 'ds-internal/recommended/tests/browser',
plugins: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { RuleTester } from '@typescript-eslint/rule-tester';
import { noVitestInternal } from '../no-vitest-internal';

const ruleTester = new RuleTester();

ruleTester.run('no-vitest-internal', noVitestInternal, {
valid: [
"import { expect } from 'vitest';",
"import { page } from 'vitest/browser';",
"import { render } from 'vitest-browser-react';",
"import { useState } from 'react';",
"import { something } from 'other-internal-lib';",
],

invalid: [
{
code: "import { runner } from 'vitest/internal/runner';",
errors: [
{
messageId: 'noVitestInternal',
line: 1,
endLine: 1,
column: 24,
endColumn: 48,
},
],
},
{
code: "import { types } from 'vitest/internal/types';",
errors: [
{
messageId: 'noVitestInternal',
line: 1,
endLine: 1,
column: 23,
endColumn: 46,
},
],
},
{
code: "import { config } from 'vitest/internal';",
errors: [
{
messageId: 'noVitestInternal',
line: 1,
endLine: 1,
column: 24,
endColumn: 41,
},
],
},
{
code: "import * as internal from 'vitest/internal/utils';",
errors: [
{
messageId: 'noVitestInternal',
line: 1,
endLine: 1,
column: 27,
endColumn: 50,
},
],
},
],
});
31 changes: 31 additions & 0 deletions packages/eslint-plugin-internal/src/rules/no-vitest-internal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { createRule } from '../create-rule';

type MessageId = 'noVitestInternal';

export const noVitestInternal = createRule<[], MessageId>({
name: 'no-vitest-internal',
meta: {
type: 'problem',
docs: {
description: 'Disallow importing from vitest internal modules.',
},
messages: {
noVitestInternal:
"Don't import from `vitest/internal/*`. These are private APIs and may break without notice.",
},
schema: [],
},
defaultOptions: [],
create(context) {
return {
ImportDeclaration(node) {
if (node.source.value.startsWith('vitest/internal')) {
context.report({
node: node.source,
messageId: 'noVitestInternal',
});
}
},
};
},
});
Loading