Skip to content

Commit

Permalink
fix(eslint-plugin): [no-unsafe-member-access] report on only the acce…
Browse files Browse the repository at this point in the history
…ssed property (#7717)
  • Loading branch information
Josh-Cena committed Oct 11, 2023
1 parent cff6e47 commit f81a2da
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 5 deletions.
Expand Up @@ -89,7 +89,7 @@ export default 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,
},
],
},
],
});

0 comments on commit f81a2da

Please sign in to comment.