-
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.
Merge pull request #3 from salesforce/apex
A new rule to warn that importing and using Apex module may not work properly on mobile when offline.
- Loading branch information
Showing
5 changed files
with
121 additions
and
2 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,37 @@ | ||
/* | ||
* 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 createRule from '../../util/createRule'; | ||
export const APEX_IMPORT_RULE_ID = 'apex-import'; | ||
|
||
export const rule = createRule({ | ||
create(context) { | ||
return { | ||
ImportDeclaration(node) { | ||
if (node.source.value.startsWith('@salesforce/apex')) { | ||
context.report({ | ||
node, | ||
messageId: APEX_IMPORT_RULE_ID | ||
}); | ||
} | ||
} | ||
}; | ||
}, | ||
name: 'apex-import', | ||
meta: { | ||
docs: { | ||
description: 'Importing apex modules can have issues on mobile for offline usage.' | ||
}, | ||
messages: { | ||
[APEX_IMPORT_RULE_ID]: | ||
'Importing apex modules can have issues on mobile for offline usage.' | ||
}, | ||
type: 'suggestion', | ||
schema: [] | ||
}, | ||
defaultOptions: [] | ||
}); |
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,13 @@ | ||
/* | ||
* 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 { ESLintUtils } from '@typescript-eslint/utils'; | ||
import { version, homepage } from '../../package.json'; | ||
|
||
export default ESLintUtils.RuleCreator( | ||
(name) => `${homepage}/blob/v${version}/lib/docs/${name}.md` | ||
); |
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,66 @@ | ||
/* | ||
* 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 { RuleTester } from '@typescript-eslint/rule-tester'; | ||
|
||
import { rule, APEX_IMPORT_RULE_ID } from '../../../src/rules/apex/apex-import'; | ||
|
||
const ruleTester = new RuleTester({ | ||
parser: '@typescript-eslint/parser' | ||
}); | ||
|
||
ruleTester.run('@salesforce/lwc-mobile/apex/apex-import', rule, { | ||
valid: [ | ||
{ | ||
code: ` | ||
import { LightningElement, wire } from 'lwc'; | ||
import getContactList from 'ContactController.getContactList'; | ||
export default class ApexWireMethodToFunction extends LightningElement { | ||
contacts; | ||
error; | ||
@wire(getContactList) | ||
wiredContacts({ error, data }) { | ||
if (data) { | ||
this.contacts = data; | ||
this.error = undefined; | ||
} else if (error) { | ||
this.error = error; | ||
this.contacts = undefined; | ||
} | ||
} | ||
} | ||
` | ||
} | ||
], | ||
invalid: [ | ||
{ | ||
code: ` | ||
import { LightningElement, wire } from 'lwc'; | ||
import getContactList from '@salesforce/apex/ContactController.getContactList'; | ||
export default class ApexWireMethodToFunction extends LightningElement { | ||
contacts; | ||
error; | ||
@wire(getContactList) | ||
wiredContacts({ error, data }) { | ||
if (data) { | ||
this.contacts = data; | ||
this.error = undefined; | ||
} else if (error) { | ||
this.error = error; | ||
this.contacts = undefined; | ||
} | ||
} | ||
} | ||
`, | ||
errors: [{ messageId: APEX_IMPORT_RULE_ID }] | ||
} | ||
] | ||
}); |