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

docs (no-exports-with-element): add docs #106

Merged
merged 1 commit into from
Aug 2, 2023
Merged
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
58 changes: 58 additions & 0 deletions docs/rules/no-exports-with-element.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Disallows exports alongside custom element exports (no-exports-with-element)

It's possible to export multiple functions and classes in a JavaScript file.
In the case of Custom Elements, exporting more than the Custom Element itself
can cause confusion when importing code. It may also be a sign that there is
too much code in a single file. If you have utility functions that the Custom
Element depends on, it might be worth splitting this out into a separate file.

## Rule Details

This rule disallows exports (other than the element class and event subclasses)
in a file with a Custom Element.

👎 Examples of **incorrect** code for this rule:

```js
// foo-bar-element.js
export class FooBarElement extends HTMLElement {
// ...
}

export function myHelper() {
// ...
}
```

👍 Examples of **correct** code for this rule:

```js
// foo-bar-element.js
import {myHelper} from './helpers.js'
export class FooBarElement extends HTMLElement {
// ...
}
```

```js
// foo-bar-element.js
import {myHelper} from './helpers.js'
export class FooReadyEvent extends Event {
// ...
}

export class FooBarElement extends HTMLElement {
// ...
}
```

```js
// helpers.js
export function myHelper() {
// ...
}
```

## When Not To Use It

If you intentionally want multiple exports in a single file then you can disable this rule.
Loading