Skip to content

Commit

Permalink
@W-17374681 include new ssr rules in ssr config (#140)
Browse files Browse the repository at this point in the history
* fix: included new ssr rules in ssr config

* minor change
  • Loading branch information
abhagta-sfdc authored Dec 9, 2024
1 parent df87119 commit 746edde
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"semver": "^7.6.2"
},
"devDependencies": {
"@lwc/eslint-plugin-lwc": "^1.8.1",
"@lwc/eslint-plugin-lwc": "^1.9.0",
"@salesforce/eslint-plugin-lightning": "^1.0.0",
"eslint": "^8.57.0",
"eslint-plugin-import": "^2.29.1",
Expand Down
9 changes: 7 additions & 2 deletions ssr.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ module.exports = {
'@lwc/eslint-plugin-lwc', // https://github.com/salesforce/eslint-plugin-lwc
],
rules: {
'@lwc/lwc/no-unsupported-ssr-properties': 'error',
'@lwc/lwc/no-restricted-browser-globals-during-ssr': 'error',
'@lwc/lwc/ssr/no-unsupported-properties': 'error',
'@lwc/lwc/ssr/no-restricted-browser-globals': 'error',
'@lwc/lwc/ssr/no-form-factor': 'error',
'@lwc/lwc/ssr/no-host-mutation-in-connected-callback': 'error',
'@lwc/lwc/ssr/no-node-env': 'error',
'@lwc/lwc/ssr/no-unsupported-node-api': 'error',
'@lwc/lwc/ssr/no-static-imports-of-user-specific-scoped-modules': 'error',
},
};
53 changes: 44 additions & 9 deletions test/ssr.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,36 @@ describe('ssr configs', () => {

const results = await cli.lintText(`
import { LightningElement } from 'lwc';
import fs from 'node:fs';
import { formFactor } from '@salesforce/client/formFactor';
import userId from '@salesforce/user/Id';
export default class Foo extends LightningElement {
connectedCallback() {
document.write("Hello world")
this.dispatchEvent("Hello world")
document.write("Hello world");
this.dispatchEvent("Hello world");
console.log(formFactor);
this.setAttribute('class', \`my-child-\${this.fromOutside}\`);
if (process.env.NODE_ENV === 'development') {
console.log('test');
}
fs.writeFileSync('file.txt', 'data');
console.log(userId);
}
}
`);

const { messages } = results[0];
assert.equal(messages.length, 2);
assert.equal(messages[0].ruleId, '@lwc/lwc/no-restricted-browser-globals-during-ssr');
assert.equal(messages[1].ruleId, '@lwc/lwc/no-unsupported-ssr-properties');
assert.equal(messages.length, 7);
assert.equal(messages[0].ruleId, '@lwc/lwc/ssr/no-form-factor');
assert.equal(
messages[1].ruleId,
'@lwc/lwc/ssr/no-static-imports-of-user-specific-scoped-modules',
);
assert.equal(messages[2].ruleId, '@lwc/lwc/ssr/no-restricted-browser-globals');
assert.equal(messages[3].ruleId, '@lwc/lwc/ssr/no-unsupported-properties');
assert.equal(messages[4].ruleId, '@lwc/lwc/ssr/no-host-mutation-in-connected-callback');
assert.equal(messages[5].ruleId, '@lwc/lwc/ssr/no-node-env');
assert.equal(messages[6].ruleId, '@lwc/lwc/ssr/no-unsupported-node-api');
});
});

Expand All @@ -65,18 +82,36 @@ describe('typescript ssr configs', () => {

const results = await cli.lintText(`
import { LightningElement } from 'lwc';
import fs from 'node:fs';
import { formFactor } from '@salesforce/client/formFactor';
import userId from '@salesforce/user/Id';
export default class Foo extends LightningElement {
connectedCallback(): void {
document.write("Hello world")
this.dispatchEvent("Hello world")
console.log(formFactor);
this.setAttribute('class', \`my-child-\${this.fromOutside}\`);
if (process.env.NODE_ENV === 'development') {
console.log('test');
}
fs.writeFileSync('file.txt', 'data');
console.log(userId);
}
}
`);

const { messages } = results[0];
assert.equal(messages.length, 2);
assert.equal(messages[0].ruleId, '@lwc/lwc/no-restricted-browser-globals-during-ssr');
assert.equal(messages[1].ruleId, '@lwc/lwc/no-unsupported-ssr-properties');
assert.equal(messages.length, 7);
assert.equal(messages[0].ruleId, '@lwc/lwc/ssr/no-form-factor');
assert.equal(
messages[1].ruleId,
'@lwc/lwc/ssr/no-static-imports-of-user-specific-scoped-modules',
);
assert.equal(messages[2].ruleId, '@lwc/lwc/ssr/no-restricted-browser-globals');
assert.equal(messages[3].ruleId, '@lwc/lwc/ssr/no-unsupported-properties');
assert.equal(messages[4].ruleId, '@lwc/lwc/ssr/no-host-mutation-in-connected-callback');
assert.equal(messages[5].ruleId, '@lwc/lwc/ssr/no-node-env');
assert.equal(messages[6].ruleId, '@lwc/lwc/ssr/no-unsupported-node-api');
});
});
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,10 @@
"@jridgewell/resolve-uri" "^3.1.0"
"@jridgewell/sourcemap-codec" "^1.4.14"

"@lwc/eslint-plugin-lwc@^1.8.1":
version "1.8.1"
resolved "https://registry.yarnpkg.com/@lwc/eslint-plugin-lwc/-/eslint-plugin-lwc-1.8.1.tgz#aa93a7115ae913fb8a4c1ca0667f10043dba06dc"
integrity sha512-xtBvjT2Cxp20Vj/o+b7YeIJkAFXlZow90DoJGjqEyRxPb6pmWSZ3FzcrffSUOacETJey01UiA29rquRftJiH8A==
"@lwc/eslint-plugin-lwc@^1.9.0":
version "1.9.0"
resolved "https://registry.yarnpkg.com/@lwc/eslint-plugin-lwc/-/eslint-plugin-lwc-1.9.0.tgz#09ddc05e05c0d827cb40c27021c9c3868e519e33"
integrity sha512-z2wEUvLanstSl9o7VT/HAI7uFWHkTApz8N1ZpRQtyh8Hg6UbBZKLrg+vMxDED1vZVLu256i2KgYUWysVQyO4tg==
dependencies:
globals "^13.24.0"
minimatch "^9.0.4"
Expand Down

0 comments on commit 746edde

Please sign in to comment.