Skip to content

Commit

Permalink
Prep for release.
Browse files Browse the repository at this point in the history
  • Loading branch information
joshwilsonvu committed Jun 1, 2022
1 parent aa0e95c commit 1119f96
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ If you want to pin a minor version, use a tilde in your `package.json`.

<!-- AUTO-GENERATED-CONTENT:START (TILDE) -->
```diff
- "eslint-plugin-solid": "^0.5.0"
+ "eslint-plugin-solid": "~0.5.0"
- "eslint-plugin-solid": "^0.6.0"
+ "eslint-plugin-solid": "~0.6.0"
```
<!-- AUTO-GENERATED-CONTENT:END -->
125 changes: 125 additions & 0 deletions docs/components-return-once.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<!-- AUTO-GENERATED-CONTENT:START (HEADER) -->
# solid/components-return-once
Disallow early returns in components. Solid components only run once, and so conditionals should be inside JSX.
This rule is **a warning** by default.

[View source](../src/rules/components-return-once.ts) · [View tests](../test/rules/components-return-once.test.ts)

<!-- AUTO-GENERATED-CONTENT:END -->

See [this issue](https://github.com/joshwilsonvu/eslint-plugin-solid/issues/24) for rationale.

<!-- AUTO-GENERATED-CONTENT:START (OPTIONS) -->
## Rule Options

```
"event-handlers": ["error", { "<key>": "<value>" }]
```

Key | Type | Description
:--- | :---: | :---
ignoreCase | `boolean` | if true, don't warn on ambiguously named event handlers like `onclick` or `onchange`
<!-- AUTO-GENERATED-CONTENT:END -->

<!-- AUTO-GENERATED-CONTENT:START (CASES) -->
### Invalid Examples

These snippets cause lint errors, and some can be auto-fixed.

```js
function Component() {
if (condition) {
return <div />;
}
return <span />;
}

const Component = () => {
if (condition) {
return <div />;
}
return <span />;
};

function Component() {
return Math.random() > 0.5 ? <div>Big!</div> : <div>Small!</div>;
}
// after eslint --fix:
function Component() {
return <>{Math.random() > 0.5 ? <div>Big!</div> : <div>Small!</div>}</>;
}

function Component() {
return Math.random() > 0.5 ? <div>Big!</div> : "Small!";
}
// after eslint --fix:
function Component() {
return <>{Math.random() > 0.5 ? <div>Big!</div> : "Small!"}</>;
}

function Component() {
return Math.random() > 0.5 ? (
<div>Big! No, really big!</div>
) : (
<div>Small!</div>
);
}
// after eslint --fix:
function Component() {
return (
<Show when={Math.random() > 0.5} fallback={<div>Small!</div>}>
<div>Big! No, really big!</div>
</Show>
);
}

function Component(props) {
return props.cond1 ? (
<div>Condition 1</div>
) : Boolean(props.cond2) ? (
<div>Not condition 1, but condition 2</div>
) : (
<div>Neither condition 1 or 2</div>
);
}
// after eslint --fix:
function Component(props) {
return (
<Switch fallback={<div>Neither condition 1 or 2</div>}>
<Match when={props.cond1}>
<div>Condition 1</div>
</Match>
<Match when={Boolean(props.cond2)}>
<div>Not condition 1, but condition 2</div>
</Match>
</Switch>
);
}

```

### Valid Examples

These snippets don't cause lint errors.

```js
function Component() {
return <div />;
}

function someFunc() {
if (condition) {
return 5;
}
return 10;
}

function notAComponent() {
if (condition) {
return <div />;
}
return <div />;
}

```
<!-- AUTO-GENERATED-CONTENT:END -->
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-solid",
"version": "0.5.0",
"version": "0.6.0",
"description": "Solid-specific linting rules for ESLint.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion src/rules/components-return-once.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TSESTree as T, TSESLint, ASTUtils } from "@typescript-eslint/utils";
import { TSESTree as T, TSESLint } from "@typescript-eslint/utils";
import type { FunctionNode } from "../utils";

const isNothing = (node?: T.Node): boolean => {
Expand Down

0 comments on commit 1119f96

Please sign in to comment.