Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ssr config #113

Merged
merged 5 commits into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"]
}
```

pmdartus marked this conversation as resolved.
Show resolved Hide resolved
### `@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');
});
});