Skip to content

Commit dcf4e35

Browse files
authored
runs tests of Windows (#2692)
* runs tests of Windows * fix * prettier * fix lint * set ``"moduleResolution": "bundler"` * set `"module": "esnext"` * try to fix examples.spec.ts * use optional chaining * add log * fix * should fix * fix new line on windows * fix * and here * maybe this * try * try * try * attempt to fix schema.spec * add shell: true * improve * try * try * try * try * try * try * try fix prettier example on windows * try * try now * try now * more * try * upd banner * merge * more * more * more * fix * log * more * now * more * try slash for filePath * yoyo * more * try * add changeset * aa * more * i know the problem * fix eslint tailwindcss * see * aa * use `"eslint-plugin-tailwindcss": "3.17.3"` * yes * should be all good now * try now * thiiis
1 parent e771499 commit dcf4e35

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+464
-672
lines changed

.changeset/chilled-rivers-prove.md

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,33 @@
44

55
1. graphql plugin can now we be specified as
66

7-
```js
8-
plugins: { '@graphql-eslint': graphqlPlugin }
9-
```
7+
```diff
8+
plugins: {
9+
- '@graphql-eslint': {
10+
- graphqlPlugin.rules
11+
- }
12+
+ '@graphql-eslint': graphqlPlugin
13+
}
14+
```
1015

1116
1. Config rules should now be accessed through the `rules` property
1217

13-
```diff
14-
rules: {
15-
- ...graphqlESLint.configs['flat/operations-recommended']
16-
+ ...graphqlESLint.configs['flat/operations-recommended'].rules
17-
```
18+
```diff
19+
rules: {
20+
- ...graphqlESLint.configs['flat/operations-recommended']
21+
+ ...graphqlESLint.configs['flat/operations-recommended'].rules
22+
```
1823

1924
1. processor can now be specified with accessing `processor` property
2025

21-
```js
22-
processor: graphqlPlugin.processor
23-
```
26+
```diff
27+
- processor: graphql.processors.graphql
28+
+ processor: graphqlPlugin.processor
29+
```
2430

2531
1. The plugin can now be imported using a default import
2632

27-
```js
28-
import graphqlPlugin from '@graphql-eslint/eslint-plugin'
29-
```
33+
```diff
34+
- import * as graphql from '@graphql-eslint/eslint-plugin'
35+
+ import graphqlPlugin from '@graphql-eslint/eslint-plugin'
36+
```

.changeset/metal-wasps-type.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-eslint/eslint-plugin': patch
3+
---
4+
5+
fix some issues on Windows by running tests with matrix on github CI

.eslintrc.cjs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ module.exports = {
88
],
99
rules: {
1010
'unicorn/prefer-array-some': 'error',
11-
'unicorn/better-regex': 'error',
1211
'prefer-destructuring': ['error', { VariableDeclarator: { object: true } }],
1312
quotes: ['error', 'single', { avoidEscape: true }], // Matches Prettier, but also replaces backticks
1413
},
@@ -28,9 +27,6 @@ module.exports = {
2827
'@typescript-eslint/array-type': ['error', { readonly: 'generic' }],
2928
'@typescript-eslint/consistent-type-imports': ['error', { prefer: 'no-type-imports' }],
3029
},
31-
parserOptions: {
32-
project: ['tsconfig.json', 'website/tsconfig.json', 'tsconfig.eslint.json'],
33-
},
3430
},
3531
{
3632
files: ['**/rules/*.ts'],
@@ -99,7 +95,12 @@ module.exports = {
9995
'error',
10096
{
10197
// TODO: figure out why there is an error only on CI
102-
whitelist: ['nextra-scrollbar'],
98+
whitelist: [
99+
'nextra-scrollbar',
100+
'_text-primary-600',
101+
'_underline',
102+
'_decoration-from-font',
103+
],
103104
},
104105
],
105106
'react/no-unknown-property': ['error', { ignore: ['jsx', 'global'] }],
@@ -110,5 +111,13 @@ module.exports = {
110111
},
111112
},
112113
},
114+
{
115+
files: ['website/**/*.mdx'],
116+
rules: {
117+
// TODO: remove `# {frontMatter.title}` and this override
118+
'@typescript-eslint/no-unused-expressions': 'off',
119+
'no-undef': 'off',
120+
},
121+
},
113122
],
114123
};

.github/workflows/test.yml

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,27 @@ jobs:
1717
githubToken: ${{ secrets.GITHUB_TOKEN }}
1818

1919
typecheck:
20-
name: typecheck / graphql v${{matrix.graphql_version}}
21-
runs-on: ubuntu-latest
20+
name: typecheck / graphql v${{matrix.graphql_version}} (${{matrix.os}})
21+
runs-on: ${{ matrix.os }}
2222
strategy:
2323
matrix:
24+
os: [ubuntu-latest]
2425
graphql_version: [16]
2526

2627
steps:
27-
- name: Checkout Master
28+
- name: Checkout out code
2829
uses: actions/checkout@v4
2930
with:
3031
fetch-depth: 0
3132

33+
- name: Cache turbo build setup
34+
uses: actions/cache@v4
35+
with:
36+
path: .turbo
37+
key: ${{ runner.os }}-turbo-${{ github.sha }}
38+
restore-keys: |
39+
${{ runner.os }}-turbo-
40+
3241
- name: Setup ENV
3342
uses: the-guild-org/shared-config/setup@main
3443
with:
@@ -39,13 +48,16 @@ jobs:
3948
run: pnpm build
4049

4150
test:
42-
name: Node.js v${{matrix.node_version}} / GraphQL v${{matrix.graphql_version}} / ESLint v9
51+
name:
52+
Node.js v${{matrix.node_version}} / GraphQL v${{matrix.graphql_version}} / ESLint v9
53+
(${{matrix.os}})
4354
timeout-minutes: 60
44-
runs-on: ubuntu-latest
55+
runs-on: ${{ matrix.os }}
4556
needs: [typecheck]
4657
strategy:
4758
matrix:
48-
node_version: [18, 20, 22]
59+
os: [ubuntu-latest, windows-latest]
60+
node_version: [22]
4961
graphql_version: [16]
5062

5163
steps:
@@ -54,6 +66,14 @@ jobs:
5466
with:
5567
fetch-depth: 0
5668

69+
- name: Cache turbo build setup
70+
uses: actions/cache@v4
71+
with:
72+
path: .turbo
73+
key: ${{ runner.os }}-turbo-${{ github.sha }}
74+
restore-keys: |
75+
${{ runner.os }}-turbo-
76+
5777
- name: Setup ENV
5878
uses: the-guild-org/shared-config/setup@main
5979
with:

.prettierrc.cjs

Lines changed: 0 additions & 7 deletions
This file was deleted.

examples/prettier/.eslintrc.cjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ module.exports = {
1212
env: {
1313
es6: true,
1414
},
15+
parserOptions: {
16+
sourceType: 'module',
17+
},
1518
},
1619
{
1720
files: ['*.graphql'],

examples/prettier/prettier.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export default {
2+
endOfLine: 'auto',
3+
singleQuote: true,
4+
};

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
},
1313
"scripts": {
1414
"build": "turbo run build --filter=!website && attw --pack packages/plugin/dist",
15-
"ci:lint": "ESLINT_USE_FLAT_CONFIG=false eslint --ignore-path .gitignore --output-file eslint_report.json --format json .",
15+
"ci:lint": "pnpm lint --output-file eslint_report.json --format json",
1616
"create-rule": "tsx scripts/create-rule.ts",
1717
"generate:configs": "tsx scripts/generate-configs.ts",
1818
"lint": "ESLINT_USE_FLAT_CONFIG=false eslint --ignore-path .gitignore --cache .",
@@ -30,7 +30,7 @@
3030
"@changesets/cli": "2.27.9",
3131
"@graphql-tools/utils": "10.5.6",
3232
"@theguild/eslint-config": "0.13.0",
33-
"@theguild/prettier-config": "2.0.7",
33+
"@theguild/prettier-config": "3.0.0",
3434
"@types/dedent": "0.7.2",
3535
"@types/node": "22.9.0",
3636
"chalk": "5.3.0",

packages/plugin/__tests__/examples.spec.ts

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { spawnSync } from 'node:child_process';
2-
import { join, relative } from 'node:path';
2+
import os from 'node:os';
3+
import path from 'node:path';
34
import { ESLint } from 'eslint';
4-
import { CWD as PROJECT_CWD } from '../src/utils.js';
5+
import { CWD as PROJECT_CWD, slash } from '../src/utils.js';
56

6-
const CWD = join(PROJECT_CWD, '..', '..');
7+
const CWD = path.join(PROJECT_CWD, '..', '..');
78

89
function countErrors(results: ESLint.LintResult[]): number {
910
return results.reduce<number>((acc, curr: ESLint.LintResult & { fatalErrorCount: number }) => {
@@ -18,7 +19,11 @@ ${results.map(result => result.messages.map(m => m.message)).join('\n\n')}
1819
}
1920

2021
function getFlatESLintOutput(cwd: string): ESLint.LintResult[] {
21-
const { stdout, stderr } = spawnSync('eslint', ['--format', 'json', '.'], { cwd });
22+
const { stdout, stderr } = spawnSync('eslint', ['--format', 'json', '.'], {
23+
cwd,
24+
// For Windows, otherwise `stdout` and `stderr` are `null`
25+
shell: os.platform() === 'win32',
26+
});
2227

2328
return parseESLintOutput({ stdout, stderr });
2429
}
@@ -30,6 +35,8 @@ function getLegacyESLintOutput(cwd: string): ESLint.LintResult[] {
3035
{
3136
cwd,
3237
env: { ...process.env, ESLINT_USE_FLAT_CONFIG: 'false' },
38+
// For Windows, otherwise `stdout` and `stderr` are `null`
39+
shell: os.platform() === 'win32',
3340
},
3441
);
3542

@@ -46,10 +53,15 @@ function parseESLintOutput({
4653
const errorOutput = stderr
4754
.toString()
4855
.replace(
49-
/\(node:\d{4,7}\) \[DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead./,
56+
/\(node:\d+\) \[DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead./,
57+
'',
58+
)
59+
.replace(
60+
/\(node:\d+\) ESLintRCWarning: You are using an eslintrc configuration file, which is deprecated and support will be removed in v10.0.0. Please migrate to an eslint.config.js file. See https:\/\/eslint.org\/docs\/latest\/use\/configure\/migration-guide for details./,
5061
'',
5162
)
5263
.replace('(Use `node --trace-deprecation ...` to show where the warning was created)', '')
64+
.replace('(Use `node --trace-warnings ...` to show where the warning was created)', '')
5365
.trimEnd();
5466
if (errorOutput) {
5567
throw new Error(errorOutput);
@@ -63,60 +75,62 @@ function parseESLintOutput({
6375
function normalizeResults(results: ESLint.LintResult[]) {
6476
return results
6577
.map(result => ({
66-
filePath: relative(CWD, result.filePath),
78+
filePath: slash(path.relative(CWD, result.filePath)),
6779
messages: result.messages,
6880
}))
6981
.filter(result => result.messages.length > 0);
7082
}
7183

7284
describe('Examples', () => {
7385
it('should work programmatically', () => {
74-
const cwd = join(CWD, 'examples/programmatic');
86+
const cwd = path.join(CWD, 'examples', 'programmatic');
7587
testESLintOutput(cwd, 6);
7688
});
7789

7890
it('should work on `.js` files', () => {
79-
const cwd = join(CWD, 'examples/code-file');
91+
const cwd = path.join(CWD, 'examples', 'code-file');
8092
testESLintOutput(cwd, 4);
8193
});
8294

8395
it('should work with `graphql-config`', () => {
84-
const cwd = join(CWD, 'examples/graphql-config');
96+
const cwd = path.join(CWD, 'examples', 'graphql-config');
8597
testESLintOutput(cwd, 2);
8698
});
8799

88100
it('should work with `eslint-plugin-prettier`', () => {
89-
const cwd = join(CWD, 'examples/prettier');
101+
const cwd = path.join(CWD, 'examples', 'prettier');
90102
testESLintOutput(cwd, 23);
91103
});
92104

93105
it('should work in monorepo', () => {
94-
const cwd = join(CWD, 'examples/monorepo');
106+
const cwd = path.join(CWD, 'examples', 'monorepo');
95107
testESLintOutput(cwd, 11);
96108
});
97109

98110
it('should work in svelte', () => {
99-
const cwd = join(CWD, 'examples/svelte-code-file');
111+
const cwd = path.join(CWD, 'examples', 'svelte-code-file');
100112
testESLintOutput(cwd, 2);
101113
});
102114

103115
it('should work in vue', () => {
104-
const cwd = join(CWD, 'examples/vue-code-file');
116+
const cwd = path.join(CWD, 'examples', 'vue-code-file');
105117
testESLintOutput(cwd, 2);
106118
});
107119

108120
it('should work in multiple projects', () => {
109-
const cwd = join(CWD, 'examples/multiple-projects-graphql-config');
121+
const cwd = path.join(CWD, 'examples', 'multiple-projects-graphql-config');
110122
testESLintOutput(cwd, 4);
111123
});
112124
});
113125

114126
function testESLintOutput(cwd: string, errorCount: number): void {
115127
const flatResults = getFlatESLintOutput(cwd);
116-
expect(countErrors(flatResults)).toBe(errorCount);
117-
expect(normalizeResults(flatResults)).toMatchSnapshot();
118-
119128
const results = getLegacyESLintOutput(cwd);
129+
// Windows has some offset for `range`, I think due \r\n handling
130+
if (os.platform() !== 'win32') {
131+
expect(normalizeResults(flatResults)).toMatchSnapshot();
132+
expect(normalizeResults(results)).toMatchSnapshot();
133+
}
134+
expect(countErrors(flatResults)).toBe(errorCount);
120135
expect(countErrors(results)).toBe(errorCount);
121-
expect(normalizeResults(results)).toMatchSnapshot();
122136
}

0 commit comments

Comments
 (0)