Skip to content

Commit 8725d1b

Browse files
authored
🛠️ ESLint: enable unicorn/prefer-node-protocol rule (#2940)
* enable `unicorn/prefer-node-protocol` rule * use `"@types/node": "^16.18.4"` since github ci is use node v16 * fix unit tests * fix * rebase
1 parent 7656cda commit 8725d1b

39 files changed

+91
-78
lines changed

.changeset/tasty-pigs-care.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'cm6-graphql': patch
3+
'codemirror-graphql': patch
4+
'graphiql': patch
5+
'graphql-language-service': patch
6+
'graphql-language-service-cli': patch
7+
'graphql-language-service-server': patch
8+
'vscode-graphql': patch
9+
'vscode-graphql-execution': patch
10+
---
11+
12+
enable `unicorn/prefer-node-protocol` rule

.eslintrc.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,8 @@ module.exports = {
276276
'@typescript-eslint/no-unused-expressions': 'error',
277277
'sonarjs/no-small-switch': 'error',
278278
'sonarjs/no-duplicated-branches': 'error',
279+
'unicorn/prefer-node-protocol': 'error',
280+
'import/no-unresolved': ['error', { ignore: ['^node:'] }],
279281
},
280282

281283
plugins: ['@typescript-eslint', 'promise', 'sonarjs', 'unicorn'],
@@ -344,7 +346,7 @@ module.exports = {
344346
'packages/vscode-graphql-execution/**',
345347
],
346348
rules: {
347-
'import/no-unresolved': ['error', { ignore: ['vscode'] }],
349+
'import/no-unresolved': ['error', { ignore: ['^node:', 'vscode'] }],
348350
},
349351
},
350352
],

examples/monaco-graphql-webpack/webpack.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const path = require('path');
1+
const path = require('node:path');
22

33
const HtmlWebpackPlugin = require('html-webpack-plugin');
44
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');

jest.config.base.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const path = require('path');
1+
const path = require('node:path');
22

33
module.exports = (dir, env = 'jsdom') => {
44
const package = require(`${dir}/package.json`);

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
"@types/express": "^4.17.11",
100100
"@types/fetch-mock": "^7.3.2",
101101
"@types/jest": "^26.0.22",
102-
"@types/node": "^14.14.22",
102+
"@types/node": "^16.18.4",
103103
"@types/prettier": "^2.7.0",
104104
"@types/react": "^17.0.37",
105105
"@types/react-dom": "^17.0.17",

packages/cm6-graphql/__tests__/test.spec.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { graphqlLanguage } from '../dist/index.js';
22
import { fileTests } from '@lezer/generator/dist/test';
33

4-
import * as fs from 'fs';
5-
import * as path from 'path';
4+
import * as fs from 'node:fs';
5+
import * as path from 'node:path';
66

77
// because of the babel transformations, __dirname is the package root (cm6-graphql)
88
const caseDir = path.resolve(path.dirname(__dirname), '__tests__');
@@ -23,7 +23,7 @@ describe('codemirror 6 language', () => {
2323
try {
2424
run(graphqlLanguage.parser);
2525
} catch (err) {
26-
require('console').log(name, err);
26+
require('node:console').log(name, err);
2727
throw err;
2828
}
2929
});

packages/codemirror-graphql/src/__tests__/lint-test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
import CodeMirror from 'codemirror';
1111
import 'codemirror/addon/lint/lint';
12-
import { readFileSync } from 'fs';
13-
import { join } from 'path';
12+
import { readFileSync } from 'node:fs';
13+
import { join } from 'node:path';
1414
import { GraphQLError, OperationDefinitionNode } from 'graphql';
1515
import '../lint';
1616
import '../mode';

packages/codemirror-graphql/src/__tests__/mode-test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
import CodeMirror from 'codemirror';
1111
import 'codemirror/addon/runmode/runmode';
12-
import { readFileSync } from 'fs';
13-
import { join } from 'path';
12+
import { readFileSync } from 'node:fs';
13+
import { join } from 'node:path';
1414
import '../mode';
1515

1616
describe('graphql-mode', () => {

packages/graphiql/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
"@testing-library/react": "12.1.5",
6868
"@types/codemirror": "^5.60.5",
6969
"@types/markdown-it": "^12.2.3",
70-
"@types/node": "^14.14.22",
70+
"@types/node": "^16.18.4",
7171
"@types/testing-library__jest-dom": "5.14.5",
7272
"babel-loader": "^8.1.0",
7373
"babel-plugin-macros": "^2.8.0",

packages/graphiql/resources/webpack.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const path = require('path');
1+
const path = require('node:path');
22
const webpack = require('webpack');
33

44
const HtmlWebpackPlugin = require('html-webpack-plugin');

packages/graphiql/test/beforeDevServer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
const express = require('express');
9-
const path = require('path');
9+
const path = require('node:path');
1010
const { graphqlHTTP } = require('express-graphql');
1111
const schema = require('./schema');
1212
const { schema: badSchema } = require('./bad-schema');

packages/graphiql/test/e2e-server.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
/* eslint-disable no-console */
99
const express = require('express');
10-
const path = require('path');
10+
const path = require('node:path');
1111
const { graphqlHTTP } = require('express-graphql');
1212
const { GraphQLError } = require('graphql');
1313
const schema = require('./schema');

packages/graphql-language-service-cli/src/client.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@
99

1010
import { GraphQLSchema, buildSchema, buildClientSchema } from 'graphql';
1111

12-
import invariant from 'assert';
13-
import fs from 'fs';
12+
import invariant from 'node:assert';
13+
import fs from 'node:fs';
1414
import {
1515
getAutocompleteSuggestions,
1616
getDiagnostics,
1717
getOutline,
1818
Position,
1919
} from 'graphql-language-service';
2020

21-
import path from 'path';
21+
import path from 'node:path';
2222

2323
import type { CompletionItem, Diagnostic } from 'graphql-language-service';
2424

packages/graphql-language-service-server/src/GraphQLCache.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import type {
1818
Uri,
1919
} from 'graphql-language-service';
2020

21-
import * as fs from 'fs';
21+
import * as fs from 'node:fs';
2222
import { GraphQLSchema, Kind, extendSchema, parse, visit } from 'graphql';
2323
import nullthrows from 'nullthrows';
2424

packages/graphql-language-service-server/src/Logger.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
import { Logger as VSCodeLogger } from 'vscode-jsonrpc';
1111
import { DiagnosticSeverity } from 'vscode-languageserver';
1212

13-
import * as fs from 'fs';
14-
import * as os from 'os';
15-
import { join } from 'path';
16-
import { Socket } from 'net';
13+
import * as fs from 'node:fs';
14+
import * as os from 'node:os';
15+
import { join } from 'node:path';
16+
import { Socket } from 'node:net';
1717

1818
import {
1919
DIAGNOSTIC_SEVERITY,

packages/graphql-language-service-server/src/MessageProcessor.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
*/
99

1010
import mkdirp from 'mkdirp';
11-
import { readFileSync, existsSync, writeFileSync, writeFile } from 'fs';
12-
import * as path from 'path';
11+
import { readFileSync, existsSync, writeFileSync, writeFile } from 'node:fs';
12+
import * as path from 'node:path';
1313
import glob from 'fast-glob';
1414
import { URI } from 'vscode-uri';
1515
import {
@@ -61,7 +61,7 @@ import { parseDocument, DEFAULT_SUPPORTED_EXTENSIONS } from './parseDocument';
6161

6262
import { Logger } from './Logger';
6363
import { printSchema, visit, parse, FragmentDefinitionNode } from 'graphql';
64-
import { tmpdir } from 'os';
64+
import { tmpdir } from 'node:os';
6565
import {
6666
ConfigEmptyError,
6767
ConfigInvalidError,
@@ -71,7 +71,7 @@ import {
7171
ProjectNotFoundError,
7272
} from 'graphql-config';
7373
import type { LoadConfigOptions } from './types';
74-
import { promisify } from 'util';
74+
import { promisify } from 'node:util';
7575

7676
const writeFileAsync = promisify(writeFile);
7777

packages/graphql-language-service-server/src/__tests__/GraphQLLanguageService-test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*/
99

10-
import { join } from 'path';
10+
import { join } from 'node:path';
1111

1212
import { GraphQLConfig } from 'graphql-config';
1313
import { GraphQLLanguageService } from '../GraphQLLanguageService';

packages/graphql-language-service-server/src/__tests__/Logger-test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*/
99

10-
import { tmpdir } from 'os';
10+
import { tmpdir } from 'node:os';
1111
import { Logger } from '../Logger';
1212

1313
describe('Logger', () => {

packages/graphql-language-service-server/src/__tests__/MessageProcessor-test.ts

+11-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* LICENSE file in the root directory of this source tree.
77
*
88
*/
9-
import { tmpdir } from 'os';
9+
import { tmpdir } from 'node:os';
1010
import { SymbolKind } from 'vscode-languageserver';
1111
import { FileChangeType } from 'vscode-languageserver-protocol';
1212
import { Position, Range } from 'graphql-language-service';
@@ -23,9 +23,9 @@ import { loadConfig } from 'graphql-config';
2323
import type { DefinitionQueryResult, Outline } from 'graphql-language-service';
2424

2525
import { Logger } from '../Logger';
26-
import { pathToFileURL } from 'url';
26+
import { pathToFileURL } from 'node:url';
2727

28-
jest.mock('fs', () => ({
28+
jest.mock('node:fs', () => ({
2929
...jest.requireActual<typeof import('fs')>('fs'),
3030
readFileSync: jest.fn(jest.requireActual('fs').readFileSync),
3131
}));
@@ -316,7 +316,8 @@ describe('MessageProcessor', () => {
316316
});
317317

318318
describe('handleDidOpenOrSaveNotification', () => {
319-
const mockReadFileSync: jest.Mock = jest.requireMock('fs').readFileSync;
319+
const mockReadFileSync: jest.Mock =
320+
jest.requireMock('node:fs').readFileSync;
320321

321322
beforeEach(() => {
322323
mockReadFileSync.mockReturnValue('');
@@ -718,7 +719,8 @@ query Test {
718719
});
719720

720721
describe('handleWatchedFilesChangedNotification', () => {
721-
const mockReadFileSync: jest.Mock = jest.requireMock('fs').readFileSync;
722+
const mockReadFileSync: jest.Mock =
723+
jest.requireMock('node:fs').readFileSync;
722724

723725
beforeEach(() => {
724726
mockReadFileSync.mockReturnValue('');
@@ -740,7 +742,8 @@ query Test {
740742
});
741743

742744
describe('handleWatchedFilesChangedNotification without graphql config', () => {
743-
const mockReadFileSync: jest.Mock = jest.requireMock('fs').readFileSync;
745+
const mockReadFileSync: jest.Mock =
746+
jest.requireMock('node:fs').readFileSync;
744747

745748
beforeEach(() => {
746749
mockReadFileSync.mockReturnValue('');
@@ -763,7 +766,8 @@ query Test {
763766
});
764767

765768
describe('handleDidChangedNotification without graphql config', () => {
766-
const mockReadFileSync: jest.Mock = jest.requireMock('fs').readFileSync;
769+
const mockReadFileSync: jest.Mock =
770+
jest.requireMock('node:fs').readFileSync;
767771

768772
beforeEach(() => {
769773
mockReadFileSync.mockReturnValue('');

packages/graphql-language-service-server/src/__tests__/findGraphQLTags-test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* LICENSE file in the root directory of this source tree.
77
*
88
*/
9-
import { tmpdir } from 'os';
9+
import { tmpdir } from 'node:os';
1010

1111
import { findGraphQLTags as baseFindGraphQLTags } from '../findGraphQLTags';
1212

packages/graphql-language-service-server/src/parseDocument.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { extname } from 'path';
1+
import { extname } from 'node:path';
22
import type { CachedContent } from 'graphql-language-service';
33
import { Range, Position } from 'graphql-language-service';
44

packages/graphql-language-service-server/src/startServer.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* LICENSE file in the root directory of this source tree.
77
*
88
*/
9-
import * as net from 'net';
9+
import * as net from 'node:net';
1010
import { MessageProcessor } from './MessageProcessor';
1111
import { GraphQLConfig, GraphQLExtensionDeclaration } from 'graphql-config';
1212
import {

packages/graphql-language-service/benchmark/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable no-console */
2-
import fs from 'fs';
3-
import path from 'path';
2+
import fs from 'node:fs';
3+
import path from 'node:path';
44
import Benchmark from 'benchmark';
55
import { parse } from 'graphql';
66
import { onlineParser, CharacterStream } from '../src';

packages/graphql-language-service/src/interface/__tests__/getAutocompleteSuggestions-test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
CompletionItem,
1313
} from 'graphql-language-service';
1414

15-
import fs from 'fs';
15+
import fs from 'node:fs';
1616
import {
1717
buildSchema,
1818
FragmentDefinitionNode,
@@ -21,7 +21,7 @@ import {
2121
version as graphQLVersion,
2222
} from 'graphql';
2323
import { Position } from '../../utils';
24-
import path from 'path';
24+
import path from 'node:path';
2525

2626
import { getAutocompleteSuggestions } from '../getAutocompleteSuggestions';
2727

packages/graphql-language-service/src/interface/__tests__/getDiagnostics-test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* @flow
99
*/
1010

11-
import fs from 'fs';
11+
import fs from 'node:fs';
1212
import {
1313
buildSchema,
1414
parse,
@@ -18,7 +18,7 @@ import {
1818
ASTVisitor,
1919
FragmentDefinitionNode,
2020
} from 'graphql';
21-
import path from 'path';
21+
import path from 'node:path';
2222

2323
import {
2424
getDiagnostics,

packages/graphql-language-service/src/interface/__tests__/getHoverInformation-test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010

1111
import { Hover } from 'vscode-languageserver-types';
1212

13-
import fs from 'fs';
13+
import fs from 'node:fs';
1414
import { buildSchema, GraphQLSchema } from 'graphql';
1515
import { Position } from 'graphql-language-service';
16-
import path from 'path';
16+
import path from 'node:path';
1717

1818
import { getHoverInformation } from '../getHoverInformation';
1919

packages/graphql-language-service/src/utils/__tests__/getVariablesJSONSchema.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9-
import { readFileSync } from 'fs';
9+
import { readFileSync } from 'node:fs';
1010
import { buildSchema, GraphQLSchema, parse } from 'graphql';
1111

12-
import { join } from 'path';
12+
import { join } from 'node:path';
1313
import { collectVariables } from '../collectVariables';
1414

1515
import { getVariablesJSONSchema } from '../getVariablesJSONSchema';

packages/graphql-language-service/src/utils/__tests__/validateWithCustomRules-test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9-
import { readFileSync } from 'fs';
9+
import { readFileSync } from 'node:fs';
1010
import {
1111
GraphQLError,
1212
buildSchema,
@@ -15,7 +15,7 @@ import {
1515
ValidationContext,
1616
ArgumentNode,
1717
} from 'graphql';
18-
import { join } from 'path';
18+
import { join } from 'node:path';
1919

2020
import { validateWithCustomRules } from '../validateWithCustomRules';
2121

0 commit comments

Comments
 (0)