Skip to content

fix: deprecate svelte/@typescript-eslint/no-unnecessary-condition rule #276

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

Merged
merged 2 commits into from
Oct 25, 2022
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
5 changes: 5 additions & 0 deletions .changeset/witty-pumas-greet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eslint-plugin-svelte": minor
---

fix: deprecate `svelte/@typescript-eslint/no-unnecessary-condition` rule
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,6 @@ These rules extend the rules provided by ESLint itself, or other plugins to work

| Rule ID | Description | |
|:--------|:------------|:---|
| [svelte/@typescript-eslint/no-unnecessary-condition](https://ota-meshi.github.io/eslint-plugin-svelte/rules/@typescript-eslint/no-unnecessary-condition/) | disallow conditionals where the type is always truthy or always falsy | :wrench: |
| [svelte/no-inner-declarations](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-inner-declarations/) | disallow variable or `function` declarations in nested blocks | :star: |
| [svelte/no-trailing-spaces](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-trailing-spaces/) | disallow trailing whitespace at the end of lines | :wrench: |

Expand All @@ -340,6 +339,15 @@ These rules relate to this plugin works:
| [svelte/comment-directive](https://ota-meshi.github.io/eslint-plugin-svelte/rules/comment-directive/) | support comment-directives in HTML template | :star: |
| [svelte/system](https://ota-meshi.github.io/eslint-plugin-svelte/rules/system/) | system rule for working this plugin | :star: |

## Deprecated

- :warning: We're going to remove deprecated rules in the next major release. Please migrate to successor/new rules.
- :innocent: We don't fix bugs which are in deprecated rules since we don't have enough resources.

| Rule ID | Replaced by |
|:--------|:------------|
| [svelte/@typescript-eslint/no-unnecessary-condition](https://ota-meshi.github.io/eslint-plugin-svelte/rules/@typescript-eslint/no-unnecessary-condition/) | This rule is no longer needed when using svelte-eslint-parser>=v0.19.0. |

<!--RULES_TABLE_END-->
<!--RULES_SECTION_END-->
<!-- prettier-ignore-end -->
Expand Down
10 changes: 9 additions & 1 deletion docs/rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ These rules extend the rules provided by ESLint itself, or other plugins to work

| Rule ID | Description | |
|:--------|:------------|:---|
| [svelte/@typescript-eslint/no-unnecessary-condition](./rules/@typescript-eslint/no-unnecessary-condition.md) | disallow conditionals where the type is always truthy or always falsy | :wrench: |
| [svelte/no-inner-declarations](./rules/no-inner-declarations.md) | disallow variable or `function` declarations in nested blocks | :star: |
| [svelte/no-trailing-spaces](./rules/no-trailing-spaces.md) | disallow trailing whitespace at the end of lines | :wrench: |

Expand All @@ -92,3 +91,12 @@ These rules relate to this plugin works:
|:--------|:------------|:---|
| [svelte/comment-directive](./rules/comment-directive.md) | support comment-directives in HTML template | :star: |
| [svelte/system](./rules/system.md) | system rule for working this plugin | :star: |

## Deprecated

- :warning: We're going to remove deprecated rules in the next major release. Please migrate to successor/new rules.
- :innocent: We don't fix bugs which are in deprecated rules since we don't have enough resources.

| Rule ID | Replaced by |
|:--------|:------------|
| [svelte/@typescript-eslint/no-unnecessary-condition](./rules/@typescript-eslint/no-unnecessary-condition.md) | This rule is no longer needed when using svelte-eslint-parser>=v0.19.0. |
3 changes: 3 additions & 0 deletions docs/rules/@typescript-eslint/no-unnecessary-condition.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ since: "v2.9.0"

> disallow conditionals where the type is always truthy or always falsy

- :warning: This rule was **deprecated**. This rule is no longer needed when using svelte-eslint-parser>=v0.19.0.
- :wrench: The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the problems reported by this rule.

## :book: Rule Details

**This rule is no longer needed when using svelte-eslint-parser>=v0.19.0.**

This rule extends the base `@typescript-eslint`'s [@typescript-eslint/no-unnecessary-condition] rule.
The [@typescript-eslint/no-unnecessary-condition] rule does not understand reactive or rerendering of Svelte components and has false positives when used with Svelte components. This rule understands reactive and rerendering of Svelte components.

Expand Down
4 changes: 4 additions & 0 deletions src/rules/@typescript-eslint/no-unnecessary-condition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ export default createRule("@typescript-eslint/no-unnecessary-condition", {
"This rule requires the `strictNullChecks` compiler option to be turned on to function correctly.",
},
type: "suggestion", // "problem", or "layout",
deprecated: true,
replacedBy: {
note: "This rule is no longer needed when using svelte-eslint-parser>=v0.19.0.",
},
},
create(context) {
const {
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export interface RuleMetaData {
hasSuggestions?: boolean
schema: JSONSchema4 | JSONSchema4[]
deprecated?: boolean
replacedBy?: string[]
replacedBy?: string[] | { note: string }
type: "problem" | "suggestion" | "layout"
}

Expand Down Expand Up @@ -112,7 +112,7 @@ export interface PartialRuleMetaData {
hasSuggestions?: boolean
schema: JSONSchema4 | JSONSchema4[]
deprecated?: boolean
replacedBy?: string[]
replacedBy?: string[] | { note: string }
type: "problem" | "suggestion" | "layout"
}

Expand Down
8 changes: 5 additions & 3 deletions tools/render-rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,11 @@ export default function renderRulesTableContent(
rule.meta.docs.ruleName || "",
)})`
const replacedRules = rule.meta.replacedBy || []
const replacedBy = replacedRules
.map((name) => `[svelte/${name}](${buildRulePath(name)})`)
.join(", ")
const replacedBy = Array.isArray(replacedRules)
? replacedRules
.map((name) => `[svelte/${name}](${buildRulePath(name)})`)
.join(", ")
: replacedRules.note

return `| ${link} | ${replacedBy || "(no replacement)"} |`
}
Expand Down
22 changes: 14 additions & 8 deletions tools/update-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,20 @@ class DocFile {

if (deprecated) {
if (replacedBy) {
const replacedRules = replacedBy.map(
(name) => `[svelte/${name}](${name}.md) rule`,
)
notes.push(
`- :warning: This rule was **deprecated** and replaced by ${formatItems(
replacedRules,
)}.`,
)
if (Array.isArray(replacedBy)) {
const replacedRules = replacedBy.map(
(name) => `[svelte/${name}](${name}.md) rule`,
)
notes.push(
`- :warning: This rule was **deprecated** and replaced by ${formatItems(
replacedRules,
)}.`,
)
} else {
notes.push(
`- :warning: This rule was **deprecated**. ${replacedBy.note}`,
)
}
} else {
notes.push("- :warning: This rule was **deprecated**.")
}
Expand Down