diff --git a/.changeset/witty-pumas-greet.md b/.changeset/witty-pumas-greet.md new file mode 100644 index 000000000..fb8b55fef --- /dev/null +++ b/.changeset/witty-pumas-greet.md @@ -0,0 +1,5 @@ +--- +"eslint-plugin-svelte": minor +--- + +fix: deprecate `svelte/@typescript-eslint/no-unnecessary-condition` rule diff --git a/README.md b/README.md index 8485e59f8..4f19f5e35 100644 --- a/README.md +++ b/README.md @@ -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: | @@ -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. | + diff --git a/docs/rules.md b/docs/rules.md index df88e4fb9..9601f4517 100644 --- a/docs/rules.md +++ b/docs/rules.md @@ -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: | @@ -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. | diff --git a/docs/rules/@typescript-eslint/no-unnecessary-condition.md b/docs/rules/@typescript-eslint/no-unnecessary-condition.md index 2857e52f0..5216ab11e 100644 --- a/docs/rules/@typescript-eslint/no-unnecessary-condition.md +++ b/docs/rules/@typescript-eslint/no-unnecessary-condition.md @@ -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. diff --git a/src/rules/@typescript-eslint/no-unnecessary-condition.ts b/src/rules/@typescript-eslint/no-unnecessary-condition.ts index 5090bf3a0..2b8278f1e 100644 --- a/src/rules/@typescript-eslint/no-unnecessary-condition.ts +++ b/src/rules/@typescript-eslint/no-unnecessary-condition.ts @@ -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 { diff --git a/src/types.ts b/src/types.ts index d6401e777..2b991c3c7 100644 --- a/src/types.ts +++ b/src/types.ts @@ -77,7 +77,7 @@ export interface RuleMetaData { hasSuggestions?: boolean schema: JSONSchema4 | JSONSchema4[] deprecated?: boolean - replacedBy?: string[] + replacedBy?: string[] | { note: string } type: "problem" | "suggestion" | "layout" } @@ -112,7 +112,7 @@ export interface PartialRuleMetaData { hasSuggestions?: boolean schema: JSONSchema4 | JSONSchema4[] deprecated?: boolean - replacedBy?: string[] + replacedBy?: string[] | { note: string } type: "problem" | "suggestion" | "layout" } diff --git a/tools/render-rules.ts b/tools/render-rules.ts index a2cc0e423..6ebcace43 100644 --- a/tools/render-rules.ts +++ b/tools/render-rules.ts @@ -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)"} |` } diff --git a/tools/update-docs.ts b/tools/update-docs.ts index 67ef962d7..fb110a2ff 100644 --- a/tools/update-docs.ts +++ b/tools/update-docs.ts @@ -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**.") }