Skip to content

Commit

Permalink
Merge pull request #14 from salesforce/misc
Browse files Browse the repository at this point in the history
Miscellaneous cleanup
  • Loading branch information
khawkins committed Jun 7, 2024
2 parents bf2fd89 + 9f07808 commit 239a641
Show file tree
Hide file tree
Showing 28 changed files with 94 additions and 72 deletions.
8 changes: 8 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations.
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp
// List of extensions which should be recommended for users of this workspace.
"recommendations": ["dbaeumer.vscode-eslint", "esbenp.prettier-vscode"],
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
"unwantedRecommendations": []
}
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
2 changes: 1 addition & 1 deletion src/configs/recommended.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { NO_SEMI_ANTI_JOIN_SUPPORTED_RULE_ID } from '../rules/graphql/no-semi-an
import { NO_MORE_THAN_1_PARENT_RECORD_RULE_ID } from '../rules/graphql/no-more-than-1-parent-record.js';
import { NO_MORE_THAN_3_CHILD_ENTITIES_RULE_ID } from '../rules/graphql/no-more-than-3-child-entities.js';
import { NO_MORE_THAN_3_ROOT_ENTITIES_RULE_ID } from '../rules/graphql/no-more-than-3-root-entities.js';
import { createScopedModuleRuleName } from '../util/createScopedModuleRuleName.js';
import { createScopedModuleRuleName } from '../util/rule-helpers.js';

export = {
extends: ['./configs/base'],
Expand Down
9 changes: 5 additions & 4 deletions src/rules/apex/apex-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/

import createRule from '../../util/createRule';
export const APEX_IMPORT_RULE_ID = 'apex-import';
import { createRule } from '../../util/rule-helpers';
export const APEX_IMPORT_RULE_ID = 'lwc-offline-apex-import';

export const rule = createRule({
create(context) {
Expand All @@ -24,11 +24,12 @@ export const rule = createRule({
name: 'apex-import',
meta: {
docs: {
description: 'Importing apex modules can have issues on mobile for offline usage.'
description:
'Using Apex in LWC Offline-enabled mobile apps requires additional considerations to ensure proper functioning in offline scenarios. See https://developer.salesforce.com/docs/atlas.en-us.mobile_offline.meta/mobile_offline/apex.htm for more details.'
},
messages: {
[APEX_IMPORT_RULE_ID]:
'Importing apex modules can have issues on mobile for offline usage.'
'Using Apex in LWC Offline-enabled mobile apps requires careful consideration.'
},
type: 'suggestion',
schema: []
Expand Down
7 changes: 4 additions & 3 deletions src/rules/graphql/no-aggregate-query-supported.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { Kind } from 'graphql';
import { GraphQLESLintRule, GraphQLESLintRuleContext } from '@graphql-eslint/eslint-plugin';
import getDocUrl from '../../util/getDocUrl';
import { getDocUrl } from '../../util/rule-helpers';

export const NO_AGGREGATE_QUERY_SUPPORTED_RULE_ID = 'offline-graphql-no-aggregate-query-supported';

Expand All @@ -17,7 +17,8 @@ export const rule: GraphQLESLintRule = {
hasSuggestions: false,
docs: {
category: 'Operations',
description: 'Aggregate operation in a query is not supported for mobile offline.',
description:
'Aggregate operations in a GraphQL query are not supported for Offline GraphQL.',
url: getDocUrl(NO_AGGREGATE_QUERY_SUPPORTED_RULE_ID),
examples: [
{
Expand Down Expand Up @@ -49,7 +50,7 @@ export const rule: GraphQLESLintRule = {
},
messages: {
[NO_AGGREGATE_QUERY_SUPPORTED_RULE_ID]:
'Offline GraphQL: Aggregate operation in a query is not supported for mobile offline'
'Offline GraphQL: Aggregate operations in a query are not supported for mobile offline'
},
schema: []
},
Expand Down
12 changes: 6 additions & 6 deletions src/rules/graphql/no-fiscal-date-filtering-supported.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { ASTNode, Kind, ArgumentNode } from 'graphql';
import { GraphQLESLintRule, GraphQLESLintRuleContext } from '@graphql-eslint/eslint-plugin';
import getDocUrl from '../../util/getDocUrl';
import { getClosestAncestorByType } from '../../util/graphqlAstUtils';
import { GraphQLESTreeNode } from './types';
import { getDocUrl } from '../../util/rule-helpers';
import { getClosestAncestorByType } from '../../util/graphql-ast-utils';
import { GraphQLESTreeNode } from '../../util/types';
export const NO_FISCAL_DATE_FILTER_SUPPORTED_RULE_ID =
'offline-graphql-no-fiscal-date-filter-supported';

export const rule: GraphQLESLintRule = {
meta: {
type: 'problem',
docs: {
description: 'fiscal date literals/ranges are not supported offline',
description: 'Fiscal date literals and ranges are not supported in Offline GraphQL',
category: 'Operations',
url: getDocUrl(NO_FISCAL_DATE_FILTER_SUPPORTED_RULE_ID),
recommended: true,
Expand Down Expand Up @@ -40,7 +40,7 @@ export const rule: GraphQLESLintRule = {
`
},
{
title: 'InCorrect',
title: 'Incorrect',
code: /* GraphQL */ `
{
uiapi {
Expand All @@ -62,7 +62,7 @@ export const rule: GraphQLESLintRule = {
`
},
{
title: 'InCorrect',
title: 'Incorrect',
code: /* GraphQL */ `
{
uiapi {
Expand Down
8 changes: 4 additions & 4 deletions src/rules/graphql/no-more-than-1-parent-record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
*/

import { GraphQLESLintRule, GraphQLESLintRuleContext } from '@graphql-eslint/eslint-plugin';
import getDocUrl from '../../util/getDocUrl';
import { DocumentStat, ViolationType } from './EntityStats';
import { getDocUrl } from '../../util/rule-helpers';
import { DocumentStat, ViolationType } from '../../util/entity-stats';

export const NO_MORE_THAN_1_PARENT_RECORD_RULE_ID = 'offline-graphql-no-more-than-1-parent-record';

Expand All @@ -17,7 +17,7 @@ export const rule: GraphQLESLintRule = {
hasSuggestions: false,
docs: {
category: 'Operations',
description: `When query fetching children entity, suggest to set query 'first' argument value to 1.`,
description: `Offline GraphQL: You should only query one parent entity, for queries fetching child entities. Set the parent's 'first' argument value to 1.`,
url: getDocUrl(NO_MORE_THAN_1_PARENT_RECORD_RULE_ID),
examples: [
{
Expand Down Expand Up @@ -92,7 +92,7 @@ export const rule: GraphQLESLintRule = {
]
},
messages: {
[NO_MORE_THAN_1_PARENT_RECORD_RULE_ID]: `Offline GraphQL: Query fetching children relation is suggested to only fetch 1 parent record. Currently it's "{{pageSize}}".`
[NO_MORE_THAN_1_PARENT_RECORD_RULE_ID]: `Offline GraphQL: Queries fetching child entities should only fetch 1 parent record. Currently it's "{{pageSize}}".`
},
schema: []
},
Expand Down
6 changes: 3 additions & 3 deletions src/rules/graphql/no-more-than-3-child-entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
*/

import { GraphQLESLintRule, GraphQLESLintRuleContext } from '@graphql-eslint/eslint-plugin';
import getDocUrl from '../../util/getDocUrl';
import { DocumentStat, ViolationType } from './EntityStats';
import { getDocUrl } from '../../util/rule-helpers';
import { DocumentStat, ViolationType } from '../../util/entity-stats';

export const NO_MORE_THAN_3_CHILD_ENTITIES_RULE_ID = 'offline-graphql-no-more-3-child-entities';

Expand All @@ -17,7 +17,7 @@ export const rule: GraphQLESLintRule = {
hasSuggestions: false,
docs: {
category: 'Operations',
description: `Do not fetch more than 3 child entities.`,
description: `Offline GraphQL: Do not fetch more than 3 child entities.`,
url: getDocUrl(NO_MORE_THAN_3_CHILD_ENTITIES_RULE_ID),
examples: [
{
Expand Down
4 changes: 2 additions & 2 deletions src/rules/graphql/no-more-than-3-root-entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
*/

import { GraphQLESLintRule, GraphQLESLintRuleContext } from '@graphql-eslint/eslint-plugin';
import getDocUrl from '../../util/getDocUrl';
import { DocumentStat, ViolationType } from './EntityStats';
import { getDocUrl } from '../../util/rule-helpers';
import { DocumentStat, ViolationType } from '../../util/entity-stats';

export const NO_MORE_THAN_3_ROOT_ENTITIES_RULE_ID = 'offline-graphql-no-more-3-root-entities';

Expand Down
6 changes: 3 additions & 3 deletions src/rules/graphql/no-mutation-supported.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

import { GraphQLESLintRule, GraphQLESLintRuleContext } from '@graphql-eslint/eslint-plugin';

import { getLocation } from '../../util/graphqlAstUtils';
import getDocUrl from '../../util/getDocUrl';
import { getLocation } from '../../util/graphql-ast-utils';
import { getDocUrl } from '../../util/rule-helpers';

export const NO_MUTATION_SUPPORTED_RULE_ID = 'offline-graphql-no-mutation-supported';

Expand All @@ -18,7 +18,7 @@ export const rule: GraphQLESLintRule = {
hasSuggestions: false,
docs: {
category: 'Operations',
description: 'Mutation is not supported for mobile offline',
description: 'Mutation (data modification) is not supported for mobile offline',
url: getDocUrl(NO_MUTATION_SUPPORTED_RULE_ID),
recommended: true,
examples: [
Expand Down
6 changes: 3 additions & 3 deletions src/rules/graphql/no-semi-anti-join-supported.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { GraphQLESLintRule, GraphQLESLintRuleContext } from '@graphql-eslint/eslint-plugin';
import getDocUrl from '../../util/getDocUrl';
import { getDocUrl } from '../../util/rule-helpers';

export const NO_SEMI_ANTI_JOIN_SUPPORTED_RULE_ID = 'offline-graphql-no-semi-anti-join-supported';

Expand All @@ -15,7 +15,7 @@ export const rule: GraphQLESLintRule = {
type: 'problem',
hasSuggestions: false,
docs: {
description: 'Semi and anti join are not supported for mobile offline',
description: 'Semi-join and anti-join filters are not supported for mobile offline',
category: 'Operations',
recommended: true,
url: getDocUrl(NO_SEMI_ANTI_JOIN_SUPPORTED_RULE_ID),
Expand Down Expand Up @@ -99,7 +99,7 @@ export const rule: GraphQLESLintRule = {
},
messages: {
[NO_SEMI_ANTI_JOIN_SUPPORTED_RULE_ID]:
'Offline GraphQL: "{{joinType}}" join is not supported for mobile offline.'
'Offline GraphQL: {{joinType}}-join filters are not supported for mobile offline.'
},
schema: []
},
Expand Down
10 changes: 6 additions & 4 deletions src/rules/graphql/unsupported-scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ export const UNSUPPORTED_SCOPE_RULE_ID = 'offline-graphql-unsupported-scope';
export const SCOPE_SUPPORTED_FOR_CERTAIN_ENTITIES_ONLY = 'ASSIGNED_TO_ME__SERVICEAPPOINTMENT_ONLY';
export const OTHER_UNSUPPORTED_SCOPE = 'OTHER_UNSUPPORTED_SCOPE';

import getDocUrl from '../../util/getDocUrl';
import { getDocUrl } from '../../util/rule-helpers';

import { GraphQLESTreeNode } from './types';
// key is scope name, value is the array of supported entities. Empty array means that all entities are supported.
import { GraphQLESTreeNode } from '../../util/types';

// Record key is scope name, value is the array of supported entities. Empty array
// means that all entities are supported.
const supportedScopes: Record<string, string[]> = {
MINE: [],
ASSIGNEDTOME: ['ServiceAppointment']
Expand All @@ -25,7 +27,7 @@ export const rule: GraphQLESLintRule = {
type: 'problem',
docs: {
category: 'Operations',
description: `For mobile offline use cases, scope "MINE" is supported and scope "ASSIGNEDTOME" is only supported for ServiceAppointment . All other scopes like TEAM, QUEUE_OWNED and USER_OWNED are not supported `,
description: `Offline GraphQL supports the scope "MINE" for all entities, and "ASSIGNEDTOME" for ServiceAppointment. All other scopes (for example TEAM, QUEUE_OWNED and USER_OWNED) are not supported.`,
url: getDocUrl(UNSUPPORTED_SCOPE_RULE_ID),
recommended: true,
examples: [
Expand Down
11 changes: 0 additions & 11 deletions src/util/createRule.ts

This file was deleted.

10 changes: 0 additions & 10 deletions src/util/createScopedModuleRuleName.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
getPageSizeFromEntityNode,
getParentEntityNode,
GraphQLESFieldNode
} from '../../util/graphqlAstUtils';
} from './graphql-ast-utils';

export const DEFAULT_PAGE_SIZE = 10;
const MAX_PARENT_RECORD_COUNT_WITH_PREDICATED_CHILD = 1;
Expand Down
4 changes: 2 additions & 2 deletions src/util/graphqlAstUtils.ts → src/util/graphql-ast-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

import { Position } from 'estree';
import { AST } from 'eslint';
import { GraphQLESTreeNode, ParentNode } from '../rules/graphql/types';
import { GraphQLESTreeNode, ParentNode } from './types';
import { ASTNode, FieldNode, Kind, DocumentNode, OperationDefinitionNode } from 'graphql';
import { DEFAULT_PAGE_SIZE } from '../rules/graphql/EntityStats';
import { DEFAULT_PAGE_SIZE } from './entity-stats';

export type GraphQLESFieldNode = GraphQLESTreeNode<FieldNode>;

Expand Down
9 changes: 8 additions & 1 deletion src/util/getDocUrl.ts → src/util/rule-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/

import { ESLintUtils } from '@typescript-eslint/utils';
import { version, homepage } from '../../package.json';

export default function getDocUrl(ruleName: string): string {
export function getDocUrl(ruleName: string): string {
return `${homepage}/blob/v${version}/lib/docs/${ruleName}.md`;
}

export const createRule = ESLintUtils.RuleCreator((name) => getDocUrl(name));

export function createScopedModuleRuleName(ruleName: string): string {
return `@salesforce/lwc-mobile/${ruleName}`;
}
24 changes: 24 additions & 0 deletions src/rules/graphql/types.ts → src/util/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
/*
* MIT License
*
* Copyright (c) 2022 Dimitri POSTOLOV
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

/*
* File: types.ts
* Author: Dimitri POSTOLOV <[email protected]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { RuleTester } from '@typescript-eslint/rule-tester';

import { rule, APEX_IMPORT_RULE_ID } from '../../../src/rules/apex/apex-import';
import { createScopedModuleRuleName } from '../../../src/util/createScopedModuleRuleName';
import { createScopedModuleRuleName } from '../../../src/util/rule-helpers';

const ruleTester = new RuleTester({
parser: '@typescript-eslint/parser'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { describe } from 'node:test';

import { expect } from '@jest/globals';
import { FieldNode } from 'graphql';
import { GraphQLESTreeNode } from '../../../src/rules/graphql/types';
import { GraphQLESTreeNode } from '../../../src/util/types';
import { mock } from 'jest-mock-extended';

import {
DocumentStat,
EntityStat,
ViolationType,
DEFAULT_PAGE_SIZE
} from '../../../src/rules/graphql/EntityStats';
} from '../../../src/util/entity-stats';

describe('DocumentStat', () => {
it('raise root entity count violation', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/rules/graphql/no-aggregate-query-supported.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
rule,
NO_AGGREGATE_QUERY_SUPPORTED_RULE_ID
} from '../../../src/rules/graphql/no-aggregate-query-supported';
import { createScopedModuleRuleName } from '../../../src/util/createScopedModuleRuleName';
import { createScopedModuleRuleName } from '../../../src/util/rule-helpers';

import { ruleTester } from '../../shared';

Expand Down
2 changes: 1 addition & 1 deletion test/rules/graphql/no-more-than-1-parent-record.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
rule,
NO_MORE_THAN_1_PARENT_RECORD_RULE_ID
} from '../../../src/rules/graphql/no-more-than-1-parent-record';
import { createScopedModuleRuleName } from '../../../src/util/createScopedModuleRuleName';
import { createScopedModuleRuleName } from '../../../src/util/rule-helpers';

import { ruleTester } from '../../shared';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
rule,
NO_MORE_THAN_3_CHILD_ENTITIES_RULE_ID
} from '../../../src/rules/graphql/no-more-than-3-child-entities';
import { createScopedModuleRuleName } from '../../../src/util/createScopedModuleRuleName';
import { createScopedModuleRuleName } from '../../../src/util/rule-helpers';

import { ruleTester } from '../../shared';

Expand Down
2 changes: 1 addition & 1 deletion test/rules/graphql/no-more-than-3-root-entities.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
rule,
NO_MORE_THAN_3_ROOT_ENTITIES_RULE_ID
} from '../../../src/rules/graphql/no-more-than-3-root-entities';
import { createScopedModuleRuleName } from '../../../src/util/createScopedModuleRuleName';
import { createScopedModuleRuleName } from '../../../src/util/rule-helpers';

import { ruleTester } from '../../shared';

Expand Down
Loading

0 comments on commit 239a641

Please sign in to comment.