Skip to content

Commit

Permalink
Update for demo.
Browse files Browse the repository at this point in the history
  • Loading branch information
sfdctaka committed May 15, 2024
1 parent 3776d1b commit 0285239
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 35 deletions.
25 changes: 25 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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
*/

'use strict';

const base = require('./configs/base');
const recommended = require('./configs/recommended');

const enforceFooBar = require('./rules/enforce-foo-bar');
const apexImport = require('./rules/apex/apex-import');

module.exports = {
rules: {
'enforce-foo-bar': enforceFooBar,
'apex-import': apexImport
},
configs: {
base,
recommended
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ module.exports = {
type: 'problem',
docs: {
description:
"Importing apex modules can have issue for offline."
`When a client device is offline, Apex-based features can read data that was cached while online, but changes (writing data) can’t be saved back to the server.`
},
fixable: 'code',
schema: []
},
create(context) {
return {
ImportDeclaration(node) {
if (node.source.includes('apex')) {
ImportDeclaration: (node) => {
if (node.source.value.startsWith('@salesforce/apex/')) {
context.report({
node,
message:
'Watch out for importing apex!'
`Importing apex modules can have issue for offline.`
});
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/configs/recommended.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type { ClassicConfig } from '@typescript-eslint/utils/ts-eslint';
export = {
extends: ['./configs/base'],
rules: {
'@salesforce/lwc-mobile/enforce-foo-bar': 'warn'
'@salesforce/lwc-mobile/enforce-foo-bar': 'warn',
'@salesforce/lwc-mobile/apex-import': 'warn'
}
} satisfies ClassicConfig.Config;
47 changes: 47 additions & 0 deletions test/lib/rules/apex/apex-import.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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
*/

'use strict';

const { RuleTester } = require('eslint');
const { RULE_TESTER_CONFIG } = require('../shared');

const allRules = require('../../../../lib/index');
const runtTester = new RuleTester(RULE_TESTER_CONFIG);

runtTester.run('@salesforce/lwc-mobile/apex-import', allRules.rules['apex-import'], {
valid: [],
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: [
{
message: `Importing apex modules can have issue for offline.`
}
]
},
],
});
30 changes: 0 additions & 30 deletions test/lib/rules/apex/import-apex.js

This file was deleted.

0 comments on commit 0285239

Please sign in to comment.