Skip to content

Commit

Permalink
reuse docUrl for all rules
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-zhang-at-salesforce committed May 22, 2024
1 parent b0710cf commit c8290d9
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 9 deletions.
2 changes: 1 addition & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const config: Config = {
displayName: 'Unit Tests',
setupFilesAfterEnv: ['jest-extended', 'jest-chain'],
preset: 'ts-jest',
testMatch: ['<rootDir>/test/rules/**/*.ts'],
testMatch: ['<rootDir>/test/**/*.ts'],
moduleFileExtensions: ['ts', 'js', 'json'],
testResultsProcessor: 'jest-sonar-reporter',
testPathIgnorePatterns: ['/node_modules/', '<rootDir>/lib/'],
Expand Down
3 changes: 2 additions & 1 deletion src/rules/graphql/no-aggregate-query-supported.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { FieldNode } from 'graphql';
import { GraphQLESLintRule, GraphQLESLintRuleContext } from '@graphql-eslint/eslint-plugin';
import getDocUrl from '../../util/getDocUrl';

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

Expand All @@ -11,7 +12,7 @@ export const rule: GraphQLESLintRule = {
category: 'Operations',
description:
'aggregate operation in graphql query is not supported for mobile offline.',
// url:
url: getDocUrl(NO_AGGREGATE_QUERY_SUPPORTED_RULE_ID),
examples: [
{
title: 'Incorrect',
Expand Down
7 changes: 5 additions & 2 deletions src/rules/graphql/no-mutation-supported.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@
*/
import { GraphQLESLintRule, GraphQLESLintRuleContext } from '@graphql-eslint/eslint-plugin';

import { getLocation } from '../../utils';
import { getLocation } from '../../util/graphqlAstUtils';
import getDocUrl from '../../util/getDocUrl';

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

export const rule: GraphQLESLintRule = {
meta: {
type: 'problem',
hasSuggestions: false,
docs: {
description: 'mutation is not supported offline',
category: 'Operations',
description: 'mutation is not supported offline',
url: getDocUrl(NO_MUTATION_SUPPORTED_RULE_ID),
recommended: true,
examples: [
{
Expand Down
6 changes: 2 additions & 4 deletions src/util/createRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
*/

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

export default ESLintUtils.RuleCreator(
(name) => `${homepage}/blob/v${version}/lib/docs/${name}.md`
);
export default ESLintUtils.RuleCreator((name) => getDocUrl(name));
12 changes: 12 additions & 0 deletions src/util/getDocUrl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* 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 { version, homepage } from '../../package.json';

export default function getDocUrl(ruleName: string): string {
return `${homepage}/blob/v${version}/lib/docs/${ruleName}.md`;
}
File renamed without changes.
14 changes: 14 additions & 0 deletions test/util/getDocUrl.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { describe } from 'node:test';

import { expect } from '@jest/globals';
import getDocUrl from '../../src/util/getDocUrl';

describe('getDocUrl', () => {
it('doc url returned should be right value', () => {
const docUrl = getDocUrl('ruleNameXYZ');
expect(
docUrl.startsWith('https://github.com/salesforce/eslint-plugin-lwc-mobile/blob/v')
).toBe(true);
expect(docUrl.endsWith('/lib/docs/ruleNameXYZ.md')).toBe(true);
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe } from 'node:test';
import { getLocation } from '../../src/utils';
import { getLocation } from '../../src/util/graphqlAstUtils';
import { Position } from 'estree';

import { expect } from '@jest/globals';
Expand Down

0 comments on commit c8290d9

Please sign in to comment.