Skip to content

Commit 85ecaff

Browse files
test(core): harden plugin invariants and lint config
add examples-plugin guards for identity stability and no-output path fix eslint/js config handling for js files and generated ui-dist ignore remove unnecessary jest global comments causing lint noise Signed-off-by: night-slayer18 <samanuaia257@gmail.com>
1 parent 8440f73 commit 85ecaff

4 files changed

Lines changed: 70 additions & 3 deletions

File tree

eslint.config.mjs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ import js from '@eslint/js';
22
import tseslint from 'typescript-eslint';
33
import globals from 'globals';
44

5+
const disableTypeCheckedForJs = tseslint.configs.disableTypeChecked;
6+
57
export default tseslint.config(
68
{
79
ignores: [
810
'**/dist/**',
11+
'**/ui-dist/**',
912
'**/node_modules/**',
1013
'**/.turbo/**',
1114
'**/coverage/**',
@@ -43,7 +46,18 @@ export default tseslint.config(
4346
},
4447
{
4548
files: ['**/*.{js,mjs,cjs}'],
46-
...tseslint.configs.disableTypeChecked,
49+
...disableTypeCheckedForJs,
50+
languageOptions: {
51+
...(disableTypeCheckedForJs.languageOptions ?? {}),
52+
globals: {
53+
...globals.node,
54+
...globals.es2021,
55+
},
56+
},
57+
rules: {
58+
...(disableTypeCheckedForJs.rules ?? {}),
59+
'@typescript-eslint/no-require-imports': 'off',
60+
},
4761
},
4862
{
4963
files: ['**/tests/**/*.ts', '**/*.test.ts', '**/*.spec.ts'],

packages/cli/jest.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* global module, process */
21
/** @type {import('ts-jest').JestConfigWithTsJest} */
32
module.exports = {
43
preset: 'ts-jest',

packages/core/jest.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* global module, process */
21
/** @type {import('ts-jest').JestConfigWithTsJest} */
32
module.exports = {
43
preset: 'ts-jest',

packages/core/tests/examples-plugin.test.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,59 @@ describe('Examples plugin', () => {
9393
const plugin = examplesPlugin({ validate: true });
9494
await expect(plugin.afterExtract?.(docs)).resolves.toBeTruthy();
9595
});
96+
97+
it('does not mutate entry identity fields or add entries', async () => {
98+
const docs: DocEntry[] = [
99+
{
100+
id: 'abc12345',
101+
name: 'SomeType',
102+
kind: 'type',
103+
fileName: 'src/types.ts',
104+
module: 'src/types',
105+
position: { line: 10, column: 0 },
106+
signature: 'type SomeType = { value: string }',
107+
documentation: {
108+
summary: 'A sample type',
109+
tags: [],
110+
examples: [{ code: 'const x: SomeType = { value: "ok" };', language: 'ts' }],
111+
},
112+
},
113+
];
114+
115+
const plugin = examplesPlugin({ validate: false });
116+
const before = { id: docs[0].id, kind: docs[0].kind, name: docs[0].name };
117+
const result = (await plugin.afterExtract?.(docs)) || docs;
118+
119+
expect(result).toHaveLength(1);
120+
expect(result[0].id).toBe(before.id);
121+
expect(result[0].kind).toBe(before.kind);
122+
expect(result[0].name).toBe(before.name);
123+
});
124+
125+
it('skips output generation when entries contain no examples', async () => {
126+
const tempDir = await createTempDir('autodocs-ex-no-output-');
127+
const outputDir = path.join(tempDir, 'docs');
128+
129+
const docs: DocEntry[] = [
130+
{
131+
id: 'NoExamples',
132+
name: 'NoExamples',
133+
kind: 'interface',
134+
fileName: 'src/no-examples.ts',
135+
module: 'src/no-examples',
136+
position: { line: 1, column: 0 },
137+
signature: 'interface NoExamples { value: string }',
138+
documentation: {
139+
summary: 'No examples here',
140+
tags: [],
141+
},
142+
},
143+
];
144+
145+
const plugin = examplesPlugin({ outputDir: 'examples' });
146+
await plugin.afterExtract?.(docs);
147+
await plugin.afterGenerate?.(outputDir);
148+
149+
await expect(fs.access(path.join(outputDir, 'examples', 'examples.json'))).rejects.toThrow();
150+
});
96151
});

0 commit comments

Comments
 (0)