Skip to content

Commit

Permalink
Merge pull request #62 from mizdra/update-project-config
Browse files Browse the repository at this point in the history
Update project config
  • Loading branch information
mizdra authored Dec 11, 2024
2 parents 8152c37 + 5e14634 commit a168371
Show file tree
Hide file tree
Showing 19 changed files with 1,098 additions and 1,144 deletions.
1 change: 0 additions & 1 deletion .eslintignore

This file was deleted.

31 changes: 0 additions & 31 deletions .eslintrc.cjs

This file was deleted.

2 changes: 1 addition & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"recommendations": ["esbenp.prettier-vscode", "dbaeumer.vscode-eslint", "ZixuanChen.vitest-explorer"]
"recommendations": ["esbenp.prettier-vscode", "dbaeumer.vscode-eslint", "vitest.explorer"]
}
2 changes: 1 addition & 1 deletion docs/api/inline-fixture-files.createiff.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Create fixtures in the specified directory.
**Signature:**

```typescript
export type CreateIFF = <const T extends Directory, U extends Directory = {}>(directory: T, options?: CreateIFFOptions | undefined, __INTERNAL__prevIFF?: CreateIFFResult<U>) => Promise<CreateIFFResult<MergeDirectory<U, T>>>;
export type CreateIFF = <const T extends Directory, U extends Directory = {}>(directory: T, options?: CreateIFFOptions, __INTERNAL__prevIFF?: CreateIFFResult<U>) => Promise<CreateIFFResult<MergeDirectory<U, T>>>;
```
**References:** [Directory](./inline-fixture-files.directory.md)<!-- -->, [CreateIFFOptions](./inline-fixture-files.createiffoptions.md)<!-- -->, [CreateIFFResult](./inline-fixture-files.createiffresult.md)

Expand Down
4 changes: 2 additions & 2 deletions docs/api/inline-fixture-files.createiffresult.fork.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ Change the root directory and take over the fixture you created.
**Signature:**

```typescript
fork<const U extends Directory>(additionalDirectory: U, forkOptions?: ForkOptions | undefined): Promise<CreateIFFResult<MergeDirectory<T, U>>>;
fork<const U extends Directory>(additionalDirectory: U, forkOptions?: ForkOptions): Promise<CreateIFFResult<MergeDirectory<T, U>>>;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| additionalDirectory | U | The definition of fixtures to be added. |
| forkOptions | [ForkOptions](./inline-fixture-files.forkoptions.md) \| undefined | _(Optional)_ The fork options. |
| forkOptions | [ForkOptions](./inline-fixture-files.forkoptions.md) | _(Optional)_ The fork options. |
**Returns:**
Expand Down
33 changes: 33 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import mizdra from '@mizdra/eslint-config-mizdra';
import tsdoc from 'eslint-plugin-tsdoc';

/** @type {import('eslint').Linter.Config[]} */
export default [
{ ignores: ['**/dist'] },
{ plugins: { tsdoc } },
...mizdra.baseConfigs,
...mizdra.typescriptConfigs,
...mizdra.nodeConfigs,
{
files: ['**/*.{ts,tsx,cts,mts}', '**/*.{js,jsx,cjs,mjs}'],
rules: {
'simple-import-sort/imports': ['error', { groups: [['^\\u0000', '^node:', '^@?\\w', '^', '^\\.']] }],
'n/no-unsupported-features/es-syntax': 'off', // temporary
'n/no-unsupported-features/node-builtins': 'off', // temporary
},
},
{
files: ['**/*.{ts,tsx,cts,mts}'],
rules: {
'tsdoc/syntax': 'error',
// In tsdoc, if you define a method type in a property style, it will not be determined as a method.
// Therefore, it forces methods to be defined in method shorthand syntax.
'@typescript-eslint/method-signature-style': ['error', 'method'],
// In tsdoc, properties of a type defined with `interface` are included in the document,
// whereas those defined with `type` are omitted from the document.
// So we force types to be defined with `interface` whenever possible.
'@typescript-eslint/consistent-type-definitions': ['error', 'interface'],
},
},
mizdra.prettierConfig,
];
29 changes: 19 additions & 10 deletions example/01-basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { rm } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import dedent from 'dedent';
import { ESLint } from 'eslint';
import { loadESLint } from 'eslint';
import { expect, test } from 'vitest';
import { defineIFFCreator } from '../src/index.js';

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const LegacyESLint = await loadESLint({ useFlatConfig: false });

const fixtureDir = join(tmpdir(), 'your-app-name', process.env['VITEST_POOL_ID']!);
const createIFF = defineIFFCreator({ generateRootDir: () => join(fixtureDir, randomUUID()) });

Expand All @@ -26,13 +27,21 @@ test('eslint reports lint errors', async () => {
// 'src/semi.js': dedent`...`,
});

const eslint = new ESLint({ cwd: iff.rootDir, useEslintrc: true });
const eslint = new LegacyESLint({ cwd: iff.rootDir, useEslintrc: true });
const results = await eslint.lintFiles([iff.paths['src/semi.js']]);
const formatter = await eslint.loadFormatter('unix');
const resultText = formatter.format(results);
expect(resultText).toStrictEqual(dedent`
${iff.paths['src/semi.js']}:2:25: Missing semicolon. [Error/semi]
1 problem
`);
const formatter = await eslint.loadFormatter('json');
const resultText = await formatter.format(results);
expect(JSON.parse(resultText)).toStrictEqual([
expect.objectContaining({
filePath: iff.paths['src/semi.js'],
messages: [
expect.objectContaining({
ruleId: 'semi',
message: 'Missing semicolon.',
line: 2,
column: 25,
}),
],
}),
]);
});
33 changes: 21 additions & 12 deletions example/02-share-fixtures-with-test-cases.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { readFile, rm } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import dedent from 'dedent';
import { ESLint } from 'eslint';
import { loadESLint } from 'eslint';
import { describe, expect, it } from 'vitest';
import { defineIFFCreator } from '../src/index.js';

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const LegacyESLint = await loadESLint({ useFlatConfig: false });

const fixtureDir = join(tmpdir(), 'your-app-name', process.env['VITEST_POOL_ID']!);
const createIFF = defineIFFCreator({ generateRootDir: () => join(fixtureDir, randomUUID()) });

Expand All @@ -28,15 +29,23 @@ describe('eslint', async () => {
`,
},
});
const eslint = new ESLint({ cwd: iff.rootDir, useEslintrc: true });
const eslint = new LegacyESLint({ cwd: iff.rootDir, useEslintrc: true });
const results = await eslint.lintFiles([iff.paths['src/semi.js']]);
const formatter = await eslint.loadFormatter('unix');
const resultText = formatter.format(results);
expect(resultText).toStrictEqual(dedent`
${iff.paths['src/semi.js']}:2:25: Missing semicolon. [Error/semi]
1 problem
`);
const formatter = await eslint.loadFormatter('json');
const resultText = await formatter.format(results);
expect(JSON.parse(resultText)).toStrictEqual([
expect.objectContaining({
filePath: iff.paths['src/semi.js'],
messages: [
expect.objectContaining({
ruleId: 'semi',
message: 'Missing semicolon.',
line: 2,
column: 25,
}),
],
}),
]);
});
it('fix lint errors', async () => {
const iff = await baseIFF.fork({
Expand All @@ -46,11 +55,11 @@ describe('eslint', async () => {
`,
},
});
const eslint = new ESLint({ cwd: iff.rootDir, useEslintrc: true, fix: true });
const eslint = new LegacyESLint({ cwd: iff.rootDir, useEslintrc: true, fix: true });
const results = await eslint.lintFiles([iff.paths['src/semi.js']]);

expect(await readFile(iff.paths['src/semi.js'], 'utf8')).toMatchInlineSnapshot('"var withoutSemicolon = 2"');
await ESLint.outputFixes(results);
await LegacyESLint.outputFixes(results);
expect(await readFile(iff.paths['src/semi.js'], 'utf8')).toMatchInlineSnapshot('"var withoutSemicolon = 2;"');
});
});
Loading

0 comments on commit a168371

Please sign in to comment.