|
1 |
| -import { ESLint } from 'eslint'; |
| 1 | +import eslintExperimentalApis from 'eslint/use-at-your-own-risk'; |
| 2 | +import { describe, it, expect } from 'vitest'; |
| 3 | +import { rules, parseForESLint } from '@graphql-eslint/eslint-plugin'; |
2 | 4 | import { ParserOptions } from '../src';
|
| 5 | +import schemaAllConfig from '../src/configs/schema-all.json'; |
| 6 | +import operationsAllConfig from '../src/configs/operations-all.json'; |
| 7 | +import relayConfig from '../src/configs/relay.json'; |
3 | 8 |
|
4 |
| -function getESLintWithConfig( |
5 |
| - configName: 'schema-all' | 'operations-all' | 'relay', |
6 |
| - parserOptions?: ParserOptions, |
7 |
| -): ESLint { |
8 |
| - return new ESLint({ |
9 |
| - useEslintrc: false, |
10 |
| - baseConfig: { |
11 |
| - overrides: [ |
12 |
| - { |
13 |
| - files: '*.graphql', |
14 |
| - extends: `plugin:@graphql-eslint/${configName}`, |
| 9 | +const { FlatESLint } = eslintExperimentalApis; |
| 10 | + |
| 11 | +function getESLintWithConfig(config: any, parserOptions?: Omit<ParserOptions, 'filePath'>) { |
| 12 | + return new FlatESLint({ |
| 13 | + overrideConfigFile: true, |
| 14 | + overrideConfig: [ |
| 15 | + { |
| 16 | + files: ['*.graphql'], |
| 17 | + languageOptions: { |
| 18 | + parser: { parseForESLint }, |
15 | 19 | parserOptions: {
|
16 | 20 | schema: 'type Query { foo: Int }',
|
17 | 21 | skipGraphQLConfig: true,
|
18 | 22 | ...parserOptions,
|
19 | 23 | },
|
20 | 24 | },
|
21 |
| - ], |
22 |
| - }, |
| 25 | + plugins: { |
| 26 | + '@graphql-eslint': { rules }, |
| 27 | + }, |
| 28 | + rules: config.rules, |
| 29 | + }, |
| 30 | + ], |
23 | 31 | });
|
24 | 32 | }
|
25 | 33 |
|
26 |
| -describe.skip('Rules', () => { |
| 34 | +describe('Rules', () => { |
27 | 35 | it('should load all rules properly from `schema-all` config', async () => {
|
28 |
| - const eslint = getESLintWithConfig('schema-all'); |
| 36 | + const eslint = getESLintWithConfig(schemaAllConfig); |
29 | 37 | const results = await eslint.lintText('{ foo }', { filePath: 'foo.graphql' });
|
30 | 38 | expect(results).toHaveLength(1);
|
31 | 39 | });
|
32 | 40 |
|
33 | 41 | it('should load all rules properly from `operations-all` config', async () => {
|
34 |
| - const eslint = getESLintWithConfig('operations-all', { operations: '{ foo }' }); |
| 42 | + const eslint = getESLintWithConfig(operationsAllConfig, { operations: '{ foo }' }); |
35 | 43 | const results = await eslint.lintText('{ foo }', { filePath: 'foo.graphql' });
|
36 | 44 | expect(results).toHaveLength(1);
|
37 | 45 | });
|
38 | 46 |
|
39 | 47 | it('should load all rules properly from `relay` config', async () => {
|
40 |
| - const eslint = getESLintWithConfig('relay', { operations: '{ foo }' }); |
| 48 | + const eslint = getESLintWithConfig(relayConfig, { operations: '{ foo }' }); |
41 | 49 | const results = await eslint.lintText('{ foo }', { filePath: 'foo.graphql' });
|
42 | 50 | expect(results).toHaveLength(1);
|
43 | 51 | });
|
|
0 commit comments