Use node: for Node.js builtin modules

Use the the `node:` protocol when importing Node.js builtin modules
and enable rule in eslint to enforce.

The `node:` protocol for Node.js builtin modules has been available
since Node.js v14.

See: https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/enforce-node-protocol-usage.md
This commit is contained in:
Alan Orth
2025-08-05 15:07:46 +03:00
parent 67a17e4ea1
commit af71c152c1
8 changed files with 25 additions and 17 deletions

View File

@@ -253,6 +253,10 @@
"forceSingleLine": true "forceSingleLine": true
} }
], ],
"import/enforce-node-protocol-usage": [
"error",
"always"
],
"unused-imports/no-unused-imports": "error", "unused-imports/no-unused-imports": "error",
"lodash/import-scope": [ "lodash/import-scope": [

View File

@@ -1,4 +1,4 @@
const fs = require('fs'); const fs = require('node:fs');
// These two global variables are used to store information about the REST API used // These two global variables are used to store information about the REST API used
// by these e2e tests. They are filled out prior to running any tests in the before() // by these e2e tests. They are filled out prior to running any tests in the before()

View File

@@ -12,8 +12,8 @@ import {
readFileSync, readFileSync,
rmSync, rmSync,
writeFileSync, writeFileSync,
} from 'fs'; } from 'node:fs';
import { join } from 'path'; import { join } from 'node:path';
import { default as htmlPlugin } from './src/rules/html'; import { default as htmlPlugin } from './src/rules/html';
import { default as tsPlugin } from './src/rules/ts'; import { default as tsPlugin } from './src/rules/ts';

View File

@@ -6,10 +6,11 @@
* http://www.dspace.org/license/ * http://www.dspace.org/license/
*/ */
import { readFileSync } from 'node:fs';
import { basename } from 'node:path';
import { TSESTree } from '@typescript-eslint/utils'; import { TSESTree } from '@typescript-eslint/utils';
import { RuleContext } from '@typescript-eslint/utils/ts-eslint'; import { RuleContext } from '@typescript-eslint/utils/ts-eslint';
import { readFileSync } from 'fs';
import { basename } from 'path';
import ts, { Identifier } from 'typescript'; import ts, { Identifier } from 'typescript';
import { import {

View File

@@ -6,13 +6,14 @@
* http://www.dspace.org/license/ * http://www.dspace.org/license/
*/ */
import { XhrFactory } from '@angular/common';
import { Injectable } from '@angular/core';
import { import {
Agent as HttpAgent, Agent as HttpAgent,
AgentOptions as HttpAgentOptions, AgentOptions as HttpAgentOptions,
} from 'http'; } from 'node:http';
import { Agent as HttpsAgent } from 'https'; import { Agent as HttpsAgent } from 'node:https';
import { XhrFactory } from '@angular/common';
import { Injectable } from '@angular/core';
import { import {
prototype, prototype,
XMLHttpRequest, XMLHttpRequest,

View File

@@ -8,7 +8,7 @@ import ITEMS from './data/items.json';
import { fakeDataBase } from './db'; import { fakeDataBase } from './db';
const { Router } = require('express'); const { Router } = require('express');
const util = require('util'); const util = require('node:util');
// you would use cookies/token etc // you would use cookies/token etc
const USER_ID = 'f9d98cf1-1b96-464e-8755-bcc2a5c09077'; // hardcoded as an example const USER_ID = 'f9d98cf1-1b96-464e-8755-bcc2a5c09077'; // hardcoded as an example

View File

@@ -1,16 +1,17 @@
import {
existsSync,
readFileSync,
writeFileSync,
} from 'node:fs';
import { join } from 'node:path';
import { import {
blue, blue,
bold, bold,
green, green,
red, red,
} from 'colors'; } from 'colors';
import {
existsSync,
readFileSync,
writeFileSync,
} from 'fs';
import { load } from 'js-yaml'; import { load } from 'js-yaml';
import { join } from 'path';
import { isNotEmpty } from '../app/shared/empty.util'; import { isNotEmpty } from '../app/shared/empty.util';
import { AppConfig } from './app-config.interface'; import { AppConfig } from './app-config.interface';

View File

@@ -1,6 +1,7 @@
import { readFileSync } from 'node:fs';
import { TransferState } from '@angular/core'; import { TransferState } from '@angular/core';
import { TranslateLoader } from '@ngx-translate/core'; import { TranslateLoader } from '@ngx-translate/core';
import { readFileSync } from 'fs';
import { import {
Observable, Observable,
of, of,