Skip to content

Commit

Permalink
🛠️ ESLint: enable unicorn/prefer-node-protocol rule (#2940)
Browse files Browse the repository at this point in the history
* enable `unicorn/prefer-node-protocol` rule

* use `"@types/node": "^16.18.4"` since github ci is use node v16

* fix unit tests

* fix

* rebase
  • Loading branch information
dimaMachina committed Feb 3, 2023
1 parent 7656cda commit 8725d1b
Show file tree
Hide file tree
Showing 39 changed files with 91 additions and 78 deletions.
12 changes: 12 additions & 0 deletions .changeset/tasty-pigs-care.md
@@ -0,0 +1,12 @@
---
'cm6-graphql': patch
'codemirror-graphql': patch
'graphiql': patch
'graphql-language-service': patch
'graphql-language-service-cli': patch
'graphql-language-service-server': patch
'vscode-graphql': patch
'vscode-graphql-execution': patch
---

enable `unicorn/prefer-node-protocol` rule
4 changes: 3 additions & 1 deletion .eslintrc.js
Expand Up @@ -276,6 +276,8 @@ module.exports = {
'@typescript-eslint/no-unused-expressions': 'error',
'sonarjs/no-small-switch': 'error',
'sonarjs/no-duplicated-branches': 'error',
'unicorn/prefer-node-protocol': 'error',
'import/no-unresolved': ['error', { ignore: ['^node:'] }],
},

plugins: ['@typescript-eslint', 'promise', 'sonarjs', 'unicorn'],
Expand Down Expand Up @@ -344,7 +346,7 @@ module.exports = {
'packages/vscode-graphql-execution/**',
],
rules: {
'import/no-unresolved': ['error', { ignore: ['vscode'] }],
'import/no-unresolved': ['error', { ignore: ['^node:', 'vscode'] }],
},
},
],
Expand Down
2 changes: 1 addition & 1 deletion examples/monaco-graphql-webpack/webpack.config.js
@@ -1,4 +1,4 @@
const path = require('path');
const path = require('node:path');

const HtmlWebpackPlugin = require('html-webpack-plugin');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
Expand Down
2 changes: 1 addition & 1 deletion jest.config.base.js
@@ -1,4 +1,4 @@
const path = require('path');
const path = require('node:path');

module.exports = (dir, env = 'jsdom') => {
const package = require(`${dir}/package.json`);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -99,7 +99,7 @@
"@types/express": "^4.17.11",
"@types/fetch-mock": "^7.3.2",
"@types/jest": "^26.0.22",
"@types/node": "^14.14.22",
"@types/node": "^16.18.4",
"@types/prettier": "^2.7.0",
"@types/react": "^17.0.37",
"@types/react-dom": "^17.0.17",
Expand Down
6 changes: 3 additions & 3 deletions packages/cm6-graphql/__tests__/test.spec.ts
@@ -1,8 +1,8 @@
import { graphqlLanguage } from '../dist/index.js';
import { fileTests } from '@lezer/generator/dist/test';

import * as fs from 'fs';
import * as path from 'path';
import * as fs from 'node:fs';
import * as path from 'node:path';

// because of the babel transformations, __dirname is the package root (cm6-graphql)
const caseDir = path.resolve(path.dirname(__dirname), '__tests__');
Expand All @@ -23,7 +23,7 @@ describe('codemirror 6 language', () => {
try {
run(graphqlLanguage.parser);
} catch (err) {
require('console').log(name, err);
require('node:console').log(name, err);
throw err;
}
});
Expand Down
4 changes: 2 additions & 2 deletions packages/codemirror-graphql/src/__tests__/lint-test.ts
Expand Up @@ -9,8 +9,8 @@

import CodeMirror from 'codemirror';
import 'codemirror/addon/lint/lint';
import { readFileSync } from 'fs';
import { join } from 'path';
import { readFileSync } from 'node:fs';
import { join } from 'node:path';
import { GraphQLError, OperationDefinitionNode } from 'graphql';
import '../lint';
import '../mode';
Expand Down
4 changes: 2 additions & 2 deletions packages/codemirror-graphql/src/__tests__/mode-test.ts
Expand Up @@ -9,8 +9,8 @@

import CodeMirror from 'codemirror';
import 'codemirror/addon/runmode/runmode';
import { readFileSync } from 'fs';
import { join } from 'path';
import { readFileSync } from 'node:fs';
import { join } from 'node:path';
import '../mode';

describe('graphql-mode', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/graphiql/package.json
Expand Up @@ -67,7 +67,7 @@
"@testing-library/react": "12.1.5",
"@types/codemirror": "^5.60.5",
"@types/markdown-it": "^12.2.3",
"@types/node": "^14.14.22",
"@types/node": "^16.18.4",
"@types/testing-library__jest-dom": "5.14.5",
"babel-loader": "^8.1.0",
"babel-plugin-macros": "^2.8.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/graphiql/resources/webpack.config.js
@@ -1,4 +1,4 @@
const path = require('path');
const path = require('node:path');
const webpack = require('webpack');

const HtmlWebpackPlugin = require('html-webpack-plugin');
Expand Down
2 changes: 1 addition & 1 deletion packages/graphiql/test/beforeDevServer.js
Expand Up @@ -6,7 +6,7 @@
*/

const express = require('express');
const path = require('path');
const path = require('node:path');
const { graphqlHTTP } = require('express-graphql');
const schema = require('./schema');
const { schema: badSchema } = require('./bad-schema');
Expand Down
2 changes: 1 addition & 1 deletion packages/graphiql/test/e2e-server.js
Expand Up @@ -7,7 +7,7 @@

/* eslint-disable no-console */
const express = require('express');
const path = require('path');
const path = require('node:path');
const { graphqlHTTP } = require('express-graphql');
const { GraphQLError } = require('graphql');
const schema = require('./schema');
Expand Down
6 changes: 3 additions & 3 deletions packages/graphql-language-service-cli/src/client.ts
Expand Up @@ -9,16 +9,16 @@

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

import invariant from 'assert';
import fs from 'fs';
import invariant from 'node:assert';
import fs from 'node:fs';
import {
getAutocompleteSuggestions,
getDiagnostics,
getOutline,
Position,
} from 'graphql-language-service';

import path from 'path';
import path from 'node:path';

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

Expand Down
Expand Up @@ -18,7 +18,7 @@ import type {
Uri,
} from 'graphql-language-service';

import * as fs from 'fs';
import * as fs from 'node:fs';
import { GraphQLSchema, Kind, extendSchema, parse, visit } from 'graphql';
import nullthrows from 'nullthrows';

Expand Down
8 changes: 4 additions & 4 deletions packages/graphql-language-service-server/src/Logger.ts
Expand Up @@ -10,10 +10,10 @@
import { Logger as VSCodeLogger } from 'vscode-jsonrpc';
import { DiagnosticSeverity } from 'vscode-languageserver';

import * as fs from 'fs';
import * as os from 'os';
import { join } from 'path';
import { Socket } from 'net';
import * as fs from 'node:fs';
import * as os from 'node:os';
import { join } from 'node:path';
import { Socket } from 'node:net';

import {
DIAGNOSTIC_SEVERITY,
Expand Down
Expand Up @@ -8,8 +8,8 @@
*/

import mkdirp from 'mkdirp';
import { readFileSync, existsSync, writeFileSync, writeFile } from 'fs';
import * as path from 'path';
import { readFileSync, existsSync, writeFileSync, writeFile } from 'node:fs';
import * as path from 'node:path';
import glob from 'fast-glob';
import { URI } from 'vscode-uri';
import {
Expand Down Expand Up @@ -61,7 +61,7 @@ import { parseDocument, DEFAULT_SUPPORTED_EXTENSIONS } from './parseDocument';

import { Logger } from './Logger';
import { printSchema, visit, parse, FragmentDefinitionNode } from 'graphql';
import { tmpdir } from 'os';
import { tmpdir } from 'node:os';
import {
ConfigEmptyError,
ConfigInvalidError,
Expand All @@ -71,7 +71,7 @@ import {
ProjectNotFoundError,
} from 'graphql-config';
import type { LoadConfigOptions } from './types';
import { promisify } from 'util';
import { promisify } from 'node:util';

const writeFileAsync = promisify(writeFile);

Expand Down
Expand Up @@ -7,7 +7,7 @@
*
*/

import { join } from 'path';
import { join } from 'node:path';

import { GraphQLConfig } from 'graphql-config';
import { GraphQLLanguageService } from '../GraphQLLanguageService';
Expand Down
Expand Up @@ -7,7 +7,7 @@
*
*/

import { tmpdir } from 'os';
import { tmpdir } from 'node:os';
import { Logger } from '../Logger';

describe('Logger', () => {
Expand Down
Expand Up @@ -6,7 +6,7 @@
* LICENSE file in the root directory of this source tree.
*
*/
import { tmpdir } from 'os';
import { tmpdir } from 'node:os';
import { SymbolKind } from 'vscode-languageserver';
import { FileChangeType } from 'vscode-languageserver-protocol';
import { Position, Range } from 'graphql-language-service';
Expand All @@ -23,9 +23,9 @@ import { loadConfig } from 'graphql-config';
import type { DefinitionQueryResult, Outline } from 'graphql-language-service';

import { Logger } from '../Logger';
import { pathToFileURL } from 'url';
import { pathToFileURL } from 'node:url';

jest.mock('fs', () => ({
jest.mock('node:fs', () => ({
...jest.requireActual<typeof import('fs')>('fs'),
readFileSync: jest.fn(jest.requireActual('fs').readFileSync),
}));
Expand Down Expand Up @@ -316,7 +316,8 @@ describe('MessageProcessor', () => {
});

describe('handleDidOpenOrSaveNotification', () => {
const mockReadFileSync: jest.Mock = jest.requireMock('fs').readFileSync;
const mockReadFileSync: jest.Mock =
jest.requireMock('node:fs').readFileSync;

beforeEach(() => {
mockReadFileSync.mockReturnValue('');
Expand Down Expand Up @@ -718,7 +719,8 @@ query Test {
});

describe('handleWatchedFilesChangedNotification', () => {
const mockReadFileSync: jest.Mock = jest.requireMock('fs').readFileSync;
const mockReadFileSync: jest.Mock =
jest.requireMock('node:fs').readFileSync;

beforeEach(() => {
mockReadFileSync.mockReturnValue('');
Expand All @@ -740,7 +742,8 @@ query Test {
});

describe('handleWatchedFilesChangedNotification without graphql config', () => {
const mockReadFileSync: jest.Mock = jest.requireMock('fs').readFileSync;
const mockReadFileSync: jest.Mock =
jest.requireMock('node:fs').readFileSync;

beforeEach(() => {
mockReadFileSync.mockReturnValue('');
Expand All @@ -763,7 +766,8 @@ query Test {
});

describe('handleDidChangedNotification without graphql config', () => {
const mockReadFileSync: jest.Mock = jest.requireMock('fs').readFileSync;
const mockReadFileSync: jest.Mock =
jest.requireMock('node:fs').readFileSync;

beforeEach(() => {
mockReadFileSync.mockReturnValue('');
Expand Down
Expand Up @@ -6,7 +6,7 @@
* LICENSE file in the root directory of this source tree.
*
*/
import { tmpdir } from 'os';
import { tmpdir } from 'node:os';

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

Expand Down
@@ -1,4 +1,4 @@
import { extname } from 'path';
import { extname } from 'node:path';
import type { CachedContent } from 'graphql-language-service';
import { Range, Position } from 'graphql-language-service';

Expand Down
Expand Up @@ -6,7 +6,7 @@
* LICENSE file in the root directory of this source tree.
*
*/
import * as net from 'net';
import * as net from 'node:net';
import { MessageProcessor } from './MessageProcessor';
import { GraphQLConfig, GraphQLExtensionDeclaration } from 'graphql-config';
import {
Expand Down
4 changes: 2 additions & 2 deletions packages/graphql-language-service/benchmark/index.ts
@@ -1,6 +1,6 @@
/* eslint-disable no-console */
import fs from 'fs';
import path from 'path';
import fs from 'node:fs';
import path from 'node:path';
import Benchmark from 'benchmark';
import { parse } from 'graphql';
import { onlineParser, CharacterStream } from '../src';
Expand Down
Expand Up @@ -12,7 +12,7 @@ import {
CompletionItem,
} from 'graphql-language-service';

import fs from 'fs';
import fs from 'node:fs';
import {
buildSchema,
FragmentDefinitionNode,
Expand All @@ -21,7 +21,7 @@ import {
version as graphQLVersion,
} from 'graphql';
import { Position } from '../../utils';
import path from 'path';
import path from 'node:path';

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

Expand Down
Expand Up @@ -8,7 +8,7 @@
* @flow
*/

import fs from 'fs';
import fs from 'node:fs';
import {
buildSchema,
parse,
Expand All @@ -18,7 +18,7 @@ import {
ASTVisitor,
FragmentDefinitionNode,
} from 'graphql';
import path from 'path';
import path from 'node:path';

import {
getDiagnostics,
Expand Down
Expand Up @@ -10,10 +10,10 @@

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

import fs from 'fs';
import fs from 'node:fs';
import { buildSchema, GraphQLSchema } from 'graphql';
import { Position } from 'graphql-language-service';
import path from 'path';
import path from 'node:path';

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

Expand Down
Expand Up @@ -6,10 +6,10 @@
* LICENSE file in the root directory of this source tree.
*/

import { readFileSync } from 'fs';
import { readFileSync } from 'node:fs';
import { buildSchema, GraphQLSchema, parse } from 'graphql';

import { join } from 'path';
import { join } from 'node:path';
import { collectVariables } from '../collectVariables';

import { getVariablesJSONSchema } from '../getVariablesJSONSchema';
Expand Down
Expand Up @@ -6,7 +6,7 @@
* LICENSE file in the root directory of this source tree.
*/

import { readFileSync } from 'fs';
import { readFileSync } from 'node:fs';
import {
GraphQLError,
buildSchema,
Expand All @@ -15,7 +15,7 @@ import {
ValidationContext,
ArgumentNode,
} from 'graphql';
import { join } from 'path';
import { join } from 'node:path';

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

Expand Down

0 comments on commit 8725d1b

Please sign in to comment.