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

fix(eslint-plugin): [no-unsafe-member-access] report on only the accessed property #7717

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -84,7 +84,7 @@ export default util.createRule({
}

context.report({
node,
node: node.property,
messageId,
data: {
property: node.computed ? `[${propertyName}]` : `.${propertyName}`,
Expand Down
67 changes: 63 additions & 4 deletions packages/eslint-plugin/tests/rules/no-unsafe-member-access.test.ts
Expand Up @@ -81,6 +81,9 @@ function foo(x: any) {
errors: [
{
messageId: 'unsafeMemberExpression',
line: 3,
column: 5,
endColumn: 6,
data: {
property: '.a',
},
Expand All @@ -96,6 +99,9 @@ function foo(x: any) {
errors: [
{
messageId: 'unsafeMemberExpression',
line: 3,
column: 5,
endColumn: 6,
data: {
property: '.a',
},
Expand All @@ -111,6 +117,9 @@ function foo(x: { a: any }) {
errors: [
{
messageId: 'unsafeMemberExpression',
line: 3,
column: 7,
endColumn: 8,
data: {
property: '.b',
},
Expand All @@ -126,6 +135,9 @@ function foo(x: any) {
errors: [
{
messageId: 'unsafeMemberExpression',
line: 3,
column: 5,
endColumn: 8,
data: {
property: "['a']",
},
Expand All @@ -141,6 +153,9 @@ function foo(x: any) {
errors: [
{
messageId: 'unsafeMemberExpression',
line: 3,
column: 5,
endColumn: 8,
data: {
property: "['a']",
},
Expand All @@ -156,6 +171,9 @@ function foo(x: { a: number }, y: any) {
errors: [
{
messageId: 'unsafeComputedMemberAccess',
line: 3,
column: 5,
endColumn: 6,
data: {
property: '[y]',
},
Expand All @@ -171,6 +189,9 @@ function foo(x?: { a: number }, y: any) {
errors: [
{
messageId: 'unsafeComputedMemberAccess',
line: 3,
column: 7,
endColumn: 8,
data: {
property: '[y]',
},
Expand All @@ -186,6 +207,9 @@ function foo(x: { a: number }, y: any) {
errors: [
{
messageId: 'unsafeComputedMemberAccess',
line: 3,
column: 6,
endColumn: 12,
data: {
property: '[y += 1]',
},
Expand All @@ -201,6 +225,9 @@ function foo(x: { a: number }, y: any) {
errors: [
{
messageId: 'unsafeComputedMemberAccess',
line: 3,
column: 5,
endColumn: 13,
data: {
property: '[1 as any]',
},
Expand All @@ -216,6 +243,9 @@ function foo(x: { a: number }, y: any) {
errors: [
{
messageId: 'unsafeComputedMemberAccess',
line: 3,
column: 5,
endColumn: 8,
data: {
property: '[y()]',
},
Expand All @@ -231,6 +261,9 @@ function foo(x: string[], y: any) {
errors: [
{
messageId: 'unsafeComputedMemberAccess',
line: 3,
column: 5,
endColumn: 6,
data: {
property: '[y]',
},
Expand Down Expand Up @@ -260,22 +293,48 @@ const methods = {
{
messageId: 'unsafeThisMemberExpression',
line: 4,
column: 12,
column: 17,
endColumn: 24,
},
{
messageId: 'unsafeThisMemberExpression',
line: 8,
column: 12,
endColumn: 31,
column: 17,
endColumn: 30,
},
{
messageId: 'unsafeThisMemberExpression',
line: 14,
column: 13,
column: 19,
endColumn: 26,
},
],
},
{
code: `
class C {
getObs$: any;
getPopularDepartments(): void {
this.getObs$.pipe().subscribe(res => {
console.log(res);
});
}
}
`,
errors: [
{
messageId: 'unsafeMemberExpression',
line: 5,
column: 18,
endColumn: 22,
},
{
messageId: 'unsafeMemberExpression',
line: 5,
column: 25,
endColumn: 34,
},
],
},
],
});