Skip to content
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

no-duplicate-spread-property: exclude class Getters and Setters #373

Merged
merged 3 commits into from
Aug 10, 2018
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
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,40 @@ var v: any;
bar: 2,
},
});

({
foo: 1,
...new class {
get foo() { return 1; }
set foo(v) {}
bar = 1;
},
});

({
foo: 1,
~~~ [error no-duplicate-spread-property: Property 'foo' is overridden later.]
...{
get foo() { return 1; },
bar: 2,
},
});

({
foo: 1,
~~~ [error no-duplicate-spread-property: Property 'foo' is overridden later.]
...{
get foo() { return 1; },
set foo(v: number) {},
bar: 2,
},
});

({
foo: 1,
~~~ [error no-duplicate-spread-property: Property 'foo' is overridden later.]
...{
set foo(v: number) {},
bar: 2,
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,37 @@ var v: any;
bar: 2,
},
});

({
foo: 1,
...new class {
get foo() { return 1; }
set foo(v) {}
bar = 1;
},
});

({
foo: 1,
...{
get foo() { return 1; },
bar: 2,
},
});

({
foo: 1,
...{
get foo() { return 1; },
set foo(v: number) {},
bar: 2,
},
});

({
foo: 1,
...{
set foo(v: number) {},
bar: 2,
},
});
12 changes: 6 additions & 6 deletions packages/mimir/src/rules/no-duplicate-spread-property.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,20 @@ function getPropertyInfoFromType(type: ts.Type): PropertyInfo {
assignedNames: [],
};
for (const prop of type.getProperties()) {
if (isClassMethod(prop))
if (!isSpreadableProperty(prop))
continue;
if ((prop.flags & ts.SymbolFlags.Optional) === 0)
result.assignedNames.push(prop.escapedName);
result.names.push(prop.escapedName);
}
return result;
}
function isClassMethod(prop: ts.Symbol): boolean | undefined {
if (prop.flags & ts.SymbolFlags.Method && prop.declarations !== undefined)
for (const declaration of prop.declarations)
function isSpreadableProperty(prop: ts.Symbol): boolean | undefined {
if (prop.flags & (ts.SymbolFlags.Method | ts.SymbolFlags.Accessor))
for (const declaration of prop.declarations!)
if (isClassLikeDeclaration(declaration.parent!))
return true;
return false;
return false;
return true;
}

function combinePropertyInfo(a: PropertyInfo, b: PropertyInfo): PropertyInfo {
Expand Down
34 changes: 34 additions & 0 deletions packages/mimir/test/no-duplicate-spread-property/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,37 @@ var v: any;
bar: 2,
},
});

({
foo: 1,
...new class {
get foo() { return 1; }
set foo(v) {}
bar = 1;
},
});

({
foo: 1,
...{
get foo() { return 1; },
bar: 2,
},
});

({
foo: 1,
...{
get foo() { return 1; },
set foo(v: number) {},
bar: 2,
},
});

({
foo: 1,
...{
set foo(v: number) {},
bar: 2,
},
});