Skip to content

Commit 96165a7

Browse files
authored
Replace deprecated ESLint rules (#6719)
## What's the problem this PR addresses? - closes #6713 `@yarnpkg/eslint-config` makes use of two ESLint rules that are now deprecated: | Linter | Deprecated Rule | | ----------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- | | [ESLint](https://eslint.org/docs/latest/rules/) | [no-new-symbol](https://eslint.org/docs/latest/rules/no-new-symbol) | | [@typescript-eslint/eslint-plugin](https://typescript-eslint.io/rules/) | [@typescript-eslint/prefer-ts-expect-error](https://typescript-eslint.io/rules/prefer-ts-expect-error/) | ## How did you fix it? Replaced the two deprecated rules as follows: | Deprecated Rule | Replacement Rule | | ------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- | | [no-new-symbol](https://eslint.org/docs/latest/rules/no-new-symbol) | [no-new-native-nonconstructor](https://eslint.org/docs/latest/rules/no-new-native-nonconstructor) | | [@typescript-eslint/prefer-ts-expect-error](https://typescript-eslint.io/rules/prefer-ts-expect-error/) | [@typescript-eslint/ban-ts-comment](https://typescript-eslint.io/rules/ban-ts-comment) | Changed all instances of `// @ts-expect-error` without comments to `// @ts-expect-error - reason TBS` to satisfy `@typescript-eslint/ban-ts-comment`. Comments may be replaced later as necessary. The rule will however encourage any new use of `// @ts-expect-error` to include an explanation comment. Executed ```shell yarn test:lint yarn typecheck:all ``` to confirm no remaining linting / TypeScript issues. ## Checklist - [X] I have read the [Contributing Guide](https://yarnpkg.com/advanced/contributing). - [X] I have set the packages that need to be released for my changes to be effective. (`@yarnpkg/eslint-config`) - [x] I will check that all automated PR checks pass before the PR gets reviewed.
1 parent d62578c commit 96165a7

File tree

24 files changed

+54
-41
lines changed

24 files changed

+54
-41
lines changed

.yarn/versions/caca25a0.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
releases:
2+
"@yarnpkg/eslint-config": patch
3+
4+
declined:
5+
- "@yarnpkg/plugin-constraints"
6+
- "@yarnpkg/plugin-npm-cli"
7+
- "@yarnpkg/core"
8+
- "@yarnpkg/doctor"
9+
- "@yarnpkg/fslib"
10+
- "@yarnpkg/libzip"
11+
- "@yarnpkg/pnp"
12+
- "@yarnpkg/pnpify"
13+
- "@yarnpkg/shell"

packages/acceptance-tests/pkg-tests-specs/sources/commands/npm/logout.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ describe(`Commands`, () => {
4848
let stderr: string;
4949

5050
try {
51-
// @ts-expect-error
51+
// @ts-expect-error - reason TBS
5252
({code, stdout, stderr} = await run(`npm`, `logout`, {
5353
env: {
5454
HOME: homePath,
@@ -107,7 +107,7 @@ describe(`Commands`, () => {
107107
let stderr: string;
108108

109109
try {
110-
// @ts-expect-error
110+
// @ts-expect-error - reason TBS
111111
({code, stdout, stderr} = await run(`npm`, `logout`, `--all`, {
112112
env: {
113113
HOME: homePath,
@@ -155,7 +155,7 @@ describe(`Commands`, () => {
155155
let stderr: string;
156156

157157
try {
158-
// @ts-expect-error
158+
// @ts-expect-error - reason TBS
159159
({code, stdout, stderr} = await run(`npm`, `logout`, `--publish`, {
160160
env: {
161161
HOME: homePath,
@@ -202,7 +202,7 @@ describe(`Commands`, () => {
202202
let stderr: string;
203203

204204
try {
205-
// @ts-expect-error
205+
// @ts-expect-error - reason TBS
206206
({code, stdout, stderr} = await run(`npm`, `logout`, `--scope`, FAKE_FIRST_SCOPE, {
207207
env: {
208208
HOME: homePath,

packages/docusaurus/config/typedoc/plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {miscUtils} from '@yarnpkg/core';
2-
// @ts-expect-error
2+
// @ts-expect-error - reason TBS
33
import pnpApi from 'pnpapi';
44
import {Application, Converter, DeclarationReflection, ProjectReflection, SignatureReflection, type Context} from 'typedoc';
55

packages/docusaurus/src/lib/npmTools.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {normalizeRepoUrl} from '@yarnpkg/monorepo/packages/plugin-git/sources/utils/normalizeRepoUrl';
22
import DOMPurify from 'dompurify';
33
import gitUrlParse from 'git-url-parse';
4-
// @ts-expect-error
4+
// @ts-expect-error - reason TBS
55
import {Marked} from 'marked';
66
import {useQuery} from 'react-query';
77
import {resolve as resolveExports} from 'resolve.exports';

packages/docusaurus/src/theme/DocRoot/Layout/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function getReactNodeFromDomNode(domNode: Element) {
1414
if (!fiberKey)
1515
throw new Error(`Assertion failed: Couldn't find the React node associated with the DOM node`);
1616

17-
// @ts-expect-error
17+
// @ts-expect-error - reason TBS
1818
const {type: Type, memoizedProps} = domNode[fiberKey];
1919
return <Type {...memoizedProps}/>;
2020
}

packages/eslint-config/rules/best-practices.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default [
2020
ignoreRestSiblings: true,
2121
}],
2222

23-
'@typescript-eslint/prefer-ts-expect-error': 2,
23+
'@typescript-eslint/ban-ts-comment': 2,
2424

2525
'arca/no-default-export': 2,
2626

packages/eslint-config/rules/errors.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export default [
5050

5151
'no-misleading-character-class': 2,
5252

53-
'no-new-symbol': 2,
53+
'no-new-native-nonconstructor': 2,
5454

5555
'no-redeclare': 2,
5656

packages/eslint-config/rules/typescript.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default [
3131
'no-const-assign': 0,
3232

3333
// Checked by Typescript - ts(2588)
34-
'no-new-symbol': 0,
34+
'no-new-native-nonconstructor': 0,
3535

3636
// Checked by Typescript - ts(2376)
3737
'no-this-before-super': 0,

packages/plugin-constraints/sources/Constraints.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import {Ident, MessageName, nodeUtils, Project, ReportError, Workspace} from '@yarnpkg/core';
33
import {miscUtils, structUtils} from '@yarnpkg/core';
44
import {xfs, ppath, PortablePath} from '@yarnpkg/fslib';
5-
// @ts-expect-error
5+
// @ts-expect-error - reason TBS
66
import plLists from 'tau-prolog/modules/lists';
77
import pl from 'tau-prolog';
88

packages/plugin-npm-cli/sources/commands/npm/info.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ export default class NpmInfoCommand extends BaseCommand {
163163
serialized = {};
164164

165165
for (const field of fields) {
166-
// @ts-expect-error
166+
// @ts-expect-error - reason TBS
167167
const value = packageInformation[field];
168168

169169
if (typeof value !== `undefined`) {

packages/yarnpkg-core/sources/Configuration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2045,7 +2045,7 @@ export class Configuration {
20452045

20462046
const ret = await hook(...args);
20472047
if (typeof ret !== `undefined`) {
2048-
// @ts-expect-error
2048+
// @ts-expect-error - reason TBS
20492049
return ret;
20502050
}
20512051
}

packages/yarnpkg-core/sources/structUtils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -527,13 +527,13 @@ export function parseRange<Opts extends ParseRangeOptions>(range: string, opts?:
527527
: null;
528528

529529
return {
530-
// @ts-expect-error
530+
// @ts-expect-error - reason TBS
531531
protocol,
532-
// @ts-expect-error
532+
// @ts-expect-error - reason TBS
533533
source,
534-
// @ts-expect-error
534+
// @ts-expect-error - reason TBS
535535
selector,
536-
// @ts-expect-error
536+
// @ts-expect-error - reason TBS
537537
params,
538538
};
539539
}

packages/yarnpkg-doctor/sources/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ async function buildJsonNode(p: PortablePath, accesses: Array<string>) {
195195
/*setParentNodes */ true,
196196
);
197197

198-
// @ts-expect-error
198+
// @ts-expect-error - reason TBS
199199
let node: ts.Node = sourceFile.statements[0].expression;
200200
if (!node)
201201
throw new Error(`Invalid source tree`);

packages/yarnpkg-fslib/sources/MountFS.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -924,14 +924,14 @@ export class MountFS<MountedFS extends MountableFS> extends BasePortableFakeFS {
924924
return this.makeCallSync(p, () => {
925925
return this.baseFs.watch(
926926
p,
927-
// @ts-expect-error
927+
// @ts-expect-error - reason TBS
928928
a,
929929
b,
930930
);
931931
}, (mountFs, {subPath}) => {
932932
return mountFs.watch(
933933
subPath,
934-
// @ts-expect-error
934+
// @ts-expect-error - reason TBS
935935
a,
936936
b,
937937
);
@@ -944,7 +944,7 @@ export class MountFS<MountedFS extends MountableFS> extends BasePortableFakeFS {
944944
return this.makeCallSync(p, () => {
945945
return this.baseFs.watchFile(
946946
p,
947-
// @ts-expect-error
947+
// @ts-expect-error - reason TBS
948948
a,
949949
b,
950950
);

packages/yarnpkg-fslib/sources/NodeFS.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export class NodeFS extends BasePortableFakeFS {
5555
this.realFs.opendir(npath.fromPortablePath(p), this.makeCallback(resolve, reject) as any);
5656
}
5757
}).then(dir => {
58-
// @ts-expect-error
58+
// @ts-expect-error - reason TBS
5959
//
6060
// We need a way to tell TS that the values returned by the `read`
6161
// methods are compatible with `Dir`, especially the `name` field.
@@ -81,7 +81,7 @@ export class NodeFS extends BasePortableFakeFS {
8181
? this.realFs.opendirSync(npath.fromPortablePath(p), opts)
8282
: this.realFs.opendirSync(npath.fromPortablePath(p));
8383

84-
// @ts-expect-error
84+
// @ts-expect-error - reason TBS
8585
//
8686
// We need a way to tell TS that the values returned by the `read`
8787
// methods are compatible with `Dir`, especially the `name` field.
@@ -572,7 +572,7 @@ export class NodeFS extends BasePortableFakeFS {
572572
watch(p: PortablePath, a?: WatchOptions | WatchCallback, b?: WatchCallback) {
573573
return this.realFs.watch(
574574
npath.fromPortablePath(p),
575-
// @ts-expect-error
575+
// @ts-expect-error - reason TBS
576576
a,
577577
b,
578578
);
@@ -583,7 +583,7 @@ export class NodeFS extends BasePortableFakeFS {
583583
watchFile(p: PortablePath, a: WatchFileOptions | WatchFileCallback, b?: WatchFileCallback) {
584584
return this.realFs.watchFile(
585585
npath.fromPortablePath(p),
586-
// @ts-expect-error
586+
// @ts-expect-error - reason TBS
587587
a,
588588
b,
589589
) as unknown as StatWatcher;

packages/yarnpkg-fslib/sources/ProxiedFS.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ export abstract class ProxiedFS<P extends Path, IP extends Path> extends FakeFS<
381381
watch(p: P, a?: WatchOptions | WatchCallback, b?: WatchCallback) {
382382
return this.baseFs.watch(
383383
this.mapToBase(p),
384-
// @ts-expect-error
384+
// @ts-expect-error - reason TBS
385385
a,
386386
b,
387387
);
@@ -392,7 +392,7 @@ export abstract class ProxiedFS<P extends Path, IP extends Path> extends FakeFS<
392392
watchFile(p: P, a: WatchFileOptions | WatchFileCallback, b?: WatchFileCallback) {
393393
return this.baseFs.watchFile(
394394
this.mapToBase(p),
395-
// @ts-expect-error
395+
// @ts-expect-error - reason TBS
396396
a,
397397
b,
398398
);

packages/yarnpkg-fslib/sources/patchFs/patchFs.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ export function patchFs(patchedFs: typeof fs, fakeFs: FakeFS<NativePath>): void
327327
}
328328

329329
setupFn(patchedFsPromises, `open`, async (...args: Array<any>) => {
330-
// @ts-expect-error
330+
// @ts-expect-error - reason TBS
331331
const fd = await fakeFs.openPromise(...args);
332332
return new FileHandle(fd, fakeFs);
333333
});
@@ -344,12 +344,12 @@ export function patchFs(patchedFs: typeof fs, fakeFs: FakeFS<NativePath>): void
344344
// https://github.com/nodejs/node/blob/dc79f3f37caf6f25b8efee4623bec31e2c20f595/lib/fs.js#L690-L691
345345
// and
346346
// https://github.com/nodejs/node/blob/ba684805b6c0eded76e5cd89ee00328ac7a59365/lib/internal/util.js#L293
347-
// @ts-expect-error
347+
// @ts-expect-error - reason TBS
348348
patchedFs.read[promisify.custom] = async (fd: number, buffer: Buffer, ...args: Array<any>) => {
349349
const res = fakeFs.readPromise(fd, buffer, ...args);
350350
return {bytesRead: await res, buffer};
351351
};
352-
// @ts-expect-error
352+
// @ts-expect-error - reason TBS
353353
patchedFs.write[promisify.custom] = async (fd: number, buffer: Buffer, ...args: Array<any>) => {
354354
const res = fakeFs.writePromise(fd, buffer, ...args);
355355
return {bytesWritten: await res, buffer};

packages/yarnpkg-fslib/tests/ProxiedFS.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import {PortablePath, ppath} from '../sources/path';
55
describe(`ProxiedFS`, () => {
66
it(`should resolve relative symlinks after remapping`, async () => {
77
class SpyFS extends NoFS {
8-
// @ts-expect-error
8+
// @ts-expect-error - reason TBS
99
symlinkPromise = jest.fn(async () => {});
1010

11-
// @ts-expect-error
11+
// @ts-expect-error - reason TBS
1212
symlinkSync = jest.fn(() => {});
1313
}
1414

packages/yarnpkg-libzip/sources/ZipFS.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,7 +1434,7 @@ export class ZipFS extends BasePortableFakeFS {
14341434
async readFilePromise(p: FSPath<PortablePath>, encoding?: BufferEncoding | null) {
14351435
// This is messed up regarding the TS signatures
14361436
if (typeof encoding === `object`)
1437-
// @ts-expect-error
1437+
// @ts-expect-error - reason TBS
14381438
encoding = encoding ? encoding.encoding : undefined;
14391439

14401440
const data = await this.readFileBuffer(p, {asyncDecompress: true});
@@ -1447,7 +1447,7 @@ export class ZipFS extends BasePortableFakeFS {
14471447
readFileSync(p: FSPath<PortablePath>, encoding?: BufferEncoding | null) {
14481448
// This is messed up regarding the TS signatures
14491449
if (typeof encoding === `object`)
1450-
// @ts-expect-error
1450+
// @ts-expect-error - reason TBS
14511451
encoding = encoding ? encoding.encoding : undefined;
14521452

14531453
const data = this.readFileBuffer(p);

packages/yarnpkg-pnp/sources/esm-loader/hooks/resolve.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as loaderUtils from '../loaderUtils';
88

99
let findPnpApi: any = (esmModule as any).findPnpApi;
1010
if (!findPnpApi) {
11-
// @ts-expect-error
11+
// @ts-expect-error - reason TBS
1212
const require = createRequire(import.meta.url);
1313

1414
const pnpApi = require(`./.pnp.cjs`);

packages/yarnpkg-pnp/sources/loader/makeApi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ export function makeApi(runtimeState: RuntimeState, opts: MakeApiOptions): PnpAp
336336
*/
337337

338338
function makeFakeModule(path: NativePath): NodeModule {
339-
// @ts-expect-error
339+
// @ts-expect-error - reason TBS
340340
const fakeModule = new Module(path, null);
341341
fakeModule.filename = path;
342342
fakeModule.paths = Module._nodeModulePaths(path);

packages/yarnpkg-pnp/sources/loader/makeManager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ export function makeManager(pnpapi: PnpApi, opts: MakeManagerOptions) {
3131
function loadApiInstance(pnpApiPath: PortablePath): PnpApi {
3232
const nativePath = npath.fromPortablePath(pnpApiPath);
3333

34-
// @ts-expect-error
34+
// @ts-expect-error - reason TBS
3535
const module = new Module(nativePath, null);
36-
// @ts-expect-error
36+
// @ts-expect-error - reason TBS
3737
module.load(nativePath);
3838

3939
return module.exports;

packages/yarnpkg-pnpify/sources/NodeModulesFS.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ export class PortableNodeModulesFS extends FakeFS<PortablePath> {
622622
} else {
623623
return this.baseFs.watch(
624624
this.resolveDirOrFilePath(p),
625-
// @ts-expect-error
625+
// @ts-expect-error - reason TBS
626626
a,
627627
b,
628628
);
@@ -634,7 +634,7 @@ export class PortableNodeModulesFS extends FakeFS<PortablePath> {
634634
watchFile(p: PortablePath, a: WatchFileOptions | WatchFileCallback, b?: WatchFileCallback): StatWatcher {
635635
return this.baseFs.watchFile(
636636
this.resolveDirOrFilePath(p),
637-
// @ts-expect-error
637+
// @ts-expect-error - reason TBS
638638
a,
639639
b,
640640
);

packages/yarnpkg-shell/sources/pipe.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export function makeProcess(name: string, args: Array<string>, opts: ShellOption
8383
process.off(`SIGTERM`, sigtermHandler);
8484
}
8585

86-
// @ts-expect-error
86+
// @ts-expect-error - reason TBS
8787
switch (error.code) {
8888
case `ENOENT`: {
8989
stdio[2].write(`command not found: ${name}\n`);

0 commit comments

Comments
 (0)