-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lint rule semi anti join not supported (#9)
* just keep it * implement no-semi-anti-join-supported eslint graphql rule * final touchup * add doc url * more polish addressing pr comments * format:fix touchup * move ruleTest creation into shared.ts
- Loading branch information
1 parent
843a9e0
commit db1739d
Showing
10 changed files
with
267 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
/* | ||
* Copyright (c) 2024, salesforce.com, inc. | ||
* All rights reserved. | ||
* SPDX-License-Identifier: MIT | ||
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT | ||
*/ | ||
import { GraphQLESLintRule, GraphQLESLintRuleContext } from '@graphql-eslint/eslint-plugin'; | ||
import getDocUrl from '../../util/getDocUrl'; | ||
|
||
export const NO_SEMI_ANTI_JOIN_SUPPORTED_RULE_ID = 'offline-graphql-no-semi-anti-join-supported'; | ||
|
||
export const rule: GraphQLESLintRule = { | ||
meta: { | ||
type: 'problem', | ||
hasSuggestions: false, | ||
docs: { | ||
description: 'Semi and anti join are not supported for mobile offline', | ||
category: 'Operations', | ||
recommended: true, | ||
url: getDocUrl(NO_SEMI_ANTI_JOIN_SUPPORTED_RULE_ID), | ||
examples: [ | ||
{ | ||
title: 'Correct', | ||
code: /* GraphQL */ ` | ||
query AccountExample { | ||
uiapi { | ||
query { | ||
Account { | ||
edges { | ||
node { | ||
Id | ||
Name { | ||
value | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
` | ||
}, | ||
{ | ||
title: 'Incorrect', | ||
code: /* GraphQL */ ` | ||
query AccountExample { | ||
uiapi { | ||
query { | ||
Account (where: { | ||
Id: { inq: { | ||
Opportunity: { | ||
StageName: { eq: "Closed Won" } }, | ||
ApiName:"AccountId" | ||
} | ||
} | ||
}) { | ||
edges { | ||
node { | ||
Id | ||
Name { value } | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
` | ||
}, | ||
{ | ||
title: 'Incorrect', | ||
code: /* GraphQL */ ` | ||
query AccountExample { | ||
uiapi { | ||
query { | ||
Account (where: { | ||
Id: { ninq: { | ||
Opportunity: { | ||
StageName: { eq: "Closed Won" } }, | ||
ApiName:"AccountId" | ||
} | ||
} | ||
}) { | ||
edges { | ||
node { | ||
Id | ||
Name { value } | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
` | ||
} | ||
] | ||
}, | ||
messages: { | ||
[NO_SEMI_ANTI_JOIN_SUPPORTED_RULE_ID]: | ||
'Offline GraphQL: "{{joinType}}" join is not supported for mobile offline.' | ||
}, | ||
schema: [] | ||
}, | ||
|
||
create(context: GraphQLESLintRuleContext) { | ||
return { | ||
ObjectField(node) { | ||
if (node.name.value === 'inq') { | ||
context.report({ | ||
node: node.name, | ||
messageId: NO_SEMI_ANTI_JOIN_SUPPORTED_RULE_ID, | ||
data: { | ||
joinType: 'Semi' | ||
} | ||
}); | ||
} else if (node.name.value === 'ninq') { | ||
context.report({ | ||
node: node.name, | ||
messageId: NO_SEMI_ANTI_JOIN_SUPPORTED_RULE_ID, | ||
data: { | ||
joinType: 'Anti' | ||
} | ||
}); | ||
} | ||
} | ||
}; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function createScopedModuleRuleName(ruleName: string): string { | ||
return `@salesforce/lwc-mobile/${ruleName}`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import { | ||
rule, | ||
NO_SEMI_ANTI_JOIN_SUPPORTED_RULE_ID | ||
} from '../../../src/rules/graphql/no-semi-anti-join-supported'; | ||
import { createScopedModuleRuleName } from '../../../src/util/createScopedModuleRuleName'; | ||
|
||
import { ruleTester } from '../../shared'; | ||
|
||
ruleTester.run(createScopedModuleRuleName(NO_SEMI_ANTI_JOIN_SUPPORTED_RULE_ID), rule as any, { | ||
valid: [ | ||
{ | ||
code: /* GraphQL */ ` | ||
query AccountExample { | ||
uiapi { | ||
query { | ||
Account { | ||
edges { | ||
node { | ||
Id | ||
Name { | ||
value | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
` | ||
} | ||
], | ||
invalid: [ | ||
{ | ||
code: /* GraphQL */ ` | ||
query AccountExample { | ||
uiapi { | ||
query { | ||
Account( | ||
where: { | ||
Id: { | ||
inq: { | ||
Opportunity: { StageName: { eq: "Closed Won" } } | ||
ApiName: "AccountId" | ||
} | ||
} | ||
} | ||
) { | ||
edges { | ||
node { | ||
Id | ||
Name { | ||
value | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
`, | ||
errors: [ | ||
{ | ||
messageId: NO_SEMI_ANTI_JOIN_SUPPORTED_RULE_ID, | ||
data: { | ||
joinType: 'Semi' | ||
} | ||
} | ||
] | ||
}, | ||
{ | ||
code: /* GraphQL */ ` | ||
query AccountExample { | ||
uiapi { | ||
query { | ||
Account( | ||
where: { | ||
Id: { | ||
ninq: { | ||
Opportunity: { StageName: { eq: "Closed Won" } } | ||
ApiName: "AccountId" | ||
} | ||
} | ||
} | ||
) { | ||
edges { | ||
node { | ||
Id | ||
Name { | ||
value | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
`, | ||
errors: [ | ||
{ | ||
messageId: NO_SEMI_ANTI_JOIN_SUPPORTED_RULE_ID, | ||
data: { | ||
joinType: 'Anti' | ||
} | ||
} | ||
] | ||
} | ||
] | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
export const RULE_TESTER_CONFIG = { | ||
import { RuleTester } from '@typescript-eslint/rule-tester'; | ||
|
||
const RULE_TESTER_CONFIG = { | ||
parser: '@graphql-eslint/eslint-plugin', | ||
parserOptions: { | ||
graphQLConfig: {} | ||
} | ||
}; | ||
|
||
export const ruleTester = new RuleTester(RULE_TESTER_CONFIG); |