Skip to content

Commit

Permalink
feat: add ssr config (#113)
Browse files Browse the repository at this point in the history
* feat: add `ssr` config

* doc: add to README

* Update README.md

Co-authored-by: Pierre-Marie Dartus <p.dartus@salesforce.com>

* doc: add missing title

---------

Co-authored-by: Pierre-Marie Dartus <p.dartus@salesforce.com>
  • Loading branch information
abdulsattar and pmdartus committed Feb 21, 2023
1 parent bfe9fba commit 46372df
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,21 @@ Add the `i18n` configuration to the `extends` field in your `.eslintrc` configur
"extends": ["@salesforce/eslint-config-lwc/recommended", "@salesforce/eslint-config-lwc/i18n"]
}
```

### `@salesforce/eslint-config-lwc/ssr` configuration

**Goal:**
Promote writing server-side-rendering friendly components. We only recommend using this configuration if your components are running in experiences supporting LWC server-side-rendering.

**Rules:**
[ SSR specific rules ](https://github.com/salesforce/eslint-plugin-lwc/blob/master/README.md#lwc) only.

**Usage:**

Add the `ssr` configuration to the `extends` field in your `.eslintrc` configuration file, for example:

```json
{
"extends": ["@salesforce/eslint-config-lwc/recommended", "@salesforce/eslint-config-lwc/ssr"]
}
```
18 changes: 18 additions & 0 deletions ssr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright (c) 2018, 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';

module.exports = {
extends: [require.resolve('./lib/defaults')],
plugins: [
'@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',
},
};
47 changes: 47 additions & 0 deletions test/ssr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (c) 2021, 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 assert = require('assert');
const eslint = require('eslint');

const { linkConfig, unlinkConfig } = require('./utils');

describe('ssr configs', () => {
before(() => {
linkConfig();
});

after(() => {
unlinkConfig();
});

it('should load properly', async () => {
const cli = new eslint.ESLint({
useEslintrc: false,
baseConfig: {
extends: ['@salesforce/eslint-config-lwc/ssr'],
},
});

const results = await cli.lintText(`
import { LightningElement } from 'lwc';
export default class Foo extends LightningElement {
connectedCallback() {
document.write("Hello world")
this.dispatchEvent("Hello world")
}
}
`);

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');
});
});

0 comments on commit 46372df

Please sign in to comment.