Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🛠️ ESLint: enable unicorn/prefer-node-protocol rule #2940

Merged
merged 5 commits into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .changeset/tasty-pigs-care.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
*/

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

describe('Logger', () => {
Expand Down
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading