Skip to content

feat(eslint-plugin): removed value from abstract property nodes #3765

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

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
2 changes: 2 additions & 0 deletions packages/ast-spec/src/element/TSAbstractClassProperty/spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import type {
export interface TSAbstractClassPropertyComputedName
extends ClassPropertyComputedNameBase {
type: AST_NODE_TYPES.TSAbstractClassProperty;
value: null;
}

export interface TSAbstractClassPropertyNonComputedName
extends ClassPropertyNonComputedNameBase {
type: AST_NODE_TYPES.TSAbstractClassProperty;
value: null;
}

export type TSAbstractClassProperty =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,6 @@ export default util.createRule<Options, MessageIds>({
return;

case AST_NODE_TYPES.ClassProperty:
case AST_NODE_TYPES.TSAbstractClassProperty:
if (node.accessibility === 'private') {
return;
}
Expand Down
1 change: 1 addition & 0 deletions packages/eslint-plugin/src/rules/member-ordering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ function getNodeType(node: Member): string | null {
case AST_NODE_TYPES.TSConstructSignatureDeclaration:
return 'constructor';
case AST_NODE_TYPES.TSAbstractClassProperty:
return 'field';
case AST_NODE_TYPES.ClassProperty:
return node.value && functionExpressions.includes(node.value.type)
? 'method'
Expand Down
18 changes: 8 additions & 10 deletions packages/eslint-plugin/tests/rules/member-ordering.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1311,7 +1311,7 @@ abstract class Foo {
private D: string;
protected static F(): {};
public E(): {};
public abstract A = () => {};
public abstract A(): void;
protected abstract G(): void;
}
`,
Expand Down Expand Up @@ -3618,7 +3618,7 @@ type Foo = {
{
code: `
abstract class Foo {
abstract A = () => {};
abstract A(): void;
B: string;
}
`,
Expand All @@ -3639,9 +3639,6 @@ abstract class Foo {
abstract class Foo {
abstract A: () => {};
B: string;
public C() {};
private D() {};
abstract E() {};
}
`,
errors: [
Expand All @@ -3659,18 +3656,19 @@ abstract class Foo {
{
code: `
abstract class Foo {
B: string;
abstract C = () => {};
abstract A: () => {};
B: string;
public C() {};
private D() {};
abstract E() {};
}
`,
options: [{ default: ['method', 'constructor', 'field'] }],
errors: [
{
messageId: 'incorrectGroupOrder',
data: {
name: 'C',
rank: 'field',
name: 'B',
rank: 'public abstract field',
},
line: 4,
column: 5,
Expand Down
63 changes: 18 additions & 45 deletions packages/eslint-plugin/tests/rules/quotes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,25 +455,25 @@ class Foo {
{
code: `
abstract class Foo {
public abstract a = "";
public abstract "a-b" = "";
public abstract a: "";
public abstract "a-b": "";
}
`,
},
{
code: `
abstract class Foo {
public abstract a = '';
public abstract 'a-b' = '';
public abstract a: '';
public abstract 'a-b': '';
}
`,
options: ['single'],
},
{
code: `
abstract class Foo {
public abstract a = \`\`;
public abstract 'a-b' = \`\`;
public abstract a: \`\`;
public abstract 'a-b': \`\`;
}
`,
options: ['backtick'],
Expand Down Expand Up @@ -1047,21 +1047,21 @@ class Foo {
{
code: `
abstract class Foo {
public abstract a = '';
public abstract 'a-b' = '';
public abstract a: '';
public abstract 'a-b': '';
}
`,
output: `
abstract class Foo {
public abstract a = "";
public abstract "a-b" = "";
public abstract a: "";
public abstract "a-b": "";
}
`,
errors: [
{
...useDoubleQuote,
line: 3,
column: 23,
column: 22,
},
{
...useDoubleQuote,
Expand All @@ -1071,28 +1071,28 @@ abstract class Foo {
{
...useDoubleQuote,
line: 4,
column: 27,
column: 26,
},
],
},
{
code: `
abstract class Foo {
public abstract a = "";
public abstract "a-b" = "";
public abstract a: "";
public abstract "a-b": "";
}
`,
output: `
abstract class Foo {
public abstract a = '';
public abstract 'a-b' = '';
public abstract a: '';
public abstract 'a-b': '';
}
`,
errors: [
{
...useSingleQuote,
line: 3,
column: 23,
column: 22,
},
{
...useSingleQuote,
Expand All @@ -1102,38 +1102,11 @@ abstract class Foo {
{
...useSingleQuote,
line: 4,
column: 27,
column: 26,
},
],
options: ['single'],
},
{
code: `
abstract class Foo {
public abstract a = "";
public abstract "a-b" = "";
}
`,
output: `
abstract class Foo {
public abstract a = \`\`;
public abstract "a-b" = \`\`;
}
`,
errors: [
{
...useBacktick,
line: 3,
column: 23,
},
{
...useBacktick,
line: 4,
column: 27,
},
],
options: ['backtick'],
},

// TSAbstractMethodDefinition
{
Expand Down
4 changes: 3 additions & 1 deletion packages/scope-manager/src/referencer/ClassVisitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,9 @@ class ClassVisitor extends Visitor {
this.#referencer.visit(node.key);
}

this.#referencer.visit(node.value);
if (node.type !== AST_NODE_TYPES.TSAbstractClassProperty) {
this.#referencer.visit(node.value);
}

if ('decorators' in node) {
node.decorators?.forEach(d => this.#referencer.visit(d));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
abstract class Foo {
abstract bar;
abstract baz = 3;
abstract baz: number;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
abstract class Foo {
public abstract readonly foo = 'string';
public abstract readonly foo: string;
}
2 changes: 1 addition & 1 deletion packages/typescript-estree/src/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,7 @@ export class Converter {
? AST_NODE_TYPES.TSAbstractClassProperty
: AST_NODE_TYPES.ClassProperty,
key: this.convertChild(node.name),
value: this.convertChild(node.initializer),
value: isAbstract ? null : this.convertChild(node.initializer),
computed: isComputedProperty(node.name),
static: hasModifier(SyntaxKind.StaticKeyword, node),
readonly: hasModifier(SyntaxKind.ReadonlyKeyword, node) || undefined,
Expand Down
1 change: 1 addition & 0 deletions packages/typescript-estree/tests/ast-alignment/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ export function preprocessBabylonAST(ast: BabelTypes.File): any {
if (node.abstract) {
node.type = AST_NODE_TYPES.TSAbstractClassProperty;
delete node.abstract;
node.value = null;
}
/**
* TS 3.7: declare class properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1417,8 +1417,8 @@ TSError {

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/invalid-mismatched-closing-tag.src 1`] = `
TSError {
"column": 3,
"index": 3,
"column": 5,
"index": 5,
"lineNumber": 1,
"message": "Expected corresponding JSX closing tag for 'a'.",
}
Expand All @@ -1435,17 +1435,17 @@ TSError {

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/invalid-mismatched-dot-tag-name.src 1`] = `
TSError {
"column": 7,
"index": 7,
"column": 9,
"index": 9,
"lineNumber": 1,
"message": "Expected corresponding JSX closing tag for 'a.b.c'.",
}
`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/invalid-mismatched-namespace-tag.src 1`] = `
TSError {
"column": 5,
"index": 5,
"column": 7,
"index": 7,
"lineNumber": 1,
"message": "Expected corresponding JSX closing tag for 'a:b'.",
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

exports[`jsx invalid-mismatched-closing-tag.src 1`] = `
TSError {
"column": 3,
"index": 3,
"column": 5,
"index": 5,
"lineNumber": 1,
"message": "Expected corresponding JSX closing tag for 'a'.",
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

exports[`jsx invalid-mismatched-dot-tag-name.src 1`] = `
TSError {
"column": 7,
"index": 7,
"column": 9,
"index": 9,
"lineNumber": 1,
"message": "Expected corresponding JSX closing tag for 'a.b.c'.",
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

exports[`jsx invalid-mismatched-namespace-tag.src 1`] = `
TSError {
"column": 5,
"index": 5,
"column": 7,
"index": 7,
"lineNumber": 1,
"message": "Expected corresponding JSX closing tag for 'a:b'.",
}
Expand Down
Loading