Skip to content

Commit ab2916c

Browse files
chore: enable eslint-plugin/no-property-in-node internally (typescript-eslint#9261)
* chore: enable eslint-plugin/no-property-in-node internally * commit yarn.lock changes
1 parent 629035f commit ab2916c

18 files changed

+116
-42
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
diff --git a/lib/rules/no-property-in-node.js b/lib/rules/no-property-in-node.js
2+
index f3e2e0c829685213c7807b34158237f59142173c..11e54e8f6d69e0f06b27bb83ed96a96690b5ed9a 100644
3+
--- a/lib/rules/no-property-in-node.js
4+
+++ b/lib/rules/no-property-in-node.js
5+
@@ -3,6 +3,7 @@
6+
const typedNodeSourceFileTesters = [
7+
/@types[/\\]estree[/\\]index\.d\.ts/,
8+
/@typescript-eslint[/\\]types[/\\]dist[/\\]generated[/\\]ast-spec\.d\.ts/,
9+
+ /packages[/\\]types[/\\]dist[/\\]generated[/\\]ast-spec\.d\.ts/,
10+
];
11+
12+
/**

eslint.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@ export default tseslint.config(
430430
'packages/eslint-plugin/src/rules/**/*.{ts,tsx,cts,mts}',
431431
],
432432
rules: {
433+
'eslint-plugin/no-property-in-node': 'error',
433434
'eslint-plugin/require-meta-docs-description': [
434435
'error',
435436
{ pattern: '^(Enforce|Require|Disallow) .+[^. ]$' },

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@
139139
"tmp": "0.2.1",
140140
"tsx": "^4.7.2",
141141
"typescript": "5.4.5",
142-
"nx@18.3.5": "patch:nx@npm%3A18.3.5#./.yarn/patches/nx-npm-18.3.5-58c0bedf91.patch"
142+
"nx@18.3.5": "patch:nx@npm%3A18.3.5#./.yarn/patches/nx-npm-18.3.5-58c0bedf91.patch",
143+
"eslint-plugin-eslint-plugin@^5.5.0": "patch:eslint-plugin-eslint-plugin@npm%3A5.5.1#./.yarn/patches/eslint-plugin-eslint-plugin-npm-5.5.1-4206c2506d.patch"
143144
},
144145
"packageManager": "yarn@3.8.2"
145146
}

packages/eslint-plugin/src/rules/adjacent-overload-signatures.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,16 @@ type RuleNode =
1010
| TSESTree.TSInterfaceBody
1111
| TSESTree.TSModuleBlock
1212
| TSESTree.TSTypeLiteral;
13+
1314
type Member =
1415
| TSESTree.ClassElement
1516
| TSESTree.ProgramStatement
1617
| TSESTree.TypeElement;
1718

19+
type MemberDeclaration =
20+
| TSESTree.DefaultExportDeclarations
21+
| TSESTree.NamedExportDeclarations;
22+
1823
export default createRule({
1924
name: 'adjacent-overload-signatures',
2025
meta: {
@@ -32,7 +37,7 @@ export default createRule({
3237
create(context) {
3338
interface Method {
3439
name: string;
35-
static: boolean;
40+
static?: boolean;
3641
callSignature: boolean;
3742
type: MemberNameType;
3843
}
@@ -42,9 +47,9 @@ export default createRule({
4247
* @param member the member being processed.
4348
* @returns the name and attribute of the member or null if it's a member not relevant to the rule.
4449
*/
45-
function getMemberMethod(member: TSESTree.Node): Method | null {
46-
const isStatic = 'static' in member && !!member.static;
47-
50+
function getMemberMethod(
51+
member: Member | MemberDeclaration,
52+
): Method | null {
4853
switch (member.type) {
4954
case AST_NODE_TYPES.ExportDefaultDeclaration:
5055
case AST_NODE_TYPES.ExportNamedDeclaration: {
@@ -64,35 +69,32 @@ export default createRule({
6469
}
6570
return {
6671
name,
67-
static: isStatic,
6872
callSignature: false,
6973
type: MemberNameType.Normal,
7074
};
7175
}
7276
case AST_NODE_TYPES.TSMethodSignature:
7377
return {
7478
...getNameFromMember(member, context.sourceCode),
75-
static: isStatic,
79+
static: !!member.static,
7680
callSignature: false,
7781
};
7882
case AST_NODE_TYPES.TSCallSignatureDeclaration:
7983
return {
8084
name: 'call',
81-
static: isStatic,
8285
callSignature: true,
8386
type: MemberNameType.Normal,
8487
};
8588
case AST_NODE_TYPES.TSConstructSignatureDeclaration:
8689
return {
8790
name: 'new',
88-
static: isStatic,
8991
callSignature: false,
9092
type: MemberNameType.Normal,
9193
};
9294
case AST_NODE_TYPES.MethodDefinition:
9395
return {
9496
...getNameFromMember(member, context.sourceCode),
95-
static: isStatic,
97+
static: !!member.static,
9698
callSignature: false,
9799
};
98100
}

packages/eslint-plugin/src/rules/class-literal-property-style.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,19 @@ const printNodeModifiers = (
3737
const isSupportedLiteral = (
3838
node: TSESTree.Node,
3939
): node is TSESTree.LiteralExpression => {
40-
if (node.type === AST_NODE_TYPES.Literal) {
41-
return true;
42-
}
40+
switch (node.type) {
41+
case AST_NODE_TYPES.Literal:
42+
return true;
4343

44-
if (
45-
node.type === AST_NODE_TYPES.TaggedTemplateExpression ||
46-
node.type === AST_NODE_TYPES.TemplateLiteral
47-
) {
48-
return ('quasi' in node ? node.quasi.quasis : node.quasis).length === 1;
49-
}
44+
case AST_NODE_TYPES.TaggedTemplateExpression:
45+
return node.quasi.quasis.length === 1;
5046

51-
return false;
47+
case AST_NODE_TYPES.TemplateLiteral:
48+
return node.quasis.length === 1;
49+
50+
default:
51+
return false;
52+
}
5253
};
5354

5455
export default createRule<Options, MessageIds>({

packages/eslint-plugin/src/rules/default-param-last.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,14 @@ export default createRule({
2424
* @private
2525
*/
2626
function isOptionalParam(node: TSESTree.Parameter): boolean {
27-
return 'optional' in node && node.optional;
27+
return (
28+
(node.type === AST_NODE_TYPES.ArrayPattern ||
29+
node.type === AST_NODE_TYPES.AssignmentPattern ||
30+
node.type === AST_NODE_TYPES.Identifier ||
31+
node.type === AST_NODE_TYPES.ObjectPattern ||
32+
node.type === AST_NODE_TYPES.RestElement) &&
33+
node.optional
34+
);
2835
}
2936

3037
/**

packages/eslint-plugin/src/rules/indent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* This is due to some really funky type conversions between different node types.
44
* This is done intentionally based on the internal implementation of the base indent rule.
55
*/
6-
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment */
6+
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment, eslint-plugin/no-property-in-node */
77

88
import type { TSESTree } from '@typescript-eslint/utils';
99
import { AST_NODE_TYPES } from '@typescript-eslint/utils';

packages/eslint-plugin/src/rules/member-ordering.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// This rule was feature-frozen before we enabled no-property-in-node.
2+
/* eslint-disable eslint-plugin/no-property-in-node */
3+
14
import type { JSONSchema, TSESLint, TSESTree } from '@typescript-eslint/utils';
25
import { AST_NODE_TYPES } from '@typescript-eslint/utils';
36
import naturalCompare from 'natural-compare';
@@ -1064,6 +1067,11 @@ export default createRule<Options, MessageIds>({
10641067
// https://github.com/typescript-eslint/typescript-eslint/issues/5439
10651068
/* eslint-disable @typescript-eslint/no-non-null-assertion */
10661069
return {
1070+
'ClassDeclaration, FunctionDeclaration'(node): void {
1071+
if ('superClass' in node) {
1072+
// ...
1073+
}
1074+
},
10671075
ClassDeclaration(node): void {
10681076
validateMembersOrder(
10691077
node.body.body,

packages/eslint-plugin/src/rules/naming-convention.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// This rule was feature-frozen before we enabled no-property-in-node.
2+
/* eslint-disable eslint-plugin/no-property-in-node */
3+
14
import { PatternVisitor } from '@typescript-eslint/scope-manager';
25
import type { TSESTree } from '@typescript-eslint/utils';
36
import { AST_NODE_TYPES, TSESLint } from '@typescript-eslint/utils';

packages/eslint-plugin/src/rules/no-extraneous-class.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@ export default createRule<Options, MessageIds>({
8787
return;
8888
}
8989

90-
const reportNode = 'id' in parent && parent.id ? parent.id : parent;
90+
const reportNode =
91+
parent.type === AST_NODE_TYPES.ClassDeclaration && parent.id
92+
? parent.id
93+
: parent;
9194
if (node.body.length === 0) {
9295
if (allowEmpty) {
9396
return;
@@ -105,7 +108,10 @@ export default createRule<Options, MessageIds>({
105108
let onlyConstructor = true;
106109

107110
for (const prop of node.body) {
108-
if ('kind' in prop && prop.kind === 'constructor') {
111+
if (
112+
prop.type === AST_NODE_TYPES.MethodDefinition &&
113+
prop.kind === 'constructor'
114+
) {
109115
if (
110116
prop.value.params.some(
111117
param => param.type === AST_NODE_TYPES.TSParameterProperty,
@@ -116,7 +122,11 @@ export default createRule<Options, MessageIds>({
116122
}
117123
} else {
118124
onlyConstructor = false;
119-
if ('static' in prop && !prop.static) {
125+
if (
126+
(prop.type === AST_NODE_TYPES.PropertyDefinition ||
127+
prop.type === AST_NODE_TYPES.MethodDefinition) &&
128+
!prop.static
129+
) {
120130
onlyStatic = false;
121131
}
122132
}

0 commit comments

Comments
 (0)