Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(eslint-plugin): [no-deprecated] should allow ignoring of deprecated value#10670

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
y-hsgw wants to merge26 commits intotypescript-eslint:main
base:main
Choose a base branch
Loading
fromy-hsgw:fix/no-deprecated
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
26 commits
Select commitHold shift + click to select a range
38e69ff
feat: create valueMatchesSomeSpecifier function
y-hsgwJan 17, 2025
ae6e55a
fix: ignore deprecated value
y-hsgwJan 17, 2025
36d8055
test: add test
y-hsgwJan 17, 2025
d545ea1
test: add test
y-hsgwJan 25, 2025
a4463a4
refactor: use AST node narrowing
y-hsgwFeb 27, 2025
95839f6
feat: support package
y-hsgwFeb 27, 2025
b80196b
test: add test
y-hsgwFeb 27, 2025
4f7a71e
Merge branch 'main' of https://github.com/y-hsgw/typescript-eslint in…
y-hsgwFeb 27, 2025
5b7b20d
Merge branch 'main' of https://github.com/y-hsgw/typescript-eslint in…
y-hsgwMar 1, 2025
af4be16
test: add test
y-hsgwMar 1, 2025
064f92d
Merge branch 'main' into fix/no-deprecated
y-hsgwMar 2, 2025
3567212
test: add test for typeMatchesSomeSpecifier function
y-hsgwMar 2, 2025
1cd8ea6
test: add test for valueMatchesSomeSpecifier function
y-hsgwMar 2, 2025
3673d21
refactor: remove default empty array from specifiers
y-hsgwMar 2, 2025
325e132
Revert "refactor: remove default empty array from specifiers"
y-hsgwMar 13, 2025
767fc7a
test: add test case with undefined argument
y-hsgwMar 13, 2025
e1c4670
Merge branch 'main' into fix/no-deprecated
y-hsgwMar 13, 2025
54f820b
fix: sync workspace
y-hsgwMar 13, 2025
3b3520b
feat: support PrivateIdentifier
y-hsgwMar 21, 2025
0e61bcf
feat: support literal case
y-hsgwApr 10, 2025
1578137
feat: support dynamic import
y-hsgwApr 11, 2025
d65268c
test: add no-deprecated test
y-hsgwApr 11, 2025
72641c0
fix: sync workspace
y-hsgwApr 11, 2025
8fca2c2
Merge branch 'main' of https://github.com/y-hsgw/typescript-eslint in…
y-hsgwMay 16, 2025
7e6b840
refactor: use named functions instead of string descriptions in descr…
y-hsgwMay 16, 2025
8ef57d2
fix: lint fix
y-hsgwMay 16, 2025
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
6 changes: 5 additions & 1 deletionpackages/eslint-plugin/src/rules/no-deprecated.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,6 +12,7 @@ import {
nullThrows,
typeOrValueSpecifiersSchema,
typeMatchesSomeSpecifier,
valueMatchesSomeSpecifier,
} from '../util';

type IdentifierLike =
Expand DownExpand Up@@ -375,7 +376,10 @@ export default createRule<Options, MessageIds>({
}

const type = services.getTypeAtLocation(node);
if (typeMatchesSomeSpecifier(type, allow, services.program)) {
if (
typeMatchesSomeSpecifier(type, allow, services.program) ||
valueMatchesSomeSpecifier(node, allow, services.program, type)
) {
return;
}

Expand Down
101 changes: 101 additions & 0 deletionspackages/eslint-plugin/tests/rules/no-deprecated.test.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -332,6 +332,21 @@ ruleTester.run('no-deprecated', rule, {
{
code: `
/** @deprecated */
function A() {
return <div />;
}

const a = <A></A>;
`,
options: [
{
allow: [{ from: 'file', name: 'A' }],
},
],
},
{
code: `
/** @deprecated */
declare class A {}

new A();
Expand All@@ -344,7 +359,62 @@ new A();
},
{
code: `
/** @deprecated */
const deprecatedValue = 45;
const bar = deprecatedValue;
`,
options: [
{
allow: [{ from: 'file', name: 'deprecatedValue' }],
},
],
},
{
code: `
class MyClass {
/** @deprecated */
#privateProp = 42;
value = this.#privateProp;
}
`,
options: [
{
allow: [{ from: 'file', name: 'privateProp' }],
},
],
},
{
code: `
/** @deprecated */
const deprecatedValue = 45;
const bar = deprecatedValue;
`,
options: [
{
allow: ['deprecatedValue'],
},
],
},
{
code: `
import { exists } from 'fs';
exists('/foo');
`,
options: [
{
allow: [
{
from: 'package',
name: 'exists',
package: 'fs',
},
],
},
],
},
{
code: `
const { exists } = import('fs');
exists('/foo');
`,
options: [
Expand DownExpand Up@@ -2915,6 +2985,37 @@ class B extends A {
},
],
},
{
code: `
import { exists } from 'fs';
exists('/foo');
`,
errors: [
{
column: 1,
data: {
name: 'exists',
reason:
'Since v1.0.0 - Use {@link stat} or {@link access} instead.',
},
endColumn: 7,
endLine: 3,
line: 3,
messageId: 'deprecatedWithReason',
},
],
options: [
{
allow: [
{
from: 'package',
name: 'exists',
package: 'hoge',
},
],
},
],
},
{
code: `
declare class A {
Expand Down
68 changes: 68 additions & 0 deletionspackages/type-utils/src/TypeOrValueSpecifier.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
import type { TSESTree } from '@typescript-eslint/types';
import type { JSONSchema4 } from '@typescript-eslint/utils/json-schema';
import type * as ts from 'typescript';

import { AST_NODE_TYPES } from '@typescript-eslint/types';
import * as tsutils from 'ts-api-utils';

import { specifierNameMatches } from './typeOrValueSpecifiers/specifierNameMatches';
Expand DownExpand Up@@ -219,3 +221,69 @@ export const typeMatchesSomeSpecifier = (
program: ts.Program,
): boolean =>
specifiers.some(specifier => typeMatchesSpecifier(type, specifier, program));

const getSpecifierNames = (specifierName: string | string[]): string[] => {
return typeof specifierName === 'string' ? [specifierName] : specifierName;
};

const getStaticName = (node: TSESTree.Node): string | undefined => {
if (
node.type === AST_NODE_TYPES.Identifier ||
node.type === AST_NODE_TYPES.JSXIdentifier ||
node.type === AST_NODE_TYPES.PrivateIdentifier
) {
return node.name;
}

if (node.type === AST_NODE_TYPES.Literal && typeof node.value === 'string') {
return node.value;
}

return undefined;
};

export function valueMatchesSpecifier(
node: TSESTree.Node,
specifier: TypeOrValueSpecifier,
program: ts.Program,
type: ts.Type,
): boolean {
const staticName = getStaticName(node);
if (!staticName) {
return false;
}

if (typeof specifier === 'string') {
return specifier === staticName;
}

if (!getSpecifierNames(specifier.name).includes(staticName)) {
return false;
}

if (specifier.from === 'package') {
const symbol = type.getSymbol() ?? type.aliasSymbol;
const declarations = symbol?.getDeclarations() ?? [];
const declarationFiles = declarations.map(declaration =>
declaration.getSourceFile(),
);
return typeDeclaredInPackageDeclarationFile(
specifier.package,
declarations,
declarationFiles,
program,
);
}

return true;
}

export const valueMatchesSomeSpecifier = (
node: TSESTree.Node,
specifiers: TypeOrValueSpecifier[] = [],
program: ts.Program,
type: ts.Type,
): boolean =>
specifiers.some(specifier =>
valueMatchesSpecifier(node, specifier, program, type),
);
Loading

[8]ページ先頭

©2009-2025 Movatter.jp